Fixed the issue that positionWS is camear-relative position but world matrix is in absolute world space
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user