# Screen space glossy reflections - viewRay calculation

## Recommended Posts

Hello, i'm currently implementing http://roar11.com/2015/07/screen-space-glossy-reflections/.

But i don't know how to calc viewRay.

here is my solution much different from example, it works but look bad at edge of screen.

	float3 viewRay = normalize(VSPositionFromDepth(input.tex.xy, depth, sslr_invProjMatrix));
float3 rayOriginVS = viewRay * LinearDepth(depth);

/*
* Since position is reconstructed in view space, just normalize it to get the
* vector from the eye to the position and then reflect that around the normal to
* get the ray direction to trace.
*/

float3 toPositionVS = normalize(worldPosition.xyz - camPosition.xyz);
float3 rayDirectionVS = normalize(reflect(toPositionVS, normalVS));
rayDirectionVS = mul(float4(rayDirectionVS, 0), sslr_viewMatrix);

// output rDotV to the alpha channel for use in determining how much to fade the ray
float rDotV = dot(rayDirectionVS, rayOriginVS);

is there a better way to do this? I'm googling for few days but can't find any working solution.

Thanks

##### Share on other sites

Update: Fixed, this because i use world space normal instead of view space. now i'm able to follow example code.

## Create an account

Register a new account

1. 1
2. 2
Rutin
19
3. 3
JoeJ
16
4. 4
5. 5

• 35
• 23
• 13
• 13
• 17
• ### Forum Statistics

• Total Topics
631700
• Total Posts
3001808
×