Can't solve the bug connected with Shadow Map under Ogre3D v1.9, iOS Platform.
As the camera movement the shadow is being changed:
OK: http://joxi.ru/v29XpWOuGq6ZYm
Bugs:
http://joxi.ru/n2YZxkdujpxbOA
http://joxi.ru/5mdvq7zhvnX3lA
http://joxi.ru/vAWLn3lhkEWg9r
DepthShadowmap:
Code: Select all
vertex_program Ogre/DepthShadowmap/CasterVP glsles
{
source DepthShadowmapCasterVp.glsles
profiles glsles
preprocessor_defines LINEAR_RANGE=0
default_params
{
param_named_auto worldViewProj worldviewproj_matrix
param_named_auto texelOffsets texel_offsets
//param_named_auto depthRange scene_depth_range
}
}
fragment_program Ogre/DepthShadowmap/CasterFP glsles
{
source DepthShadowmapCasterFp.glsles
profiles glsles
preprocessor_defines LINEAR_RANGE=0
default_params
{
}
}
// Generic Shadow caster material (floating point shadowmap)
material Ogre/DepthShadowmap/Caster/Float
{
technique
{
pass
{
vertex_program_ref Ogre/DepthShadowmap/CasterVP
{
}
fragment_program_ref Ogre/DepthShadowmap/CasterFP
{
}
}
}
}
Code: Select all
#version 100
precision highp int;
precision highp float;
uniform mat4 worldViewProj;
uniform vec4 texelOffsets;
uniform vec4 depthRange;
attribute vec4 position;
varying vec2 depth;
void main()
{
gl_Position = worldViewProj * position;
// fix pixel / texel alignment
gl_Position.xy += texelOffsets.zw * gl_Position.w;
// linear depth storage
// offset / scale range output
#if LINEAR_RANGE
depth.x = (gl_Position.z - depthRange.x) * depthRange.w;
#else
depth.x = gl_Position.z;
#endif
depth.y = gl_Position.w;
}
Code: Select all
#version 100
precision highp int;
precision highp float;
varying vec2 depth;
void main()
{
#if LINEAR_RANGE
float finalDepth = depth.x;
#else
float finalDepth = depth.x / depth.y;
#endif
// just smear across all components
// therefore this one needs high individual channel precision
gl_FragColor.r = finalDepth;// = vec4(finalDepth, finalDepth, finalDepth, 1.0);
}
Now I'm trying to show the shadow on my floor:
Material:
Code: Select all
vertex_program Led_ProjectionVS glsles
{
source Led_ProjectionVS.glsles
profiles glsles
default_params
{
param_named_auto modelViewProjectionMatrix worldviewproj_matrix
param_named_auto modelWorldMatrix world_matrix
param_named_auto texWorldViewProj texture_viewproj_matrix
}
}
fragment_program Led_ProjectionFS glsles
{
source Led_ProjectionFS.glsles
profiles glsles
default_params
{
param_named shadowMap int 0
}
}
material Led
{
technique
{
pass
{
vertex_program_ref Led_ProjectionVS
{
}
fragment_program_ref Led_ProjectionFS
{
}
texture_unit
{
content_type shadow
tex_address_mode clamp
filtering none
}
}
}
}
Code: Select all
#version 100
precision highp int;
precision highp float;
uniform mat4 modelViewProjectionMatrix;
uniform mat4 modelWorldMatrix;
uniform mat4 texWorldViewProj;
attribute vec4 position;
attribute vec4 uv0;
varying vec4 oUv;
varying vec4 texCoord;
void main()
{
gl_Position = modelViewProjectionMatrix * position;
vec4 shadowPosition = modelWorldMatrix * position;
texCoord = texWorldViewProj * shadowPosition;
oUv = uv0;
}
Code: Select all
#version 100
precision highp int;
precision highp float;
uniform sampler2D shadowMap;
varying vec4 oUv;
varying vec4 texCoord;
void main()
{
vec4 shadowUV1 = texCoord / texCoord.w;
float shadow1 = texture2D( shadowMap, shadowUV1.xy ).x;
vec4 final = vec4(1.0, 1.0, 1.0, 1.0) * shadow1;
gl_FragColor = final;
}
Code: Select all
mSceneMgr->setShadowTechnique(SHADOWTYPE_TEXTURE_ADDITIVE_INTEGRATED);
mSceneMg->setShadowTextureSettings(1024, 1);
mSceneMgr->setShadowColour(0, 0, 0, 0.25);
mSceneMgr->setShadowTextureSelfShadow(true);
mSceneMgr->setShadowTexturePixelFormat(PF_A8R8G8B8);
mSceneMgr->setShadowTextureCasterMaterial("Ogre/DepthShadowmap/Caster/Float");