Skip to content

Commit

Permalink
support for refraction index
Browse files Browse the repository at this point in the history
  • Loading branch information
turanszkij committed Jan 25, 2025
1 parent 805015c commit eb6589c
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion WickedEngine/shaders/objectHF.hlsli
Original file line number Diff line number Diff line change
Expand Up @@ -1068,7 +1068,7 @@ float4 main(PixelInput input, in bool is_frontface : SV_IsFrontFace) : SV_Target
#endif // UNLIT

#ifdef INTERIORMAPPING
color = surface.baseColor * InteriorMapping(surface.P, surface.V, material, meshinstance);
color = surface.baseColor * InteriorMapping(surface, material, meshinstance);
#endif // INTERIORMAPPING


Expand Down
8 changes: 4 additions & 4 deletions WickedEngine/shaders/shadingHF.hlsli
Original file line number Diff line number Diff line change
Expand Up @@ -668,7 +668,7 @@ inline uint AlphaToCoverage(half alpha, half alphaTest, float4 svposition)
return 0;
}

half4 InteriorMapping(in float3 P, in float3 V, in ShaderMaterial material, in ShaderMeshInstance meshinstance)
half4 InteriorMapping(in Surface surface, in ShaderMaterial material, in ShaderMeshInstance meshinstance)
{
[branch]
if (!material.textures[BASECOLORMAP].IsValid())
Expand All @@ -689,15 +689,15 @@ half4 InteriorMapping(in float3 P, in float3 V, in ShaderMaterial material, in S
float4x4 interiorTransform = mul(meshinstance.transformRaw.GetMatrix(), scaleMatrix);
float4x4 interiorProjection = inverse(interiorTransform);

const half3 clipSpacePos = mul(interiorProjection, float4(P, 1)).xyz;
const half3 clipSpacePos = mul(interiorProjection, float4(surface.P, 1)).xyz;

half3 R = -V;
half3 R = refract(-surface.V, surface.N, 1 - material.GetRefraction());
half3 RayLS = mul((half3x3)interiorProjection, R);
half3 FirstPlaneIntersect = (1 - clipSpacePos) / RayLS;
half3 SecondPlaneIntersect = (-1 - clipSpacePos) / RayLS;
half3 FurthestPlane = max(FirstPlaneIntersect, SecondPlaneIntersect);
half Distance = min(FurthestPlane.x, min(FurthestPlane.y, FurthestPlane.z));
half3 R_parallaxCorrected = P - meshinstance.center + R * Distance;
half3 R_parallaxCorrected = surface.P - meshinstance.center + R * Distance;

// By rotating the sampling vector I fix the cube projection to the object's rotation:
float3 t, s;
Expand Down
2 changes: 1 addition & 1 deletion WickedEngine/shaders/visibility_surfaceCS.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ void main(uint Gid : SV_GroupID, uint groupIndex : SV_GroupIndex)
}

#ifdef INTERIORMAPPING
surface.baseColor *= InteriorMapping(surface.P, surface.V, surface.material, surface.inst);
surface.baseColor *= InteriorMapping(surface, surface.material, surface.inst);
#endif // INTERIORMAPPING

#if defined(UNLIT) || defined(INTERIORMAPPING)
Expand Down

0 comments on commit eb6589c

Please sign in to comment.