Got a problem with trying to get a lightmap shader to work.
When I try different lightmap images the objects either are lit up or darkened, the whole thing. One really odd thing is when I switch texture image with a timer on one object where I tried the lightmap, the different texture images are shaded differently.
The shader:
Vertex:
attribute vec3 position;
attribute vec3 normal;
attribute vec2 uv;
attribute vec2 uv1;
varying vec2 uv0Varying;
varying vec2 uv1Varying;
uniform vec4 uvBounds0;
uniform mat4 agk_WorldViewProj;
void main()
{
gl_Position = agk_WorldViewProj * vec4(position,1);
uv0Varying = uv * uvBounds0.xy + uvBounds0.zw;
uv1Varying = uv1 * uvBounds0.xy + uvBounds0.zw;
}
Fragment:
uniform sampler2D texture0;
uniform sampler2D texture1;
varying vec2 uv0Varying;
varying vec2 uv1Varying;
void main()
{
gl_FragColor = (texture2D(texture1, uv1Varying)+vec4(0.5,0.5,0.5,1))*texture2D(texture0, uv0Varying);
}
I took it from the 3D example in AGK. But I can't see anything wrong with the actual shader.
Heeeelp
Edit: To clarify:
lightmap image, 64x64 png, one half white, one half black.
If I do this:
print(test)
if keyboard.spaceKey = 1 then inc test
if test > 1299 then test = 1291
setObjectImage(hlObj[0].ID, test, 0)
(1291-1299 are images in an animated texture on a plane, 64x64 each)
The difference in shade shows up at image 5. As if.. yeah
Edit 2:
Also tried the pixel shader like this:
uniform sampler2D texture0;
uniform sampler2D texture1;
varying vec2 uv0Varying;
varying vec2 uv1Varying;
void main()
{
vec4 color = texture2D(texture0, uv0Varying);
vec4 light = texture2D(texture1, uv1Varying);
vec4 finalcol = light*color;
gl_FragColor = finalcol;
}
It acts exactly as if texture1 is like 8 times larger than texture0
Edit 3:
Doesn't this just feel wrong? From the vertex shader:
uv0Varying = uv * uvBounds0.xy + uvBounds0.zw;
uv1Varying = uv1 * uvBounds0.xy + uvBounds0.zw;
I mean it should still work, but what's the point of calculating the same thing twice..
Edit 4:
Fixed it! Thanks everyone for being my therapist!
Edit 5:
Might as well share the lightmap shaders I'm using:
Vertex:
attribute vec3 position;
attribute vec3 normal;
attribute vec2 uv;
varying vec2 uv0Varying;
varying vec2 uv1Varying;
uniform vec4 uvBounds0;
uniform vec4 uvBounds1;
uniform mat4 agk_WorldViewProj;
void main()
{
gl_Position = agk_WorldViewProj * vec4(position,1);
uv0Varying = uv * uvBounds0.xy + uvBounds0.zw;
uv1Varying = uv * uvBounds1.xy + uvBounds1.zw;
}
Note here, uv1 doesn't work, which was probably what caused the whole thing to not work.
Pixel:
#ifdef GL_ES
#ifdef GL_FRAGMENT_PRECISION_HIGH
precision highp float;
#else
precision mediump float;
#endif
#endif
uniform sampler2D texture0;
uniform sampler2D texture1;
varying vec2 uv0Varying;
varying vec2 uv1Varying;
void main()
{
vec4 color = texture2D(texture0, uv0Varying);
vec4 light = texture2D(texture1, uv1Varying);
gl_FragColor = color*light;
}
My hovercraft is full of eels