Reconstruction from Depth, correct value to reconstruct

Started by
45 comments, last by csisy 12 years, 10 months ago

You said something about 'viewray should be multipled by the word matrix', so i thought that that would be the most appropriate answer.
Didn't really know what you were getting at to be honest.


The way you you and MJP calculate your eyeRay/eyeToPixel is considerably different, I was wondering why you do your the way that you do?


here's my pointlight shader using MJPs method for reconstruction



VS_OUTPUT_LIGHTPASS_INSTANCE vs_lightPass(VS_INPUT_INSTANCE In)
{
In.Pos.xyz *= In.insPos.w;
In.Pos.xyz += In.insPos.xyz;
Out.vEyeRay = In.Pos.xyz - camPos.xyz;
}

PS_output ps_pointLight(in VS_OUTPUT_LIGHTPASS_INSTANCE In )
{
const float3 eyeToPixel = normalize(In.vEyeRay.xyz);
}




MJPS

VS_OUTPUT VS( VS_INPUT Input )
{
float4 positionScaled = float4(Input.PositionOS * Scale, 1.0f);
Output.PositionWS = mul(positionScaled, World).xyz;
Output.ViewRay = Output.PositionWS - CameraPosWS;

return Output;
}

PS_OUTPUT_RECONSTRUCT PSReconstructLinear(PS_INPUT Input)
{
float3 viewRay = normalize(Input.ViewRay);
float3 positionWS = CameraPosWS + viewRay * depth;
return output;
}



So have you found your error?


Not yet unfortunately
Advertisement
Are there any other suggestions?
Can anyone provide any suggestions?

The way you you and MJP calculate your eyeRay/eyeToPixel is considerably different, I was wondering why you do your the way that you do?


It isn't really different, I'm just rendering the point lights with hardware instancing and scale and offset the vertices with the instance data (In.insPos).

I'm successfully using his method for point lights and directional lights.

Unfortunately I have no new suggestions, but I could fire up rendermonkey real quick and try to make a minimal example.
Alright so here is a point light example for RenderMonkey:

http://www.mediafire.com/file/iy62h4jahm5pgcd/pointlight.zip

14ul6oi.png

Hope it helps.

Edit: aligned texels to pixels, now it's even looking correct
Hi

I have a deferred lighting system. It works correctly if the Depth is in a r32f rendertarget, and the depth = Position.z / position.w (where Position is the transformed object space position with view and projection)
But I'd like to use a linear depth with point lights (with bounding volumes = spheres)

Here my code: (it has some hacks which will be removed when it will work :))

GBUFFER
//vertex shader

float4x4 world;
//float4x4 viewProj;
float4x4 view;
float4x4 proj;

void main(
in out float4 Position : POSITION0,
in float3 Normal : NORMAL0,
in out float2 Texcoord : TEXCOORD0,
in float3 Tangent : TANGENT0,
in float3 Binormal : BINORMAL0,

out float2 Depth : TEXCOORD1,
out float3x3 Wtt : TEXCOORD2)
{
float4 wpos = mul(Position, world);
float4 vpos = mul(wpos, view);
Position = mul(vpos, proj);
//Position = mul(wpos, viewProj);

Depth.x = vpos.z;
Depth.y = 30.0f;
//Depth.x = Position.z;
//Depth.y = Position.w;

Wtt[0] = mul(normalize(Tangent), world);
Wtt[1] = mul(normalize(Binormal), world);
Wtt[2] = mul(normalize(Normal), world);
}

//pixel shader

sampler2D samplerDiffuse : register(s0);
sampler2D samplerNormal : register(s1);

void main(
in float2 Texcoord : TEXCOORD0,
in float2 Depth : TEXCOORD1,
in float3x3 Wtt : TEXCOORD2,

out float4 RT0 : COLOR0,
out float4 RT1 : COLOR1,
out float4 RT2 : COLOR2)
{
Texcoord *= 5.0f;
RT0.xyz = tex2D(samplerDiffuse, Texcoord).xyz;
RT0.w = 1.0f;

float3 normal = 2.0f * tex2D(samplerNormal, Texcoord) - 1.0f;
normal = mul(normal, Wtt);
RT1.xyz = 0.5f * (normalize(normal) + 1.0f);
RT1.w = 1.0f;

RT2 = Depth.x / Depth.y;
}



And the point light shader


//vertex shader

float4x4 world;
float4x4 viewProj;

void main(
in out float4 Position : POSITION0,
out float4 ScreenPos : TEXCOORD0,
out float3 WorldPos : TEXCOORD1)
{
float4 wpos = mul(Position, world);
Position = mul(wpos, viewProj);

ScreenPos = Position;
WorldPos = wpos.xyz;
}

//pixel shader

//....

float3 viewRay = normalize(WorldPos - cameraPosition);
float3 position = cameraPosition + viewRay * depthText;
//...


The position is incorrect, so the lighting is also wrong. I'd be happy if someone could help me. ;)
sorry for my bad english
Can anyone help me?
sorry for my bad english
[color=#1C2837][size=2]Can anyone help me?
sorry for my bad english

This topic is closed to new replies.

Advertisement