浏览代码

decal projects correctly onto dbuffer albedo surface (test pattern)

/Add-support-for-light-specular-color-tint
Paul Melamed 7 年前
当前提交
d9dc83f4
共有 2 个文件被更改,包括 28 次插入40 次删除
  1. 38
      ScriptableRenderPipeline/HDRenderPipeline/Decal/DecalSystem.cs
  2. 30
      ScriptableRenderPipeline/HDRenderPipeline/ShaderPass/ShaderPassDBuffer.hlsl

38
ScriptableRenderPipeline/HDRenderPipeline/Decal/DecalSystem.cs


internal HashSet<Decal> m_DecalsBoth = new HashSet<Decal>();
Mesh m_CubeMesh;
private readonly static int m_WorldToDecal = Shader.PropertyToID("_WorldToDecal");
private static readonly int m_WorldToDecal = Shader.PropertyToID("_WorldToDecal");
public DecalSystem()
{

Vector3[] vertices = new Vector3[8];
vertices[0] = new Vector3(-0.5f, -0.5f, -0.5f);
vertices[1] = new Vector3(0.5f, -0.5f, -0.5f);
vertices[2] = new Vector3(0.5f, 0.5f, -0.5f);
vertices[3] = new Vector3(-0.5f, 0.5f, -0.5f);
vertices[4] = new Vector3(-0.5f, -0.5f, 0.5f);
vertices[5] = new Vector3(0.5f, -0.5f, 0.5f);
vertices[6] = new Vector3(0.5f, 0.5f, 0.5f);
vertices[7] = new Vector3(-0.5f, 0.5f, 0.5f);
vertices[0] = new Vector3(-0.5f, -1.0f, -0.5f);
vertices[1] = new Vector3( 0.5f, -1.0f, -0.5f);
vertices[2] = new Vector3( 0.5f, 0.0f, -0.5f);
vertices[3] = new Vector3(-0.5f, 0.0f, -0.5f);
vertices[4] = new Vector3(-0.5f, -1.0f, 0.5f);
vertices[5] = new Vector3( 0.5f, -1.0f, 0.5f);
vertices[6] = new Vector3( 0.5f, 0.0f, 0.5f);
vertices[7] = new Vector3(-0.5f, 0.0f, 0.5f);
m_CubeMesh.vertices = vertices;

{
if (m_CubeMesh == null)
CreateCubeMesh();
Matrix4x4 CRWStoAWS = new Matrix4x4();
if (ShaderConfig.s_CameraRelativeRendering == 1)
{
Vector4 worldSpaceCameraPos = Shader.GetGlobalVector(HDShaderIDs._WorldSpaceCameraPos);
CRWStoAWS = Matrix4x4.Translate(worldSpaceCameraPos);
}
else
{
CRWStoAWS = Matrix4x4.identity;
}
{
Matrix4x4 offset = Matrix4x4.Translate(new Vector3(0.0f, -0.5f, 0.0f));
Matrix4x4 final = decal.transform.localToWorldMatrix * offset;
Vector4 positionWS = new Vector4(0,5,0,1);
Vector4 positionDS = final.inverse * positionWS;
cmd.SetGlobalMatrix(m_WorldToDecal, final.inverse);
{
Matrix4x4 final = decal.transform.localToWorldMatrix;
Matrix4x4 worldToDecal = Matrix4x4.Translate(new Vector3(0.5f, 0.0f, 0.5f)) * Matrix4x4.Scale(new Vector3(1.0f, -1.0f, 1.0f)) * final.inverse;
cmd.SetGlobalMatrix(m_WorldToDecal, worldToDecal * CRWStoAWS);
//DrawMesh(Mesh mesh, Matrix4x4 matrix, Material material, int submeshIndex, int shaderPass);
cmd.DrawMesh(m_CubeMesh, final, decal.m_Material, 0, 0);
}

30
ScriptableRenderPipeline/HDRenderPipeline/ShaderPass/ShaderPassDBuffer.hlsl


ENCODE_INTO_GBUFFER(surfaceData, bakeDiffuseLighting, outGBuffer);
ENCODE_VELOCITY_INTO_GBUFFER(builtinData.velocity, outVelocityBuffer);
*/
// float d = LinearEyeDepth(SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, sampler_CameraDepthTexture, posInput.positionSS.xy), _ZBufferParams);
posInput.positionWS.xyz += _WorldSpaceCameraPos;
clip(posInput.positionWS.y < 0 ? -1 : 1);
//clip(posInput.positionWS.y > 0.0001 ? -1 : 1);
outDBuffer0.xyzw = float4(posInput.positionWS.xyz + float3(0.5, 0.0, 0.5), 1.0f);
/*
// float d = Linear01Depth(SAMPLE_TEXTURE_2D(_CameraDepthTexture, sampler_CameraDepthTexture, posInput.positionSS.xy).z);
float4 res;
res = float4(posInput.positionSS.x,posInput.positionSS.y,0,0);
res = float4(0,0,posInput.depthRaw,0);
res = float4(0,0,d,0);
res = float4(posInput.positionWS.xyz,1);
res = mul(_WorldToDecal, res);
clip(res.y < 0.5 ? -1 : 1);
clip(res.x < 0.5 ? -1 : 1);
clip(res.z < 0.5 ? -1 : 1);
clip(res.y > 0.5 ? -1 : 1);
clip(res.x > 0.5 ? -1 : 1);
clip(res.z > 0.5 ? -1 : 1);
// clip(float3(1.0f, 1.0f, 1.0f) - res.xyz);
// float4 res = packedInput.vmesh.positionCS;
outDBuffer0.xyzw = float4(res.xyz, 1.0f);
*/
float3 positionWS = posInput.positionWS;
float3 positionDS = mul(_WorldToDecal, float4(positionWS, 1.0f)).xyz;
clip(positionDS < 0 ? -1 : 1);
clip(positionDS > 1 ? -1 : 1);
outDBuffer0.xyzw = float4(positionDS, 1.0f);
}
正在加载...
取消
保存