remi666 Posted December 18, 2011 Share Posted December 18, 2011 Hello Josh, hello everybody, I come back on a well-known topic: texture baking (or lightmap) Well, I posted one or two years ago on that topic, and someone (very kind) proposed me a shader, which multiplied the diffuse texture with the baked one. Here is an extract of the _mesh.frag related to this shader, inserted in the Bloom shader: //Bloom #ifdef LW_BLOOM vec4 bloomcolor = texture2D(LW_BLOOM,texcoord) * fragcolor; gl_FragData[3] = bloomcolor; gl_FragData[3].w = 0; #else #ifdef LW_GIMAP vec4 gicolor = texture2D(LW_GIMAP,vec2(texcoord1.x,texcoord1.y)); gicolor *= diffuse; gicolor.w = 1.0; gl_FragData[3] = gicolor; #else The issue with that algo, is that we do not have exactly the same result with the real-time engine as the “non-realtime”rendering engine (for example mental ray,…). I searched a lot by myself, and on the Internet. The fact is, when you combine linearly both maps, you will never get the exact result (Example: if you try diffuse*Baked or diffuse+baked, or diffuse*Baked+y*diffuse, etc…) Here is an example of this, with some pictures (based on a forum post on the game engine “Nova”): With the “classic algo” Diffuse Map*BakedMap (too dark result): cf doc file attached... With the algo Diffuse Map+BakedMap (too bright result): cf doc file attached... What we would like: cf doc file attached... The proposed algo, which is only an approximation of the wanted result, is the following: 1) For each pixel of Baked Map, convert the value RGB as HSL, and test the V value. 2) If V > 0,5 (in fact, this value can be modified…), perform DiffuseMap+BakedMap for that pixel 3) If V < 0,5 (in fact, this value can be modified…), perform DiffuseMap*BakedMap for that pixel Well, as I know nothing about shader coding, I hope that someone could help me to code this shader, which will be probably very useful for many people. Thanks in advance PS: And for those who will ask "why don't you use deferred rendering ?", I will say "try to dvelop a video game, with IA, Navmesh,...And you will know why ;-)..TO SAVE FRAMES PER SECONDS !!! Baking_00.doc Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.