[DX11]Defferd Rendering

Started by
3 comments, last by Tordin 12 years, 8 months ago
Hello!

Im working with Defferd rendering and i stumbeld on a wierd problem.

When i am using my own engine i cant get defferd rendering to work, EA, i cant seem to calulate the values right.
and i dont know in which end it could be lying it.

First tought was that i dident send the values to the shader correct. i lookt at pix and it told me that i acctualy did.
Then i tought it was somthing with my equation, and no, it´s not, i have calulated it over ten times.
Then i tought maybe it got somthing to do with my G-Buffer? and here is where i am right now.
when i did this the last time i saved the postion in world space, thats what im doing right now. but i still get wierd values.
Unforunelty i cant debug the pixel in PIX since it crashes every time i try to debug something there... o_O

When i am using another engine i get it working right away...

So internetZ, do you have any advice or clues?
"There will be major features. none to be thought of yet"
Advertisement
If you render the GBuffer outputs to the screen (or save them to file), do you see anything wrong with them? Try posting your code or render output here... someone might catch the bug.
true true!

Here is the code for rendering the G buffer
[source]

VS_OUTPUT VS_NormalMapped( VS_INPUT IN )
{
VS_OUTPUT OUT;

float4 viewPos = mul(IN.imWorld,float4(IN.Position.xyz,1.0));
OUT.Position = viewPos;
OUT.Normal = IN.Normal;
OUT.UV = IN.UV;
viewPos = mul(g_MatrixView,viewPos);
OUT.Depth = abs((viewPos.z - 0.1f) / ( 128.0f - 0.1f));

return OUT;
}


//////////////////////////////////////////////////////////////////////////
//HULL & DOMAIN SHADERS
///////////////////////////////////////////////////////////////////////////

HS_CONSTANT_DATA_OUTPUT ConstantHS( InputPatch<VS_OUTPUT, 3> ip,uint PatchID : SV_PrimitiveID )
{
HS_CONSTANT_DATA_OUTPUT Output;
float2 UV = (ip[0].UV + ip[1].UV + ip[2].UV) / 3;
float TessFac = 1;
Output.Edges[0] = Output.Edges[1] = Output.Edges[2] = TessFac;
Output.Inside = TessFac;
return Output;
}

[domain("tri")]
[partitioning("fractional_odd")]
[outputtopology("triangle_cw")]
[outputcontrolpoints(3)]
[patchconstantfunc("ConstantHS")]
HS_OUTPUT HS( InputPatch<VS_OUTPUT, 3> IN,uint i : SV_OutputControlPointID,
uint PatchID : SV_PrimitiveID )
{
HS_OUTPUT OUT;
OUT.Position = IN.Position;
OUT.Normal = IN.Normal;
OUT.UV = IN.UV;
OUT.Depth = IN.Depth;
return OUT;

}

[domain("tri")]
DS_OUTPUT DS( HS_CONSTANT_DATA_OUTPUT input,float3 UV : SV_DomainLocation,const OutputPatch<HS_OUTPUT, 3> quad )
{
DS_OUTPUT Output;
//Calculate the new position
float time = 0.0f;
float3 finalPos = ( UV.x * quad[0].Position + UV.y * quad[1].Position + UV.z * quad[2].Position );
float finalDepth = ( UV.x * quad[0].Depth + UV.y * quad[1].Depth + UV.z * quad[2].Depth );
float3 finalNormal = ( UV.x * quad[0].Normal + UV.y * quad[1].Normal + UV.z * quad[2].Normal );
float3 normal = normalize(finalNormal);
float2 uv = ( UV.x * quad[0].UV + UV.y * quad[1].UV + UV.z * quad[2].UV );
float4 dis = color.SampleLevel(SamplerStateAnisoWrap, uv + time, 1);

//finalPos = finalPos + (normal * df);
Output.Position = mul( g_MatrixViewProj, float4(finalPos,1.0) );
Output.UV = uv;
Output.Normal = normal;
Output.Depth = finalDepth;
return Output;
}


PS_OUTPUT PS_NormalMapped( VS_OUTPUT IN )
{
PS_OUTPUT OUT;
float4 TexColor = color.Sample( SamplerStateAnisoWrap, IN.UV );
float3 Color = TexColor.rgb;

OUT.Color = float4( Color, 1.0 );
OUT.Depth = float4( IN.Depth,0.0,0.0,0.0 );
OUT.Pos = IN.Position;
OUT.Normal = float4(IN.Normal,1.0);

return OUT;
}
[/source]
"There will be major features. none to be thought of yet"
One more thing... can you explain in detail what the problem is? Showing a screenshot of desired output versus your engine's output will help (since you said you can get it working on other engines).

One more thing... can you explain in detail what the problem is? Showing a screenshot of desired output versus your engine's output will help (since you said you can get it working on other engines).


I gona explain the problem in code ;)

[source]

PS_OUTPUT PS_MAIN(VS_OUTPUT IN)
{
PS_OUTPUT OUT;
float3 texColor = tex0.Sample(SamplerStateAnisoWrap, IN.UV).xyz;
float3 texPosition = tex2.Sample(SamplerStateAnisoWrap, IN.UV).xyz;
float3 texNormal = tex3.Sample(SamplerStateAnisoWrap, IN.UV).xyz;
float3 color = texColor * 0.2;
for(int i = 0; i<g_NumLights; ++i)
{
float3 lightPos = g_LightPos;
float3 vec = texPosition - lightPos;
float vecLength = dot(vec,vec);
float intensity = 1.0 - saturate(vecLength / (g_LightRange * g_LightRange) );
color += texColor * intensity;
}
OUT.Color = float4(color,1.0);
return OUT;
}
[/source]

intensity will become zero.
And here is an explanation behind the entire equation.

1 : Get the postion from the texture
2 : Get the position from the light.
3 : Get a direction vector
4 : Get the length^2
5 : divide the length^2 by the max range^2 (of the light) (then we will get a value from 0->1 if the light is in range and 1->inf if the light is out of range)
6 : saturate this value so it rages from 0->1
7 : subtract one to get the less values futher away.
8 : add the color multiplyed by the intesity we calculated.

And this works for the other engine..
"There will be major features. none to be thought of yet"

This topic is closed to new replies.

Advertisement