浏览代码
refactor to address all comments by Sebastien in slack conversation.
/Add-support-for-light-specular-color-tint
refactor to address all comments by Sebastien in slack conversation.
/Add-support-for-light-specular-color-tint
Paul Melamed
7 年前
当前提交
d9d7b2cb
共有 15 个文件被更改,包括 312 次插入 和 260 次删除
-
53ScriptableRenderPipeline/HDRenderPipeline/Decal/DecalSystem.cs
-
19ScriptableRenderPipeline/HDRenderPipeline/HDRenderPipeline.cs
-
12ScriptableRenderPipeline/HDRenderPipeline/Material/Decal/Decal.cs
-
25ScriptableRenderPipeline/HDRenderPipeline/Material/Decal/Decal.cs.hlsl
-
108ScriptableRenderPipeline/HDRenderPipeline/Material/Decal/Decal.hlsl
-
80ScriptableRenderPipeline/HDRenderPipeline/Material/Decal/Decal.shader
-
15ScriptableRenderPipeline/HDRenderPipeline/Material/Decal/DecalData.hlsl
-
11ScriptableRenderPipeline/HDRenderPipeline/Material/Decal/Editor/DecalUI.cs
-
22ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/LitData.hlsl
-
8ScriptableRenderPipeline/HDRenderPipeline/Material/Material.hlsl
-
21ScriptableRenderPipeline/HDRenderPipeline/ShaderPass/ShaderPassDBuffer.hlsl
-
7ScriptableRenderPipeline/HDRenderPipeline/ShaderVariables.hlsl
-
110ScriptableRenderPipeline/HDRenderPipeline/Decal/DecalProjectorComponent.cs
-
13ScriptableRenderPipeline/HDRenderPipeline/Material/Decal/DecalUtilities.hlsl
-
68ScriptableRenderPipeline/HDRenderPipeline/Decal/DecalComponent.cs
|
|||
#include "Decal.cs.hlsl" |
|||
|
|||
#define DBufferType0 float4 |
|||
#define DBufferType0 float4 |
|||
#define DBufferType1 float4 |
|||
#define DBufferType2 float4 |
|||
#define DBufferType3 float4 |
|||
|
|||
#ifdef DBUFFERMATERIAL_COUNT |
|||
|
|||
#if DBUFFERMATERIAL_COUNT == 1 |
|||
|
|||
#define OUTPUT_DBUFFER(NAME) \ |
|||
out DBufferType0 MERGE_NAME(NAME, 0) : SV_Target0 |
|||
|
|||
#define DECLARE_DBUFFER_TEXTURE(NAME) \ |
|||
TEXTURE2D(MERGE_NAME(NAME, 0)); |
|||
|
|||
#define FETCH_DBUFFER(NAME, TEX, unCoord2) \ |
|||
DBufferType0 MERGE_NAME(NAME, 0) = LOAD_TEXTURE2D(MERGE_NAME(TEX, 0), unCoord2); |
|||
|
|||
#define ENCODE_INTO_DBUFFER(DECAL_SURFACE_DATA, NAME) EncodeIntoDBuffer(DECAL_SURFACE_DATA, MERGE_NAME(NAME,0)) |
|||
#define DECODE_FROM_DBUFFER(NAME, DECAL_SURFACE_DATA) DecodeFromDBuffer(MERGE_NAME(NAME,0), DECAL_SURFACE_DATA) |
|||
|
|||
|
|||
#elif DBUFFERMATERIAL_COUNT == 2 |
|||
|
|||
#define OUTPUT_DBUFFER(NAME) \ |
|||
out DBufferType0 MERGE_NAME(NAME, 0) : SV_Target0, \ |
|||
out DBufferType1 MERGE_NAME(NAME, 1) : SV_Target1 |
|||
|
|||
#define DECLARE_DBUFFER_TEXTURE(NAME) \ |
|||
TEXTURE2D(MERGE_NAME(NAME, 0)); \ |
|||
TEXTURE2D(MERGE_NAME(NAME, 1)); |
|||
|
|||
#define FETCH_DBUFFER(NAME, TEX, unCoord2) \ |
|||
DBufferType0 MERGE_NAME(NAME, 0) = LOAD_TEXTURE2D(MERGE_NAME(TEX, 0), unCoord2); \ |
|||
DBufferType1 MERGE_NAME(NAME, 1) = LOAD_TEXTURE2D(MERGE_NAME(TEX, 1), unCoord2); |
|||
|
|||
#define ENCODE_INTO_DBUFFER(DECAL_SURFACE_DATA, NAME) EncodeIntoDBuffer(DECAL_SURFACE_DATA, MERGE_NAME(NAME,0), MERGE_NAME(NAME,1)) |
|||
#define DECODE_FROM_DBUFFER(NAME, DECAL_SURFACE_DATA) DecodeFromDBuffer(MERGE_NAME(NAME,0), MERGE_NAME(NAME,1), DECAL_SURFACE_DATA) |
|||
|
|||
#elif DBUFFERMATERIAL_COUNT == 3 |
|||
|
|||
#define OUTPUT_DBUFFER(NAME) \ |
|||
out DBufferType0 MERGE_NAME(NAME, 0) : SV_Target0, \ |
|||
out DBufferType1 MERGE_NAME(NAME, 1) : SV_Target1, \ |
|||
out DBufferType2 MERGE_NAME(NAME, 2) : SV_Target2 |
|||
|
|||
#define DECLARE_DBUFFER_TEXTURE(NAME) \ |
|||
TEXTURE2D(MERGE_NAME(NAME, 0)); \ |
|||
TEXTURE2D(MERGE_NAME(NAME, 1)); \ |
|||
TEXTURE2D(MERGE_NAME(NAME, 2)); |
|||
|
|||
#define FETCH_DBUFFER(NAME, TEX, unCoord2) \ |
|||
DBufferType0 MERGE_NAME(NAME, 0) = LOAD_TEXTURE2D(MERGE_NAME(TEX, 0), unCoord2); \ |
|||
DBufferType1 MERGE_NAME(NAME, 1) = LOAD_TEXTURE2D(MERGE_NAME(TEX, 1), unCoord2); \ |
|||
DBufferType2 MERGE_NAME(NAME, 2) = LOAD_TEXTURE2D(MERGE_NAME(TEX, 2), unCoord2); |
|||
|
|||
#define ENCODE_INTO_DBUFFER(DECAL_SURFACE_DATA, NAME) EncodeIntoDBuffer(DECAL_SURFACE_DATA, MERGE_NAME(NAME,0), MERGE_NAME(NAME,1), MERGE_NAME(NAME,2)) |
|||
#define DECODE_FROM_DBUFFER(NAME, DECAL_SURFACE_DATA) DecodeFromDBuffer(MERGE_NAME(NAME,0), MERGE_NAME(NAME,1), MERGE_NAME(NAME,2), DECAL_SURFACE_DATA) |
|||
|
|||
#elif DBUFFERMATERIAL_COUNT == 4 |
|||
|
|||
#define OUTPUT_DBUFFER(NAME) \ |
|||
out DBufferType0 MERGE_NAME(NAME, 0) : SV_Target0, \ |
|||
out DBufferType1 MERGE_NAME(NAME, 1) : SV_Target1, \ |
|||
out DBufferType2 MERGE_NAME(NAME, 2) : SV_Target2, \ |
|||
out DBufferType3 MERGE_NAME(NAME, 3) : SV_Target3 |
|||
|
|||
#define DECLARE_DBUFFER_TEXTURE(NAME) \ |
|||
TEXTURE2D(MERGE_NAME(NAME, 0)); \ |
|||
TEXTURE2D(MERGE_NAME(NAME, 1)); \ |
|||
TEXTURE2D(MERGE_NAME(NAME, 2)); \ |
|||
TEXTURE2D(MERGE_NAME(NAME, 3)); |
|||
|
|||
#define FETCH_DBUFFER(NAME, TEX, unCoord2) \ |
|||
DBufferType0 MERGE_NAME(NAME, 0) = LOAD_TEXTURE2D(MERGE_NAME(TEX, 0), unCoord2); \ |
|||
DBufferType1 MERGE_NAME(NAME, 1) = LOAD_TEXTURE2D(MERGE_NAME(TEX, 1), unCoord2); \ |
|||
DBufferType2 MERGE_NAME(NAME, 2) = LOAD_TEXTURE2D(MERGE_NAME(TEX, 2), unCoord2); \ |
|||
DBufferType3 MERGE_NAME(NAME, 3) = LOAD_TEXTURE2D(MERGE_NAME(TEX, 3), unCoord2); |
|||
|
|||
#define ENCODE_INTO_DBUFFER(DECAL_SURFACE_DATA, NAME) EncodeIntoDBuffer(DECAL_SURFACE_DATA, MERGE_NAME(NAME,0), MERGE_NAME(NAME,1), MERGE_NAME(NAME,2), MERGE_NAME(NAME,3)) |
|||
#define DECODE_FROM_DBUFFER(NAME, DECAL_SURFACE_DATA) DecodeFromDBuffer(MERGE_NAME(NAME,0), MERGE_NAME(NAME,1), MERGE_NAME(NAME,2), MERGE_NAME(NAME,3), DECAL_SURFACE_DATA) |
|||
|
|||
#endif |
|||
#endif // #ifdef DBUFFERMATERIAL_COUNT |
|||
|
|||
|
|||
// Must be in sync with RT declared in HDRenderPipeline.cs ::Rebuild |
|||
void EncodeIntoDBuffer( DecalSurfaceData surfaceData, |
|||
out DBufferType0 outDBuffer0, |
|||
out DBufferType1 outDBuffer1 |
|||
) |
|||
{ |
|||
outDBuffer0 = surfaceData.baseColor; |
|||
outDBuffer1 = surfaceData.normalWS; |
|||
} |
|||
|
|||
void DecodeFromDBuffer( |
|||
DBufferType0 inDBuffer0, |
|||
DBufferType1 inDBuffer1, |
|||
out DecalSurfaceData surfaceData |
|||
) |
|||
{ |
|||
ZERO_INITIALIZE(DecalSurfaceData, surfaceData); |
|||
surfaceData.baseColor = inDBuffer0; |
|||
surfaceData.normalWS = inDBuffer1 * float4(2.0f, 2.0f, 2.0f, 1.0f) - float4(1.0f, 1.0f, 1.0f, 0.0f); |
|||
} |
|||
|
|
|||
//------------------------------------------------------------------------------------- |
|||
// Fill SurfaceData/Builtin data function |
|||
//------------------------------------------------------------------------------------- |
|||
#include "../../../Core/ShaderLibrary/Packing.hlsl" |
|||
#include "../../../Core/ShaderLibrary/EntityLighting.hlsl" |
|||
void GetSurfaceAndBuiltinData(FragInputs input, float3 V, inout PositionInputs posInput, out SurfaceData surfaceData, out BuiltinData builtinData) |
|||
void GetSurfaceData(float2 texCoordDS, out DecalSurfaceData surfaceData) |
|||
float3 positionWS = posInput.positionWS; |
|||
float3 positionDS = mul(_WorldToDecal, float4(positionWS, 1.0f)).xyz; |
|||
clip(positionDS < 0 ? -1 : 1); |
|||
clip(positionDS > 1 ? -1 : 1); |
|||
surfaceData.baseColor = SAMPLE_TEXTURE2D(_BaseColorMap, sampler_BaseColorMap, positionDS.xz); |
|||
surfaceData.baseColor = SAMPLE_TEXTURE2D(_BaseColorMap, sampler_BaseColorMap, texCoordDS.xy); |
|||
ZERO_INITIALIZE(BuiltinData, builtinData); |
|||
texCoord.uv = positionDS.xz; |
|||
texCoord.uv = texCoordDS.xy; |
|||
surfaceData.normalWS.xyz = 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.w = totalBlend; |
|||
#endif |
|||
} |
|
|||
using System; |
|||
using UnityEditor; |
|||
using UnityEngine; |
|||
namespace UnityEngine.Experimental.Rendering.HDPipeline |
|||
{ |
|||
[ExecuteInEditMode] |
|||
public class DecalProjectorComponent : MonoBehaviour |
|||
{ |
|||
private static readonly int m_WorldToDecal = Shader.PropertyToID("_WorldToDecal"); |
|||
private static readonly int m_DecalToWorldR = Shader.PropertyToID("_DecalToWorldR"); |
|||
|
|||
public Material m_Material; |
|||
|
|||
private MaterialPropertyBlock m_PropertyBlock; |
|||
|
|||
public void OnEnable() |
|||
{ |
|||
DecalSystem.instance.AddDecal(this); |
|||
} |
|||
|
|||
public void Start() |
|||
{ |
|||
m_PropertyBlock = new MaterialPropertyBlock(); |
|||
UpdatePropertyBlock(); |
|||
DecalSystem.instance.AddDecal(this); |
|||
} |
|||
|
|||
public void OnDisable() |
|||
{ |
|||
DecalSystem.instance.RemoveDecal(this); |
|||
} |
|||
|
|||
public void OnValidate() |
|||
{ |
|||
if (m_Material != null) |
|||
{ |
|||
Shader shader = m_Material.shader; |
|||
if((shader != null) && (shader.name != "HDRenderPipeline/Decal")) |
|||
{ |
|||
Debug.LogWarning("Decal projector component material is not using HDRenderPipeline/Decal shader.", this); |
|||
} |
|||
} |
|||
} |
|||
|
|||
|
|||
private void DrawGizmo(bool selected) |
|||
{ |
|||
var col = new Color(0.0f, 0.7f, 1f, 1.0f); |
|||
col.a = selected ? 0.3f : 0.1f; |
|||
Gizmos.color = col; |
|||
Matrix4x4 offset = Matrix4x4.Translate(new Vector3(0.0f, -0.5f, 0.0f)); |
|||
Gizmos.matrix = transform.localToWorldMatrix * offset; |
|||
Gizmos.DrawCube(Vector3.zero, Vector3.one); |
|||
col.a = selected ? 0.5f : 0.2f; |
|||
Gizmos.color = col; |
|||
Gizmos.DrawWireCube(Vector3.zero, Vector3.one); |
|||
} |
|||
|
|||
public void OnDrawGizmos() |
|||
{ |
|||
//DrawGizmo(false);
|
|||
} |
|||
public void OnDrawGizmosSelected() |
|||
{ |
|||
DrawGizmo(true); |
|||
} |
|||
|
|||
[MenuItem("GameObject/Effects/Decal", false, 0)] |
|||
static void CreateDecal(MenuCommand menuCommand) |
|||
{ |
|||
// Create a custom game object
|
|||
GameObject go = new GameObject("Decal"); |
|||
go.AddComponent<DecalProjectorComponent>(); |
|||
// Ensure it gets re-parented if this was a context click (otherwise does nothing)
|
|||
GameObjectUtility.SetParentAndAlign(go, menuCommand.context as GameObject); |
|||
// Register the creation in the undo system
|
|||
Undo.RegisterCreatedObjectUndo(go, "Create " + go.name); |
|||
Selection.activeObject = go; |
|||
} |
|||
|
|||
public void UpdatePropertyBlock() |
|||
{ |
|||
Matrix4x4 CRWStoAWS = new Matrix4x4(); |
|||
if (ShaderConfig.s_CameraRelativeRendering == 1) |
|||
{ |
|||
// Vector4 worldSpaceCameraPos = Shader.GetGlobalVector(HDShaderIDs._WorldSpaceCameraPos);
|
|||
CRWStoAWS = Matrix4x4.Translate(Camera.main.transform.position); |
|||
} |
|||
else |
|||
{ |
|||
CRWStoAWS = Matrix4x4.identity; |
|||
} |
|||
|
|||
Matrix4x4 final = transform.localToWorldMatrix; |
|||
Matrix4x4 decalToWorldR = Matrix4x4.Rotate(transform.localRotation); |
|||
Matrix4x4 worldToDecal = Matrix4x4.Translate(new Vector3(0.5f, 0.0f, 0.5f)) * Matrix4x4.Scale(new Vector3(1.0f, -1.0f, 1.0f)) * final.inverse; |
|||
if (m_PropertyBlock == null) |
|||
{ |
|||
m_PropertyBlock = new MaterialPropertyBlock(); |
|||
} |
|||
m_PropertyBlock.SetMatrix(m_DecalToWorldR, decalToWorldR); |
|||
m_PropertyBlock.SetMatrix(m_WorldToDecal, worldToDecal); |
|||
} |
|||
|
|||
public MaterialPropertyBlock GetPropertyBlock() |
|||
{ |
|||
return m_PropertyBlock; |
|||
} |
|||
} |
|||
} |
|
|||
#include "Decal.hlsl" |
|||
|
|||
DECLARE_DBUFFER_TEXTURE(_DBufferTexture); |
|||
|
|||
void AddDecalContribution(uint2 unPositionSS, inout SurfaceData surfaceData) |
|||
{ |
|||
FETCH_DBUFFER(DBuffer, _DBufferTexture, unPositionSS); |
|||
DecalSurfaceData decalSurfaceData; |
|||
DECODE_FROM_DBUFFER(DBuffer, decalSurfaceData); |
|||
|
|||
surfaceData.baseColor.xyz = lerp(surfaceData.baseColor.xyz, decalSurfaceData.baseColor.xyz, decalSurfaceData.baseColor.w); |
|||
surfaceData.normalWS.xyz = normalize(lerp(surfaceData.normalWS.xyz, decalSurfaceData.normalWS.xyz, decalSurfaceData.normalWS.w)); |
|||
} |
|
|||
using UnityEditor; |
|||
using UnityEngine; |
|||
namespace UnityEngine.Experimental.Rendering.HDPipeline |
|||
{ |
|||
[ExecuteInEditMode] |
|||
public class DecalComponent : MonoBehaviour |
|||
{ |
|||
public enum Kind |
|||
{ |
|||
DiffuseOnly, |
|||
NormalsOnly, |
|||
Both |
|||
} |
|||
|
|||
public Kind m_Kind; |
|||
public Material m_Material; |
|||
|
|||
public void OnEnable() |
|||
{ |
|||
DecalSystem.instance.AddDecal(this); |
|||
} |
|||
|
|||
public void Start() |
|||
{ |
|||
DecalSystem.instance.AddDecal(this); |
|||
} |
|||
|
|||
public void OnDisable() |
|||
{ |
|||
DecalSystem.instance.RemoveDecal(this); |
|||
} |
|||
|
|||
private void DrawGizmo(bool selected) |
|||
{ |
|||
var col = new Color(0.0f, 0.7f, 1f, 1.0f); |
|||
col.a = selected ? 0.3f : 0.1f; |
|||
Gizmos.color = col; |
|||
Matrix4x4 offset = Matrix4x4.Translate(new Vector3(0.0f, -0.5f, 0.0f)); |
|||
Gizmos.matrix = transform.localToWorldMatrix * offset; |
|||
Gizmos.DrawCube(Vector3.zero, Vector3.one); |
|||
col.a = selected ? 0.5f : 0.2f; |
|||
Gizmos.color = col; |
|||
Gizmos.DrawWireCube(Vector3.zero, Vector3.one); |
|||
} |
|||
|
|||
public void OnDrawGizmos() |
|||
{ |
|||
//DrawGizmo(false);
|
|||
} |
|||
public void OnDrawGizmosSelected() |
|||
{ |
|||
DrawGizmo(true); |
|||
} |
|||
|
|||
[MenuItem("GameObject/Effects/Decal", false, 0)] |
|||
static void CreateDecal(MenuCommand menuCommand) |
|||
{ |
|||
// Create a custom game object
|
|||
GameObject go = new GameObject("Decal"); |
|||
go.AddComponent<DecalComponent>(); |
|||
// Ensure it gets re-parented if this was a context click (otherwise does nothing)
|
|||
GameObjectUtility.SetParentAndAlign(go, menuCommand.context as GameObject); |
|||
// Register the creation in the undo system
|
|||
Undo.RegisterCreatedObjectUndo(go, "Create " + go.name); |
|||
Selection.activeObject = go; |
|||
} |
|||
} |
|||
} |
撰写
预览
正在加载...
取消
保存
Reference in new issue