#Help with screen space reflections

2 messages · Page 1 of 1 (latest)

steel verge
#

I've been working on screen space reflections and oddly I get good reflections when the camera is almost perfectly straight, but I have stretching issue, and close up reflections are almost entirely missing.

⁨```bool RayMarch(float3 viewPos, float3 reflDir, out float2 outRayUV)
{
outRayUV = float2(0, 0);
bool hit = false;
float3 rayPos = viewPos;
float currStep = stepSize;
for (int i = 0; i < 32; ++i)
{
rayPos += reflDir * currStep;
float4 rayProj = mul(proj, float4(rayPos, 1.0f));
rayProj /= rayProj.w;
float2 rayUV = rayProj.xy * 0.5f + 0.5;
rayUV.y = 1.0 - rayUV.y;

    if (any(rayUV < 0.0) || any(rayUV > 1.0))
    {
        return false;
    }
    
    float sampleDepth = ReconstructViewPos(depthTex.Sample(pointSampler, rayUV).r, rayUV, inverseProj).z;
    
    float depthDiff = rayPos.z - sampleDepth;
    if (depthDiff > thickness)
    {
        hit = true;
        outRayUV = rayUV;
        if (currStep < 1)
        {
            break;
        }
        rayPos -= reflDir * currStep;
        currStep *= 0.5;
    }

}
return hit;

}

float4 ps_main(VSOut input) : SV_Target
{
float2 rayUV;//final coordinates to sample from

float4 rmeao = rmeaoTex.Sample(pointSampler, input.texUV);
float roughness = rmeao.r;
float metalness = rmeao.g;
clip(metalness - 0.01);


float3 viewPos = ReconstructViewPos(depthTex.Sample(pointSampler, input.texUV).r, input.texUV, inverseProj);
float3 normal = normalize(2.0f * normalTex.Sample(pointSampler, input.texUV).xyz - 1.0f);


float3 reflDir = reflect(normalize(viewPos), normal);

float3 outColor = float3(0, 0, 0);

bool hitFound = RayMarch(viewPos, reflDir, rayUV);

if (hitFound)
{
    outColor = lightTex.Sample(pointSampler, rayUV).rgb * metalness;
}

return float4(outColor, 1.0f);

}```⁩

steel verge
#

Small update. Changing the step method to smal steps and scaling by 1.5 for each miss lets me start with lower values so I hit more things up close. Just got a smearing issue now