Hello.
So I’ve got this big 2d image for map and to implement lighting I got the lightmap image for it and a shader. Lightmap image is a simple black-white image. I know how to use multitexturing in a “normal” way whay, when you bind the texture and set glMultiTexCoords() but what when you want to use that texture as lightmap for all your objects you are drawing? This lightmap must be used when drawing other objects over the map, for example when drawing a player over the map on (x,y) position, I must use lightmap (x,y) position. The problem is I have no idea how to resolve object coordinates to correct texture coordinates in shader.
For example: Both map image and lightmap image are 800x600. I draw the map and use lightmap normally with multiTexCoords(). Now I want to draw player that is located at (100,100), but this time I can’t set the lightmap texture with glMultiTexCoords(). How to calculate proper lightmap coords in shader?
this is my fragment shader now:
uniform sampler2D texture;
uniform sampler2D lightMap;
varying vec2 VaryingTexCoord0;
out vec4 fragColor;
void main (void)
{
// original texture
fragColor = texture2D(texture, VaryingTexCoord0.st);
// common lightmap affects lighting the pixel
fragColor *= texture2D(lightMap, NEED_THIS.st);
}
Any ideas on how to resolve texture coordinates I must use in second step?
Thank you all for your time.