Skip to content

Commit

Permalink
Merge pull request #29 from Lehm2000/ja-texture-alpha-improvement
Browse files Browse the repository at this point in the history
Improved texture sampling to allow for soft/dithered texture edges (Resubmit).
  • Loading branch information
SamBoots authored Nov 10, 2024
2 parents 209369b + 9baa483 commit 4a8ca93
Showing 1 changed file with 8 additions and 15 deletions.
23 changes: 8 additions & 15 deletions RT/Renderer/Backend/DX12/assets/shaders/include/common.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -768,6 +768,10 @@ bool IsHitTransparent(uint instance_idx, uint primitive_idx, float2 barycentrics
};
float2 uv = GetHitAttribute(uvs, barycentrics);
float2 uv_rotated = GetRotatedUVs(orient, uv);
float4 color = UnpackRGBA(instance_data.material_color);
float4 tri_color = UnpackRGBA(hit_triangle.color);
float base_alpha = color.a * tri_color.a;
float dither = RandomSample(pixel_pos, instance_idx) * 0.99; // NOTE: dither is multiplied by .99 because dither should never be 1.0 (You end up with single pixel holes in geometry)

// TODO(daniel): Clean this messy silly code up!
if (material_index2 != 0xFFFFFFFF)
Expand All @@ -783,29 +787,18 @@ bool IsHitTransparent(uint instance_idx, uint primitive_idx, float2 barycentrics
return true;
}

if (albedo2.a > 0.0)
if ( dither >= albedo2.a )
{
material_index = material_index2;
uv = uv_rotated;
material = g_materials[material_index2];
return dither >= base_alpha;
}
}

material = g_materials[material_index];
Texture2D tex_albedo = GetTextureFromIndex(material.albedo_index);
float4 albedo = tex_albedo.SampleLevel(g_sampler_point_wrap, uv, 0);

if (albedo.a == 0.0)
{
return true;
}
else
{
float4 color = UnpackRGBA(instance_data.material_color);
float4 tri_color = UnpackRGBA(hit_triangle.color);
float dither = RandomSample(pixel_pos, instance_idx);

return dither > color.a * tri_color.a;
}
return dither >= albedo.a * base_alpha;
}

// -----------------------------------------------------------
Expand Down

0 comments on commit 4a8ca93

Please sign in to comment.