I copied the OpenGL ES 2.0 style of specifying vertices with an "attribute vec4 position;" along with other things (is this how it's supposed to be done in OpenGL 4?).
But now my shadow mapping is messed up as the shadows aren't effected by the camera's rotation/movement.
I think it might be caused by the w component of "position" not matching what it would be in gl_Position.
What should I be setting the w component to?
Here is my shader code:
Vertex shader
attribute vec4 position;
uniform mat4 projection;
uniform mat4 model;
uniform mat4 view;
uniform mat4 modelViewInv;
uniform mat4 lightMatrix;
uniform vec3 lightPos;
uniform vec3 lightDir;
varying vec4 lpos;
attribute vec3 normalIn;
varying vec3 normalOut;
attribute vec2 texCoordIn0;
varying vec2 texCoordOut0;
void main(void)
{
vec4 vpos = (view * (model * position));
lpos = lightMatrix * vpos;
gl_Position = projection * (view * (model * position));
vec3 normalEyeSpace = vec3( modelViewInv * vec4(normalIn, 0.0) );
normalOut = normalize(normalEyeSpace);
texCoordOut0 = texCoordIn0;
}
Fragment shader
uniform vec4 color;
uniform sampler2D texture0;
uniform sampler2D shadowMap;
varying vec4 lpos;
varying vec2 texCoordOut0;
void main (void)
{
vec3 smcoord = lpos.xyz / lpos.w;
float shadow = max(0.5, float(smcoord.z <= texture2D(shadowMap, smcoord.xy).x));
vec4 texColor = texture2D(texture0, texCoordOut0);
gl_FragColor = vec4(color.xyz * texColor.xyz * shadow, color.w * texColor.w);
}