I am writing a small RPG demo, right now, I'm stuck with homemade terrain - the GLSL shader.
I am able to connect all alpha and texture layers to get correct surface but I'm not able to add lights and shadows.
I am totally green in this subject - forgive me.
Can I get help with that? Sorry I know that this is huge subject
Shader FG:
Code: Select all
// MultiTexture.frag:
uniform sampler2D alpha0;
uniform sampler2D texture0; //alpha
uniform sampler2D texture1;
uniform sampler2D alpha1; //alpha
uniform sampler2D texture2;
uniform vec4 ldiffuse;
uniform vec4 lspecular;
uniform vec4 lposition;
uniform vec4 cposition;
uniform vec4 attenuation;
uniform float exponent;
vec4 invcol(in vec4 p) {
return (1.0 - p);
}
void main()
{
gl_FragColor =(texture2D(texture0, gl_TexCoord[0].st)* texture2D(alpha0, gl_TexCoord[0].st));
gl_FragColor +=(invcol(texture2D(alpha0, gl_TexCoord[0].st))* texture2D(texture1, gl_TexCoord[0].st));
gl_FragColor *= texture2D(alpha1, gl_TexCoord[0].st);
gl_FragColor +=(invcol(texture2D(alpha1, gl_TexCoord[0].st))* texture2D(texture2, gl_TexCoord[0].st));
//gl_FragColor *=ldiffuse+lspecular;
}
Code: Select all
pParams->setNamedAutoConstant("ldiffuse", Ogre::GpuProgramParameters::AutoConstantType::ACT_LIGHT_DIFFUSE_COLOUR,0);
pParams->setNamedAutoConstant("lspecular",Ogre::GpuProgramParameters::AutoConstantType::ACT_LIGHT_SPECULAR_COLOUR,0);
pParams->setNamedAutoConstant("lposition",Ogre::GpuProgramParameters::AutoConstantType::ACT_LIGHT_POSITION_OBJECT_SPACE,0);
pParams->setNamedAutoConstant("cposition",Ogre::GpuProgramParameters::AutoConstantType::ACT_CAMERA_POSITION_OBJECT_SPACE,0);
pParams->setNamedAutoConstant("attenuation",Ogre::GpuProgramParameters::AutoConstantType::ACT_LIGHT_ATTENUATION,0);
pParams->setNamedConstant("exponent",(Ogre::Real)63);
Code: Select all
material TerrainMaterial
{
technique
{
pass
{
fragment_program_ref TerrainFP
{
param_named alpha0 int 0
param_named texture0 int 1
param_named texture1 int 2
param_named alpha1 int 3
param_named texture2 int 4
}
texture_unit 0
{
texture terrain3.png
}
texture_unit 1
{
texture BeachStones.jpg
}
texture_unit 2
{
texture MtlPlat2.jpg
}
texture_unit 3
{
texture terrain4.png
}
texture_unit 4
{
texture 1d_debug.png
}
}
}
}