浏览代码
Merge remote-tracking branch 'origin/master' into scriptablerenderloop-materialgraph
/scriptablerenderloop-materialgraph
Merge remote-tracking branch 'origin/master' into scriptablerenderloop-materialgraph
/scriptablerenderloop-materialgraph
Paul Demeulenaere
8 年前
当前提交
66d8d3f0
共有 25 个文件被更改,包括 2035 次插入 和 1242 次删除
-
1Assets/ScriptableRenderLoop/HDRenderLoop/HDRenderLoop.cs
-
254Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Material/Lit/LitData.hlsl
-
226Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Material/Lit/LitDefault.shader
-
16Assets/ScriptableRenderLoop/ShaderLibrary/API/D3D11.hlsl
-
19Assets/ScriptableRenderLoop/fptl/FptlLighting.cs
-
5Assets/TestScenes/HDTest/JulienTest.unity
-
453Assets/TestScenes/HDTest/Material/HDRenderLoopMaterials/Layered.mat
-
2Assets/TestScenes/HDTest/Material/HDRenderLoopMaterials/Layered.mat.meta
-
2ProjectSettings/ProjectVersion.txt
-
367Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Material/LayeredLit/LayeredLitDefault.shader
-
28Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Material/Lit/LitDebugPass.hlsl
-
9Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Material/Lit/LitDebugPass.hlsl.meta
-
106Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Material/Lit/LitDepthPass.hlsl
-
9Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Material/Lit/LitDepthPass.hlsl.meta
-
91Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Material/Lit/LitMetaPass.hlsl
-
9Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Material/Lit/LitMetaPass.hlsl.meta
-
9Assets/Shaders.meta
-
1001Assets/TestScenes/HDTest/GlobalIlluminationTest.unity
-
8Assets/TestScenes/HDTest/GlobalIlluminationTest.unity.meta
-
210Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Material/LayeredLit/LayeredLit.shader
-
9Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Material/LayeredLit/LayeredLitCommon.hlsl.meta
-
443Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Material/LayeredLit/LayeredLitCommon.hlsl
-
0/Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Material/LayeredLit/LayeredLitDefault.shader.meta
-
0/Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Material/Lit/LitSharePass.hlsl.meta
-
0/Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Material/Lit/LitSharePass.hlsl
|
|||
fileFormatVersion: 2 |
|||
guid: 6e7fa39a7d1b15c4184c9f51d86eba22 |
|||
timeCreated: 1476275536 |
|||
timeCreated: 1478608944 |
|||
licenseType: Pro |
|||
NativeFormatImporter: |
|||
userData: '{"GUIDArray":["01fa3be727161d249a81ad7065c15459","3acf8f156d29e494e8cd196462d1a17c","62b3c923bc540b94a803550e9927936a","c569253e641dc934db7c3595b31890da"]}' |
|
|||
m_EditorVersion: 5.6.0a1 |
|||
m_EditorVersion: 5.6.0a2 |
|
|||
Shader "HDRenderLoop/LayeredLit" |
|||
{ |
|||
Properties |
|||
{ |
|||
// Following set of parameters represent the parameters node inside the MaterialGraph. |
|||
// They are use to fill a SurfaceData. With a MaterialGraph this should not exist. |
|||
|
|||
// Reminder. Color here are in linear but the UI (color picker) do the conversion sRGB to linear |
|||
_BaseColor0("BaseColor0", Color) = (1,1,1,1) |
|||
_BaseColor1("BaseColor1", Color) = (1, 1, 1, 1) |
|||
_BaseColor2("BaseColor2", Color) = (1, 1, 1, 1) |
|||
_BaseColor3("BaseColor3", Color) = (1, 1, 1, 1) |
|||
|
|||
_BaseColorMap0("BaseColorMap0", 2D) = "white" {} |
|||
_BaseColorMap1("BaseColorMap1", 2D) = "white" {} |
|||
_BaseColorMap2("BaseColorMap2", 2D) = "white" {} |
|||
_BaseColorMap3("BaseColorMap3", 2D) = "white" {} |
|||
|
|||
_Metallic0("Metallic0", Range(0.0, 1.0)) = 0 |
|||
_Metallic1("Metallic1", Range(0.0, 1.0)) = 0 |
|||
_Metallic2("Metallic2", Range(0.0, 1.0)) = 0 |
|||
_Metallic3("Metallic3", Range(0.0, 1.0)) = 0 |
|||
|
|||
_Smoothness0("Smoothness0", Range(0.0, 1.0)) = 0.5 |
|||
_Smoothness1("Smoothness1", Range(0.0, 1.0)) = 0.5 |
|||
_Smoothness2("Smoothness2", Range(0.0, 1.0)) = 0.5 |
|||
_Smoothness3("Smoothness3", Range(0.0, 1.0)) = 0.5 |
|||
|
|||
_MaskMap0("MaskMap0", 2D) = "white" {} |
|||
_MaskMap1("MaskMap1", 2D) = "white" {} |
|||
_MaskMap2("MaskMap2", 2D) = "white" {} |
|||
_MaskMap3("MaskMap3", 2D) = "white" {} |
|||
|
|||
_SpecularOcclusionMap0("SpecularOcclusion0", 2D) = "white" {} |
|||
_SpecularOcclusionMap1("SpecularOcclusion1", 2D) = "white" {} |
|||
_SpecularOcclusionMap2("SpecularOcclusion2", 2D) = "white" {} |
|||
_SpecularOcclusionMap3("SpecularOcclusion3", 2D) = "white" {} |
|||
|
|||
_NormalMap0("NormalMap0", 2D) = "bump" {} |
|||
_NormalMap1("NormalMap1", 2D) = "bump" {} |
|||
_NormalMap2("NormalMap2", 2D) = "bump" {} |
|||
_NormalMap3("NormalMap3", 2D) = "bump" {} |
|||
|
|||
[Enum(TangentSpace, 0, ObjectSpace, 1)] _NormalMapSpace("NormalMap space", Float) = 0 |
|||
|
|||
_HeightMap0("HeightMap0", 2D) = "black" {} |
|||
_HeightMap1("HeightMap1", 2D) = "black" {} |
|||
_HeightMap2("HeightMap2", 2D) = "black" {} |
|||
_HeightMap3("HeightMap3", 2D) = "black" {} |
|||
|
|||
_HeightScale0("Height Scale0", Float) = 1 |
|||
_HeightScale1("Height Scale1", Float) = 1 |
|||
_HeightScale2("Height Scale2", Float) = 1 |
|||
_HeightScale3("Height Scale3", Float) = 1 |
|||
|
|||
_HeightBias0("Height Bias0", Float) = 0 |
|||
_HeightBias1("Height Bias1", Float) = 0 |
|||
_HeightBias2("Height Bias2", Float) = 0 |
|||
_HeightBias3("Height Bias3", Float) = 0 |
|||
|
|||
[Enum(Parallax, 0, Displacement, 1)] _HeightMapMode("Heightmap usage", Float) = 0 |
|||
|
|||
_EmissiveColor0("EmissiveColor0", Color) = (0, 0, 0) |
|||
_EmissiveColor1("EmissiveColor1", Color) = (0, 0, 0) |
|||
_EmissiveColor2("EmissiveColor2", Color) = (0, 0, 0) |
|||
_EmissiveColor3("EmissiveColor3", Color) = (0, 0, 0) |
|||
|
|||
_EmissiveColorMap0("EmissiveColorMap0", 2D) = "white" {} |
|||
_EmissiveColorMap1("EmissiveColorMap1", 2D) = "white" {} |
|||
_EmissiveColorMap2("EmissiveColorMap2", 2D) = "white" {} |
|||
_EmissiveColorMap3("EmissiveColorMap3", 2D) = "white" {} |
|||
|
|||
_EmissiveIntensity0("EmissiveIntensity0", Float) = 0 |
|||
_EmissiveIntensity1("EmissiveIntensity1", Float) = 0 |
|||
_EmissiveIntensity2("EmissiveIntensity2", Float) = 0 |
|||
_EmissiveIntensity3("EmissiveIntensity3", Float) = 0 |
|||
|
|||
_LayerMaskMap("LayerMaskMap", 2D) = "white" {} |
|||
|
|||
[ToggleOff] _DistortionOnly("Distortion Only", Float) = 0.0 |
|||
[ToggleOff] _DistortionDepthTest("Distortion Only", Float) = 0.0 |
|||
|
|||
[ToggleOff] _AlphaCutoffEnable("Alpha Cutoff Enable", Float) = 0.0 |
|||
|
|||
_AlphaCutoff("Alpha Cutoff", Range(0.0, 1.0)) = 0.5 |
|||
|
|||
// Blending state |
|||
[HideInInspector] _SurfaceType("__surfacetype", Float) = 0.0 |
|||
[HideInInspector] _BlendMode ("__blendmode", Float) = 0.0 |
|||
[HideInInspector] _SrcBlend ("__src", Float) = 1.0 |
|||
[HideInInspector] _DstBlend ("__dst", Float) = 0.0 |
|||
[HideInInspector] _ZWrite ("__zw", Float) = 1.0 |
|||
[HideInInspector] _CullMode("__cullmode", Float) = 2.0 |
|||
// Material Id |
|||
[HideInInspector] _MaterialId("_MaterialId", FLoat) = 0 |
|||
|
|||
[HideInInspector] _LayerCount("__layerCount", Float) = 2.0 |
|||
|
|||
[Enum(Mask Alpha, 0, BaseColor Alpha, 1)] _SmoothnessTextureChannel("Smoothness texture channel", Float) = 1 |
|||
[Enum(Use Emissive Color, 0, Use Emissive Mask, 1)] _EmissiveColorMode("Emissive color mode", Float) = 1 |
|||
[Enum(None, 0, DoubleSided, 1, DoubleSidedLigthingFlip, 2, DoubleSidedLigthingMirror, 3)] _DoubleSidedMode("Double sided mode", Float) = 0 |
|||
} |
|||
|
|||
HLSLINCLUDE |
|||
|
|||
#pragma target 5.0 |
|||
#pragma only_renderers d3d11 // TEMP: unitl we go futher in dev |
|||
|
|||
#pragma shader_feature _ALPHATEST_ON |
|||
#pragma shader_feature _ _DOUBLESIDED_LIGHTING_FLIP _DOUBLESIDED_LIGHTING_MIRROR |
|||
#pragma shader_feature _NORMALMAP |
|||
#pragma shader_feature _NORMALMAP_TANGENT_SPACE |
|||
#pragma shader_feature _MASKMAP |
|||
#pragma shader_feature _SPECULAROCCLUSIONMAP |
|||
#pragma shader_feature _SMOOTHNESS_TEXTURE_ALBEDO_CHANNEL_A |
|||
#pragma shader_feature _EMISSIVE_COLOR |
|||
#pragma shader_feature _EMISSIVE_COLOR_MAP |
|||
#pragma shader_feature _HEIGHTMAP |
|||
#pragma shader_feature _HEIGHTMAP_AS_DISPLACEMENT |
|||
#pragma shader_feature _LAYERMASKMAP |
|||
#pragma shader_feature _ _LAYEREDLIT_3_LAYERS _LAYEREDLIT_4_LAYERS |
|||
|
|||
//------------------------------------------------------------------------------------- |
|||
// Define |
|||
//------------------------------------------------------------------------------------- |
|||
|
|||
#define UNITY_MATERIAL_LIT // Need to be define before including Material.hlsl |
|||
|
|||
//------------------------------------------------------------------------------------- |
|||
// Include |
|||
//------------------------------------------------------------------------------------- |
|||
|
|||
#include "common.hlsl" |
|||
#include "Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/ShaderConfig.cs" |
|||
#include "Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/ShaderVariables.hlsl" |
|||
#include "Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/ShaderPass/ShaderPass.cs.hlsl" |
|||
#include "Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Debug/DebugViewMaterial.hlsl" |
|||
|
|||
//------------------------------------------------------------------------------------- |
|||
// variable declaration |
|||
//------------------------------------------------------------------------------------- |
|||
|
|||
// Set of users variables |
|||
#define PROP_DECL(type, name) type name, name##0, name##1, name##2, name##3; |
|||
#define PROP_DECL_TEX2D(name)\ |
|||
TEXTURE2D(name##0); \ |
|||
SAMPLER2D(sampler##name##0); \ |
|||
TEXTURE2D(name##1); \ |
|||
TEXTURE2D(name##2); \ |
|||
TEXTURE2D(name##3); |
|||
#define PROP_SAMPLE(name, textureName, texcoord, swizzle)\ |
|||
name##0 = SAMPLE_TEXTURE2D(textureName##0, sampler##textureName##0, texcoord).##swizzle; \ |
|||
name##1 = SAMPLE_TEXTURE2D(textureName##1, sampler##textureName##0, texcoord).##swizzle; \ |
|||
name##2 = SAMPLE_TEXTURE2D(textureName##2, sampler##textureName##0, texcoord).##swizzle; \ |
|||
name##3 = SAMPLE_TEXTURE2D(textureName##3, sampler##textureName##0, texcoord).##swizzle; |
|||
#define PROP_MUL(name, multiplier, swizzle)\ |
|||
name##0 *= multiplier##0.##swizzle; \ |
|||
name##1 *= multiplier##1.##swizzle; \ |
|||
name##2 *= multiplier##2.##swizzle; \ |
|||
name##3 *= multiplier##3.##swizzle; |
|||
#define PROP_ASSIGN(name, input, swizzle)\ |
|||
name##0 = input##0.##swizzle; \ |
|||
name##1 = input##1.##swizzle; \ |
|||
name##2 = input##2.##swizzle; \ |
|||
name##3 = input##3.##swizzle; |
|||
#define PROP_ASSIGN_VALUE(name, input)\ |
|||
name##0 = input; \ |
|||
name##1 = input; \ |
|||
name##2 = input; \ |
|||
name##3 = input; |
|||
#define PROP_BLEND_COLOR(name, mask) name = BlendLayeredColor(name##0, name##1, name##2, name##3, mask); |
|||
#define PROP_BLEND_SCALAR(name, mask) name = BlendLayeredScalar(name##0, name##1, name##2, name##3, mask); |
|||
|
|||
#define _MAX_LAYER 4 |
|||
|
|||
#if defined(_LAYEREDLIT_4_LAYERS) |
|||
# define _LAYER_COUNT 4 |
|||
#elif defined(_LAYEREDLIT_3_LAYERS) |
|||
# define _LAYER_COUNT 3 |
|||
#else |
|||
# define _LAYER_COUNT 2 |
|||
#endif |
|||
|
|||
//------------------------------------------------------------------------------------- |
|||
// variable declaration |
|||
//------------------------------------------------------------------------------------- |
|||
|
|||
// Set of users variables |
|||
PROP_DECL(float4, _BaseColor); |
|||
|
|||
//PROP_DECL_TEX2D(_BaseColorMap); |
|||
TEXTURE2D(_BaseColorMap0); |
|||
TEXTURE2D(_BaseColorMap1); |
|||
TEXTURE2D(_BaseColorMap2); |
|||
TEXTURE2D(_BaseColorMap3); |
|||
SAMPLER2D(sampler_BaseColorMap0); |
|||
|
|||
|
|||
PROP_DECL(float, _Metallic); |
|||
PROP_DECL(float, _Smoothness); |
|||
PROP_DECL_TEX2D(_MaskMap); |
|||
PROP_DECL_TEX2D(_SpecularOcclusionMap); |
|||
PROP_DECL_TEX2D(_NormalMap); |
|||
PROP_DECL_TEX2D(_Heightmap); |
|||
PROP_DECL(float, _HeightScale); |
|||
PROP_DECL(float, _HeightBias); |
|||
PROP_DECL(float4, _EmissiveColor); |
|||
PROP_DECL(float, _EmissiveIntensity); |
|||
|
|||
float _AlphaCutoff; |
|||
TEXTURE2D(_LayerMaskMap); |
|||
SAMPLER2D(sampler_LayerMaskMap); |
|||
|
|||
ENDHLSL |
|||
|
|||
SubShader |
|||
{ |
|||
Tags { "RenderType"="Opaque" "PerformanceChecks"="False" } |
|||
LOD 300 |
|||
|
|||
// ------------------------------------------------------------------ |
|||
// Deferred pass |
|||
Pass |
|||
{ |
|||
Name "GBuffer" // Name is not used |
|||
Tags { "LightMode" = "GBuffer" } // This will be only for opaque object based on the RenderQueue index |
|||
|
|||
Cull [_CullMode] |
|||
|
|||
HLSLPROGRAM |
|||
|
|||
#pragma vertex VertDefault |
|||
#pragma fragment Frag |
|||
|
|||
#define SHADERPASS SHADERPASS_GBUFFER |
|||
#define LAYERED_LIT_SHADER |
|||
|
|||
#include "../../Material/Material.hlsl" |
|||
#include "../Lit/LitData.hlsl" |
|||
#include "../Lit/LitSharePass.hlsl" |
|||
|
|||
#include "../../ShaderPass/ShaderPassGBuffer.hlsl" |
|||
|
|||
ENDHLSL |
|||
} |
|||
|
|||
// ------------------------------------------------------------------ |
|||
// Debug pass |
|||
Pass |
|||
{ |
|||
Name "Debug" |
|||
Tags{ "LightMode" = "DebugViewMaterial" } |
|||
|
|||
Cull[_CullMode] |
|||
|
|||
HLSLPROGRAM |
|||
|
|||
#pragma vertex VertDefault |
|||
#pragma fragment Frag |
|||
|
|||
#define SHADERPASS SHADERPASS_DEBUG_VIEW_MATERIAL |
|||
#define LAYERED_LIT_SHADER |
|||
|
|||
#include "../../Material/Material.hlsl" |
|||
#include "../Lit/LitData.hlsl" |
|||
#include "../Lit/LitSharePass.hlsl" |
|||
#include "../Lit/LitDebugPass.hlsl" |
|||
|
|||
#include "../../ShaderPass/ShaderPassDebugViewMaterial.hlsl" |
|||
|
|||
ENDHLSL |
|||
} |
|||
|
|||
// ------------------------------------------------------------------ |
|||
// Extracts information for lightmapping, GI (emission, albedo, ...) |
|||
// This pass it not used during regular rendering. |
|||
// ------------------------------------------------------------------ |
|||
Pass |
|||
{ |
|||
Name "META" |
|||
Tags{ "LightMode" = "Meta" } |
|||
|
|||
Cull Off |
|||
|
|||
HLSLPROGRAM |
|||
|
|||
// Lightmap memo |
|||
// DYNAMICLIGHTMAP_ON is used when we have an "enlighten lightmap" ie a lightmap updated at runtime by enlighten.This lightmap contain indirect lighting from realtime lights and realtime emissive material.Offline baked lighting(from baked material / light, |
|||
// both direct and indirect lighting) will hand up in the "regular" lightmap->LIGHTMAP_ON. |
|||
|
|||
#pragma vertex Vert |
|||
#pragma fragment Frag |
|||
|
|||
#define SHADERPASS SHADERPASS_LIGHT_TRANSPORT |
|||
#define LAYERED_LIT_SHADER |
|||
#include "../../Material/Material.hlsl" |
|||
#include "../Lit/LitData.hlsl" |
|||
#include "../Lit/LitMetaPass.hlsl" |
|||
|
|||
#include "../../ShaderPass/ShaderPassLightTransport.hlsl" |
|||
|
|||
ENDHLSL |
|||
} |
|||
|
|||
// ------------------------------------------------------------------ |
|||
// Depth only |
|||
// ------------------------------------------------------------------ |
|||
Pass |
|||
{ |
|||
Name "ShadowCaster" |
|||
Tags{ "LightMode" = "ShadowCaster" } |
|||
|
|||
Cull[_CullMode] |
|||
|
|||
ZWrite On ZTest LEqual |
|||
|
|||
HLSLPROGRAM |
|||
|
|||
#pragma vertex Vert |
|||
#pragma fragment Frag |
|||
|
|||
#define SHADERPASS SHADERPASS_DEPTH_ONLY |
|||
#define LAYERED_LIT_SHADER |
|||
#include "../../Material/Material.hlsl" |
|||
#include "../Lit/LitData.hlsl" |
|||
#include "../Lit/LitDepthPass.hlsl" |
|||
|
|||
#include "../../ShaderPass/ShaderPassDepthOnly.hlsl" |
|||
|
|||
ENDHLSL |
|||
} |
|||
|
|||
// ------------------------------------------------------------------ |
|||
// forward pass |
|||
Pass |
|||
{ |
|||
Name "Forward" // Name is not used |
|||
Tags{ "LightMode" = "Forward" } // This will be only for transparent object based on the RenderQueue index |
|||
|
|||
Blend[_SrcBlend][_DstBlend] |
|||
ZWrite[_ZWrite] |
|||
Cull[_CullMode] |
|||
|
|||
HLSLPROGRAM |
|||
|
|||
#pragma vertex VertDefault |
|||
#pragma fragment Frag |
|||
|
|||
#define SHADERPASS SHADERPASS_FORWARD |
|||
// TEMP until pragma work in include |
|||
// #include "../../Lighting/Forward.hlsl" |
|||
#pragma multi_compile LIGHTLOOP_SINGLE_PASS |
|||
#define LAYERED_LIT_SHADER |
|||
//#pragma multi_compile SHADOWFILTERING_FIXED_SIZE_PCF |
|||
|
|||
#include "../../Lighting/Lighting.hlsl" |
|||
#include "../Lit/LitData.hlsl" |
|||
#include "../Lit/LitSharePass.hlsl" |
|||
|
|||
#include "../../ShaderPass/ShaderPassForward.hlsl" |
|||
|
|||
ENDHLSL |
|||
} |
|||
} |
|||
|
|||
CustomEditor "LayeredLitGUI" |
|||
} |
|
|||
#ifndef SHADERPASS |
|||
#error Undefine_SHADERPASS |
|||
#endif |
|||
|
|||
void GetVaryingsDataDebug(uint paramId, FragInput input, inout float3 result, inout bool needLinearToSRGB) |
|||
{ |
|||
switch (paramId) |
|||
{ |
|||
case DEBUGVIEW_VARYING_TEXCOORD0: |
|||
result = float3(input.texCoord0 * 0.5 + 0.5, 0.0); |
|||
break; |
|||
case DEBUGVIEW_VARYING_TEXCOORD1: |
|||
result = float3(input.texCoord1 * 0.5 + 0.5, 0.0); |
|||
break; |
|||
case DEBUGVIEW_VARYING_TEXCOORD2: |
|||
result = float3(input.texCoord2 * 0.5 + 0.5, 0.0); |
|||
break; |
|||
case DEBUGVIEW_VARYING_VERTEXTANGENTWS: |
|||
result = input.tangentToWorld[0].xyz * 0.5 + 0.5; |
|||
break; |
|||
case DEBUGVIEW_VARYING_VERTEXBITANGENTWS: |
|||
result = input.tangentToWorld[1].xyz * 0.5 + 0.5; |
|||
break; |
|||
case DEBUGVIEW_VARYING_VERTEXNORMALWS: |
|||
result = input.tangentToWorld[2].xyz * 0.5 + 0.5; |
|||
break; |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: afea19c25b5e93847af6262c2c00401f |
|||
timeCreated: 1478601047 |
|||
licenseType: Pro |
|||
ShaderImporter: |
|||
defaultTextures: [] |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
#ifndef SHADERPASS |
|||
#error Undefine_SHADERPASS |
|||
#endif |
|||
|
|||
#define NEED_TANGENT_TO_WORLD (defined(_HEIGHTMAP) && !defined (_HEIGHTMAP_AS_DISPLACEMENT)) |
|||
#define NEED_TEXCOORD0 defined(_ALPHATEST_ON) || NEED_TANGENT_TO_WORLD |
|||
|
|||
struct Attributes |
|||
{ |
|||
float3 positionOS : POSITION; |
|||
#if NEED_TEXCOORD0 |
|||
float2 uv0 : TEXCOORD0; |
|||
#endif |
|||
#if NEED_TANGENT_TO_WORLD |
|||
float4 tangentOS : TANGENT; |
|||
#endif |
|||
}; |
|||
|
|||
struct Varyings |
|||
{ |
|||
float4 positionCS; |
|||
#if NEED_TEXCOORD0 |
|||
float2 texCoord0; |
|||
#endif |
|||
#if NEED_TANGENT_TO_WORLD |
|||
float3 positionWS; |
|||
float3 tangentToWorld[3]; |
|||
#endif |
|||
}; |
|||
|
|||
struct PackedVaryings |
|||
{ |
|||
float4 positionCS : SV_Position; |
|||
#if NEED_TANGENT_TO_WORLD |
|||
float4 interpolators[4] : TEXCOORD0; |
|||
#elif NEED_TEXCOORD0 |
|||
float4 interpolators[1] : TEXCOORD0; |
|||
#endif |
|||
}; |
|||
|
|||
// Function to pack data to use as few interpolator as possible, the ShaderGraph should generate these functions |
|||
PackedVaryings PackVaryings(Varyings input) |
|||
{ |
|||
PackedVaryings output; |
|||
output.positionCS = input.positionCS; |
|||
#if NEED_TANGENT_TO_WORLD |
|||
output.interpolators[0].xyz = input.positionWS.xyz; |
|||
output.interpolators[1].xyz = input.tangentToWorld[0]; |
|||
output.interpolators[2].xyz = input.tangentToWorld[1]; |
|||
output.interpolators[3].xyz = input.tangentToWorld[2]; |
|||
|
|||
output.interpolators[0].w = input.texCoord0.x; |
|||
output.interpolators[1].w = input.texCoord0.y; |
|||
#elif NEED_TEXCOORD0 |
|||
output.interpolators[0] = float4(input.texCoord0, 0.0, 0.0); |
|||
#endif |
|||
|
|||
return output; |
|||
} |
|||
|
|||
FragInput UnpackVaryings(PackedVaryings input) |
|||
{ |
|||
FragInput output; |
|||
ZERO_INITIALIZE(FragInput, output); |
|||
|
|||
output.unPositionSS = input.positionCS; |
|||
|
|||
#if NEED_TANGENT_TO_WORLD |
|||
output.positionWS.xyz = input.interpolators[0].xyz; |
|||
output.tangentToWorld[0] = input.interpolators[1].xyz; |
|||
output.tangentToWorld[1] = input.interpolators[2].xyz; |
|||
output.tangentToWorld[2] = input.interpolators[3].xyz; |
|||
|
|||
output.texCoord0.xy = float2(input.interpolators[0].w, input.interpolators[1].w); |
|||
#elif NEED_TEXCOORD0 |
|||
output.texCoord0.xy = input.interpolators[0].xy; |
|||
#endif |
|||
|
|||
return output; |
|||
} |
|||
|
|||
PackedVaryings Vert(Attributes input) |
|||
{ |
|||
Varyings output; |
|||
|
|||
float3 positionWS = TransformObjectToWorld(input.positionOS); |
|||
output.positionCS = TransformWorldToHClip(positionWS); |
|||
|
|||
#if NEED_TEXCOORD0 |
|||
output.texCoord0 = input.uv0; |
|||
#endif |
|||
|
|||
#if NEED_TANGENT_TO_WORLD |
|||
output.positionWS = positionWS; |
|||
|
|||
float3 normalWS = TransformObjectToWorldNormal(input.normalOS); |
|||
float4 tangentWS = float4(TransformObjectToWorldDir(input.tangentOS.xyz), input.tangentOS.w); |
|||
|
|||
float3x3 tangentToWorld = CreateTangentToWorld(normalWS, tangentWS.xyz, tangentWS.w); |
|||
output.tangentToWorld[0] = tangentToWorld[0]; |
|||
output.tangentToWorld[1] = tangentToWorld[1]; |
|||
output.tangentToWorld[2] = tangentToWorld[2]; |
|||
#endif |
|||
|
|||
return PackVaryings(output); |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: ebc0bb36f3769ea4aa775d0002e90508 |
|||
timeCreated: 1478601047 |
|||
licenseType: Pro |
|||
ShaderImporter: |
|||
defaultTextures: [] |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
#ifndef SHADERPASS |
|||
#error Undefine_SHADERPASS |
|||
#endif |
|||
CBUFFER_START(UnityMetaPass) |
|||
// x = use uv1 as raster position |
|||
// y = use uv2 as raster position |
|||
bool4 unity_MetaVertexControl; |
|||
|
|||
// x = return albedo |
|||
// y = return normal |
|||
bool4 unity_MetaFragmentControl; |
|||
|
|||
CBUFFER_END |
|||
|
|||
// This was not in constant buffer in original unity, so keep outiside. But should be in as ShaderRenderPass frequency |
|||
float unity_OneOverOutputBoost; |
|||
float unity_MaxOutputValue; |
|||
|
|||
struct Attributes |
|||
{ |
|||
float3 positionOS : POSITION; |
|||
float3 normalOS : NORMAL; |
|||
float2 uv0 : TEXCOORD0; |
|||
float2 uv1 : TEXCOORD1; |
|||
float2 uv2 : TEXCOORD2; |
|||
float4 tangentOS : TANGENT; |
|||
}; |
|||
|
|||
struct Varyings |
|||
{ |
|||
float4 positionCS; |
|||
float2 texCoord0; |
|||
float2 texCoord1; |
|||
}; |
|||
|
|||
struct PackedVaryings |
|||
{ |
|||
float4 positionCS : SV_Position; |
|||
float4 interpolators[1] : TEXCOORD0; |
|||
}; |
|||
|
|||
// Function to pack data to use as few interpolator as possible, the ShaderGraph should generate these functions |
|||
PackedVaryings PackVaryings(Varyings input) |
|||
{ |
|||
PackedVaryings output; |
|||
output.positionCS = input.positionCS; |
|||
output.interpolators[0].xy = input.texCoord0; |
|||
output.interpolators[0].zw = input.texCoord1; |
|||
|
|||
return output; |
|||
} |
|||
|
|||
FragInput UnpackVaryings(PackedVaryings input) |
|||
{ |
|||
FragInput output; |
|||
ZERO_INITIALIZE(FragInput, output); |
|||
|
|||
output.unPositionSS = input.positionCS; |
|||
output.texCoord0 = input.interpolators[0].xy; |
|||
output.texCoord1 = input.interpolators[0].zw; |
|||
|
|||
return output; |
|||
} |
|||
|
|||
PackedVaryings Vert(Attributes input) |
|||
{ |
|||
Varyings output; |
|||
|
|||
// Output UV coordinate in vertex shader |
|||
if (unity_MetaVertexControl.x) |
|||
{ |
|||
input.positionOS.xy = input.uv1 * unity_LightmapST.xy + unity_LightmapST.zw; |
|||
// OpenGL right now needs to actually use incoming vertex position, |
|||
// so use it in a very dummy way |
|||
//v.positionOS.z = vertex.z > 0 ? 1.0e-4f : 0.0f; |
|||
} |
|||
if (unity_MetaVertexControl.y) |
|||
{ |
|||
input.positionOS.xy = input.uv2 * unity_DynamicLightmapST.xy + unity_DynamicLightmapST.zw; |
|||
// OpenGL right now needs to actually use incoming vertex position, |
|||
// so use it in a very dummy way |
|||
//v.positionOS.z = vertex.z > 0 ? 1.0e-4f : 0.0f; |
|||
} |
|||
|
|||
float3 positionWS = TransformObjectToWorld(input.positionOS); |
|||
output.positionCS = TransformWorldToHClip(positionWS); |
|||
output.texCoord0 = input.uv0; |
|||
output.texCoord1 = input.uv1; |
|||
|
|||
return PackVaryings(output); |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: a55741149134f0a4280500a1842a7460 |
|||
timeCreated: 1478601047 |
|||
licenseType: Pro |
|||
ShaderImporter: |
|||
defaultTextures: [] |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
fileFormatVersion: 2 |
|||
guid: f449d3af78d5535459739664d3d41d1e |
|||
folderAsset: yes |
|||
timeCreated: 1476191704 |
|||
licenseType: Pro |
|||
DefaultImporter: |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
1001
Assets/TestScenes/HDTest/GlobalIlluminationTest.unity
文件差异内容过多而无法显示
查看文件
文件差异内容过多而无法显示
查看文件
|
|||
fileFormatVersion: 2 |
|||
guid: b9e9391dee8ab62499f562ee51dc4e4d |
|||
timeCreated: 1478514554 |
|||
licenseType: Pro |
|||
DefaultImporter: |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
Shader "HDRenderLoop/LayeredLit" |
|||
{ |
|||
Properties |
|||
{ |
|||
// Following set of parameters represent the parameters node inside the MaterialGraph. |
|||
// They are use to fill a SurfaceData. With a MaterialGraph this should not exist. |
|||
|
|||
// Reminder. Color here are in linear but the UI (color picker) do the conversion sRGB to linear |
|||
_BaseColor0("BaseColor0", Color) = (1,1,1,1) |
|||
_BaseColor1("BaseColor1", Color) = (1, 1, 1, 1) |
|||
_BaseColor2("BaseColor2", Color) = (1, 1, 1, 1) |
|||
_BaseColor3("BaseColor3", Color) = (1, 1, 1, 1) |
|||
|
|||
_BaseColorMap0("BaseColorMap0", 2D) = "white" {} |
|||
_BaseColorMap1("BaseColorMap1", 2D) = "white" {} |
|||
_BaseColorMap2("BaseColorMap2", 2D) = "white" {} |
|||
_BaseColorMap3("BaseColorMap3", 2D) = "white" {} |
|||
|
|||
_Metallic0("Metallic0", Range(0.0, 1.0)) = 0 |
|||
_Metallic1("Metallic1", Range(0.0, 1.0)) = 0 |
|||
_Metallic2("Metallic2", Range(0.0, 1.0)) = 0 |
|||
_Metallic3("Metallic3", Range(0.0, 1.0)) = 0 |
|||
|
|||
_Smoothness0("Smoothness0", Range(0.0, 1.0)) = 0.5 |
|||
_Smoothness1("Smoothness1", Range(0.0, 1.0)) = 0.5 |
|||
_Smoothness2("Smoothness2", Range(0.0, 1.0)) = 0.5 |
|||
_Smoothness3("Smoothness3", Range(0.0, 1.0)) = 0.5 |
|||
|
|||
_MaskMap0("MaskMap0", 2D) = "white" {} |
|||
_MaskMap1("MaskMap1", 2D) = "white" {} |
|||
_MaskMap2("MaskMap2", 2D) = "white" {} |
|||
_MaskMap3("MaskMap3", 2D) = "white" {} |
|||
|
|||
_SpecularOcclusionMap0("SpecularOcclusion0", 2D) = "white" {} |
|||
_SpecularOcclusionMap1("SpecularOcclusion1", 2D) = "white" {} |
|||
_SpecularOcclusionMap2("SpecularOcclusion2", 2D) = "white" {} |
|||
_SpecularOcclusionMap3("SpecularOcclusion3", 2D) = "white" {} |
|||
|
|||
_NormalMap0("NormalMap0", 2D) = "bump" {} |
|||
_NormalMap1("NormalMap1", 2D) = "bump" {} |
|||
_NormalMap2("NormalMap2", 2D) = "bump" {} |
|||
_NormalMap3("NormalMap3", 2D) = "bump" {} |
|||
|
|||
[Enum(TangentSpace, 0, ObjectSpace, 1)] _NormalMapSpace("NormalMap space", Float) = 0 |
|||
|
|||
_HeightMap0("HeightMap0", 2D) = "black" {} |
|||
_HeightMap1("HeightMap1", 2D) = "black" {} |
|||
_HeightMap2("HeightMap2", 2D) = "black" {} |
|||
_HeightMap3("HeightMap3", 2D) = "black" {} |
|||
|
|||
_HeightScale0("Height Scale0", Float) = 1 |
|||
_HeightScale1("Height Scale1", Float) = 1 |
|||
_HeightScale2("Height Scale2", Float) = 1 |
|||
_HeightScale3("Height Scale3", Float) = 1 |
|||
|
|||
_HeightBias0("Height Bias0", Float) = 0 |
|||
_HeightBias1("Height Bias1", Float) = 0 |
|||
_HeightBias2("Height Bias2", Float) = 0 |
|||
_HeightBias3("Height Bias3", Float) = 0 |
|||
|
|||
[Enum(Parallax, 0, Displacement, 1)] _HeightMapMode("Heightmap usage", Float) = 0 |
|||
|
|||
_EmissiveColor0("EmissiveColor0", Color) = (0, 0, 0) |
|||
_EmissiveColor1("EmissiveColor1", Color) = (0, 0, 0) |
|||
_EmissiveColor2("EmissiveColor2", Color) = (0, 0, 0) |
|||
_EmissiveColor3("EmissiveColor3", Color) = (0, 0, 0) |
|||
|
|||
_EmissiveColorMap0("EmissiveColorMap0", 2D) = "white" {} |
|||
_EmissiveColorMap1("EmissiveColorMap1", 2D) = "white" {} |
|||
_EmissiveColorMap2("EmissiveColorMap2", 2D) = "white" {} |
|||
_EmissiveColorMap3("EmissiveColorMap3", 2D) = "white" {} |
|||
|
|||
_EmissiveIntensity0("EmissiveIntensity0", Float) = 0 |
|||
_EmissiveIntensity1("EmissiveIntensity1", Float) = 0 |
|||
_EmissiveIntensity2("EmissiveIntensity2", Float) = 0 |
|||
_EmissiveIntensity3("EmissiveIntensity3", Float) = 0 |
|||
|
|||
_LayerMaskMap("LayerMaskMap", 2D) = "white" {} |
|||
|
|||
[ToggleOff] _DistortionOnly("Distortion Only", Float) = 0.0 |
|||
[ToggleOff] _DistortionDepthTest("Distortion Only", Float) = 0.0 |
|||
|
|||
[ToggleOff] _AlphaCutoffEnable("Alpha Cutoff Enable", Float) = 0.0 |
|||
|
|||
_AlphaCutoff("Alpha Cutoff", Range(0.0, 1.0)) = 0.5 |
|||
|
|||
// Blending state |
|||
[HideInInspector] _SurfaceType("__surfacetype", Float) = 0.0 |
|||
[HideInInspector] _BlendMode ("__blendmode", Float) = 0.0 |
|||
[HideInInspector] _SrcBlend ("__src", Float) = 1.0 |
|||
[HideInInspector] _DstBlend ("__dst", Float) = 0.0 |
|||
[HideInInspector] _ZWrite ("__zw", Float) = 1.0 |
|||
[HideInInspector] _CullMode("__cullmode", Float) = 2.0 |
|||
// Material Id |
|||
[HideInInspector] _MaterialId("_MaterialId", FLoat) = 0 |
|||
|
|||
[HideInInspector] _LayerCount("__layerCount", Float) = 2.0 |
|||
|
|||
[Enum(Mask Alpha, 0, BaseColor Alpha, 1)] _SmoothnessTextureChannel("Smoothness texture channel", Float) = 1 |
|||
[Enum(Use Emissive Color, 0, Use Emissive Mask, 1)] _EmissiveColorMode("Emissive color mode", Float) = 1 |
|||
[Enum(None, 0, DoubleSided, 1, DoubleSidedLigthingFlip, 2, DoubleSidedLigthingMirror, 3)] _DoubleSidedMode("Double sided mode", Float) = 0 |
|||
} |
|||
|
|||
HLSLINCLUDE |
|||
|
|||
#pragma target 5.0 |
|||
#pragma only_renderers d3d11 // TEMP: unitl we go futher in dev |
|||
|
|||
#pragma shader_feature _ALPHATEST_ON |
|||
#pragma shader_feature _ _DOUBLESIDED_LIGHTING_FLIP _DOUBLESIDED_LIGHTING_MIRROR |
|||
#pragma shader_feature _NORMALMAP |
|||
#pragma shader_feature _NORMALMAP_TANGENT_SPACE |
|||
#pragma shader_feature _MASKMAP |
|||
#pragma shader_feature _SPECULAROCCLUSIONMAP |
|||
#pragma shader_feature _SMOOTHNESS_TEXTURE_ALBEDO_CHANNEL_A |
|||
#pragma shader_feature _EMISSIVE_COLOR |
|||
#pragma shader_feature _EMISSIVE_COLOR_MAP |
|||
#pragma shader_feature _HEIGHTMAP |
|||
#pragma shader_feature _HEIGHTMAP_AS_DISPLACEMENT |
|||
#pragma shader_feature _LAYERMASKMAP |
|||
#pragma shader_feature _ _LAYEREDLIT_3_LAYERS _LAYEREDLIT_4_LAYERS |
|||
|
|||
//------------------------------------------------------------------------------------- |
|||
// Include |
|||
//------------------------------------------------------------------------------------- |
|||
#include "common.hlsl" |
|||
#include "../../ShaderPass/ShaderPass.cs.hlsl" |
|||
|
|||
ENDHLSL |
|||
|
|||
SubShader |
|||
{ |
|||
Tags { "RenderType"="Opaque" "PerformanceChecks"="False" } |
|||
LOD 300 |
|||
|
|||
// ------------------------------------------------------------------ |
|||
// Deferred pass |
|||
Pass |
|||
{ |
|||
Name "GBuffer" // Name is not used |
|||
Tags { "LightMode" = "GBuffer" } // This will be only for opaque object based on the RenderQueue index |
|||
|
|||
Cull [_CullMode] |
|||
|
|||
HLSLPROGRAM |
|||
|
|||
#pragma vertex VertDefault |
|||
#pragma fragment Frag |
|||
|
|||
#ifdef SHADER_STAGE_FRAGMENT |
|||
|
|||
#define SHADERPASS SHADERPASS_GBUFFER |
|||
#include "LayeredLitCommon.hlsl" |
|||
|
|||
#include "../../ShaderPass/ShaderPassGBuffer.hlsl" |
|||
|
|||
#endif |
|||
|
|||
ENDHLSL |
|||
} |
|||
|
|||
// ------------------------------------------------------------------ |
|||
// Debug pass |
|||
Pass |
|||
{ |
|||
Name "Debug" |
|||
Tags{ "LightMode" = "DebugViewMaterial" } |
|||
|
|||
Cull[_CullMode] |
|||
|
|||
HLSLPROGRAM |
|||
|
|||
#pragma vertex VertDefault |
|||
#pragma fragment Frag |
|||
|
|||
#define SHADERPASS SHADERPASS_DEBUG_VIEW_MATERIAL |
|||
#include "LayeredLitCommon.hlsl" |
|||
|
|||
#include "../../ShaderPass/ShaderPassDebugViewMaterial.hlsl" |
|||
|
|||
ENDHLSL |
|||
} |
|||
|
|||
// ------------------------------------------------------------------ |
|||
// forward pass |
|||
Pass |
|||
{ |
|||
Name "Forward" // Name is not used |
|||
Tags{ "LightMode" = "Forward" } // This will be only for transparent object based on the RenderQueue index |
|||
|
|||
Blend[_SrcBlend][_DstBlend] |
|||
ZWrite[_ZWrite] |
|||
Cull[_CullMode] |
|||
|
|||
HLSLPROGRAM |
|||
|
|||
#pragma vertex VertDefault |
|||
#pragma fragment Frag |
|||
|
|||
#define SHADERPASS SHADERPASS_FORWARD |
|||
#include "LayeredLitCommon.hlsl" |
|||
|
|||
#include "../../ShaderPass/ShaderPassForward.hlsl" |
|||
|
|||
ENDHLSL |
|||
} |
|||
} |
|||
|
|||
CustomEditor "LayeredLitGUI" |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 4475f12491047e54d9ddd0a61e36ead2 |
|||
timeCreated: 1476924487 |
|||
licenseType: Pro |
|||
ShaderImporter: |
|||
defaultTextures: [] |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
// GENERATED BY SHADER GRAPH |
|||
// Question for shader graph: how to handle dynamic parameter data like matData0 that can change name |
|||
|
|||
// No guard header! |
|||
|
|||
#define UNITY_MATERIAL_LIT // Need to be define before including Material.hlsl |
|||
#include "Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Lighting/Lighting.hlsl" // This include Material.hlsl |
|||
#include "Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/ShaderVariables.hlsl" |
|||
#include "Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Debug/DebugViewMaterial.hlsl" |
|||
|
|||
// This files is generated by the ShaderGraph or written by hand |
|||
|
|||
// Note for ShaderGraph: |
|||
// ShaderGraph should generate the vertex shader output to add the variable that may be required |
|||
// For example if we require view vector in shader graph, the output must contain positionWS and we calcualte the view vector with it. |
|||
// Still some input are mandatory depends on the type of loop. positionWS is mandatory in this current framework. So the ShaderGraph should always generate it. |
|||
|
|||
|
|||
#define PROP_DECL(type, name) type name, name##0, name##1, name##2, name##3; |
|||
#define PROP_DECL_TEX2D(name)\ |
|||
TEXTURE2D(name##0);\ |
|||
SAMPLER2D(sampler##name##0); \ |
|||
TEXTURE2D(name##1);\ |
|||
TEXTURE2D(name##2);\ |
|||
TEXTURE2D(name##3); |
|||
#define PROP_SAMPLE(name, textureName, texcoord, swizzle)\ |
|||
name##0 = SAMPLE_TEXTURE2D(textureName##0, sampler##textureName##0, texcoord).##swizzle; \ |
|||
name##1 = SAMPLE_TEXTURE2D(textureName##1, sampler##textureName##0, texcoord).##swizzle; \ |
|||
name##2 = SAMPLE_TEXTURE2D(textureName##2, sampler##textureName##0, texcoord).##swizzle; \ |
|||
name##3 = SAMPLE_TEXTURE2D(textureName##3, sampler##textureName##0, texcoord).##swizzle; |
|||
#define PROP_MUL(name, multiplier, swizzle)\ |
|||
name##0 *= multiplier##0.##swizzle; \ |
|||
name##1 *= multiplier##1.##swizzle; \ |
|||
name##2 *= multiplier##2.##swizzle; \ |
|||
name##3 *= multiplier##3.##swizzle; |
|||
#define PROP_ASSIGN(name, input, swizzle)\ |
|||
name##0 = input##0.##swizzle; \ |
|||
name##1 = input##1.##swizzle; \ |
|||
name##2 = input##2.##swizzle; \ |
|||
name##3 = input##3.##swizzle; |
|||
#define PROP_ASSIGN_VALUE(name, input)\ |
|||
name##0 = input; \ |
|||
name##1 = input; \ |
|||
name##2 = input; \ |
|||
name##3 = input; |
|||
#define PROP_BLEND_COLOR(name, mask) name = BlendLayeredColor(name##0, name##1, name##2, name##3, mask); |
|||
#define PROP_BLEND_SCALAR(name, mask) name = BlendLayeredScalar(name##0, name##1, name##2, name##3, mask); |
|||
|
|||
#define _MAX_LAYER 4 |
|||
|
|||
#if defined(_LAYEREDLIT_4_LAYERS) |
|||
# define _LAYER_COUNT 4 |
|||
#elif defined(_LAYEREDLIT_3_LAYERS) |
|||
# define _LAYER_COUNT 3 |
|||
#else |
|||
# define _LAYER_COUNT 2 |
|||
#endif |
|||
|
|||
//------------------------------------------------------------------------------------- |
|||
// variable declaration |
|||
//------------------------------------------------------------------------------------- |
|||
|
|||
// Set of users variables |
|||
PROP_DECL(float4, _BaseColor); |
|||
PROP_DECL_TEX2D(_BaseColorMap); |
|||
PROP_DECL(float, _Metallic); |
|||
PROP_DECL(float, _Smoothness); |
|||
PROP_DECL_TEX2D(_MaskMap); |
|||
PROP_DECL_TEX2D(_SpecularOcclusionMap); |
|||
PROP_DECL_TEX2D(_NormalMap); |
|||
PROP_DECL_TEX2D(_Heightmap); |
|||
PROP_DECL(float, _HeightScale); |
|||
PROP_DECL(float, _HeightBias); |
|||
PROP_DECL(float4, _EmissiveColor); |
|||
PROP_DECL(float, _EmissiveIntensity); |
|||
|
|||
float _AlphaCutoff; |
|||
TEXTURE2D(_LayerMaskMap); |
|||
SAMPLER2D(sampler_LayerMaskMap); |
|||
|
|||
//------------------------------------------------------------------------------------- |
|||
// Lighting architecture |
|||
//------------------------------------------------------------------------------------- |
|||
|
|||
// TODO: Check if we will have different Varyings based on different pass, not sure about that... |
|||
|
|||
// Forward |
|||
struct Attributes |
|||
{ |
|||
float3 positionOS : POSITION; |
|||
float3 normalOS : NORMAL; |
|||
float2 uv0 : TEXCOORD0; |
|||
float4 tangentOS : TANGENT; |
|||
float4 color : TANGENT; |
|||
}; |
|||
|
|||
struct Varyings |
|||
{ |
|||
float4 positionCS; |
|||
float3 positionWS; |
|||
float2 texCoord0; |
|||
float3 tangentToWorld[3]; |
|||
float4 vertexColor; |
|||
|
|||
#ifdef SHADER_STAGE_FRAGMENT |
|||
#if defined(_DOUBLESIDED_LIGHTING_FLIP) || defined(_DOUBLESIDED_LIGHTING_MIRROR) |
|||
FRONT_FACE_TYPE cullFace; |
|||
#endif |
|||
#endif |
|||
}; |
|||
|
|||
struct PackedVaryings |
|||
{ |
|||
float4 positionCS : SV_Position; |
|||
float4 interpolators[6] : TEXCOORD0; |
|||
|
|||
#ifdef SHADER_STAGE_FRAGMENT |
|||
#if defined(_DOUBLESIDED_LIGHTING_FLIP) || defined(_DOUBLESIDED_LIGHTING_MIRROR) |
|||
FRONT_FACE_TYPE cullFace : FRONT_FACE_SEMATIC; |
|||
#endif |
|||
#endif |
|||
}; |
|||
|
|||
// Function to pack data to use as few interpolator as possible, the ShaderGraph should generate these functions |
|||
PackedVaryings PackVaryings(Varyings input) |
|||
{ |
|||
PackedVaryings output; |
|||
output.positionCS = input.positionCS; |
|||
output.interpolators[0].xyz = input.positionWS.xyz; |
|||
output.interpolators[0].w = input.texCoord0.x; |
|||
output.interpolators[1].xyz = input.tangentToWorld[0]; |
|||
output.interpolators[2].xyz = input.tangentToWorld[1]; |
|||
output.interpolators[3].xyz = input.tangentToWorld[2]; |
|||
output.interpolators[4].x = input.texCoord0.y; |
|||
output.interpolators[4].yzw = float3(0.0, 0.0, 0.0); |
|||
output.interpolators[5] = input.vertexColor; |
|||
|
|||
return output; |
|||
} |
|||
|
|||
Varyings UnpackVaryings(PackedVaryings input) |
|||
{ |
|||
Varyings output; |
|||
output.positionCS = input.positionCS; |
|||
output.positionWS.xyz = input.interpolators[0].xyz; |
|||
output.texCoord0.x = input.interpolators[0].w; |
|||
output.texCoord0.y = input.interpolators[4].x; |
|||
output.tangentToWorld[0] = input.interpolators[1].xyz; |
|||
output.tangentToWorld[1] = input.interpolators[2].xyz; |
|||
output.tangentToWorld[2] = input.interpolators[3].xyz; |
|||
output.vertexColor = input.interpolators[5]; |
|||
|
|||
#ifdef SHADER_STAGE_FRAGMENT |
|||
#if defined(_DOUBLESIDED_LIGHTING_FLIP) || defined(_DOUBLESIDED_LIGHTING_MIRROR) |
|||
output.cullFace = input.cullFace; |
|||
#endif |
|||
#endif |
|||
|
|||
return output; |
|||
} |
|||
|
|||
// TODO: Here we will also have all the vertex deformation (GPU skinning, vertex animation, morph target...) or we will need to generate a compute shaders instead (better! but require work to deal with unpacking like fp16) |
|||
PackedVaryings VertDefault(Attributes input) |
|||
{ |
|||
Varyings output; |
|||
|
|||
output.positionWS = TransformObjectToWorld(input.positionOS); |
|||
// TODO deal with camera center rendering and instancing (This is the reason why we always perform tow steps transform to clip space + instancing matrix) |
|||
output.positionCS = TransformWorldToHClip(output.positionWS); |
|||
|
|||
float3 normalWS = TransformObjectToWorldNormal(input.normalOS); |
|||
|
|||
output.texCoord0 = input.uv0; |
|||
|
|||
float4 tangentWS = float4(TransformObjectToWorldDir(input.tangentOS.xyz), input.tangentOS.w); |
|||
|
|||
float3x3 tangentToWorld = CreateTangentToWorld(normalWS, tangentWS.xyz, tangentWS.w); |
|||
output.tangentToWorld[0].xyz = tangentToWorld[0]; |
|||
output.tangentToWorld[1].xyz = tangentToWorld[1]; |
|||
output.tangentToWorld[2].xyz = tangentToWorld[2]; |
|||
|
|||
output.vertexColor = input.color; |
|||
|
|||
return PackVaryings(output); |
|||
} |
|||
|
|||
|
|||
//------------------------------------------------------------------------------------- |
|||
// Fill SurfaceData/Lighting data function |
|||
//------------------------------------------------------------------------------------- |
|||
|
|||
#if SHADER_STAGE_FRAGMENT |
|||
|
|||
float3 BlendLayeredColor(float3 rgb0, float3 rgb1, float3 rgb2, float3 rgb3, float weight[4]) |
|||
{ |
|||
float3 result = float3(0.0, 0.0, 0.0); |
|||
|
|||
result = rgb0 * weight[0] + rgb1 * weight[1]; |
|||
#if _LAYER_COUNT >= 3 |
|||
result += (rgb2 * weight[2]); |
|||
#endif |
|||
#if _LAYER_COUNT >= 4 |
|||
result += rgb3 * weight[3]; |
|||
#endif |
|||
|
|||
return result; |
|||
} |
|||
|
|||
float3 BlendLayeredNormal(float3 normal0, float3 normal1, float3 normal2, float3 normal3, float weight[4]) |
|||
{ |
|||
float3 result = float3(0.0, 0.0, 0.0); |
|||
|
|||
// TODO : real normal map blending function |
|||
result = normal0 * weight[0] + normal1 * weight[1]; |
|||
#if _LAYER_COUNT >= 3 |
|||
result += normal2 * weight[2]; |
|||
#endif |
|||
#if _LAYER_COUNT >= 4 |
|||
result += normal3 * weight[3]; |
|||
#endif |
|||
|
|||
return result; |
|||
} |
|||
|
|||
float BlendLayeredScalar(float x0, float x1, float x2, float x3, float weight[4]) |
|||
{ |
|||
float result = 0.0; |
|||
|
|||
result = x0 * weight[0] + x1 * weight[1]; |
|||
#if _LAYER_COUNT >= 3 |
|||
result += x2 * weight[2]; |
|||
#endif |
|||
#if _LAYER_COUNT >= 4 |
|||
result += x3 * weight[3]; |
|||
#endif |
|||
|
|||
return result; |
|||
} |
|||
|
|||
void ComputeMaskWeights(float4 inputMasks, out float outWeights[_MAX_LAYER]) |
|||
{ |
|||
float masks[_MAX_LAYER]; |
|||
masks[0] = inputMasks.r; |
|||
masks[1] = inputMasks.g; |
|||
masks[2] = inputMasks.b; |
|||
masks[3] = inputMasks.a; |
|||
|
|||
// calculate weight of each layers |
|||
float left = 1.0f; |
|||
|
|||
// ATTRIBUTE_UNROLL |
|||
for (int i = _LAYER_COUNT - 1; i > 0; --i) |
|||
{ |
|||
outWeights[i] = masks[i] * left; |
|||
left -= outWeights[i]; |
|||
} |
|||
outWeights[0] = left; |
|||
} |
|||
|
|||
void GetSurfaceAndBuiltinData(Varyings input, out SurfaceData surfaceData, out BuiltinData builtinData) |
|||
{ |
|||
float4 maskValues = float4(1.0, 1.0, 1.0, 1.0);// input.vertexColor; |
|||
|
|||
#ifdef _LAYERMASKMAP |
|||
float4 maskMap = SAMPLE_TEXTURE2D(_LayerMaskMap, sampler_LayerMaskMap, input.texCoord0); |
|||
maskValues *= maskMap; |
|||
#endif |
|||
|
|||
float weights[_MAX_LAYER]; |
|||
ComputeMaskWeights(maskValues, weights); |
|||
|
|||
PROP_DECL(float3, baseColor); |
|||
PROP_SAMPLE(baseColor, _BaseColorMap, input.texCoord0, rgb); |
|||
PROP_MUL(baseColor, _BaseColor, rgb); |
|||
PROP_BLEND_COLOR(baseColor, weights); |
|||
|
|||
surfaceData.baseColor = baseColor; |
|||
|
|||
PROP_DECL(float, alpha); |
|||
#ifdef _SMOOTHNESS_TEXTURE_ALBEDO_CHANNEL_A |
|||
PROP_ASSIGN(alpha, _BaseColor, a); |
|||
#else |
|||
PROP_SAMPLE(alpha, _BaseColorMap, input.texCoord0, a); |
|||
PROP_MUL(alpha, _BaseColor, a); |
|||
#endif |
|||
PROP_BLEND_SCALAR(alpha, weights); |
|||
|
|||
#ifdef _ALPHATEST_ON |
|||
clip(alpha - _AlphaCutoff); |
|||
#endif |
|||
|
|||
builtinData.opacity = alpha; |
|||
|
|||
PROP_DECL(float, specularOcclusion); |
|||
#ifdef _SPECULAROCCLUSIONMAP |
|||
// TODO: Do something. For now just take alpha channel |
|||
PROP_SAMPLE(specularOcclusion, _SpecularOcclusionMap, input.texCoord0, a); |
|||
#else |
|||
// Horizon Occlusion for Normal Mapped Reflections: http://marmosetco.tumblr.com/post/81245981087 |
|||
//surfaceData.specularOcclusion = saturate(1.0 + horizonFade * dot(r, input.tangentToWorld[2].xyz); |
|||
// smooth it |
|||
//surfaceData.specularOcclusion *= surfaceData.specularOcclusion; |
|||
PROP_ASSIGN_VALUE(specularOcclusion, 1.0); |
|||
#endif |
|||
PROP_BLEND_SCALAR(specularOcclusion, weights); |
|||
surfaceData.specularOcclusion = specularOcclusion; |
|||
|
|||
// TODO: think about using BC5 |
|||
float3 vertexNormalWS = input.tangentToWorld[2].xyz; |
|||
|
|||
#ifdef _NORMALMAP |
|||
#ifdef _NORMALMAP_TANGENT_SPACE |
|||
float3 normalTS0 = UnpackNormalAG(SAMPLE_TEXTURE2D(_NormalMap0, sampler_NormalMap0, input.texCoord0)); |
|||
float3 normalTS1 = UnpackNormalAG(SAMPLE_TEXTURE2D(_NormalMap1, sampler_NormalMap0, input.texCoord0)); |
|||
float3 normalTS2 = UnpackNormalAG(SAMPLE_TEXTURE2D(_NormalMap2, sampler_NormalMap0, input.texCoord0)); |
|||
float3 normalTS3 = UnpackNormalAG(SAMPLE_TEXTURE2D(_NormalMap3, sampler_NormalMap0, input.texCoord0)); |
|||
|
|||
float3 normalTS = BlendLayeredNormal(normalTS0, normalTS1, normalTS2, normalTS3, weights); |
|||
|
|||
surfaceData.normalWS = TransformTangentToWorld(normalTS, input.tangentToWorld); |
|||
#else // Object space (TODO: We need to apply the world rotation here!) |
|||
surfaceData.normalWS = SAMPLE_TEXTURE2D(_NormalMap, sampler_NormalMap, input.texCoord0).rgb; |
|||
#endif |
|||
#else |
|||
surfaceData.normalWS = vertexNormalWS; |
|||
#endif |
|||
|
|||
#if defined(_DOUBLESIDED_LIGHTING_FLIP) || defined(_DOUBLESIDED_LIGHTING_MIRROR) |
|||
#ifdef _DOUBLESIDED_LIGHTING_FLIP |
|||
float3 oppositeNormalWS = -surfaceData.normalWS; |
|||
#else |
|||
// Mirror the normal with the plane define by vertex normal |
|||
float3 oppositeNormalWS = reflect(surfaceData.normalWS, vertexNormalWS); |
|||
#endif |
|||
// TODO : Test if GetOdddNegativeScale() is necessary here in case of normal map, as GetOdddNegativeScale is take into account in CreateTangentToWorld(); |
|||
surfaceData.normalWS = IS_FRONT_VFACE(input.cullFace, GetOdddNegativeScale() >= 0.0 ? surfaceData.normalWS : oppositeNormalWS, -GetOdddNegativeScale() >= 0.0 ? surfaceData.normalWS : oppositeNormalWS); |
|||
#endif |
|||
|
|||
|
|||
PROP_DECL(float, perceptualSmoothness); |
|||
#ifdef _SMOOTHNESS_TEXTURE_ALBEDO_CHANNEL_A |
|||
PROP_SAMPLE(perceptualSmoothness, _BaseColorMap, input.texCoord0, a); |
|||
#elif defined(_MASKMAP) |
|||
PROP_SAMPLE(perceptualSmoothness, _MaskMap, input.texCoord0, a); |
|||
#else |
|||
PROP_ASSIGN_VALUE(perceptualSmoothness, 1.0); |
|||
#endif |
|||
PROP_MUL(perceptualSmoothness, _Smoothness, r); |
|||
PROP_BLEND_SCALAR(perceptualSmoothness, weights); |
|||
|
|||
surfaceData.perceptualSmoothness = perceptualSmoothness; |
|||
|
|||
surfaceData.materialId = 0; |
|||
|
|||
// MaskMap is Metallic, Ambient Occlusion, (Optional) - emissive Mask, Optional - Smoothness (in alpha) |
|||
PROP_DECL(float, metallic); |
|||
PROP_DECL(float, ambientOcclusion); |
|||
#ifdef _MASKMAP |
|||
PROP_SAMPLE(metallic, _MaskMap, input.texCoord0, a); |
|||
PROP_SAMPLE(ambientOcclusion, _MaskMap, input.texCoord0, g); |
|||
#else |
|||
PROP_ASSIGN_VALUE(metallic, 1.0); |
|||
PROP_ASSIGN_VALUE(ambientOcclusion, 1.0); |
|||
#endif |
|||
PROP_MUL(metallic, _Metallic, r); |
|||
|
|||
PROP_BLEND_SCALAR(metallic, weights); |
|||
PROP_BLEND_SCALAR(ambientOcclusion, weights); |
|||
|
|||
surfaceData.metallic = metallic; |
|||
surfaceData.ambientOcclusion = ambientOcclusion; |
|||
|
|||
surfaceData.tangentWS = float3(1.0, 0.0, 0.0); |
|||
surfaceData.anisotropy = 0; |
|||
surfaceData.specular = 0.04; |
|||
|
|||
surfaceData.subSurfaceRadius = 1.0; |
|||
surfaceData.thickness = 0.0; |
|||
surfaceData.subSurfaceProfile = 0; |
|||
|
|||
surfaceData.coatNormalWS = float3(1.0, 0.0, 0.0); |
|||
surfaceData.coatPerceptualSmoothness = 1.0; |
|||
surfaceData.specularColor = float3(0.0, 0.0, 0.0); |
|||
|
|||
// Builtin Data |
|||
|
|||
// TODO: Sample lightmap/lightprobe/volume proxy |
|||
// This should also handle projective lightmap |
|||
// Note that data input above can be use to sample into lightmap (like normal) |
|||
builtinData.bakeDiffuseLighting = float3(0.0, 0.0, 0.0); |
|||
|
|||
// If we chose an emissive color, we have a dedicated texture for it and don't use MaskMap |
|||
PROP_DECL(float3, emissiveColor); |
|||
#ifdef _EMISSIVE_COLOR |
|||
#ifdef _EMISSIVE_COLOR_MAP |
|||
PROP_SAMPLE(emissiveColor, _EmissiveColorMap, input.texCoord0, rgb); |
|||
#else |
|||
PROP_ASSIGN(emissiveColor, _EmissiveColor, rgb); |
|||
#endif |
|||
#elif defined(_MASKMAP) // If we have a MaskMap, use emissive slot as a mask on baseColor |
|||
PROP_SAMPLE(emissiveColor, _MaskMap, input.texCoord0, bbb); |
|||
PROP_MUL(emissiveColor, baseColor, rgb); |
|||
#else |
|||
PROP_ASSIGN_VALUE(emissiveColor, float3(0.0, 0.0, 0.0)); |
|||
#endif |
|||
PROP_BLEND_COLOR(emissiveColor, weights); |
|||
builtinData.emissiveColor = emissiveColor; |
|||
|
|||
PROP_DECL(float, emissiveIntensity); |
|||
PROP_ASSIGN(emissiveIntensity, _EmissiveIntensity, r); |
|||
PROP_BLEND_SCALAR(emissiveIntensity, weights); |
|||
builtinData.emissiveIntensity = emissiveIntensity; |
|||
|
|||
builtinData.velocity = float2(0.0, 0.0); |
|||
|
|||
builtinData.distortion = float2(0.0, 0.0); |
|||
builtinData.distortionBlur = 0.0; |
|||
} |
|||
|
|||
void GetVaryingsDataDebug(uint paramId, Varyings input, inout float3 result, inout bool needLinearToSRGB) |
|||
{ |
|||
switch (paramId) |
|||
{ |
|||
case DEBUGVIEW_VARYING_TEXCOORD0: |
|||
// TODO: require a remap |
|||
result = float3(input.texCoord0, 0.0); |
|||
break; |
|||
case DEBUGVIEW_VARYING_VERTEXNORMALWS: |
|||
result = input.tangentToWorld[2].xyz * 0.5 + 0.5; |
|||
break; |
|||
case DEBUGVIEW_VARYING_VERTEXTANGENTWS: |
|||
result = input.tangentToWorld[0].xyz * 0.5 + 0.5; |
|||
break; |
|||
case DEBUGVIEW_VARYING_VERTEXBITANGENTWS: |
|||
result = input.tangentToWorld[1].xyz * 0.5 + 0.5; |
|||
break; |
|||
case DEBUGVIEW_VARYING_VERTEXCOLOR: |
|||
result = input.vertexColor.xyz; |
|||
break; |
|||
} |
|||
} |
|||
|
|||
#endif // #if SHADER_STAGE_FRAGMENT |
撰写
预览
正在加载...
取消
保存
Reference in new issue