2 registered members (TipmyPip, AndrewAMD),
1,151
guests, and 4
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
Re: Need help with realtime local reflections
[Re: Hummel]
#408213
09/27/12 14:03
09/27/12 14:03
|
Joined: Sep 2003
Posts: 6,861 Kiel (Germany)
Superku
OP
Senior Expert
|
OP
Senior Expert
Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
|
Yes, but he only uses them for a gradient mip map selection. I think an interesting part in the source code is the following:
// Transform the View Space Reflection to Screen Space
// This because we want to ray march in to the depth buffer in Screen Space (thus you can use the default hardware depthbuffer)
// Depth is linear in Screen Space per Screen Pixel
float3 vspPosReflect = Input.ViewPos + vspReflect;
float3 sspPosReflect = mul(float4(vspPosReflect, 1.0), g_mProj).xyz / vspPosReflect.z;
float3 sspReflect = sspPosReflect - Input.ScreenPos;
Two thoughts come to my mind: How does his projection matrix look like and esp. why does he divide by vspPosReflect.z (including the z-component of ssPosReflect)? I had to adapt my code as follows to get somehow passable results:
// transform from view to screen space
float4 tPos = mul(float4(viewpos+dir,1), matProj);
tPos.xy = tPos.xy/tPos.w;
float3 screenDir = tPos.xyz-projViewPos;
"Falls das Resultat nicht einfach nur dermassen gut aussieht, sollten Sie nochmal von vorn anfangen..." - Manual Check out my new game: Pogostuck: Rage With Your Friends
|
|
|
Re: Need help with realtime local reflections
[Re: Superku]
#408215
09/27/12 14:56
09/27/12 14:56
|
Joined: Mar 2006
Posts: 2,252
Hummel
Expert
|
Expert
Joined: Mar 2006
Posts: 2,252
|
He is just dividing by linear depth since vspPosReflect is in view space. He could have also done the following:
float3 vspPosReflect = Input.ViewPos + vspReflect;
float4 sspPosReflect = mul(float4(vspPosReflect, 1.0), g_mProj).xyzw;
sspPosReflect.xyz /= sspPosReflect.w;
float3 sspReflect = sspPosReflect.xyz - Input.ScreenPos;
And since Input.ScreenPos uses non-linear depth in the z-value too they cancel out each other. I tried something alike (I didn't divide the z value, though...) but ended up with the same problem like you. So the magic seems to hide somewhere else.
|
|
|
Re: Need help with realtime local reflections
[Re: Hummel]
#408402
09/30/12 16:17
09/30/12 16:17
|
Joined: Jun 2009
Posts: 2,210 Bavaria, Germany
Kartoffel
Expert
|
Expert
Joined: Jun 2009
Posts: 2,210
Bavaria, Germany
|
I've got a simple suggestion to improve the quality (you see it on the right side): I changed the line return tex2D(CameraSampler, screenPos.xy); in reflect.fx to
float Intensity = saturate(1.0f - distance(screenPos.xy, float2(0.5f, 0.5f)) * 2.0f);
Intensity = Intensity * (2.0f - Intensity);
return tex2D(CameraSampler, screenPos.xy) * Intensity;
POTATO-MAN saves the day! - Random
|
|
|
|