소스 검색

Adjust the LOD of textures in the hit shaders based on roughness and distance from the camera

Panagiotis Christopoulos Charitos 1 년 전
부모
커밋
62afb38011
4개의 변경된 파일13개의 추가작업 그리고 2개의 파일을 삭제
  1. 2 2
      AnKi/Shaders/GBufferGeneric.ankiprog
  2. 1 0
      AnKi/Shaders/RtMaterialFetch.hlsl
  3. 1 0
      AnKi/Shaders/RtMaterialFetchDbg.ankiprog
  4. 9 0
      AnKi/Shaders/RtReflections.ankiprog

+ 2 - 2
AnKi/Shaders/GBufferGeneric.ankiprog

@@ -716,7 +716,7 @@ GBufferPixelOut main(
 
 
 	// Diffuse
 	// Diffuse
 #		if DIFFUSE_TEX
 #		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
 #		else
 	RVec3 diffColor = 1.0;
 	RVec3 diffColor = 1.0;
 #		endif
 #		endif
@@ -725,7 +725,7 @@ GBufferPixelOut main(
 
 
 	// Emissive
 	// Emissive
 #		if EMISSIVE_TEX
 #		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
 #		else
 	RVec3 emission = 1.0;
 	RVec3 emission = 1.0;
 #		endif
 #		endif

+ 1 - 0
AnKi/Shaders/RtMaterialFetch.hlsl

@@ -15,6 +15,7 @@ struct [raypayload] RtMaterialFetchRayPayload
 	Vec3 m_worldNormal : write(closesthit, miss): read(caller);
 	Vec3 m_worldNormal : write(closesthit, miss): read(caller);
 	Vec3 m_emission : write(closesthit, miss): read(caller);
 	Vec3 m_emission : write(closesthit, miss): read(caller);
 	F32 m_rayT : 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
 // Have a common resouce interface for all shaders

+ 1 - 0
AnKi/Shaders/RtMaterialFetchDbg.ankiprog

@@ -27,6 +27,7 @@
 	// Trace
 	// Trace
 	RtMaterialFetchRayPayload payload;
 	RtMaterialFetchRayPayload payload;
 	payload = (RtMaterialFetchRayPayload)0;
 	payload = (RtMaterialFetchRayPayload)0;
+	payload.m_textureLod = 0.0;
 	const U32 flags = RAY_FLAG_FORCE_OPAQUE;
 	const U32 flags = RAY_FLAG_FORCE_OPAQUE;
 	const U32 sbtRecordOffset = 0u;
 	const U32 sbtRecordOffset = 0u;
 	const U32 sbtRecordStride = 0u;
 	const U32 sbtRecordStride = 0u;

+ 9 - 0
AnKi/Shaders/RtReflections.ankiprog

@@ -261,9 +261,18 @@ ANKI_FAST_CONSTANTS(Consts, g_consts)
 	const F32 pdf = 1.0;
 	const F32 pdf = 1.0;
 #	endif
 #	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
 	// Trace
 	RtMaterialFetchRayPayload payload;
 	RtMaterialFetchRayPayload payload;
 	payload = (RtMaterialFetchRayPayload)0;
 	payload = (RtMaterialFetchRayPayload)0;
+	payload.m_textureLod = textureLod;
+
 	constexpr U32 flags = RAY_FLAG_FORCE_OPAQUE | RAY_FLAG_SKIP_PROCEDURAL_PRIMITIVES;
 	constexpr U32 flags = RAY_FLAG_FORCE_OPAQUE | RAY_FLAG_SKIP_PROCEDURAL_PRIMITIVES;
 	const U32 sbtRecordOffset = 0u;
 	const U32 sbtRecordOffset = 0u;
 	const U32 sbtRecordStride = 0u;
 	const U32 sbtRecordStride = 0u;