Skip to content

Commit

Permalink
Merge pull request #298 from alandtse/deferred-shadows
Browse files Browse the repository at this point in the history
  • Loading branch information
alandtse authored Apr 30, 2024
2 parents a879ab5 + 837e786 commit ac95b04
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,14 @@ half2 ViewToUV(half3 position, bool is_position, uint a_eyeIndex)

uint eyeIndex = GetEyeIndexFromTexCoord(uv);

half3 viewPosition = DepthToView(uv, rawDepth, eyeIndex);
half3 viewPosition = DepthToView(ConvertFromStereoUV(uv, eyeIndex), rawDepth, eyeIndex); // viewPosition is in VR nonstereospace
viewPosition.z = depth;

half3 endPosVS = viewPosition + DirLightDirectionVS[eyeIndex].xyz * 5;
half2 endPosUV = ViewToUV(endPosVS, false, eyeIndex);

half2 startPosPixel = clamp(uv * BufferDim, 0, BufferDim);
half2 endPosPixel = clamp(endPosUV * BufferDim, 0, BufferDim);
half2 startPosPixel = clamp(uv * BufferDim, 0, BufferDim); // uv is in VR stereo space
half2 endPosPixel = clamp(ConvertToStereoUV(endPosUV, eyeIndex) * BufferDim, 0, BufferDim); // convert back to stereospace since derived from viewPosition

half NdotL = dot(normalVS, DirLightDirectionVS[eyeIndex].xyz);

Expand All @@ -89,7 +89,7 @@ half2 ViewToUV(half3 position, bool is_position, uint a_eyeIndex)
half slope = -NdotL;

for (int i = 0; i < 5; i++) {
uint2 tmpCoords = lerp(startPosPixel, endPosPixel, pos);
uint2 tmpCoords = lerp(startPosPixel, endPosPixel, pos); // coords are in stereo space to access Textures
half3 tmpNormal = DecodeNormal(NormalRoughnessTexture[tmpCoords].xy);
half tmpDepth = GetScreenDepth(DepthTexture[tmpCoords]);
half tmpNdotL = dot(tmpNormal, DirLightDirectionVS[eyeIndex].xyz);
Expand Down
2 changes: 1 addition & 1 deletion package/Shaders/Common/VR.hlsli
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ uint GetEyeIndexVS(uint instanceID = 0)

/**
Gets VR Output
@param texCoord Texcoord on the screen [0,1]
@param clipPos clipPosition. Typically the VSHADER position at SV_POSITION0
@param a_eyeIndex The eyeIndex; 0 is left, 1 is right
@returns VR_OUTPUT with VR values
*/
Expand Down

0 comments on commit ac95b04

Please sign in to comment.