RT Shader System Component (RTSS)

Discussion area about developing or extending OGRE, adding plugins for it or building applications on it. No newbie questions please, use the Help forum for that.
User avatar
boyamer
Orc
Posts: 459
Joined: Sat Jan 24, 2009 11:16 am
Location: Italy
x 6

Re: RT Shader System Component (RTSS)

Post by boyamer »

I think that the Photoshop blend modes can't be found into the mercurial repository but only into the source forge repository of ogre,anyone knows why?

Can this be committed to Mercurial too?

Thanks
al2950
OGRE Expert User
OGRE Expert User
Posts: 1227
Joined: Thu Dec 11, 2008 7:56 pm
Location: Bristol, UK
x 157

Re: RT Shader System Component (RTSS)

Post by al2950 »

Its definitely in Mercurial, looking at it now! However it is only in V1.8 as it is considered an extra feature so wont be merged into 1.7.
User avatar
syedhs
Silver Sponsor
Silver Sponsor
Posts: 2703
Joined: Mon Aug 29, 2005 3:24 pm
Location: Kuala Lumpur, Malaysia
x 51

Re: RT Shader System Component (RTSS)

Post by syedhs »

I have searched quite many times, but I haven't found any related thread or link... I am integrating PSSM (+directional light) and it works great. However as soon as I turn on spotlight, the software throws exception:-
OGRE EXCEPTION(2:InvalidParametersException): Could not create gpu programs from render state in ProgramManager::acquireGpuPrograms at .\RTShader\OgreShaderProgramManager.cpp (line 102)
Edit: I have made some test.. so the question can be simplified as this: how to properly use SpotLight in RTShader? Is there any setup or gotcha that I need to be aware of..? Thanks.
A willow deeply scarred, somebody's broken heart
And a washed-out dream
They follow the pattern of the wind, ya' see
Cause they got no place to be
That's why I'm starting with me
User avatar
Nir Hasson
OGRE Retired Team Member
OGRE Retired Team Member
Posts: 363
Joined: Wed Nov 05, 2008 4:40 pm
Location: TLV - Israel
x 2
Contact:

Re: RT Shader System Component (RTSS)

Post by Nir Hasson »

@syedhs

You should check out the log file for detailed error report.
My guess is that the output program contains some errors or has too many instruction and therefore can't be compiled.
If you can provide more details it will be great.
User avatar
syedhs
Silver Sponsor
Silver Sponsor
Posts: 2703
Joined: Mon Aug 29, 2005 3:24 pm
Location: Kuala Lumpur, Malaysia
x 51

Re: RT Shader System Component (RTSS)

Post by syedhs »

Thanks nirhasson.

I stepped thru the source code to find where exactly it failed.. it is right in this function

Code: Select all

bool ProgramProcessor::compactVsOutputs(Function* vsMain, Function* fsMain)
{
...
	// Case the total number of used floats is bigger than maximum - nothing we can do.
	if (outTexCoordFloats > mMaxTexCoordFloats)	
		return false;
I will try to get more information. Meanwhile if you can explain more on this part , that would be nice..
A willow deeply scarred, somebody's broken heart
And a washed-out dream
They follow the pattern of the wind, ya' see
Cause they got no place to be
That's why I'm starting with me
al2950
OGRE Expert User
OGRE Expert User
Posts: 1227
Joined: Thu Dec 11, 2008 7:56 pm
Location: Bristol, UK
x 157

Re: RT Shader System Component (RTSS)

Post by al2950 »

@syedhs
I have PSSM shadows working with a directional light and have another spotlight influencing the scene. It works fine apart from one problem, read below! I dont know how much you understand about shdaers, but you basically have a limited number of inputs (Well sort of! Read up on shaders!). Your issue is that you are asking RTSS to build shaders which require more inputs than your Shader Model (SM) version can handle. Here are a few things to look at;
  • - Make sure you only have two lights in the scene, more lights = more inputs.
  • - How many PSSM split points do you have, 3 is normal, any more and you require quite a few more shader inputs
  • - Do have any other custom render states enabled, eg reflection map? They will also require extra inputs
  • - What shader model does your GPU support. New cards support newer Shader Models that allow more 'shader inputs'
Hope that helps!

@Nir
Hi Nir....
I was just wondering if had a chance to look at the problem i mentioned before about having multiple lights and PSSM shadows enabled. I have been trying to find a solution but i am not sure RTSS in its current state can do this. At the moment the shadow is applied to the combined lighting value, instead of affecting a single light. I think the RTSS needs to be expanded so all light values are combined at the end, that is fairly simple i think! However i can not work out how would know what light value you should apply the shadow to.

If you have any thoughts please let me know!
User avatar
syedhs
Silver Sponsor
Silver Sponsor
Posts: 2703
Joined: Mon Aug 29, 2005 3:24 pm
Location: Kuala Lumpur, Malaysia
x 51

Re: RT Shader System Component (RTSS)

Post by syedhs »

al,

Thanks for the reply. Yeah.. it is obvious that the 'shader requested' exceed the maximum allowed. Immediately after the previous post, I was looking for way to specify higher shader model but I noticed that 'mMaxTexCoordSlots' is hardcoded to 8 so probably it is of no use - correct me if I am wrong... So if that is true, is it any desirable (read: feature request :mrgreen: ) to be able to specify shader model for both vs & ps, and therefore influence the maximum texture coordinate slots?

As for my scene, there are two kind of them in my software. One which uses PSSM3 shadow (so three splits) + two spotlights which come from a vehicle. Another type of scene is no shadow but lots of spotlights (many cars which has spotlights turned on).

Btw, is there an RTS function to dump the exact shader code to text file? I can take a look and figure out something...
A willow deeply scarred, somebody's broken heart
And a washed-out dream
They follow the pattern of the wind, ya' see
Cause they got no place to be
That's why I'm starting with me
al2950
OGRE Expert User
OGRE Expert User
Posts: 1227
Joined: Thu Dec 11, 2008 7:56 pm
Location: Bristol, UK
x 157

Re: RT Shader System Component (RTSS)

Post by al2950 »

@syedhs

RTSS always selects the highest supported SM, however i think you can force it to a certain one if you want.

If you set the shader cache path it will write the shaders to file for you
ie.

Code: Select all

Ogre::RTShader::ShaderGenerator::getSingletonPtr()->setShaderCachePath("c:/shaderCachePath");	
User avatar
Nir Hasson
OGRE Retired Team Member
OGRE Retired Team Member
Posts: 363
Joined: Wed Nov 05, 2008 4:40 pm
Location: TLV - Israel
x 2
Contact:

Re: RT Shader System Component (RTSS)

Post by Nir Hasson »

Hi Guys -
I did some digging regarding RTSS and multiple light shadow caster sources and managed to make it work.
Attached here is a screenshot of the tweaked Shader System sample with two shadow caster lights: directional and spotlight.
Directional+Spotlight casters
Directional+Spotlight casters
The result is far from being fine but that is because I didn’t fine tuned the shadow camera setup, I just used the PSSMShadowCameraSetup without any specific modification or even parametric modifications.

The main steps that one should follow in order to enable multiple light casters are:
1. Make sure each light that should cast shadow has this property set to true (Daaa).
2. Make sure each light caster type have 3 shadow textures.

Code: Select all

mSceneMgr->setShadowTextureCountPerLightType(Ogre::Light::LT_DIRECTIONAL, 3);
mSceneMgr->setShadowTextureCountPerLightType(Ogre::Light::LT_SPOTLIGHT, 3);
.
3. Make sure that the total amount of shadow textures is valid. I.E if you have two types of lights that cast shadows and you use PSSM with 3 splits you should have at least 6 shadow textures totally.

Code: Select all

mSceneMgr->setShadowTextureSettings(512, 6, PF_FLOAT32_R);

The current implementation of the IntegratedPSSM3 sub render state is limited to be hosted in single light pass, that means that each material should be converted into multi-pass rendering technique (I.E additive lighting).
Attached here is the material script I used for the sample.
Note that I included dedicated pass for each light source type.

Code: Select all

material RTSS/PerPixel_PSSMTest
{
	technique
	{
		scheme SrcTechnique
		
		// Base ambient pass
		pass ambient
		{
			// base colours, not needed for rendering, but as information
			// to lighting pass categorisation routine
			ambient 1 1 1
			diffuse 0 0 0 
			specular 0 0 0 0 
			
			// RT Shader system section.			
 			rtshader_system Default
 			{	
 				// Override dynamic light count with zero light count.
 				// Doing this will cause the RTSS to create 
 				// ambient lighting shaders.
 				// If not doing that the RTSS it will use the current scene light count
 				// which will result in full lighting calculation in this pass.
				light_count 0 0 0
			}
		}
		
		// Lighting pass.
		pass lighting_d
		{			
			// base colours, not needed for rendering, but as information
			// to lighting pass categorisation routine
			ambient 0 0 0 
						
			iteration once_per_light directional

			scene_blend add		
			
			// RT Shader system section.
 			rtshader_system Default
 			{	 	
 				integrated_pssm4 5 64 300 1800
 				
 			}			
		}	
		
		// Lighting pass.
		pass lighting_p
		{			
			// base colours, not needed for rendering, but as information
			// to lighting pass categorisation routine
			ambient 0 0 0 
						
			iteration once_per_light point

			scene_blend add		
			
			// RT Shader system section.
 			rtshader_system Default
 			{	 
 				integrated_pssm4 5 64 300 1800
 				
 			}			
		}
		
		// Lighting pass.
		pass lighting_s
		{			
			// base colours, not needed for rendering, but as information
			// to lighting pass categorisation routine
			ambient 0 0 0 
			
			// do this for each point light
			// You MUST specify the light type when working with the RT Shader System in iterative lighting method. 
			// otherwise an exception will be thrown.
			iteration once_per_light spot

			scene_blend add		
			
			// RT Shader system section.
 			rtshader_system Default
 			{	 
 				integrated_pssm4 5 64 300 1800	
 				
 			}			
		}		
		
		// Decal pass
		pass decal
		{
			
			lighting off
			
			scene_blend dest_colour zero
			texture_unit decalmap
			{
				texture Panels_Diffuse.png
			}
			
			// RT Shader system section.
 			rtshader_system Default
 			{
 				 	
 			}			
		}							
	}
}

BTW: Note that I specified the scheme name of the main technique to be SrcTechnique and that the scheme name of the rtshader_system section defined to Default.
This way the given technique will be converted immediately to shader based technique using the default viewport settings.
Hope this will help you with the system needs.
Another option is to extend the IntegratedPSS3 sub render state to support multiple light casters, but practically speaking I think it won't worth it since it will use 6 textures slots just for the shadow maps themselves, and I even didn't count the amount of output regs from the VS for each light...
User avatar
Assaf Raman
OGRE Team Member
OGRE Team Member
Posts: 3092
Joined: Tue Apr 11, 2006 3:58 pm
Location: TLV, Israel
x 76

Re: RT Shader System Component (RTSS)

Post by Assaf Raman »

Nice work.
Watch out for my OGRE related tweets here.
User avatar
syedhs
Silver Sponsor
Silver Sponsor
Posts: 2703
Joined: Mon Aug 29, 2005 3:24 pm
Location: Kuala Lumpur, Malaysia
x 51

Re: RT Shader System Component (RTSS)

Post by syedhs »

Very nice nir, does this get added to 1.7 (I guess only trunk get modified)..

Well I just noticed one thing - the reason why I didn't get shader program written in the shader cache path. It is because I didn't include the slash (forward or backward) as the last char in the argument:-

Code: Select all

// doesn't work!
RTShader::ShaderGenerator::getSingleton().setShaderCachePath("./scene/cache");
// okay work...
RTShader::ShaderGenerator::getSingleton().setShaderCachePath("./scene/cache/");
So I thought I will just make it more robust by modifying setShaderCachePath to the following...

Code: Select all

void ShaderGenerator::setShaderCachePath( const String& cachePath )
{
	String copyCachePath = StringUtil::standardisePath(cachePath);
        if (mShaderCachePath != copyCachePath)
        ... from now on.. use copyCachePath
}
The nice thing about StringUtil::standardisePath is it will convert back slash to forward slash and append a forward slash at the end.
So the function is going to be less picky about your path unless if you supply the wrong one ;)
A willow deeply scarred, somebody's broken heart
And a washed-out dream
They follow the pattern of the wind, ya' see
Cause they got no place to be
That's why I'm starting with me
al2950
OGRE Expert User
OGRE Expert User
Posts: 1227
Joined: Thu Dec 11, 2008 7:56 pm
Location: Bristol, UK
x 157

Re: RT Shader System Component (RTSS)

Post by al2950 »

Thanks Nir

However, all I want is to a single shadow caster and another light in the scene, which will fit into the number of available slots. Another pass is a bit overkill for what i need. Is it possible to update the PSSM renderState to cope with multiple lights (not multiple shadow casting lights), or is that just not possible!!

Cheers :D
User avatar
Nir Hasson
OGRE Retired Team Member
OGRE Retired Team Member
Posts: 363
Joined: Wed Nov 05, 2008 4:40 pm
Location: TLV - Israel
x 2
Contact:

Re: RT Shader System Component (RTSS)

Post by Nir Hasson »

@syedhs -

I have to admit that I also fall into this one time after time.. :D
Your suggestion accepted - just commit it to trunk..

@al

As far as I know it should work - you can test by modifying the sahder system sample, when turn the PSSM on simply modify the spot light box to
mSpotLightCheckBox->setChecked(true);
That way you'll have one directional light that cast shadow + spot light that doesn't in a single pass.
I didn't tested deeply but from a short overview it looks fine...
al2950
OGRE Expert User
OGRE Expert User
Posts: 1227
Joined: Thu Dec 11, 2008 7:56 pm
Location: Bristol, UK
x 157

Re: RT Shader System Component (RTSS)

Post by al2950 »

I have very quickly changed the RTSS sample as you said to show my problem. As you can see the spotlight has been shadowed when it should not be, because the shadow is applied to the combined light colour of lights in that pass
Attachments
screenshot10252010_172819299.jpg
User avatar
Nir Hasson
OGRE Retired Team Member
OGRE Retired Team Member
Posts: 363
Joined: Wed Nov 05, 2008 4:40 pm
Location: TLV - Israel
x 2
Contact:

Re: RT Shader System Component (RTSS)

Post by Nir Hasson »

Ok - I Got you now..

In order to fix this issue the IntegratedPSSM3 SubRenderState should apply the shadow factor only on the shadow caster lights diffuse/specular terms.
When using per-vertex lighting (I.E the FFP) the lighting are computed on the VS stage and since the shadowing is done in the PS stage separating the lighting terms requires splitting the output vertex shader color to multiple channels - so I think we'll skip this one.
On per-pixel lighting models this is simple task, but it require the IntegratedPSSM3 SubRenderState to be aware of the internal function invocation order of the lighting SubRenderState.
I thought about some kind of callback mechanism that will allow such tasks to be done without deep coupling of the stages, but unfortunately such a mechanism still lay on the paper...
This is output FS of the ground plane when using per pixel lighting and two lights with shadow on:

Code: Select all

//-----------------------------------------------------------------------------
// Function Name: main
// Function Desc: Pixel Program Entry point
//-----------------------------------------------------------------------------
void main
	(
	 in float3	iTexcoord3_0 : TEXCOORD0, 
	 in float3	iTexcoord3_1 : TEXCOORD1, 
	 in float2	iTexcoord2_2 : TEXCOORD2, 
	 in float	iTexcoord1_3 : TEXCOORD3, 
	 in float4	iTexcoord4_4 : TEXCOORD4, 
	 in float4	iTexcoord4_5 : TEXCOORD5, 
	 in float4	iTexcoord4_6 : TEXCOORD6, 
	 out float4	oColor_0 : COLOR
	)
{
	float4	lLocalParam_0;
	float4	lLocalParam_1;
	float4	lPerPixelDiffuse;
	float4	texel;
	float4	source1;
	float4	source2;
	float	lShadowFactor;

	FFP_Construct(1.0, 1.0, 1.0, 1.0, lLocalParam_0);

	FFP_Construct(0.0, 0.0, 0.0, 0.0, lLocalParam_1);

	FFP_Assign(lLocalParam_0, oColor_0);

	FFP_Assign(derived_scene_colour, lPerPixelDiffuse);

	SGX_Light_Directional_Diffuse(iTexcoord3_0, light_direction_view_space0.xyz, derived_light_diffuse1.xyz, lPerPixelDiffuse.xyz, lPerPixelDiffuse.xyz);

	SGX_Light_Spot_Diffuse(iTexcoord3_0, iTexcoord3_1, light_position_view_space2.xyz, light_direction_view_space3.xyz, light_attenuation4, spotlight_params0, derived_light_diffuse5.xyz, lPerPixelDiffuse.xyz, lPerPixelDiffuse.xyz);

	FFP_Assign(lPerPixelDiffuse, lLocalParam_0);

	FFP_Assign(lLocalParam_0, oColor_0);

	SGX_ComputeShadowFactor_PSSM3(iTexcoord1_3, pssm_split_points6, iTexcoord4_4, iTexcoord4_5, iTexcoord4_6, shadow_map1, shadow_map2, shadow_map3, inv_shadow_texture_size7, inv_shadow_texture_size8, inv_shadow_texture_size9, lShadowFactor);

	SGX_ApplyShadowFactor_Diffuse(derived_scene_colour, lLocalParam_0, lShadowFactor, lLocalParam_0);

	SGX_ModulateScalar(lShadowFactor, lLocalParam_1, lLocalParam_1);

	FFP_Assign(lLocalParam_0, oColor_0);

	FFP_SampleTexture(gTextureSampler0, iTexcoord2_2, texel);

	FFP_Assign(texel, source1);

	FFP_Assign(lLocalParam_0, source2);

	FFP_Modulate(source1, source2, oColor_0);

	FFP_Add(oColor_0.xyz, lLocalParam_1.xyz, oColor_0.xyz);
}
The right shader that will do what you are looking for is

Code: Select all

//-----------------------------------------------------------------------------
// Function Name: main
// Function Desc: Pixel Program Entry point
//-----------------------------------------------------------------------------
void main
	(
	 in float3	iTexcoord3_0 : TEXCOORD0, 
	 in float3	iTexcoord3_1 : TEXCOORD1, 
	 in float2	iTexcoord2_2 : TEXCOORD2, 
	 in float	iTexcoord1_3 : TEXCOORD3, 
	 in float4	iTexcoord4_4 : TEXCOORD4, 
	 in float4	iTexcoord4_5 : TEXCOORD5, 
	 in float4	iTexcoord4_6 : TEXCOORD6, 
	 out float4	oColor_0 : COLOR
	)
{
	float4	lLocalParam_0;
	float4	lLocalParam_1;
	float4	lPerPixelDiffuse;
	float4	texel;
	float4	source1;
	float4	source2;
	float	lShadowFactor;

	FFP_Construct(1.0, 1.0, 1.0, 1.0, lLocalParam_0);

	FFP_Construct(0.0, 0.0, 0.0, 0.0, lLocalParam_1);

	FFP_Assign(lLocalParam_0, oColor_0);

	SGX_ComputeShadowFactor_PSSM3(iTexcoord1_3, pssm_split_points6, iTexcoord4_4, iTexcoord4_5, iTexcoord4_6, shadow_map1, shadow_map2, shadow_map3, inv_shadow_texture_size7, inv_shadow_texture_size8, inv_shadow_texture_size9, lShadowFactor);

	

	FFP_Assign(derived_scene_colour, lPerPixelDiffuse);

	SGX_Light_Directional_Diffuse(iTexcoord3_0, light_direction_view_space0.xyz, derived_light_diffuse1.xyz, lPerPixelDiffuse.xyz, lPerPixelDiffuse.xyz);

        SGX_ApplyShadowFactor_Diffuse(derived_scene_colour, lPerPixelDiffuse, lShadowFactor, lPerPixelDiffuse);

	SGX_Light_Spot_Diffuse(iTexcoord3_0, iTexcoord3_1, light_position_view_space2.xyz, light_direction_view_space3.xyz, light_attenuation4, spotlight_params0, derived_light_diffuse5.xyz, lPerPixelDiffuse.xyz, lPerPixelDiffuse.xyz);

	FFP_Assign(lPerPixelDiffuse, lLocalParam_0);

	FFP_Assign(lLocalParam_0, oColor_0);

	SGX_ModulateScalar(lShadowFactor, lLocalParam_1, lLocalParam_1);

	FFP_Assign(lLocalParam_0, oColor_0);

	FFP_SampleTexture(gTextureSampler0, iTexcoord2_2, texel);

	FFP_Assign(texel, source1);

	FFP_Assign(lLocalParam_0, source2);

	FFP_Modulate(source1, source2, oColor_0);

	FFP_Add(oColor_0.xyz, lLocalParam_1.xyz, oColor_0.xyz);
}


Another solution I can think about is to create explicit local shadow coeff parameter for each light that will be initialized to 1 by default, then force each lighting sub render to take this factor into account when doing the lighting calculations..

Any other ideas/solutions are welcome - I hope I can get to it since I'm quite busy with my start-up lately... 8)
al2950
OGRE Expert User
OGRE Expert User
Posts: 1227
Joined: Thu Dec 11, 2008 7:56 pm
Location: Bristol, UK
x 157

Re: RT Shader System Component (RTSS)

Post by al2950 »

Exactly!! I am glad it was not just me being stupid!

I did think about slightly it differently though. My plan was to change how the lighting shader is created. I was going to create a local parameter for each light calculation, and combine them at a later stage. That way it is a bit more 'open' so developers can add other renderstates that affect specific lights in a single pass.

**Edit** Started to write shader code example but confused myself. :oops: Food for thought anyway!!
al2950
OGRE Expert User
OGRE Expert User
Posts: 1227
Joined: Thu Dec 11, 2008 7:56 pm
Location: Bristol, UK
x 157

Re: RT Shader System Component (RTSS)

Post by al2950 »

The PSSM shadows seemed to have stopped working. It seemed to happen when the new instanced viewports were added.
User avatar
Assaf Raman
OGRE Team Member
OGRE Team Member
Posts: 3092
Joined: Tue Apr 11, 2006 3:58 pm
Location: TLV, Israel
x 76

Re: RT Shader System Component (RTSS)

Post by Assaf Raman »

I will have a look.
Watch out for my OGRE related tweets here.
User avatar
Assaf Raman
OGRE Team Member
OGRE Team Member
Posts: 3092
Joined: Tue Apr 11, 2006 3:58 pm
Location: TLV, Israel
x 76

Re: RT Shader System Component (RTSS)

Post by Assaf Raman »

The PSSM in the trunk should work now.
Watch out for my OGRE related tweets here.
al2950
OGRE Expert User
OGRE Expert User
Posts: 1227
Joined: Thu Dec 11, 2008 7:56 pm
Location: Bristol, UK
x 157

Re: RT Shader System Component (RTSS)

Post by al2950 »

Thanks Assaf.

I have another strange issue which i would like you to confirm please. It is easily noticeable in the sample app with PSSM shadows enabled. Basically the shadows completely mess up, i was hoping it was an intermittent bug or my machine messing up, but can you please confirm. It happens when you rotate the camera around 180 degrees to face away from the shapes. You will notice the plane floor will have some very messy shadows, like this;
Attachments
screenshot11082010_153642182.jpg
User avatar
Assaf Raman
OGRE Team Member
OGRE Team Member
Posts: 3092
Joined: Tue Apr 11, 2006 3:58 pm
Location: TLV, Israel
x 76

Re: RT Shader System Component (RTSS)

Post by Assaf Raman »

confirm. note - this is not related to my changes.
Watch out for my OGRE related tweets here.
al2950
OGRE Expert User
OGRE Expert User
Posts: 1227
Joined: Thu Dec 11, 2008 7:56 pm
Location: Bristol, UK
x 157

Re: RT Shader System Component (RTSS)

Post by al2950 »

Grumble.... its in 1.7 as well! I have a look into it!
User avatar
Wolfmanfx
OGRE Team Member
OGRE Team Member
Posts: 1525
Joined: Fri Feb 03, 2006 10:37 pm
Location: Austria - Leoben
x 99
Contact:

Re: RT Shader System Component (RTSS)

Post by Wolfmanfx »

Hi,

I have problem regarding normal mapping with rtss this is the material

Code: Select all

abstract material baseMat
{

	technique
	{
		pass
		{
                                    //specular 1.0 1.0 1.0 32
			texture_unit
			{
				filtering anisotropic
                max_anisotropy 16
				texture myTex.png
				scroll $scrollAttr
                scale 8 8
			}
			// RT Shader system section.
 			rtshader_system
 			{	 	
 				// Override lighting stage with normal map lighting.
 				lighting_stage normal_map myTex_NRM.png tangent_space 0 bilinear 1 -1.0
 			}	
		}
	}
}
The problem is that myTex.png is a texture atlas so i am using scroll/scale which works out of the box with rtss the problem is that this factors are not applied to the normal map lookup. Maybe someone can point into the right direction where the right place is.
-----------------
Also i played a little bit with the PSSM rtss sample and its lacking of discarding of transparent fragments. This works for HLSL:

Code: Select all

void shadow_caster_vs(
	float4 position		: POSITION,
	float2 uv          	: TEXCOORD0,
	out float4 oPosition	: POSITION,
	out float2 oDepth	: TEXCOORD0,
	out float2 outUV      	: TEXCOORD1,
	uniform float4x4 wvpMat)
{
	// this is the view space position
	oPosition = mul(wvpMat, position);

	// depth info for the fragment.
	oDepth.x = oPosition.z;
	oDepth.y = oPosition.w;

	outUV = uv;
}

void shadow_caster_ps(
	float2 depth			: TEXCOORD0,
	float2 uv         		: TEXCOORD1,
	uniform sampler2D diffuseMap 	: register(s0),
	out float4 oColour		: COLOR,
	uniform float4 pssmSplitPoints)
{
	float finalDepth = depth.x / depth.y;
	oColour = float4(finalDepth, finalDepth, finalDepth, 1);

	float alpha = tex2D(diffuseMap,uv).a;
	if (alpha < 0.01)
   	{   
   		discard;
    	}
}

User avatar
Wolfmanfx
OGRE Team Member
OGRE Team Member
Posts: 1525
Joined: Fri Feb 03, 2006 10:37 pm
Location: Austria - Leoben
x 99
Contact:

Re: RT Shader System Component (RTSS)

Post by Wolfmanfx »

Here the vertex shader and pixel shader

Code: Select all

//-----------------------------------------------------------------------------
// Program Type: Vertex shader
// Language: hlsl
// Created by Ogre RT Shader Generator. All rights reserved.
//-----------------------------------------------------------------------------

//-----------------------------------------------------------------------------
//                         PROGRAM DEPENDENCIES
//-----------------------------------------------------------------------------
#include "FFPLib_Transform.hlsl"
#include "FFPLib_Common.hlsl"
#include "SGXLib_NormalMapLighting.hlsl"
#include "FFPLib_Texturing.hlsl"

//-----------------------------------------------------------------------------
//                         GLOBAL PARAMETERS
//-----------------------------------------------------------------------------

float4x4	worldviewproj_matrix;
float4	light_direction_obj_space0;
float4x4	texture_matrix;
float4x4	world_texture_view_proj0;
float4x4	world_texture_view_proj1;
float4x4	world_texture_view_proj2;

//-----------------------------------------------------------------------------
// Function Name: main
// Function Desc: Vertex Program Entry point
//-----------------------------------------------------------------------------
void main
	(
	 in float4	iPos_0 : POSITION, 
	 in float3	iNormal_0 : NORMAL, 
	 in float3	iTangent_0 : TANGENT0, 
	 in float2	iTexcoord2_0 : TEXCOORD0, 
	 out float4	oPos_0 : POSITION, 
	 out float2	oTexcoord2_0 : TEXCOORD0, 
	 out float3	oTexcoord3_1 : TEXCOORD1, 
	 out float2	oTexcoord2_2 : TEXCOORD2, 
	 out float	oTexcoord1_3 : TEXCOORD3, 
	 out float4	oTexcoord4_4 : TEXCOORD4, 
	 out float4	oTexcoord4_5 : TEXCOORD5, 
	 out float4	oTexcoord4_6 : TEXCOORD6
	)
{
	float4	lLocalParam_0;
	float4	lLocalParam_1;
	float3x3	lMatTBN;

	FFP_Transform(worldviewproj_matrix, iPos_0, oPos_0);

	FFP_Construct(1.0, 1.0, 1.0, 1.0, lLocalParam_0);

	FFP_Construct(0.0, 0.0, 0.0, 0.0, lLocalParam_1);

	SGX_ConstructTBNMatrix(iNormal_0, iTangent_0, lMatTBN);

	FFP_Assign(iTexcoord2_0, oTexcoord2_0);

	SGX_TransformNormal(lMatTBN, light_direction_obj_space0.xyz, oTexcoord3_1);

	FFP_TransformTexCoord(texture_matrix, iTexcoord2_0, oTexcoord2_2);

	FFP_Assign(oPos_0.z, oTexcoord1_3);

	FFP_Transform(world_texture_view_proj0, iPos_0, oTexcoord4_4);

	FFP_Transform(world_texture_view_proj1, iPos_0, oTexcoord4_5);

	FFP_Transform(world_texture_view_proj2, iPos_0, oTexcoord4_6);
}

Code: Select all

//-----------------------------------------------------------------------------
// Program Type: Fragment shader
// Language: hlsl
// Created by Ogre RT Shader Generator. All rights reserved.
//-----------------------------------------------------------------------------

//-----------------------------------------------------------------------------
//                         PROGRAM DEPENDENCIES
//-----------------------------------------------------------------------------
#include "FFPLib_Common.hlsl"
#include "SGXLib_NormalMapLighting.hlsl"
#include "FFPLib_Texturing.hlsl"
#include "SGXLib_IntegratedPSSM.hlsl"

//-----------------------------------------------------------------------------
//                         GLOBAL PARAMETERS
//-----------------------------------------------------------------------------

sampler2D	gNormalMapSampler1 : register(s1);
float4	derived_ambient_light_colour;
float4	surface_diffuse_colour;
float4	surface_specular_colour;
float4	surface_emissive_colour;
float4	derived_scene_colour;
float	surface_shininess;
float4	derived_light_diffuse0;
sampler2D	gTextureSampler0 : register(s0);
float4	pssm_split_points1;
sampler2D	shadow_map2 : register(s2);
float4	inv_shadow_texture_size2;
sampler2D	shadow_map3 : register(s3);
float4	inv_shadow_texture_size3;
sampler2D	shadow_map4 : register(s4);
float4	inv_shadow_texture_size4;

//-----------------------------------------------------------------------------
// Function Name: main
// Function Desc: Pixel Program Entry point
//-----------------------------------------------------------------------------
void main
	(
	 in float2	iTexcoord2_0 : TEXCOORD0, 
	 in float3	iTexcoord3_1 : TEXCOORD1, 
	 in float2	iTexcoord2_2 : TEXCOORD2, 
	 in float	iTexcoord1_3 : TEXCOORD3, 
	 in float4	iTexcoord4_4 : TEXCOORD4, 
	 in float4	iTexcoord4_5 : TEXCOORD5, 
	 in float4	iTexcoord4_6 : TEXCOORD6, 
	 out float4	oColor_0 : COLOR
	)
{
	float4	lLocalParam_0;
	float4	lLocalParam_1;
	float3	lLocalParam_2;
	float4	lNormalMapDiffuse;
	float4	texel;
	float4	source1;
	float4	source2;
	float	lShadowFactor;

	FFP_Construct(1.0, 1.0, 1.0, 1.0, lLocalParam_0);

	FFP_Construct(0.0, 0.0, 0.0, 0.0, lLocalParam_1);

	FFP_Assign(lLocalParam_0, oColor_0);

	SGX_FetchNormal(gNormalMapSampler1, iTexcoord2_0, lLocalParam_2);

	FFP_Assign(derived_scene_colour, lNormalMapDiffuse);

	SGX_Light_Directional_Diffuse(lLocalParam_2, iTexcoord3_1.xyz, derived_light_diffuse0.xyz, lNormalMapDiffuse.xyz, lNormalMapDiffuse.xyz);

	FFP_Assign(lNormalMapDiffuse, lLocalParam_0);

	FFP_Assign(lLocalParam_0, oColor_0);

	SGX_ComputeShadowFactor_PSSM3(iTexcoord1_3, pssm_split_points1, iTexcoord4_4, iTexcoord4_5, iTexcoord4_6, shadow_map2, shadow_map3, shadow_map4, inv_shadow_texture_size2, inv_shadow_texture_size3, inv_shadow_texture_size4, lShadowFactor);

	SGX_ApplyShadowFactor_Diffuse(derived_scene_colour, lLocalParam_0, lShadowFactor, lLocalParam_0);

	SGX_ModulateScalar(lShadowFactor, lLocalParam_1, lLocalParam_1);

	FFP_Assign(lLocalParam_0, oColor_0);

	FFP_SampleTexture(gTextureSampler0, iTexcoord2_2, texel);

	FFP_Assign(texel, source1);

	FFP_Assign(lLocalParam_0, source2);

	FFP_Modulate(source1, source2, oColor_0);

	FFP_Add(oColor_0.xyz, lLocalParam_1.xyz, oColor_0.xyz);
}
So the problem is that SGX_FetchNormal is using iTexcoord2_0 which is the unmodified texCoordSet but it should use iTexcoord2_2 (this one is multiplied with the texturematrix). So the main issue that rtss generates iTexcoord2_2 instead of overwriting iTexcoord2_0 (i mean the mult result with the texMatrix).

So what todo here?
User avatar
Nir Hasson
OGRE Retired Team Member
OGRE Retired Team Member
Posts: 363
Joined: Wed Nov 05, 2008 4:40 pm
Location: TLV - Israel
x 2
Contact:

Re: RT Shader System Component (RTSS)

Post by Nir Hasson »

@Wolfman -

Regarding the shadow caster, you are right but it is out of the RTSS scope, i think it worth adding the transparent caster to the PSSM caster material file of Ogre as well.

Regarding the normal map issue, from a fast overview of the code I found out that the texturing stage assign the output VS texcoord content with the unknown type by default, and modify it to be texture coordinate only in case that no transform matrix applied.

Code: Select all

Parameter::Content texCoordContent = Parameter::SPC_UNKNOWN;
....

	if (textureUnitParams->mTextureMatrix.get() == NULL)
				texCoordContent = Parameter::Content(Parameter::SPC_TEXTURE_COORDINATE0 + textureUnitParams->mTextureUnitState->getTextureCoordSet());

I think that removing the condition of no texture matrix will do the trick for you because the normal map lighting stage looks for VS output with content of texture coordinates.
However I can't remember right now if there is a reason for that... 8)
Let me know if this fix the problem...
Post Reply