浏览代码

upgrading to new shader library.

/main
Tim Cooper 7 年前
当前提交
7995a0e9
共有 14 个文件被更改,包括 127 次插入107 次删除
  1. 27
      MaterialGraphProject/Assets/ShaderVariables.hlsl
  2. 6
      MaterialGraphProject/Assets/ShaderVariablesFunctions.hlsl
  3. 11
      MaterialGraphProject/Assets/UnityShaderEditor.meta
  4. 2
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/AbstractMaterialGraph.cs
  5. 2
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/CubemapShaderProperty.cs
  6. 4
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/TextureShaderProperty.cs
  7. 1
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/LightweightPipeline/LightWeightPBRSubShader.cs
  8. 1
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/LightweightPipeline/LightWeightUnlitSubShader.cs
  9. 16
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Input/Texture/CubemapNode.cs
  10. 4
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Util/ShaderGenerator.cs
  11. 5
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Resources.meta
  12. 92
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Templates/lightweightPBRExtraPasses.template
  13. 61
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Templates/lightweightPBRForwardPass.template
  14. 2
      MaterialGraphProject/UnityPackageManager/manifest.json

27
MaterialGraphProject/Assets/ShaderVariables.hlsl


CBUFFER_START(UnityPerCamera)
// Time (t = time since current level load) values from Unity
float4 _Time; // (t/20, t, t*2, t*3)
float4 _LastTime; // Last frame time (t/20, t, t*2, t*3)
float4 _SinTime; // sin(t/8), sin(t/4), sin(t/2), sin(t)
float4 _CosTime; // cos(t/8), cos(t/4), cos(t/2), cos(t)
float4 unity_DeltaTime; // dt, 1/dt, smoothdt, 1/smoothdt

int unity_StereoEyeIndex;
#endif
float4 unity_ShadowColor;
float3 unity_ShadowColor;
uint _TaaFrameIndex; // [0, 7]
TEXTURE2D_FLOAT(_MainDepthTexture);
SAMPLER2D(sampler_MainDepthTexture);
// These are the samplers available in the HDRenderPipeline.
// Avoid declaring extra samplers as they are 4x SGPR each on GCN.
SAMPLER(s_linear_clamp_sampler);
SAMPLER(s_trilinear_clamp_sampler);
// ----------------------------------------------------------------------------
TEXTURE2D(_MainDepthTexture);
SAMPLER(sampler_MainDepthTexture);
SAMPLER2D(samplerunity_Lightmap);
SAMPLER(samplerunity_Lightmap);
SAMPLER2D(samplerunity_DynamicLightmap);
SAMPLER(samplerunity_DynamicLightmap);
TEXTURE2D(unity_DynamicDirectionality);

// TODO: Change code here so probe volume use only one transform instead of all this parameters!
TEXTURE3D_FLOAT(unity_ProbeVolumeSH);
SAMPLER3D(samplerunity_ProbeVolumeSH);
TEXTURE3D(unity_ProbeVolumeSH);
SAMPLER(samplerunity_ProbeVolumeSH);
float4x4 unity_MatrixPreviousMI;
//X : Use last frame positions (right now skinned meshes are the only objects that use this
//Y : Force No Motion
//Z : Z bias value
float4 unity_MotionVectorsParams;
CBUFFER_END

6
MaterialGraphProject/Assets/ShaderVariablesFunctions.hlsl


return unity_WorldTransformParams.w;
}
float3 WorldSpaceViewDir(float3 cameraPositionWS, float3 positionOS)
{
float3 worldPos = mul(GetObjectToWorldMatrix(), float4(positionOS, 1.0)).xyz;
return normalize(cameraPositionWS - worldPos);
}
float3 TransformWorldToView(float3 positionWS)
{
return mul(GetWorldToViewMatrix(), float4(positionWS, 1.0)).xyz;

11
MaterialGraphProject/Assets/UnityShaderEditor.meta


fileFormatVersion: 2
guid: b100142c357c2d745b9707d6e2f987fd
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
fileFormatVersion: 2
guid: 0b601fe23f0347ab8e4892edf2cf76d7
timeCreated: 1513757926

2
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/AbstractMaterialGraph.cs


finalShader.AddShaderChunk("#include \"Packing.hlsl\"", false);
finalShader.AddShaderChunk("#include \"ShaderVariables.hlsl\"", false);
finalShader.AddShaderChunk("#include \"ShaderVariablesFunctions.hlsl\"", false);
finalShader.AddShaderChunk(shaderFunctionVisitor.GetShaderString(2), false);
finalShader.AddShaderChunk(graphVertexInput, false);
finalShader.AddShaderChunk(surfaceInputs.GetShaderString(2), false);

2
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/CubemapShaderProperty.cs


public override string GetPropertyDeclarationString()
{
return "samplerCUBE " + referenceName + ";";
return string.Format("TEXTURECUBE({0});\nSAMPLER(sampler{0});", referenceName);
}
public override PreviewProperty GetPreviewMaterialProperty()

4
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/TextureShaderProperty.cs


public override string GetPropertyDeclarationString()
{
return string.Format("TEXTURE2D({0});\nSAMPLER2D(sampler{0});", referenceName);
return string.Format("TEXTURE2D({0});\nSAMPLER(sampler{0});", referenceName);
return "UNITY_DECLARE_TEX2D_NOSAMPLER(" + referenceName + ");";
return string.Format("TEXTURE2D({0});", referenceName);
}
public override PreviewProperty GetPreviewMaterialProperty()

1
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/LightweightPipeline/LightWeightPBRSubShader.cs


float4 color : COLOR;
float4 texcoord0 : TEXCOORD0;
float4 lightmapUV : TEXCOORD1;
UNITY_VERTEX_INPUT_INSTANCE_ID
};";
surfaceInputs.AddShaderChunk("struct SurfaceInputs{", false);

1
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/LightweightPipeline/LightWeightUnlitSubShader.cs


float4 color : COLOR;
float4 texcoord0 : TEXCOORD0;
float4 lightmapUV : TEXCOORD1;
UNITY_VERTEX_INPUT_INSTANCE_ID
};";
surfaceInputs.AddShaderChunk("struct SurfaceInputs{", false);

16
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Input/Texture/CubemapNode.cs


// Node generations
public virtual void GenerateNodeCode(ShaderGenerator visitor, GenerationMode generationMode)
{
string result = string.Format("{0}4 {1} = texCUBElod ({2}, {0}4(reflect(-{3}, {4}), {5}));"
, precision
, GetVariableNameForSlot(OutputSlotId)
, GetSlotValue(CubemapInputId, generationMode)
, GetSlotValue(ViewDirInputId, generationMode)
, GetSlotValue(NormalInputId, generationMode)
, GetSlotValue(LODInputId, generationMode));
var id = GetSlotValue(CubemapInputId, generationMode);
string result = string.Format("{0}4 {1} = SAMPLE_TEXTURECUBE_LOD({2}, {3}, reflect(-{4}, {5}), {6});"
, precision
, GetVariableNameForSlot(OutputSlotId)
, id
, "sampler" + id
, GetSlotValue(ViewDirInputId, generationMode)
, GetSlotValue(NormalInputId, generationMode)
, GetSlotValue(LODInputId, generationMode));
visitor.AddShaderChunk(result, true);
}

4
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Util/ShaderGenerator.cs


{
var name = preferedCoordinateSpace.ToVariableName(InterpolatorType.ViewDirection);
interpolators.AddShaderChunk(string.Format("float3 {0} : TEXCOORD{1};", name, interpolatorIndex), false);
vertexShader.AddShaderChunk(string.Format("o.{0} = {1};", name, ConvertBetweenSpace("WorldSpaceViewDir(_WorldSpaceCameraPos.xyz, v.vertex)", CoordinateSpace.World, preferedCoordinateSpace, InputType.Vector)), false);
var worldSpaceViewDir = "SafeNormalize(_WorldSpaceCameraPos.xyz - mul(GetObjectToWorldMatrix(), float4(v.vertex.xyz, 1.0)).xyz)";
vertexShader.AddShaderChunk(string.Format("o.{0} = {1};", name, ConvertBetweenSpace(worldSpaceViewDir, CoordinateSpace.World, preferedCoordinateSpace, InputType.Vector)), false);
pixelShader.AddShaderChunk(string.Format("float3 {0} = normalize(IN.{0});", name), false);
interpolatorIndex++;
}

5
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Resources.meta


fileFormatVersion: 2
guid: c34a1714ab2ee6c47b8fb9a14777df23
guid: 64c9c5df0004c44f0896e816c69c7aa1
timeCreated: 1485544540
licenseType: Pro
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

92
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Templates/lightweightPBRExtraPasses.template


Pass
{
Tags{"LightMode" = "ShadowCaster"}
Pass
{
Tags{"LightMode" = "ShadowCaster"}
ZWrite On ZTest LEqual
ZWrite On ZTest LEqual
CGPROGRAM
#pragma target 2.0
#pragma vertex ShadowPassVertex
#pragma fragment ShadowPassFragment
HLSLPROGRAM
// Required to compile gles 2.0 with standard srp library
#pragma prefer_hlslcc gles
#pragma target 2.0
#pragma vertex ShadowPassVertex
#pragma fragment ShadowPassFragment
#include "UnityCG.cginc"
#include "LightweightPassShadow.cginc"
ENDCG
}
#include "LightweightPassShadow.hlsl"
ENDHLSL
}
Pass
{
Tags{"LightMode" = "DepthOnly"}
Pass
{
Tags{"LightMode" = "DepthOnly"}
ZWrite On
ColorMask 0
ZWrite On
ColorMask 0
CGPROGRAM
#pragma target 2.0
#pragma vertex vert
#pragma fragment frag
HLSLPROGRAM
// Required to compile gles 2.0 with standard srp library
#pragma prefer_hlslcc gles
#pragma target 2.0
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
#include "LightweightShaderLibrary/Core.hlsl"
float4 vert(float4 pos : POSITION) : SV_POSITION
{
return UnityObjectToClipPos(pos);
}
float4 vert(float4 pos : POSITION) : SV_POSITION
{
return TransformObjectToHClip(pos.xyz);
}
half4 frag() : SV_TARGET
{
return 0;
}
ENDHLSL
}
half4 frag() : SV_TARGET
{
return 0;
}
ENDCG
}
// This pass it not used during regular rendering, only for lightmap baking.
Pass
{
Tags{"LightMode" = "Meta"}
Cull Off
HLSLPROGRAM
// Required to compile gles 2.0 with standard srp library
#pragma prefer_hlslcc gles
#pragma vertex LightweightVertexMeta
#pragma fragment LightweightFragmentMeta
#pragma shader_feature _EMISSION
#pragma shader_feature _METALLICSPECGLOSSMAP
#pragma shader_feature _ _SMOOTHNESS_TEXTURE_ALBEDO_CHANNEL_A
#pragma shader_feature EDITOR_VISUALIZATION
#pragma shader_feature _SPECGLOSSMAP
#include "LightweightPassMeta.hlsl"
ENDHLSL
}

61
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Templates/lightweightPBRForwardPass.template


${ZTest}
${ZWrite}
CGPROGRAM
#pragma target 3.0
HLSLPROGRAM
// Required to compile gles 2.0 with standard srp library
#pragma prefer_hlslcc gles
#pragma target 3.0
#pragma multi_compile _ _MAIN_LIGHT_COOKIE
#pragma multi_compile _MAIN_DIRECTIONAL_LIGHT _MAIN_SPOT_LIGHT

#pragma multi_compile _ _VERTEX_LIGHTS
#pragma multi_compile_fog
#pragma multi_compile_instancing
#pragma glsl
#pragma debug
#include "LightweightLighting.cginc"
#include "LightweightShaderLibrary/Core.hlsl"
#include "LightweightShaderLibrary/Lighting.hlsl"
float4 position : SV_POSITION;
#ifdef LIGHTMAP_ON
float4 lightmapUV : TEXCOORD0;
#else
float4 vertexSH : TEXCOORD0;
#endif
float4 clipPos : SV_POSITION;
float4 lightmapUVOrVertexSH : TEXCOORD0;
UNITY_VERTEX_OUTPUT_STEREO
};
GraphVertexOutput vert (GraphVertexInput v)

UNITY_SETUP_INSTANCE_ID(v);
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o);
${VertexShader}
${VertexShader}
float3 lwWNormal = TransformObjectToWorldNormal(v.normal);
float3 lwWorldPos = TransformObjectToWorld(v.vertex.xyz);
float4 clipPos = TransformWorldToHClip(lwWorldPos);
float3 lwWNormal = normalize(UnityObjectToWorldNormal(v.normal));
float4 lwWorldPos = mul(unity_ObjectToWorld, v.vertex);
float4 clipPos = mul(UNITY_MATRIX_VP, lwWorldPos);
// We either sample GI from lightmap or SH. lightmap UV and vertex SH coefficients
// are packed in lightmapUVOrVertexSH to save interpolator.
// The following funcions initialize
OUTPUT_LIGHTMAP_UV(v.lightmapUV, unity_LightmapST, o.lightmapUVOrVertexSH);
OUTPUT_SH(lwWNormal, o.lightmapUVOrVertexSH);
#ifdef LIGHTMAP_ON
o.lightmapUV.zw = v.lightmapUV * unity_LightmapST.xy + unity_LightmapST.zw;
#else
o.vertexSH = half4(EvaluateSHPerVertex(lwWNormal), 0.0);
#endif
half3 vertexLight = VertexLighting(lwWorldPos, lwWNormal);
half fogFactor = ComputeFogFactor(clipPos.z);
o.fogFactorAndVertexLight = half4(fogFactor, vertexLight);
o.fogFactorAndVertexLight.yzw = VertexLighting(lwWorldPos.xyz, lwWNormal);
o.fogFactorAndVertexLight.x = ComputeFogFactor(clipPos.z);
o.position = clipPos;
o.clipPos = clipPos;
fixed4 frag (GraphVertexOutput IN) : SV_Target
half4 frag (GraphVertexOutput IN) : SV_Target
{
${LocalPixelShader}

half3 normalWS = normalize(WorldSpaceNormal);
#endif
#if LIGHTMAP_ON
half3 indirectDiffuse = SampleLightmap(IN.lightmapUV.zw, normalWS);
#else
half3 indirectDiffuse = EvaluateSHPerPixel(normalWS, IN.vertexSH);
#endif
half3 indirectDiffuse = SampleGI(IN.lightmapUVOrVertexSH, normalWS);
half4 color = LightweightFragmentPBR(
WorldSpacePosition,

return color;
}
ENDCG
ENDHLSL
}

2
MaterialGraphProject/UnityPackageManager/manifest.json


{
"registry": "https://staging-packages.unity.com",
"dependencies": {
"com.unity.render-pipelines.lightweight" : "0.1.20"
"com.unity.render-pipelines.lightweight" : "0.1.22"
}
}
正在加载...
取消
保存