GitHub
7 年前
当前提交
bb442f25
共有 40 个文件被更改,包括 881 次插入 和 9 次删除
-
1ScriptableRenderPipeline/HDRenderPipeline/HDCustomSamplerId.cs
-
62ScriptableRenderPipeline/HDRenderPipeline/HDRenderPipeline.cs
-
10ScriptableRenderPipeline/HDRenderPipeline/HDStringConstants.cs
-
2ScriptableRenderPipeline/HDRenderPipeline/Material/LayeredLit/LayeredLitData.hlsl
-
8ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/LitData.hlsl
-
1ScriptableRenderPipeline/HDRenderPipeline/Material/Material.hlsl
-
3ScriptableRenderPipeline/HDRenderPipeline/ShaderPass/ShaderPass.cs
-
1ScriptableRenderPipeline/HDRenderPipeline/ShaderPass/ShaderPass.cs.hlsl
-
8ScriptableRenderPipeline/HDRenderPipeline/Decal.meta
-
8ScriptableRenderPipeline/HDRenderPipeline/Material/Decal.meta
-
33ScriptableRenderPipeline/HDRenderPipeline/ShaderPass/ShaderPassDBuffer.hlsl
-
9ScriptableRenderPipeline/HDRenderPipeline/ShaderPass/ShaderPassDBuffer.hlsl.meta
-
104ScriptableRenderPipeline/HDRenderPipeline/Decal/DecalProjectorComponent.cs
-
88ScriptableRenderPipeline/HDRenderPipeline/Decal/DecalSystem.cs
-
11ScriptableRenderPipeline/HDRenderPipeline/Decal/DecalProjectorComponent.cs.meta
-
11ScriptableRenderPipeline/HDRenderPipeline/Decal/DecalSystem.cs.meta
-
17ScriptableRenderPipeline/HDRenderPipeline/Material/Decal/DecalProperties.hlsl
-
44ScriptableRenderPipeline/HDRenderPipeline/Material/Decal/Decal.cs.hlsl
-
110ScriptableRenderPipeline/HDRenderPipeline/Material/Decal/Decal.hlsl
-
24ScriptableRenderPipeline/HDRenderPipeline/Material/Decal/DecalData.hlsl
-
13ScriptableRenderPipeline/HDRenderPipeline/Material/Decal/DecalUtilities.hlsl
-
40ScriptableRenderPipeline/HDRenderPipeline/Material/Decal/Decal.cs
-
9ScriptableRenderPipeline/HDRenderPipeline/Material/Decal/Decal.cs.hlsl.meta
-
11ScriptableRenderPipeline/HDRenderPipeline/Material/Decal/Decal.cs.meta
-
9ScriptableRenderPipeline/HDRenderPipeline/Material/Decal/Decal.hlsl.meta
-
76ScriptableRenderPipeline/HDRenderPipeline/Material/Decal/Decal.shader
-
9ScriptableRenderPipeline/HDRenderPipeline/Material/Decal/Decal.shader.meta
-
9ScriptableRenderPipeline/HDRenderPipeline/Material/Decal/DecalData.hlsl.meta
-
9ScriptableRenderPipeline/HDRenderPipeline/Material/Decal/DecalProperties.hlsl.meta
-
9ScriptableRenderPipeline/HDRenderPipeline/Material/Decal/DecalUtilities.hlsl.meta
-
8ScriptableRenderPipeline/HDRenderPipeline/Material/Decal/Editor.meta
-
98ScriptableRenderPipeline/HDRenderPipeline/Material/Decal/Editor/DecalUI.cs
-
11ScriptableRenderPipeline/HDRenderPipeline/Material/Decal/Editor/DecalUI.cs.meta
-
8ScriptableRenderPipeline/HDRenderPipeline/Material/Decal/ShaderPass.meta
-
7ScriptableRenderPipeline/HDRenderPipeline/Material/Decal/ShaderPass/DecalSharePass.hlsl
-
9ScriptableRenderPipeline/HDRenderPipeline/Material/Decal/ShaderPass/DecalSharePass.hlsl.meta
|
|||
fileFormatVersion: 2 |
|||
guid: e23938c16411b694c9f86517a2ad5e5e |
|||
folderAsset: yes |
|||
DefaultImporter: |
|||
externalObjects: {} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
fileFormatVersion: 2 |
|||
guid: ce1e252deae73a04a96dc6d2014164ca |
|||
folderAsset: yes |
|||
DefaultImporter: |
|||
externalObjects: {} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
#if SHADERPASS != SHADERPASS_DBUFFER |
|||
#error SHADERPASS_is_not_correctly_define |
|||
#endif |
|||
|
|||
#include "VertMesh.hlsl" |
|||
|
|||
PackedVaryingsType Vert(AttributesMesh inputMesh) |
|||
{ |
|||
VaryingsType varyingsType; |
|||
varyingsType.vmesh = VertMesh(inputMesh); |
|||
return PackVaryingsType(varyingsType); |
|||
} |
|||
|
|||
|
|||
void Frag( PackedVaryingsToPS packedInput, |
|||
OUTPUT_DBUFFER(outDBuffer) |
|||
) |
|||
{ |
|||
PositionInputs posInput = GetPositionInput(packedInput.vmesh.positionCS, _ScreenSize.zw); |
|||
|
|||
float d = LOAD_TEXTURE2D(_MainDepthTexture, posInput.positionSS).x; |
|||
UpdatePositionInput(d, UNITY_MATRIX_I_VP, UNITY_MATRIX_VP, posInput); |
|||
|
|||
float3 positionWS = posInput.positionWS; |
|||
float3 positionDS = mul(_WorldToDecal, float4(positionWS, 1.0f)).xyz; |
|||
clip(positionDS < 0 ? -1 : 1); |
|||
clip(positionDS > 1 ? -1 : 1); |
|||
|
|||
DecalSurfaceData surfaceData; |
|||
GetSurfaceData(positionDS.xz, surfaceData); |
|||
|
|||
ENCODE_INTO_DBUFFER(surfaceData, outDBuffer); |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 3e465a3a5bd2869419f16363a863b82d |
|||
ShaderImporter: |
|||
externalObjects: {} |
|||
defaultTextures: [] |
|||
nonModifiableTextures: [] |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
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(); |
|||
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 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(Vector3 cameraPos) |
|||
{ |
|||
Matrix4x4 CRWStoAWS = new Matrix4x4(); |
|||
if (ShaderConfig.s_CameraRelativeRendering == 1) |
|||
{ |
|||
CRWStoAWS = Matrix4x4.Translate(cameraPos); |
|||
} |
|||
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 * CRWStoAWS); |
|||
} |
|||
|
|||
public MaterialPropertyBlock GetPropertyBlock() |
|||
{ |
|||
return m_PropertyBlock; |
|||
} |
|||
} |
|||
} |
|
|||
using System.Collections.Generic; |
|||
using UnityEngine.Experimental.Rendering; |
|||
using UnityEngine.Rendering; |
|||
|
|||
namespace UnityEngine.Experimental.Rendering.HDPipeline |
|||
{ |
|||
public class DecalSystem |
|||
{ |
|||
static DecalSystem m_Instance; |
|||
static public DecalSystem instance |
|||
{ |
|||
get |
|||
{ |
|||
if (m_Instance == null) |
|||
m_Instance = new DecalSystem(); |
|||
return m_Instance; |
|||
} |
|||
} |
|||
|
|||
internal HashSet<DecalProjectorComponent> m_Decals = new HashSet<DecalProjectorComponent>(); |
|||
Mesh m_CubeMesh; |
|||
|
|||
public DecalSystem() |
|||
{ |
|||
CreateCubeMesh(); |
|||
} |
|||
|
|||
void CreateCubeMesh() |
|||
{ |
|||
m_CubeMesh = new Mesh(); |
|||
|
|||
Vector3[] vertices = new Vector3[8]; |
|||
|
|||
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; |
|||
|
|||
int[] triangles = new int[36]; |
|||
|
|||
triangles[0] = 0; triangles[1] = 2; triangles[2] = 1; |
|||
triangles[3] = 0; triangles[4] = 3; triangles[5] = 2; |
|||
triangles[6] = 1; triangles[7] = 6; triangles[8] = 5; |
|||
triangles[9] = 1; triangles[10] = 2; triangles[11] = 6; |
|||
triangles[12] = 5; triangles[13] = 7; triangles[14] = 4; |
|||
triangles[15] = 5; triangles[16] = 6; triangles[17] = 7; |
|||
triangles[18] = 4; triangles[19] = 3; triangles[20] = 0; |
|||
triangles[21] = 4; triangles[22] = 7; triangles[23] = 3; |
|||
triangles[24] = 3; triangles[25] = 6; triangles[26] = 2; |
|||
triangles[27] = 3; triangles[28] = 7; triangles[29] = 6; |
|||
triangles[30] = 4; triangles[31] = 1; triangles[32] = 5; |
|||
triangles[33] = 4; triangles[34] = 0; triangles[35] = 1; |
|||
|
|||
m_CubeMesh.triangles = triangles; |
|||
} |
|||
|
|||
public void AddDecal(DecalProjectorComponent d) |
|||
{ |
|||
if (d.m_Material.GetTexture("_BaseColorMap") || d.m_Material.GetTexture("_NormalMap")) |
|||
{ |
|||
RemoveDecal(d); |
|||
m_Decals.Add(d); |
|||
} |
|||
} |
|||
|
|||
public void RemoveDecal(DecalProjectorComponent d) |
|||
{ |
|||
m_Decals.Remove(d); |
|||
} |
|||
|
|||
public void Render(ScriptableRenderContext renderContext, Vector3 cameraPos, CommandBuffer cmd) |
|||
{ |
|||
if (m_CubeMesh == null) |
|||
CreateCubeMesh(); |
|||
foreach (var decal in m_Decals) |
|||
{ |
|||
decal.UpdatePropertyBlock(cameraPos); |
|||
cmd.DrawMesh(m_CubeMesh, decal.transform.localToWorldMatrix, decal.m_Material, 0, 0, decal.GetPropertyBlock()); |
|||
} |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: f19d9143a39eb3b46bc4563e9889cfbd |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
fileFormatVersion: 2 |
|||
guid: 3305c9249c40f8b43a953a8a6eb87a82 |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
#ifndef UNITY_DECALPROPERTIES_INCLUDED |
|||
#define UNITY_DECALPROPERTIES_INCLUDED |
|||
|
|||
|
|||
TEXTURE2D(_BaseColorMap); |
|||
SAMPLER2D(sampler_BaseColorMap); |
|||
TEXTURE2D(_NormalMap); |
|||
SAMPLER2D(sampler_NormalMap); |
|||
|
|||
float _DecalBlend; |
|||
|
|||
CBUFFER_START(Decal) |
|||
float4x4 _WorldToDecal; |
|||
float4x4 _DecalToWorldR; |
|||
CBUFFER_END |
|||
|
|||
#endif |
|
|||
// |
|||
// This file was automatically generated. Please don't edit by hand. |
|||
// |
|||
|
|||
#ifndef DECAL_CS_HLSL |
|||
#define DECAL_CS_HLSL |
|||
// |
|||
// UnityEngine.Experimental.Rendering.HDPipeline.Decal+DecalSurfaceData: static fields |
|||
// |
|||
#define DEBUGVIEW_DECAL_DECALSURFACEDATA_BASE_COLOR (10000) |
|||
#define DEBUGVIEW_DECAL_DECALSURFACEDATA_NORMAL_WS (10001) |
|||
|
|||
// |
|||
// UnityEngine.Experimental.Rendering.HDPipeline.Decal+DBufferMaterial: static fields |
|||
// |
|||
#define DBUFFERMATERIAL_COUNT (2) |
|||
|
|||
// Generated from UnityEngine.Experimental.Rendering.HDPipeline.Decal+DecalSurfaceData |
|||
// PackingRules = Exact |
|||
struct DecalSurfaceData |
|||
{ |
|||
float4 baseColor; |
|||
float4 normalWS; |
|||
}; |
|||
|
|||
// |
|||
// Debug functions |
|||
// |
|||
void GetGeneratedDecalSurfaceDataDebug(uint paramId, DecalSurfaceData decalsurfacedata, inout float3 result, inout bool needLinearToSRGB) |
|||
{ |
|||
switch (paramId) |
|||
{ |
|||
case DEBUGVIEW_DECAL_DECALSURFACEDATA_BASE_COLOR: |
|||
result = decalsurfacedata.baseColor.xyz; |
|||
needLinearToSRGB = true; |
|||
break; |
|||
case DEBUGVIEW_DECAL_DECALSURFACEDATA_NORMAL_WS: |
|||
result = decalsurfacedata.normalWS.xyz; |
|||
break; |
|||
} |
|||
} |
|||
|
|||
|
|||
#endif |
|
|||
#include "Decal.cs.hlsl" |
|||
|
|||
#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.xyz = inDBuffer1.xyz * 2.0f - 1.0f; |
|||
surfaceData.normalWS.w = inDBuffer1.w; |
|||
} |
|||
|
|
|||
//------------------------------------------------------------------------------------- |
|||
// Fill SurfaceData/Builtin data function |
|||
//------------------------------------------------------------------------------------- |
|||
#include "ShaderLibrary/Packing.hlsl" |
|||
#include "ShaderLibrary/SampleUVMapping.hlsl" |
|||
|
|||
void GetSurfaceData(float2 texCoordDS, out DecalSurfaceData surfaceData) |
|||
{ |
|||
surfaceData.baseColor = float4(0,0,0,0); |
|||
surfaceData.normalWS = float4(0,0,0,0); |
|||
float totalBlend = _DecalBlend; |
|||
#if _COLORMAP |
|||
surfaceData.baseColor = SAMPLE_TEXTURE2D(_BaseColorMap, sampler_BaseColorMap, texCoordDS.xy); |
|||
totalBlend *= surfaceData.baseColor.w; |
|||
surfaceData.baseColor.w = totalBlend; |
|||
#endif |
|||
UVMapping texCoord; |
|||
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.w = totalBlend; |
|||
#endif |
|||
} |
|
|||
#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 UnityEngine.Rendering; |
|||
|
|||
namespace UnityEngine.Experimental.Rendering.HDPipeline |
|||
{ |
|||
public partial class Decal |
|||
{ |
|||
// Main structure that store the user data (i.e user input of master node in material graph)
|
|||
[GenerateHLSL(PackingRules.Exact, false, true, 10000)] |
|||
public struct DecalSurfaceData |
|||
{ |
|||
[SurfaceDataAttributes("Base Color", false, true)] |
|||
public Vector4 baseColor; |
|||
[SurfaceDataAttributes("Normal", true)] |
|||
public Vector4 normalWS; |
|||
}; |
|||
|
|||
[GenerateHLSL(PackingRules.Exact)] |
|||
public enum DBufferMaterial |
|||
{ |
|||
// Note: This count doesn't include the velocity buffer. On shader and csharp side the velocity buffer will be added by the framework
|
|||
Count = 2 |
|||
}; |
|||
|
|||
//-----------------------------------------------------------------------------
|
|||
// DBuffer management
|
|||
//-----------------------------------------------------------------------------
|
|||
|
|||
// should this be combined into common class shared with Lit.cs???
|
|||
static public int GetMaterialDBufferCount() { return (int)DBufferMaterial.Count; } |
|||
|
|||
static RenderTextureFormat[] m_RTFormat = { RenderTextureFormat.ARGB32, RenderTextureFormat.ARGB32}; |
|||
static RenderTextureReadWrite[] m_RTReadWrite = { RenderTextureReadWrite.sRGB, RenderTextureReadWrite.Linear}; |
|||
|
|||
static public void GetMaterialDBufferDescription(out RenderTextureFormat[] RTFormat, out RenderTextureReadWrite[] RTReadWrite) |
|||
{ |
|||
RTFormat = m_RTFormat; |
|||
RTReadWrite = m_RTReadWrite; |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 2f597db7b26e3364e96b55892e001ff8 |
|||
ShaderImporter: |
|||
externalObjects: {} |
|||
defaultTextures: [] |
|||
nonModifiableTextures: [] |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
fileFormatVersion: 2 |
|||
guid: 77304d3868098cb40af6328dba0bafda |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
fileFormatVersion: 2 |
|||
guid: 24e76285bfb1d4648aeaf39ced47c9ee |
|||
ShaderImporter: |
|||
externalObjects: {} |
|||
defaultTextures: [] |
|||
nonModifiableTextures: [] |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
Shader "HDRenderPipeline/Decal" |
|||
{ |
|||
Properties |
|||
{ |
|||
_BaseColorMap("BaseColorMap", 2D) = "white" {} |
|||
_NormalMap("NormalMap", 2D) = "bump" {} // Tangent space normal map |
|||
_DecalBlend("_DecalBlend", Range(0.0, 1.0)) = 0.5 |
|||
} |
|||
|
|||
HLSLINCLUDE |
|||
|
|||
#pragma target 4.5 |
|||
#pragma only_renderers d3d11 ps4 xboxone vulkan metal |
|||
//#pragma enable_d3d11_debug_symbols |
|||
|
|||
//------------------------------------------------------------------------------------- |
|||
// Variant |
|||
//------------------------------------------------------------------------------------- |
|||
#pragma shader_feature _COLORMAP |
|||
#pragma shader_feature _NORMALMAP |
|||
|
|||
|
|||
//------------------------------------------------------------------------------------- |
|||
// Define |
|||
//------------------------------------------------------------------------------------- |
|||
#define UNITY_MATERIAL_DECAL // do we need this now that Material.hlsl is not getting included? |
|||
|
|||
|
|||
//------------------------------------------------------------------------------------- |
|||
// Include |
|||
//------------------------------------------------------------------------------------- |
|||
|
|||
#include "ShaderLibrary/Common.hlsl" |
|||
#include "ShaderLibrary/Wind.hlsl" |
|||
#include "../../ShaderPass/FragInputs.hlsl" |
|||
#include "../../ShaderPass/ShaderPass.cs.hlsl" |
|||
|
|||
|
|||
//------------------------------------------------------------------------------------- |
|||
// variable declaration |
|||
//------------------------------------------------------------------------------------- |
|||
|
|||
#include "DecalProperties.hlsl" |
|||
|
|||
// All our shaders use same name for entry point |
|||
#pragma vertex Vert |
|||
#pragma fragment Frag |
|||
|
|||
ENDHLSL |
|||
|
|||
SubShader |
|||
{ |
|||
Pass |
|||
{ |
|||
Name "DBuffer" // Name is not used |
|||
Tags { "LightMode" = "DBuffer" } // This will be only for opaque object based on the RenderQueue index |
|||
|
|||
// need to optimize this and use proper Cull and ZTest modes for cases when decal geometry is clipped by camera |
|||
Cull Off |
|||
ZWrite Off |
|||
ZTest Always |
|||
|
|||
HLSLPROGRAM |
|||
|
|||
#define SHADERPASS SHADERPASS_DBUFFER |
|||
#include "../../ShaderVariables.hlsl" |
|||
#include "Decal.hlsl" |
|||
#include "ShaderPass/DecalSharePass.hlsl" |
|||
#include "DecalData.hlsl" |
|||
#include "../../ShaderPass/ShaderPassDBuffer.hlsl" |
|||
|
|||
ENDHLSL |
|||
} |
|||
} |
|||
CustomEditor "Experimental.Rendering.HDPipeline.DecalUI" |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 1d64af84bdc970c4fae0c1e06dd95b73 |
|||
ShaderImporter: |
|||
externalObjects: {} |
|||
defaultTextures: [] |
|||
nonModifiableTextures: [] |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
fileFormatVersion: 2 |
|||
guid: 8d7b72155c1f8c74592263fbe5a557df |
|||
ShaderImporter: |
|||
externalObjects: {} |
|||
defaultTextures: [] |
|||
nonModifiableTextures: [] |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
fileFormatVersion: 2 |
|||
guid: 295b85a50f6edfe488511041c695c48a |
|||
ShaderImporter: |
|||
externalObjects: {} |
|||
defaultTextures: [] |
|||
nonModifiableTextures: [] |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
fileFormatVersion: 2 |
|||
guid: 025b8dd135d8eac4da1b8178d944d4a6 |
|||
ShaderImporter: |
|||
externalObjects: {} |
|||
defaultTextures: [] |
|||
nonModifiableTextures: [] |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
fileFormatVersion: 2 |
|||
guid: 63b8d3eb0967b4f41b631c98f7e9b027 |
|||
folderAsset: yes |
|||
DefaultImporter: |
|||
externalObjects: {} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using System; |
|||
using UnityEngine; |
|||
using UnityEngine.Experimental.Rendering; |
|||
using UnityEngine.Experimental.Rendering.HDPipeline; |
|||
|
|||
namespace UnityEditor.Experimental.Rendering.HDPipeline |
|||
{ |
|||
public class DecalUI : ShaderGUI |
|||
{ |
|||
protected static class Styles |
|||
{ |
|||
public static string InputsText = "Inputs"; |
|||
|
|||
public static GUIContent baseColorText = new GUIContent("Base Color + Blend", "Albedo (RGB) and Blend Factor (A)"); |
|||
public static GUIContent normalMapText = new GUIContent("Normal Map", "Normal Map (BC7/BC5/DXT5(nm))"); |
|||
public static GUIContent decalBlendText = new GUIContent("Decal Blend", "Combines with Base Color (A)"); |
|||
} |
|||
|
|||
protected MaterialProperty baseColorMap = new MaterialProperty(); |
|||
protected const string kBaseColorMap = "_BaseColorMap"; |
|||
|
|||
protected MaterialProperty normalMap = new MaterialProperty(); |
|||
protected const string kNormalMap = "_NormalMap"; |
|||
|
|||
protected MaterialProperty decalBlend = new MaterialProperty(); |
|||
protected const string kDecalBlend = "_DecalBlend"; |
|||
|
|||
|
|||
|
|||
protected MaterialEditor m_MaterialEditor; |
|||
|
|||
// This is call by the inspector
|
|||
|
|||
void FindMaterialProperties(MaterialProperty[] props) |
|||
{ |
|||
baseColorMap = FindProperty(kBaseColorMap, props); |
|||
normalMap = FindProperty(kNormalMap, props); |
|||
decalBlend = FindProperty(kDecalBlend, props); |
|||
} |
|||
|
|||
|
|||
// All Setup Keyword functions must be static. It allow to create script to automatically update the shaders with a script if code change
|
|||
static public void SetupMaterialKeywordsAndPass(Material material) |
|||
{ |
|||
CoreUtils.SetKeyword(material, "_COLORMAP", material.GetTexture(kBaseColorMap)); |
|||
CoreUtils.SetKeyword(material, "_NORMALMAP", material.GetTexture(kNormalMap)); |
|||
} |
|||
|
|||
protected void SetupMaterialKeywordsAndPassInternal(Material material) |
|||
{ |
|||
SetupMaterialKeywordsAndPass(material); |
|||
} |
|||
|
|||
|
|||
public void ShaderPropertiesGUI(Material material) |
|||
{ |
|||
// Use default labelWidth
|
|||
EditorGUIUtility.labelWidth = 0f; |
|||
|
|||
// Detect any changes to the material
|
|||
EditorGUI.BeginChangeCheck(); |
|||
{ |
|||
EditorGUILayout.LabelField(Styles.InputsText, EditorStyles.boldLabel); |
|||
|
|||
EditorGUI.indentLevel++; |
|||
|
|||
m_MaterialEditor.TexturePropertySingleLine(Styles.baseColorText, baseColorMap); |
|||
m_MaterialEditor.TexturePropertySingleLine(Styles.normalMapText, normalMap); |
|||
m_MaterialEditor.ShaderProperty(decalBlend, Styles.decalBlendText); |
|||
|
|||
EditorGUI.indentLevel--; |
|||
|
|||
} |
|||
|
|||
if (EditorGUI.EndChangeCheck()) |
|||
{ |
|||
foreach (var obj in m_MaterialEditor.targets) |
|||
SetupMaterialKeywordsAndPassInternal((Material)obj); |
|||
} |
|||
} |
|||
|
|||
public override void OnGUI(MaterialEditor materialEditor, MaterialProperty[] props) |
|||
{ |
|||
m_MaterialEditor = materialEditor; |
|||
// We should always do this call at the beginning
|
|||
m_MaterialEditor.serializedObject.Update(); |
|||
|
|||
FindMaterialProperties(props); |
|||
|
|||
Material material = materialEditor.target as Material; |
|||
ShaderPropertiesGUI(material); |
|||
|
|||
// We should always do this call at the end
|
|||
m_MaterialEditor.serializedObject.ApplyModifiedProperties(); |
|||
} |
|||
|
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: bd489cfbe365c5749980ef35538739db |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
fileFormatVersion: 2 |
|||
guid: c95c191806c59d74ebecbd500cbed836 |
|||
folderAsset: yes |
|||
DefaultImporter: |
|||
externalObjects: {} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
#ifndef SHADERPASS |
|||
#error Undefine_SHADERPASS |
|||
#endif |
|||
|
|||
|
|||
// This include will define the various Attributes/Varyings structure |
|||
#include "../../ShaderPass/VaryingMesh.hlsl" |
|
|||
fileFormatVersion: 2 |
|||
guid: 264d5aec19233224fa311299fb752e53 |
|||
ShaderImporter: |
|||
externalObjects: {} |
|||
defaultTextures: [] |
|||
nonModifiableTextures: [] |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
撰写
预览
正在加载...
取消
保存
Reference in new issue