浏览代码

generating decal normal to decal space matrix in vertex shader

/main
Paul Melamed 7 年前
当前提交
651c6311
共有 4 个文件被更改,包括 42 次插入5 次删除
  1. 5
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Material/Decal/DecalData.hlsl
  2. 3
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Material/Decal/ShaderPass/DecalSharePass.hlsl
  3. 36
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/ShaderPass/ShaderPassDBuffer.hlsl
  4. 3
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/ShaderPass/VertMesh.hlsl

5
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Material/Decal/DecalData.hlsl


#include "CoreRP/ShaderLibrary/Packing.hlsl"
#include "CoreRP/ShaderLibrary/Sampling/SampleUVMapping.hlsl"
void GetSurfaceData(float2 texCoordDS, out DecalSurfaceData surfaceData)
void GetSurfaceData(float2 texCoordDS, float3x3 decalToWorld, out DecalSurfaceData surfaceData)
{
surfaceData.baseColor = float4(0,0,0,0);
surfaceData.normalWS = float4(0,0,0,0);

ZERO_INITIALIZE(UVMapping, texCoord);
texCoord.uv = texCoordDS.xy;
#if _NORMALMAP
surfaceData.normalWS.xyz = mul((float3x3)_DecalToWorldR, SAMPLE_UVMAPPING_NORMALMAP(_NormalMap, sampler_NormalMap, texCoord, 1)) * 0.5f + 0.5f;
// surfaceData.normalWS.xyz = mul((float3x3)_DecalToWorldR, SAMPLE_UVMAPPING_NORMALMAP(_NormalMap, sampler_NormalMap, texCoord, 1)) * 0.5f + 0.5f;
surfaceData.normalWS.xyz = mul(decalToWorld, SAMPLE_UVMAPPING_NORMALMAP(_NormalMap, sampler_NormalMap, texCoord, 1)) * 0.5f + 0.5f;
surfaceData.normalWS.w = totalBlend;
#endif
#if _MASKMAP

3
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Material/Decal/ShaderPass/DecalSharePass.hlsl


#error Undefine_SHADERPASS
#endif
// 3 interpolators for decal normal map tangent space
#define VARYINGS_NEED_POSITION_WS
#define VARYINGS_NEED_TANGENT_TO_WORLD
// This include will define the various Attributes/Varyings structure
#include "../../ShaderPass/VaryingMesh.hlsl"

36
ScriptableRenderPipeline/HDRenderPipeline/HDRP/ShaderPass/ShaderPassDBuffer.hlsl


#include "VertMesh.hlsl"
float3 RemoveScale(float3 val)
{
return normalize(val / length(val));
}
VaryingsMeshType Transform(AttributesMesh input)
{
VaryingsMeshType output;
float3 positionWS = TransformObjectToWorld(input.positionOS);
positionWS = GetCameraRelativePositionWS(positionWS);
output.positionCS = TransformWorldToHClip(positionWS);
float3x3 decalRotation;
decalRotation[0] = RemoveScale(float3(UNITY_MATRIX_M[0][0], UNITY_MATRIX_M[0][1], UNITY_MATRIX_M[0][2]));
decalRotation[2] = RemoveScale(float3(UNITY_MATRIX_M[1][0], UNITY_MATRIX_M[1][1], UNITY_MATRIX_M[1][2]));
decalRotation[1] = RemoveScale(float3(UNITY_MATRIX_M[2][0], UNITY_MATRIX_M[2][1], UNITY_MATRIX_M[2][2]));
decalRotation = transpose(decalRotation);
output.positionWS = decalRotation[0];
output.normalWS = decalRotation[1];
output.tangentWS = float4(decalRotation[2], 0);
return output;
}
varyingsType.vmesh = VertMesh(inputMesh);
varyingsType.vmesh = Transform(inputMesh);
return PackVaryingsType(varyingsType);
}

clip(positionDS > 1 ? -1 : 1);
DecalSurfaceData surfaceData;
GetSurfaceData(positionDS.xz, surfaceData);
float3x3 decalToWorld;
decalToWorld[0] = packedInput.vmesh.interpolators0;
decalToWorld[1] = packedInput.vmesh.interpolators1;
decalToWorld[2] = packedInput.vmesh.interpolators2.xyz;
GetSurfaceData(positionDS.xz, decalToWorld, surfaceData);
ENCODE_INTO_DBUFFER(surfaceData, outDBuffer);
}

3
ScriptableRenderPipeline/HDRenderPipeline/HDRP/ShaderPass/VertMesh.hlsl


float3 normalWS = float3(0.0, 0.0, 0.0); // We need this case to be able to compile ApplyVertexModification that doesn't use normal.
#endif
float4 tangentWS = float4(0.0, 0.0, 0.0, 0.0);
float4 tangentWS = float4(TransformObjectToWorldDir(input.tangentOS.xyz), input.tangentOS.w);
tangentWS = float4(TransformObjectToWorldDir(input.tangentOS.xyz), input.tangentOS.w);
#endif
// TODO: deal with camera center rendering and instancing (This is the reason why we always perform two steps transform to clip space + instancing matrix)

正在加载...
取消
保存