Hi dear shader gurus. I need some help getting lighting to work.. What exactly do I need to add lighting / shadow back into the renderer?
I know the default PS shader adds lighting in the way the manual describes.
Basically a standard PS with lighting ;
varying highp vec2 uvVarying;
uniform sampler2D texture0;
varying mediump vec3 normalVarying;
varying mediump vec3 lightVarying;
varying highp vec3 posVarying;
mediump vec3 GetPSLighting( mediump vec3 normal, highp vec3 pos );
uniform mediump vec4 agk_MeshDiffuse;
uniform mediump vec4 agk_MeshEmissive;
void main()
{
mediump vec4 blendTex = vec4(1.0,1.0,1.0,1.0);
mediump vec3 norm = normalize(normalVarying);
mediump vec3 light = lightVarying + GetPSLighting( norm, posVarying );
mediump vec4 texColor = texture2D(texture0, uvVarying);
gl_FragColor = texColor * blendTex * vec4(light, 1.0) * agk_MeshDiffuse + agk_MeshEmissive;
}
However any combining I do keeps giving me a GetPSLighting 'function not found' error.
I am trying to combine with;
uniform sampler2D texture0;
uniform sampler2D texture1;
uniform sampler2D texture2;
varying vec2 uvVarying;
void main()
{
vec4 basecolor = texture2D(texture0, uvVarying);
vec4 bloomcolor = texture2D(texture1, uvVarying);
float depthcolor = texture2D(texture2, uvVarying).r;
gl_FragColor = vec4(mix(basecolor,bloomcolor,depthcolor));
}
...which is the final render pass of a depth of field shader. I probably should add it to one of the blur passes instead, so it gets blurred too. But I basically want to understand why I am getting the aforementioned error.
Any tips of ideas pointing me in the right direction is greatly appreciated. I'm a bit stuck here.
I initially tried to uncomment the code below from the Depth ps pass, however the same error shows up... or no shadows shown
//uniform sampler2D texture0; //
uniform vec2 DOF_Focus;
varying highp vec3 posVarying;
//varying mediump vec3 normalVarying; //
//varying mediump vec2 uvVarying; //
//varying mediump vec3 lightVarying; //
//mediump vec3 GetPSLighting( mediump vec3 normal, highp vec3 pos ); //
//mediump vec3 ApplyFog( mediump vec3 color, highp vec3 pointPos ); //
void main()
{
// mediump vec3 norm = normalize(normalVarying); //
// mediump vec3 light = lightVarying + GetPSLighting( norm, posVarying ); //
// mediump vec3 color = texture2D(texture0, uvVarying).rgb * light; //
// color = ApplyFog( color, posVarying ); //
float depth = gl_FragCoord.z/gl_FragCoord.w;
float CloseDepth=clamp(1.0-(depth/DOF_Focus.x),0.0,1.0);
float FarDepth=CloseDepth+clamp((-DOF_Focus.y+depth)/DOF_Focus.y,0.0,1.0);
gl_FragColor = vec4(FarDepth);
}