Hi,
I'm doing SSR and I have artificats around the cube like some points that are spread as you notice
How would I remove them ?
float4 position_from_texture(float2 uv)
{
return (position_tex.Sample(position_sampler, uv).xyzw);
}
float3 BinarySearch(inout float3 dir, inout float3 hitCoord, inout float dDepth)
{
float depth;
float4 projectedCoord;
float2 tex_size;
depth_tex.GetDimensions(tex_size.x, tex_size.y);
float3 lowerHitCoord = hitCoord;
for(int i = 0; i < 5; i++)
{
projectedCoord = mul(proj, float4(hitCoord, 1.0));
projectedCoord.xy = (projectedCoord.xy / projectedCoord.w) * float2(-0.5, -0.5) + 0.5;
depth = position_from_texture(projectedCoord.xy).z;
dDepth = hitCoord.z - depth;
dir *= 0.5;
if(dDepth > 0.0)
{
hitCoord += dir;
lowerHitCoord = hitCoord;
}
else
{
hitCoord -= dir;
}
}
projectedCoord = mul(proj,float4(lowerHitCoord, 1.0));
projectedCoord.xy = (projectedCoord.xy / projectedCoord.w) * float2(-0.5, -0.5) + 0.5;
return float3(projectedCoord.xy, depth);
}
float2 rayCast(float3 dir, inout float3 hitCoord, out float dDepth) {
dir *= 0.01;
for (int i = 0; i < 17; i++) {
hitCoord += dir;
float4 projectedCoord = mul(proj,float4(hitCoord, 1.0));
projectedCoord.xy = (projectedCoord.xy / projectedCoord.w) * float2(-0.5, -0.5) + 0.5;
float depth = position_from_texture(projectedCoord.xy).z;
dDepth = hitCoord.z - depth;
if ((dir.z - dDepth) < 1.2 && dDepth <= 0.0) {
return BinarySearch(dir, hitCoord, dDepth);
}
}
return float2(-1.0);
}
float3 hash(float3 a)
{
a = frac(a * Scale);
a += dot(a, a.yxz + K);
return frac((a.xxy + a.yxx)*a.zyx);
}
PS_Output main(PS_Input input)
{
PS_Output output;
float minRayStep = 0.4;
float LLimiter = 0.5;
float2 tex_size;
position_tex.GetDimensions(tex_size.x, tex_size.y);
float2 tex_coord = float2(input.position.xy) / float2(tex_size);
float3 viewPos = position_from_texture(tex_coord).xyz;
float3 c_w = color_tex.Sample(color_sampler, tex_coord.xy).w ;
float3 normal = normal_tex.Sample(normal_sampler, tex_coord);
float3 reflected = normalize(reflect(normalize(viewPos), normalize(normal)));
float3 worldPos = float3( mul(inv_view, float4(viewPos, 1.0)).xyz);
float3 jitt = lerp(float3(0.0), float3(hash(worldPos)), c_w);
float3 hitPos = viewPos;
float dDepth;
float2 coords = rayCast(jitt + reflected * max(-viewPos.z, minRayStep), hitPos, dDepth);
float L = length(position_from_texture(tex_coord).xyz - viewPos);
L = clamp(L * LLimiter, 0, 1);
float error = 1 - L;
float fresnel = fresnel(reflected, normal);
float4 uv = float4(0.0);
//return output;
if (coords.x != -1 && coords.y != -1 ) {
int size = 50;
float separation = 2.0;
float count = 0.0;
float2 color = float3(0.0);
for (float i = -size; i <= size; ++i)
{
for (float j = -size; j <= size; ++j)
{
color.xy += ((float2(i, j) * separation) + (coords.xy * tex_size) / tex_size);
count += 1.0;
}
}
color.xy /= count;
float4 filtered_color = color_tex.Sample(color_sampler, color.xy);
float4 rgba_c = color_tex.Sample(color_sampler, tex_coord.xy).rgba;
output.color = lerp( rgba_c, filtered_color, 0.8);
return output;
}
output.color = color_tex.Sample(color_sampler, tex_coord.xy);
return output;
}
![](https://media.discordapp.net/attachments/377557956775903232/854564415553536020/unknown.png?width=1043&height=586)