diff --git a/AnKi/Shaders/GBufferGeneric.ankiprog b/AnKi/Shaders/GBufferGeneric.ankiprog index 022353c9d..788ae5ad2 100644 --- a/AnKi/Shaders/GBufferGeneric.ankiprog +++ b/AnKi/Shaders/GBufferGeneric.ankiprog @@ -716,7 +716,7 @@ GBufferPixelOut main( // Diffuse # if DIFFUSE_TEX - RVec3 diffColor = getBindlessTexture2DRVec4(localConstants.m_diffuseTex).SampleLevel(g_globalSampler, uv, 0.0).xyz; + RVec3 diffColor = getBindlessTexture2DRVec4(localConstants.m_diffuseTex).SampleLevel(g_globalSampler, uv, payload.m_textureLod).xyz; # else RVec3 diffColor = 1.0; # endif @@ -725,7 +725,7 @@ GBufferPixelOut main( // Emissive # if EMISSIVE_TEX - RVec3 emission = getBindlessTexture2DRVec4(localConstants.m_emissiveTex).SampleLevel(g_globalSampler, uv, 0.0).rgb; + RVec3 emission = getBindlessTexture2DRVec4(localConstants.m_emissiveTex).SampleLevel(g_globalSampler, uv, payload.m_textureLod).rgb; # else RVec3 emission = 1.0; # endif diff --git a/AnKi/Shaders/RtMaterialFetch.hlsl b/AnKi/Shaders/RtMaterialFetch.hlsl index ff6219d81..e60f4f75a 100644 --- a/AnKi/Shaders/RtMaterialFetch.hlsl +++ b/AnKi/Shaders/RtMaterialFetch.hlsl @@ -15,6 +15,7 @@ struct [raypayload] RtMaterialFetchRayPayload Vec3 m_worldNormal : write(closesthit, miss): read(caller); Vec3 m_emission : write(closesthit, miss): read(caller); F32 m_rayT : write(closesthit, miss): read(caller); + F32 m_textureLod : write(caller): read(closesthit); }; // Have a common resouce interface for all shaders diff --git a/AnKi/Shaders/RtMaterialFetchDbg.ankiprog b/AnKi/Shaders/RtMaterialFetchDbg.ankiprog index c8ba3b969..2937a1bb1 100644 --- a/AnKi/Shaders/RtMaterialFetchDbg.ankiprog +++ b/AnKi/Shaders/RtMaterialFetchDbg.ankiprog @@ -27,6 +27,7 @@ // Trace RtMaterialFetchRayPayload payload; payload = (RtMaterialFetchRayPayload)0; + payload.m_textureLod = 0.0; const U32 flags = RAY_FLAG_FORCE_OPAQUE; const U32 sbtRecordOffset = 0u; const U32 sbtRecordStride = 0u; diff --git a/AnKi/Shaders/RtReflections.ankiprog b/AnKi/Shaders/RtReflections.ankiprog index 0280af2a3..4bca81c99 100644 --- a/AnKi/Shaders/RtReflections.ankiprog +++ b/AnKi/Shaders/RtReflections.ankiprog @@ -261,9 +261,18 @@ ANKI_FAST_CONSTANTS(Consts, g_consts) const F32 pdf = 1.0; # endif + // The more rough and the more far this pixel is then instruct the hit shaders to choose less detail mip + const F32 distanceToMaxMip = 50.0; + const F32 pixelDistFromCamera = length(worldPos - g_globalRendererConstants.m_cameraPosition); + const F32 distFactor = pow(pixelDistFromCamera / distanceToMaxMip, 4.0); + const F32 maxMips = 8.0; + const F32 textureLod = max(roughness, distFactor) * maxMips; + // Trace RtMaterialFetchRayPayload payload; payload = (RtMaterialFetchRayPayload)0; + payload.m_textureLod = textureLod; + constexpr U32 flags = RAY_FLAG_FORCE_OPAQUE | RAY_FLAG_SKIP_PROCEDURAL_PRIMITIVES; const U32 sbtRecordOffset = 0u; const U32 sbtRecordStride = 0u;