Page 7 of 10
Posted: Fri May 02, 2008 7:24 pm
by hpesoj
Saw this when it was first posted, but have only just got round to trying it out. They're damned good shadows. Ta muchly Null!
Here's a teapot and a bunch of boxes. I wish I could be bothered to make a more structured scene

.
Joe
Posted: Sat May 17, 2008 9:24 am
by shaill
Hello nullsquared!!
I want to ask u a programming skill.
If I want to have more than one light source, what steps I have to do?
And about the material scripts,ex.
Code: Select all
param_named_auto depthRange shadow_scene_depth_range 0
We must need different light's attribute. And the number to indicate light number(like above "0") must change the number at run time right?
But how to do it?
And according to
Code: Select all
param_named_auto light_viewprojection texture_viewproj_matrix
There is no extra params. Does it mean Ogre will according to different lights to give the different texture_viewproj_matrix? Right?
Thanks a lot!!!!
Posted: Sat May 17, 2008 12:52 pm
by nullsquared
Code: Select all
pass your_lighting_pass
{
iteration once_per_light
scene_blend add
// shaders to calculate light and shadow here for 1 light
}
Any parameters that need a "light index" you should pass 0 - each pass of the "iteration once_per_light" will increase this light index automatically.
Alternatively, you can ignore the iteration, and manually pass in multiple parameters of the same type, but with different light indices - 0 for the first light, 1 for the second, 2 for the third, so on. Read the manual.
Posted: Tue Jun 17, 2008 11:59 am
by xadhoom
Hi Nullsquared!
I tested your demo and it seems, that after a certain number of lights created/recreated with space. The visible lights seem to switch between there
current state (position direction and lightcolor) maybe to there previous state, depending on my camera position. So if I fly threw your demo dungeon the lights switch between certain positions.
Is this a "feature" of your code or could this be a driver problem?
I´m happy about any hint!
Posted: Tue Jun 17, 2008 9:11 pm
by nullsquared
xadhoom wrote:Hi Nullsquared!
I tested your demo and it seems, that after a certain number of lights created/recreated with space. The visible lights seem to switch between there
current state (position direction and lightcolor) maybe to there previous state, depending on my camera position. So if I fly threw your demo dungeon the lights switch between certain positions.
Is this a "feature" of your code or could this be a driver problem?
I´m happy about any hint!
Check "config.ini" (or whatever the config file was named, I think it was in /data/). There should be a numShadowTextures variable. With default Ogre shadow textures, you have a 1:1 ratio between lights and shadow textures. Meaning, if you want 15 shadowing lights, you need 15 shadow textures. If you have only, say, 4 shadow textures, then Ogre will try to "nudge" the closest lights into shadowing.
A solution is to use 1 shadow map for all lights (practically free for any number of lights, in terms of memory). However, this is very impractical with forward shading, when many lights are done at once with little control over each light. Deferred shading addresses this issue nicely, since each light is automatically a separate pass you have 100% control over, meaning you can use the same shadow map for all of the lights.
Posted: Wed Jun 18, 2008 11:59 am
by xadhoom
Ok, thank you I will adjust the config file to see if it works.
It seems comprehensible.
I thought that using the flag "once per light" would lead to a kind of deferred shading... but this seems to be wrong.
Posted: Wed Jun 18, 2008 1:54 pm
by xadhoom
Hi Null!
I´ve some problems to port the shadows to my App (I seem to be the only one

).
I could integrate the material (for tests your material) and see it highlighted correctly by a number of spotlights. So far so good. But I can´t see any shadow.
For debugging I changed the return value of the shader method shadow() to zero and get as the result no lighting except the ambient pass, which should be correct.
(Btw this showes, that the shadow shader is present at runtime)
So it seems that the shader determines, that there is no shadowing object at all... . I´ve worked myself through your code three times but did not see a thing I could have missed.
I copied your initShadow method completely.
Btw: Your Mgr is a ShadowListener, which is never called because it is not registered anywhere... was this for testing?
Posted: Thu Jun 19, 2008 2:44 pm
by xadhoom
Ok, I got them working. I did not notice, that our OFusion importer resets the shadowsystem depending on the imported model.

Posted: Thu Jun 19, 2008 5:08 pm
by xadhoom
Ok, I´m afraid I wont get a reaction in this thread, but its worth a try.
My shadows work for now as they should except the fact that they fade out smoothly over time until they are fully invisible (no shadows anymore). The fade speed is light independent but present. I figured out that it has to do with
the incoming shadow map in the diffuse material shader. I really do nothing
over time which could lead to such behaviour...
Any hint? Thx!
Softshadows for an object with no texture
Posted: Fri Jun 20, 2008 5:28 pm
by vitefalcon
Hi nullsquared, I've tried out the soft-shadows in my project but I'm having one problem. One of my materials doesn't have a texture unit. Instead it gets coloured by the diffuse colour
How do I change the diffuse.cg to work like, if there's a texture use the colour value of the corresponding UV coordinates otherwise use the diffuse colour? Thanks in advance.
Re: Softshadows for an object with no texture
Posted: Fri Jun 20, 2008 9:39 pm
by nullsquared
vitefalcon wrote:Hi nullsquared, I've tried out the soft-shadows in my project but I'm having one problem. One of my materials doesn't have a texture unit. Instead it gets coloured by the diffuse colour
How do I change the diffuse.cg to work like, if there's a texture use the colour value of the corresponding UV coordinates otherwise use the diffuse colour? Thanks in advance.
The best solution is to integrate only the shadowing code into your own shaders. Meaning, diffuse_vs/ps is really only there as an example, you're not meant to actually use it (unless you specifically want to, of course).
The second and easiest solution is to just use a 4x4 white texture as the diffuse texture, which should pose practically no speed difference on relatively new cards. Then you'd just interpolate COLOR0 from the vertex shader down to COLOR0 (or just a TEXCOORD) of the pixel shader, and use that.
The third solution is to use a #define to have something like diffuse_vertexcolour_vs/ps, where if something like USE_DIFFUSE_MAP is not defined, then no diffuse map is considered, and instead the above is done - interpolate COLOR0 from the vertex shader down to the pixel shader.
Posted: Tue Jun 24, 2008 3:27 pm
by vitefalcon
Hi nullsquared... sorry for this late reply. Can you show me a code example of how to implement the second option. I'm just starting on shaders. I understood most of the concepts but I don't know in which shader i should implement what you've mentioned. Thanks in advance.
Posted: Tue Jun 24, 2008 3:53 pm
by vitefalcon
I just solved the issue using ur advice... I think it's the second one... here's how i did it...
diffuse_no_tex.cg
Code: Select all
struct VIn {
float4 p : POSITION;
float3 n : NORMAL;
float4 d : COLOR0; // Taken off texture coordinates and put diffuse colour instead
};
struct VOut {
float4 p : POSITION;
float4 d : TEXCOORD0;
float4 wp : TEXCOORD1;
float3 n : TEXCOORD2;
float4 lp : TEXCOORD3;
float3 sdir : TEXCOORD4;
};
struct PIn {
float4 d : TEXCOORD0;
float4 wp : TEXCOORD1;
float3 n : TEXCOORD2;
float4 lp : TEXCOORD3;
float3 sdir : TEXCOORD4;
};
struct POut {
float4 c : COLOR;
};
VOut diffuse_no_tex_vs(VIn IN,
uniform float4x4 wMat,
uniform float4x4 wvpMat,
uniform float4x4 tvpMat,
uniform float4 spotlightDir
) {
VOut OUT;
OUT.wp = mul(wMat, IN.p);
OUT.p = mul(wvpMat, IN.p);
OUT.d = IN.d;
OUT.n = mul(wMat, float4(IN.n, 0)).xyz; // world-space normal
OUT.sdir = mul(wMat, spotlightDir).xyz; // spotlight dir in world space
OUT.lp = mul(tvpMat, OUT.wp);
return OUT;
}
float2 btex2D_rg(sampler2D map, float2 uv, float radius, float2 offset) {
// this is sometimes too slow and long
// (3 * 2 + 1) ^ 2 = 7 ^ 2 = 49 samples
// float2 sample = float2(0, 0);
// for (float x = -radius; x <= radius; x += 1) {
// for (float y = -radius; y <= radius; y += 1) {
// sample += tex2D(map, float2(uv.x + x * offset.x, uv.y + y * offset.y)).rg;
// }
// }
// return sample / ((radius * 2 + 1) * (radius * 2 + 1));
// simple 3x3 filter
float2 o = offset;
float2 c = tex2D(map, uv.xy).rg; // center
c += tex2D(map, uv.xy - o.xy).rg; // top left
c += tex2D(map, uv.xy + o.xy).rg; // bottom right
c += tex2D(map, float2(uv.x - o.x, uv.y)).rg; // left
c += tex2D(map, float2(uv.x + o.x, uv.y)).rg; // right
c += tex2D(map, float2(uv.x, uv.y + o.y)).rg; // bottom
c += tex2D(map, float2(uv.x, uv.y - o.y)).rg; // top
c += tex2D(map, float2(uv.x - o.x, uv.y + o.y)).rg; // bottom left
c += tex2D(map, float2(uv.x + o.x, uv.y - o.y)).rg; // top right
return c / 9;
}
float shadow(
sampler2D shadowMap, float4 shadowMapPos, float ourDepth, float radius, float2 offset) {
float2 suv = shadowMapPos.xy / shadowMapPos.w;
float2 moments = //tex2D(shadowMap, suv).rg;
// blurred texture read
btex2D_rg(shadowMap, suv, radius, offset);
float litFactor = (ourDepth <= moments.x ? 1 : 0);
// standard variance shadow mapping code
float E_x2 = moments.y;
float Ex_2 = moments.x * moments.x;
float vsmEpsilon = 0.0001;
float variance = min(max(E_x2 - Ex_2, 0.0) + vsmEpsilon, 1.0);
float m_d = moments.x - ourDepth;
float p = variance / (variance + m_d * m_d);
return smoothstep(0.4, 1, max(litFactor, p));
//return litFactor;
}
// to put it simply, this does 100% per pixel diffuse lighting
POut diffuse_no_tex_ps(PIn IN,
uniform float3 lightDif0,
uniform float4 lightPos0,
uniform float4 lightAtt0,
uniform float4 depthRange,
uniform float4 invSMSize,
uniform float4 spotlightParams,
uniform sampler2D dMap : TEXUNIT0,
uniform sampler2D shadowMap : TEXUNIT1
) {
POut OUT;
// direction
float3 ld0 = normalize(lightPos0.xyz - (lightPos0.w * IN.wp.xyz));
// attenuation
half ila = length(lightPos0.xyz - IN.wp.xyz) / lightAtt0.r;
ila *= ila; // quadratic falloff
half la = 1.0 - ila;
float3 normal = normalize(IN.n);
float3 LdotN0 = max(dot(ld0, normal), 0);
// calculate the spotlight effect
float spot = dot(ld0, normalize(-IN.sdir)); // angle between spotlight dir and actual dir
spot = saturate((spot - spotlightParams.y) / (spotlightParams.x - spotlightParams.y));
float3 light0C =
// N . L LIGHT DIF TEX DIF ATT
(LdotN0 * lightDif0 * IN.d.xyz) * la * spot
* shadow(
// pass in the shadow map
shadowMap,
// the calculated shadow position in the shadow map
IN.lp,
// distance to light, done just as in the caster shader
(length(lightPos0.xyz - IN.wp.xyz) - depthRange.x) * depthRange.w,
// radius to blur (we discussed)
3,
// inverse shadow map size so we know how much to move when blurring
invSMSize.xy);
OUT.c = float4(light0C, 1);
return OUT;
}
diffuse_no_tex.material
Code: Select all
vertex_program diffuse_no_tex_vs cg
{
source diffuse_no_tex.cg
profiles vs_1_1 arbvp1
entry_point diffuse_no_tex_vs
default_params
{
param_named_auto wMat world_matrix
param_named_auto wvpMat worldviewproj_matrix
param_named_auto tvpMat texture_viewproj_matrix 0
param_named_auto spotlightDir light_direction_object_space 0
}
}
fragment_program diffuse_no_tex_ps cg
{
source diffuse_no_tex.cg
profiles ps_2_x arbfp1
entry_point diffuse_no_tex_ps
default_params
{
param_named_auto lightDif0 light_diffuse_colour 0
param_named_auto lightPos0 light_position 0
param_named_auto lightAtt0 light_attenuation 0
param_named_auto invSMSize inverse_texture_size 1
param_named_auto depthRange shadow_scene_depth_range 0
param_named_auto spotlightParams spotlight_params 0
}
}
material diffuse_no_tex_template
{
technique
{
pass
{
ambient 1 1 1
diffuse 0 0 0
specular 0 0 0 0
emissive 0 0 0
vertex_program_ref ambient_vs
{
}
fragment_program_ref ambient_ps
{
}
}
pass
{
max_lights 8
scene_blend add
iteration once_per_light
ambient 0 0 0
diffuse 1 1 1
specular 1 1 1 128
vertex_program_ref diffuse_no_tex_vs
{
}
fragment_program_ref diffuse_no_tex_ps
{
}
texture_unit shadow_tex
{
content_type shadow
filtering anisotropic
max_anisotropy 16
tex_address_mode border
tex_border_colour 1 1 1
}
}
}
}
and that did the trick. Thanks a lot nullsquared.
Posted: Tue Jun 24, 2008 5:37 pm
by vitefalcon
Posted: Tue Jun 24, 2008 6:45 pm
by nullsquared
First, log please

. It's possible that OpenGL is just failing to compile the same shader that D3D is ok with.
Second, change this part of diffuse_no_tex_ps:
Code: Select all
uniform sampler2D dMap : TEXUNIT0,
uniform sampler2D shadowMap : TEXUNIT1
to this:
Code: Select all
uniform sampler2D shadowMap : TEXUNIT0
Third, in the material, change this:
to this:
Change anything?
Posted: Wed Jun 25, 2008 11:12 am
by vitefalcon
WUHUUUU.. the changes u mentioned worked...
it was this statement that made it work...
Code: Select all
uniform sampler2D shadowMap : TEXUNIT0
I guess it's the optimization of the shader program that makes the problem, since i had dMap at TEXTUREUNIT0 and was not using dMap at all in the code.
so now the complete material file and shader file looks like this...
Material File
Code: Select all
vertex_program diffuse_no_tex_vs cg
{
source diffuse_no_tex.cg
profiles vs_1_1 arbvp1
entry_point diffuse_no_tex_vs
default_params
{
param_named_auto wMat world_matrix
param_named_auto wvpMat worldviewproj_matrix
param_named_auto tvpMat texture_viewproj_matrix 0
param_named_auto spotlightDir light_direction_object_space 0
}
}
fragment_program diffuse_no_tex_ps cg
{
source diffuse_no_tex.cg
profiles ps_2_x arbfp1
entry_point diffuse_no_tex_ps
default_params
{
param_named_auto lightDif0 light_diffuse_colour 0
param_named_auto lightPos0 light_position 0
param_named_auto lightAtt0 light_attenuation 0
param_named_auto invSMSize inverse_texture_size 1
param_named_auto depthRange shadow_scene_depth_range 0
param_named_auto spotlightParams spotlight_params 0
}
}
material diffuse_no_tex_template
{
technique
{
pass
{
ambient 1 1 1
diffuse vertexcolour
specular 0 0 0 0
emissive 0 0 0
vertex_program_ref ambient_vs
{
}
fragment_program_ref ambient_ps
{
}
}
pass
{
max_lights 8
scene_blend add
iteration once_per_light
ambient 0 0 0
diffuse 1 1 1
specular 1 1 1 128
vertex_program_ref diffuse_no_tex_vs
{
}
fragment_program_ref diffuse_no_tex_ps
{
}
texture_unit shadow_tex
{
content_type shadow
filtering anisotropic
max_anisotropy 16
tex_address_mode border
tex_border_colour 1 1 1
}
}
}
}
Shader file
Code: Select all
struct VIn {
float4 p : POSITION;
float3 n : NORMAL;
float4 d : COLOR0;
};
struct VOut {
float4 p : POSITION;
float4 d : TEXCOORD0;
float4 wp : TEXCOORD1;
float3 n : TEXCOORD2;
float4 lp : TEXCOORD3;
float3 sdir : TEXCOORD4;
};
struct PIn {
float4 d : TEXCOORD0;
float4 wp : TEXCOORD1;
float3 n : TEXCOORD2;
float4 lp : TEXCOORD3;
float3 sdir : TEXCOORD4;
};
struct POut {
float4 c : COLOR;
};
VOut diffuse_no_tex_vs(VIn IN,
uniform float4x4 wMat,
uniform float4x4 wvpMat,
uniform float4x4 tvpMat,
uniform float4 spotlightDir
) {
VOut OUT;
OUT.wp = mul(wMat, IN.p);
OUT.p = mul(wvpMat, IN.p);
OUT.d = IN.d;
OUT.n = mul(wMat, float4(IN.n, 0)).xyz; // world-space normal
OUT.sdir = mul(wMat, spotlightDir).xyz; // spotlight dir in world space
OUT.lp = mul(tvpMat, OUT.wp);
return OUT;
}
float2 btex2D_rg(sampler2D map, float2 uv, float radius, float2 offset) {
// this is sometimes too slow and long
// (3 * 2 + 1) ^ 2 = 7 ^ 2 = 49 samples
// float2 sample = float2(0, 0);
// for (float x = -radius; x <= radius; x += 1) {
// for (float y = -radius; y <= radius; y += 1) {
// sample += tex2D(map, float2(uv.x + x * offset.x, uv.y + y * offset.y)).rg;
// }
// }
// return sample / ((radius * 2 + 1) * (radius * 2 + 1));
// simple 3x3 filter
float2 o = offset;
float2 c = tex2D(map, uv.xy).rg; // center
c += tex2D(map, uv.xy - o.xy).rg; // top left
c += tex2D(map, uv.xy + o.xy).rg; // bottom right
c += tex2D(map, float2(uv.x - o.x, uv.y)).rg; // left
c += tex2D(map, float2(uv.x + o.x, uv.y)).rg; // right
c += tex2D(map, float2(uv.x, uv.y + o.y)).rg; // bottom
c += tex2D(map, float2(uv.x, uv.y - o.y)).rg; // top
c += tex2D(map, float2(uv.x - o.x, uv.y + o.y)).rg; // bottom left
c += tex2D(map, float2(uv.x + o.x, uv.y - o.y)).rg; // top right
return c / 9;
}
float shadow(
sampler2D shadowMap, float4 shadowMapPos, float ourDepth, float radius, float2 offset) {
float2 suv = shadowMapPos.xy / shadowMapPos.w;
float2 moments = //tex2D(shadowMap, suv).rg;
// blurred texture read
btex2D_rg(shadowMap, suv, radius, offset);
float litFactor = (ourDepth <= moments.x ? 1 : 0);
// standard variance shadow mapping code
float E_x2 = moments.y;
float Ex_2 = moments.x * moments.x;
float vsmEpsilon = 0.0001;
float variance = min(max(E_x2 - Ex_2, 0.0) + vsmEpsilon, 1.0);
float m_d = moments.x - ourDepth;
float p = variance / (variance + m_d * m_d);
return smoothstep(0.4, 1, max(litFactor, p));
//return litFactor;
}
// to put it simply, this does 100% per pixel diffuse lighting
POut diffuse_no_tex_ps(PIn IN,
uniform float3 lightDif0,
uniform float4 lightPos0,
uniform float4 lightAtt0,
uniform float4 depthRange,
uniform float4 invSMSize,
uniform float4 spotlightParams,
uniform sampler2D shadowMap : TEXUNIT0
) {
POut OUT;
// direction
float3 ld0 = normalize(lightPos0.xyz - (lightPos0.w * IN.wp.xyz));
// attenuation
half ila = length(lightPos0.xyz - IN.wp.xyz) / lightAtt0.r;
ila *= ila; // quadratic falloff
half la = 1.0 - ila;
float3 normal = normalize(IN.n);
float3 LdotN0 = max(dot(ld0, normal), 0);
// calculate the spotlight effect
float spot = dot(ld0, normalize(-IN.sdir)); // angle between spotlight dir and actual dir
spot = saturate((spot - spotlightParams.y) / (spotlightParams.x - spotlightParams.y));
float3 light0C =
// N . L LIGHT DIF TEX DIF ATT
(LdotN0 * lightDif0 * IN.d.xyz) * la * spot
* shadow(
// pass in the shadow map
shadowMap,
// the calculated shadow position in the shadow map
IN.lp,
// distance to light, done just as in the caster shader
(length(lightPos0.xyz - IN.wp.xyz) - depthRange.x) * depthRange.w,
// radius to blur (we discussed)
3,
// inverse shadow map size so we know how much to move when blurring
invSMSize.xy);
OUT.c = float4(light0C, 1);
return OUT;
}
..
P.S.: There were no error messages or exceptions in Ogre.log regarding the shader file or material file for both DirectX and OpenGL renderers. Only warnings about textures and my manual mesh. Just in case if you're interested I'll be happy to put the log in here. However, there was this Ogre::Exception in the log which you might be interested in...
Code: Select all
11:01:13: OGRE EXCEPTION(7:InternalErrorException): Unable to compile Cg program blur_ps: CG ERROR : The compile returned an error.
(0) : error C6001: Temporary register limit of 12 exceeded; 49 registers needed to compile program
in CgProgram::loadFromSource at e:\projects\ogrecvs\branches\eihort\ogre\plugins\cgprogrammanager\src\ogrecgprogrammanagerdll.cpp (line 66)
11:01:13: High-level program blur_ps encountered an error during loading and is thus not supported.
OGRE EXCEPTION(7:InternalErrorException): Unable to compile Cg program blur_ps: CG ERROR : The compile returned an error.
(0) : error C6001: Temporary register limit of 12 exceeded; 49 registers needed to compile program
in CgProgram::loadFromSource at e:\projects\ogrecvs\branches\eihort\ogre\plugins\cgprogrammanager\src\ogrecgprogrammanagerdll.cpp (line 66)
Posted: Sat Jun 28, 2008 8:36 pm
by nullsquared
Right, you can just get rid of those blur shaders. I was going to use a blur compositor for the shadow map, but it create very ugly VSM halos, and it was hardly any faster than doing the filtering right inside the lighting shader. Anyways, I ended up keeping them included in the final demo, even though they are never used (and don't work to begin with

).
Posted: Sat Jun 28, 2008 9:18 pm
by vitefalcon
LOL... thanks for that info....

Posted: Wed Jul 09, 2008 4:12 pm
by TheSHEEEP
Hey, guys.
I tried to integrate those shadows inte my game, but it isn't quite working.
And I have the same problem
xadhoom had.
I'm also working with oFusion (CE), but already disabled the shadow setting part of the loader. Still no shadows at all.
Here is the relevant part of the code:
Code: Select all
SceneManager *mgr = mRoot->createSceneManager(ST_GENERIC, "Default SceneManager");
mgr->setShadowTextureSelfShadow(true);
mgr->setShadowTextureCasterMaterial("shadow_caster");
mgr->setShadowTextureCount( 1 );
mgr->setShadowTextureSize( 512 );
mgr->setShadowTexturePixelFormat(PF_FLOAT16_RGB);
mgr->setShadowCasterRenderBackFaces(false);
const unsigned numShadowRTTs = mgr->getShadowTextureCount();
for (unsigned i = 0; i < numShadowRTTs; ++i) {
Ogre::TexturePtr tex = mgr->getShadowTexture(i);
Ogre::Viewport *vp = tex->getBuffer()->getRenderTarget()->getViewport(0);
vp->setBackgroundColour(Ogre::ColourValue(1, 1, 1, 1));
vp->setClearEveryFrame(true);
}
mgr->setShadowTechnique(Ogre::SHADOWTYPE_TEXTURE_ADDITIVE_INTEGRATED);
}
As you can see, it is basically copied from the demo. Just without the config file.
I copied shadow_caster.material and shadow_caster.cg into my resource folder. I seriously don't know what went wrong.
Also, there are no errors in the Ogre.log...
Posted: Wed Jul 09, 2008 4:55 pm
by nullsquared
You mean your shadows fade over time?
This is a seriously odd and isolated issue

. Time is not taken into account whatsoever by the shadows themselves, so the only reason why they might fade is if the shadows get lower-resolution as time passes. Except, they shouldn't do that unless you manually make them lower-resolution. So I'm very confused. Are you using any special type of camera setup, or maybe LiSPSM?
Posted: Thu Jul 10, 2008 7:33 am
by TheSHEEEP
No, my problem is, as stated

, that there are no shadows
at all.
That was what I meant with the same problem xadhoom had
And I'm not using any kind of Shadow Camera. Should I?
If yes, how?
I found 'em mentioned in some threads but couldn't find a proper explanation of what they are for and how they can be used...
Edit: I found an error in the log, sry for not seeing it before o.O
Code: Select all
08:44:42: OGRE EXCEPTION(7:InternalErrorException): Unable to compile Cg program shadow_caster_ps: CG ERROR : The compile returned an error.
(38) : error C3004: function "length" not supported in this profile
in CgProgram::loadFromSource at ..\src\OgreCgProgramManagerDll.cpp (line 66)
08:44:42: High-level program shadow_caster_ps encountered an error during loading and is thus not supported.
OGRE EXCEPTION(7:InternalErrorException): Unable to compile Cg program shadow_caster_ps: CG ERROR : The compile returned an error.
(38) : error C3004: function "length" not supported in this profile
in CgProgram::loadFromSource at ..\src\OgreCgProgramManagerDll.cpp (line 66)
Unfortunately, I have no idea how to fix that.
Posted: Thu Jul 10, 2008 11:05 am
by xadhoom
Hi Sheep!
I really don´t know where this odd bug with the fading shadow came from, but it
wents away when I redesigned the shader a bit (but there was no logical
reason, thats the reason why I did not post a solution). But thats not your problem...
My problems with OFusion were solved by killing the whole OFusion load process.
I do it manually know which is no problem in my case. But if you commented the
shadow settings part in the ofusion importer it should work.
Do you init your shadows before loading any mesh? You know initShadow() method in the demo.
Do you add a ShadowListener (Eihort) to manage the shadow camera distance
per light? Do your models cast/receive shadows (flag in osm file)? Do your lights cast shadows etc.?
Did you test some simple meshes which you loaded manually? If they have shadows or not you are a big step further...
Posted: Thu Jul 10, 2008 12:07 pm
by TheSHEEEP
Thanks for your answer!
xadhoom wrote:
Do you init your shadows before loading any mesh? You know initShadow() method in the demo.
Yup, this was my code example. No mesh is loaded before that.
xadhoom wrote:
Do you add a ShadowListener (Eihort) to manage the shadow camera distance
per light?
Nope, how exactly do I have to implement that?
xadhoom wrote:Do your models cast/receive shadows (flag in osm file)? Do your lights cast shadows etc.?
Yup. Yup.
xadhoom wrote:
Did you test some simple meshes which you loaded manually? If they have shadows or not you are a big step further...
No, will try to do so after figuring out how to implement a Shadow Listener, some help would always be appreciated

Posted: Thu Jul 10, 2008 1:59 pm
by nullsquared
Look at the demo, the basic "manager" there is a shadow listener with the appropriate code. You just need to do something that I forgot to add in the demo (not necessarily needed, but a good little optimization):
Code: Select all
sceneMgr->addShadowListener(theShadowListener);
As for why you see no shadows, it's because of that error in the log you just posted. The shadow caster material is not getting compiled successfully. Can I see the material file for the shadow caster? I'm 110% sure ps_2_0 and arbfp1 support length(), so there's probably a small typo.
Also, something I forgot to mention: my SSAO demo (show case forums if you're looking for it) is pretty much an "extension" to this demo - with all of the fixes I never made to the actual shadows demo. You might want to take a look at it as well, since it does the shadow listener stuff as well as some smarter depth-scaling (in the shaders).
Posted: Thu Jul 10, 2008 3:24 pm
by TheSHEEEP
You were right about the typo in the shader material file. Was my mistake, sry
The only thing that still appears in Orge.log is:
WARNING: Texture instance 'Ogre/ShadowTexture0' was defined as manually loaded, but no manual loader was provided. This Resource will be lost if it has to be reloaded.
But I don't know if it has anything to do with the shader or the problem at all.
Anyway,
when I tried to copy the Shadow Listener from your demo, it gave me many errors, so I tried to make a Shadow Listener class myself, similar to the one in the demo.
Code: Select all
class ShadowClass : public ShadowListener, public WindowEventListener
{
void shadowTextureCasterPreViewProj(Ogre::Light *light, Ogre::Camera *cam);
void shadowTexturesUpdated(size_t) {}
void shadowTextureReceiverPreViewProj(Ogre::Light*, Ogre::Frustum*) {}
};
//inserting the Shadow Class;
ShadowClass* ShadowL;
ShadowL = new ShadowClass();
mgr->addShadowListener(ShadowL);
That didn't compile due a LNK1120, because of
void shadowTextureCasterPreViewProj(Ogre::Light *light, Ogre::Camera *cam)
;
So I changed it to:
Code: Select all
void shadowTextureCasterPreViewProj(Ogre::Light *light, Ogre::Camera *cam){
protected:
public:
void shadowTextureCasterPreViewProj(Ogre::Light *light, Ogre::Camera *cam)
{
cam->setFOVy(Degree(30));
cam->setNearClipDistance(0.01);
cam->setFarClipDistance(light->getAttenuationRange());
}
void shadowTexturesUpdated(size_t) {}
void shadowTextureReceiverPreViewProj(Ogre::Light*, Ogre::Frustum*) {}
}
(found that one on the forums)
And my test setup is the following, completely replacing all oFusion stuff:
Code: Select all
Entity* pEntity = mMan->createEntity("LevelEntity", "LevelEntity.mesh");
pEntity->setCastShadows(true);
pEntity->setMaterialName("karte");
SceneNode* pLNode = mMan->getRootSceneNode()->createChildSceneNode("TestNode");
pLNode->attachObject( pEntity );
pLNode->scale(0.1, 0.1, 0.1);
pLNode->setPosition( Vector3(0,0,0));
pEntity = mMan->createEntity("TestLemming","Lemming_01.mesh");
pEntity->setCastShadows(true);
SceneNode* pONode = mMan->getRootSceneNode()->createChildSceneNode("LemNode");
pONode->attachObject( pEntity );
pONode->setPosition( Vector3(0,30,10));
Light* light = mMan->createLight("Omni");
light->setCastShadows(true);
light->setType(Light::LT_SPOTLIGHT);
light->setDiffuseColour( 1, 1, 1 );
light->setPosition(Vector3(0, 400, 10));
light->setDirection(0, -1, 0);
light->setSpotlightInnerAngle( Radian(Degree(50)));
light->setSpotlightOuterAngle( Radian(Degree(25)));
Still, no shadows

Goddamn it!
I bet I'm doing something very basic very wrong here. I want to have those shadows... the Stencil ones are just too much of an fps-reducer
(yes, it is a game about Lemmings

)