Sign in to follow this  
mrshooter

Problem with ShadowMap test using FX Composer

Recommended Posts

It's my first time to use FX Composer and I try to make a shadow map test.
Unfortunately, the result is wrong
[img]http://uploads.gamedev5.net/gallery/album_196/gallery_0_196_52854.png[/img]
and I got the warning message in the 'Tast' tab:
[code]Warning Effect uses script commands on an object effect instead of a pre or post processing effect...[/code]
what does this mean, does it lead the wrong result?

Before i paste my fx code, someone please tell me what's the 'EvaluateScene' -> 'Render' node for? I try to use it to render the scene but the result is wrong too. Shall I use it to test the shaders?

[code]
// global definition
#define SHADOW_SIZE 512
#define SHADOW_FMT "r32f"

// matrices
float4x4 gWVP : WorldViewProjection;

float4x4 gWorldView : WorldView;

float4x4 gProj : Projection;

float4x4 gViewInv : ViewInverse;

float4x4 gLampViewXf : View <
string UIName = "Lamp View Xform";
//string UIWidget="None";
string Object = "DirectionalLight0";
>;

float4x4 gLampProjXf : Projection <
string UIName = "Lamp Projection Xform";
//string UIWidget="None";
string Object = "DirectionalLight0";
>;

// textures
texture gShadMap : RENDERCOLORTARGET <
float2 Dimensions = { SHADOW_SIZE, SHADOW_SIZE };
string Format = (SHADOW_FMT) ;
string UIWidget = "None";
>;
sampler2D gShadSampler = sampler_state {
texture = <gShadMap>;
AddressU = Clamp;
AddressV = Clamp;
MinFilter = Point;
MagFilter = Point;
MipFilter = Point;
};

texture gShadDepthTarget : RENDERDEPTHSTENCILTARGET <
float2 Dimensions = { SHADOW_SIZE, SHADOW_SIZE };
string format = "D24S8";
string UIWidget = "None";
>;

//
float gClearDepth <string UIWidget = "none";> = 1.0;

float4 gShadowClearColor <
string UIName = "Shadow Far BG";
string UIWidget = "none";
> = {1.0,1.0,1.0,0.0};

struct ShadowVertexOutput
{
float4 position : POSITION;
float2 depth : TEXCOORD0;
};

ShadowVertexOutput ShadowVS(float4 pos : POSITION,
float3 normal : NORMAL,
float2 texcoord: TEXCOORD0)
{
ShadowVertexOutput OUT = (ShadowVertexOutput)0;
OUT.position = mul(pos, gLampViewXf);
OUT.position = mul(OUT.position, gLampProjXf);
OUT.depth.xy = OUT.position.zw;
return OUT;
}

float4 ShadowPS(ShadowVertexOutput IN) : COLOR {
float depth = IN.depth.x / IN.depth.y;
return depth;
}

struct UseShadowVertexOutput
{
float4 position : POSITION;
float4 lightPos : TEXCOORD0;
};

UseShadowVertexOutput UseShadowVS(float4 pos : POSITION,
float3 normal : NORMAL,
float2 texcoord: TEXCOORD0)
{
UseShadowVertexOutput OUT = (UseShadowVertexOutput)0;
float4 vpos = mul(pos, gWorldView);
OUT.position = mul(vpos, gProj);

float4x4 viewToLightProj = gViewInv;
viewToLightProj = mul(viewToLightProj, gLampViewXf);
viewToLightProj = mul(viewToLightProj, gLampProjXf);

OUT.lightPos = mul(vpos, viewToLightProj);
return OUT;
}

float4 UseShadowPS(UseShadowVertexOutput IN) : COLOR {
float2 ShadowTexC = 0.5 * IN.lightPos.xy / IN.lightPos.w + float2(0.5, 0.5);
ShadowTexC.y = 1.0f - ShadowTexC.y;

float shadow = (tex2D(gShadSampler, ShadowTexC) + 0.00005f < (IN.lightPos.z / IN.lightPos.w)) ? 0.0f : 1.0f;
return shadow;
}

technique Main<
string Script = "Pass=MakeShadow;"
"Pass=UseShadow;";>
{
pass MakeShadow <
string Script = "RenderColorTarget0=gShadMap;"
"RenderDepthStencilTarget=gShadDepthTarget;"
"RenderPort=DirectionalLight0;"
"ClearSetColor=gShadowClearColor;"
"ClearSetDepth=gClearDepth;"
"Clear=Color;"
"Clear=Depth;"
"Draw=geometry;";
>
{
VertexShader = compile vs_2_0 ShadowVS();
ZEnable = true;
ZWriteEnable = true;
ZFunc = LessEqual;
AlphaBlendEnable = false;
CullMode = None;
PixelShader = compile ps_2_0 ShadowPS();
}

pass UseShadow <string Script = "RenderColorTarget0=;"
"RenderDepthStencilTarget=;"
"RenderPort=;"
"ClearSetColor=gClearColor;"
"ClearSetDepth=gClearDepth;"
"Clear=Color;"
"Clear=Depth;"
"Draw=geometry;";
>
{
VertexShader = compile vs_2_0 UseShadowVS();
ZEnable = true;
ZWriteEnable = true;
ZFunc = LessEqual;
AlphaBlendEnable = false;
CullMode = None;
PixelShader = compile ps_2_0 UseShadowPS();
}
}
[/code]

Let me sum up my question to make it clear:
1) someone plz tell me what's the warning info mean
2) I don't know if it's the right way to use a render target in fx composer, I use this script
[code]string Script = "RenderColorTarget0=gShadMap;" "RenderDepthStencilTarget=gShadDepthTarget;"[/code]
and have no idea if it's ok. please tell me if i'm right.
3) what's the 'EvaluateScene' -> 'Render' node for?
4) what on earth is the problem of this demo?

Many Thanks,
:)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this