Hey guys!
I was thinking of generating the normal map of the player and enemies of my game real-time.
Since I didn’t find much about it I was wondering if it’s an effective thing to do at all?
If so are there any techniques you could reccomend?
Hey guys!
I was thinking of generating the normal map of the player and enemies of my game real-time.
Since I didn’t find much about it I was wondering if it’s an effective thing to do at all?
If so are there any techniques you could reccomend?
what do you mean by “realtime-normal-map” ?
By real-time normalmap I mean that I don’t generate the normal map of the characters with a program and load the created texture and use that with the diffuse.
I’d like to take the diffuse texture make a normal map of it runtime and pass the “freshly” generated normal map to the shader and use that.
aah got it.
extracting the “bump” of a diffuse map is not possible to do exact.
one way of approximation is converting the diffusemap to grayscale and using it like any grayscale bump-map.
one way to get from a heightmap to a normal-map (http://en.wikipedia.org/wiki/Normal_mapping) is to use the central difference method (http://en.wikipedia.org/wiki/Finite_difference).
could look like (pseudocode ):
// for each texel in heightmap :
float sampleTexture( in vec2 atCoord )
{
return texture(grayscale_map, atCoord).x;
}
float eps = vec2(1.0) / textureSize(grascale_map, 1); // search radius. different numbers affects smoothness.
vec2 st; // texel coord.
vec3 normal = vec3( sampleTexture( vec2(st.x - eps.x, st.y) ) - sampleTexture( vec2(st.x + eps.x, st.y) ),
sampleTexture( vec2(st.x, st.y - eps.y) ) - sampleTexture( vec2(st.x, st.y + eps.y) ),
eps.x + eps.y );
normal = normalize(normal);
another way could be to use glsl [icode]fwidth()[/icode], [icode]dFdx()[/icode] and [icode]dFdy()[/icode].
o/