Fixed the issue that positionWS is camear-relative position but world matrix is in absolute world space

This commit is contained in:
2025-02-20 00:55:38 +09:00
parent ef2bdeac98
commit 0f4f10a138
3 changed files with 21 additions and 15 deletions

View File

@@ -1,18 +1,17 @@
#ifndef VOLUME_SDF
#define VOLUME_SDF
#include "Packages/com.misaki.ao-volume/Runtime/Shader/Includes/VolumeData.cs.hlsl"
float3 GetPositionLS(float4x4 inverseWorldMatrix, float3 positionWS)
float3 GetPositionOS(float4x4 inverseWorldMatrix, float3 positionWS)
{
return mul(inverseWorldMatrix, float4(positionWS, 1.0)).xyz;
// To handle camera relative rendering we need to apply translation before converting to object space
return mul(ApplyCameraTranslationToInverseMatrix(inverseWorldMatrix), float4(positionWS, 1.0)).xyz;
}
float BoxSDF(float3 positionWS, VolumeData data)
{
float3 halfDim = data.size * 0.5;
float3 positionLS = GetPositionLS(data.inverseWorldMatrix, positionWS);
float3 positionLS = GetPositionOS(data.inverseWorldMatrix, positionWS);
float3 d = halfDim - abs(positionLS);
float distToFace = min(d.x, min(d.y, d.z));
@@ -23,7 +22,7 @@ float BoxSDF(float3 positionWS, VolumeData data)
float CapsuleSDF(float3 positionWS, VolumeData data)
{
float3 positionLS = GetPositionLS(data.inverseWorldMatrix, positionWS);
float3 positionLS = GetPositionOS(data.inverseWorldMatrix, positionWS);
float radius = data.size.x;
float length = data.size.y;