浏览代码

Fixes for PR

/main
Matt Dean 7 年前
当前提交
5aa5451a
共有 15 个文件被更改,包括 50 次插入99 次删除
  1. 10
      MaterialGraphProject/Assets/SRP/ScriptableRenderPipeline/LightweightPipeline/Shaders/CGIncludes/LightweightCore.cginc
  2. 13
      MaterialGraphProject/Assets/SRP/ScriptableRenderPipeline/LightweightPipeline/Shaders/CGIncludes/LightweightFastBlinn.cginc
  3. 16
      MaterialGraphProject/Assets/SRP/ScriptableRenderPipeline/LightweightPipeline/Shaders/CGIncludes/LightweightInput.cginc
  4. 13
      MaterialGraphProject/Assets/SRP/ScriptableRenderPipeline/LightweightPipeline/Shaders/CGIncludes/LightweightPBR.cginc
  5. 8
      MaterialGraphProject/Assets/SRP/ScriptableRenderPipeline/LightweightPipeline/Shaders/CGIncludes/LightweightShadows.cginc
  6. 6
      MaterialGraphProject/Assets/SRP/ScriptableRenderPipeline/LightweightPipeline/Shaders/CGIncludes/LightweightUnlit.cginc
  7. 5
      MaterialGraphProject/Assets/SRP/ScriptableRenderPipeline/LightweightPipeline/Shaders/LightweightFastBlinn.shader
  8. 5
      MaterialGraphProject/Assets/SRP/ScriptableRenderPipeline/LightweightPipeline/Shaders/LightweightPBR.shader
  9. 5
      MaterialGraphProject/Assets/SRP/ScriptableRenderPipeline/LightweightPipeline/Shaders/LightweightUnlit.shader
  10. 2
      MaterialGraphProject/Assets/SRP/ScriptableRenderPipeline/LightweightPipeline/Shaders/MetallicTest.ShaderGraph.meta
  11. 2
      MaterialGraphProject/Assets/SRP/ScriptableRenderPipeline/LightweightPipeline/Shaders/SpecularTest.ShaderGraph.meta
  12. 34
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Templates/lightweightSubshaderPBR.template
  13. 13
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/LightweightPipeline/LightweightMetallicMasterNode.cs
  14. 13
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/LightweightPipeline/LightweightSpecularMasterNode.cs
  15. 4
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/LightweightPipeline/ShaderTest.unity

10
MaterialGraphProject/Assets/SRP/ScriptableRenderPipeline/LightweightPipeline/Shaders/CGIncludes/LightweightCore.cginc


#endif
}
// This is temp because the shader graph version does work
inline void CalculateNormal(half3 vNormal, out half3 normal)
{
normal = normalize(vNormal);
}
half4 OutputColor(half3 color, half alpha)
{
#if defined(_ALPHABLEND_ON) || defined(_ALPHAPREMULTIPLY_ON)

#endif
}
void ModifyVertex(inout LightweightVertexInput v);
LightweightVertexOutput LightweightVertex(LightweightVertexInput v)
{

UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o);
//ModifyVertex(v);
o.uv01.xy = TRANSFORM_TEX(v.texcoord, _MainTex);
#ifdef LIGHTMAP_ON

13
MaterialGraphProject/Assets/SRP/ScriptableRenderPipeline/LightweightPipeline/Shaders/CGIncludes/LightweightFastBlinn.cginc


half3 lightDirection;
half4 specularGloss = half4(s.Specular, s.Glossiness);
#ifdef _SHADOWS
#if _NORMALMAP
half3 vertexNormal = half3(i.tangentToWorld0.z, i.tangentToWorld1.z, i.tangentToWorld2.z); // Fix this
#else
half3 vertexNormal = i.normal;
#endif
#endif
lightAtten *= ComputeShadowAttenuation(normal, i.posWS, _ShadowLightDirection.xyz);
lightAtten *= ComputeShadowAttenuation(vertexNormal, i.posWS, _ShadowLightDirection.xyz);
#endif
#ifdef LIGHTWEIGHT_SPECULAR_HIGHLIGHTS

half3 color = half3(0, 0, 0);
#ifdef _SHADOWS
half shadowAttenuation = ComputeShadowAttenuation(normal, i.posWS, _ShadowLightDirection.xyz);
half shadowAttenuation = ComputeShadowAttenuation(vertexNormal, i.posWS, _ShadowLightDirection.xyz);
#endif
int pixelLightCount = min(globalLightCount.x, unity_LightIndicesOffsetAndCount.y);
for (int lightIter = 0; lightIter < pixelLightCount; ++lightIter)

16
MaterialGraphProject/Assets/SRP/ScriptableRenderPipeline/LightweightPipeline/Shaders/CGIncludes/LightweightInput.cginc


{
float4 vertex : POSITION;
float3 normal : NORMAL;
float4 tangent : TANGENT; // normal map
float2 texcoord : TEXCOORD0; // uv
float4 tangent : TANGENT;
float2 texcoord : TEXCOORD0;
float2 lightmapUV : TEXCOORD1;
UNITY_VERTEX_INPUT_INSTANCE_ID
};

float4 uv01 : TEXCOORD0; // uv01.xy: uv0, uv01.zw: uv1 // uv
float4 posWS : TEXCOORD1; // lighting
float4 posWS : TEXCOORD1;
half3 tangentToWorld0 : TEXCOORD2; // tangentToWorld matrix // normal map
half3 tangentToWorld0 : TEXCOORD2; // tangentToWorld matrix
half3 normal : TEXCOORD2; // no normal map
half3 normal : TEXCOORD2;
half4 viewDir : TEXCOORD5; // xyz: viewDir // lighting
half4 fogCoord : TEXCOORD6; // x: fogCoord, yzw: vertexColor // fog
float4 hpos : SV_POSITION; // lighting
half4 viewDir : TEXCOORD5; // xyz: viewDir
half4 fogCoord : TEXCOORD6; // x: fogCoord, yzw: vertexColor
float4 hpos : SV_POSITION;
UNITY_VERTEX_OUTPUT_STEREO
};

13
MaterialGraphProject/Assets/SRP/ScriptableRenderPipeline/LightweightPipeline/Shaders/CGIncludes/LightweightPBR.cginc


// Roughness is (1.0 - smoothness)²
half perceptualRoughness = 1.0h - smoothness;
// TODO - Actually handle normal
half3 normal;
CalculateNormal(s.Normal, i, normal);

half3 color = LightweightBRDFIndirect(diffColor, specColor, indirectLight, perceptualRoughness * perceptualRoughness, grazingTerm, fresnelTerm);
half3 lightDirection;
#ifdef _SHADOWS
#if _NORMALMAP
half3 vertexNormal = half3(i.tangentToWorld0.z, i.tangentToWorld1.z, i.tangentToWorld2.z); // Fix this
#else
half3 vertexNormal = i.normal;
#endif
#endif
#ifndef _MULTIPLE_LIGHTS
LightInput light;
INITIALIZE_MAIN_LIGHT(light);

lightAtten *= ComputeShadowAttenuation(i.normal, i.posWS, _ShadowLightDirection.xyz);
lightAtten *= ComputeShadowAttenuation(vertexNormal, i.posWS, _ShadowLightDirection.xyz);
#endif
half NdotL = saturate(dot(normal, lightDirection));

#ifdef _SHADOWS
half shadowAttenuation = ComputeShadowAttenuation(i.normal, i.posWS, _ShadowLightDirection.xyz);
half shadowAttenuation = ComputeShadowAttenuation(vertexNormal, i.posWS, _ShadowLightDirection.xyz);
#endif
int pixelLightCount = min(globalLightCount.x, unity_LightIndicesOffsetAndCount.y);
for (int lightIter = 0; lightIter < pixelLightCount; ++lightIter)

8
MaterialGraphProject/Assets/SRP/ScriptableRenderPipeline/LightweightPipeline/Shaders/CGIncludes/LightweightShadows.cginc


return attenuation * 0.25;
}
inline half ComputeShadowAttenuation(half3 normal, half4 posWS, half3 shadowDir)
inline half ComputeShadowAttenuation(half3 vertexNormal, half4 posWS, half3 shadowDir)
//#if _NORMALMAP
//half3 vertexNormal = half3(i.tangentToWorld0.z, i.tangentToWorld1.z, i.tangentToWorld2.z); // Fix this
//#else
half3 vertexNormal = normal;
//#endif
half NdotL = dot(vertexNormal, shadowDir);
half bias = saturate(1.0 - NdotL) * _ShadowData.z;

6
MaterialGraphProject/Assets/SRP/ScriptableRenderPipeline/LightweightPipeline/Shaders/CGIncludes/LightweightUnlit.cginc


#ifndef LIGHTWEIGHT_UNLIT_INCLUDED
#define LIGHTWEIGHT_UNLIT_INCLUDED
//#include "UnityStandardInput.cginc"
struct appdata_unlit
{
float4 vertex : POSITION;

half4 _Color;
half _Cutoff;
void ModifyVertex(inout appdata_unlit v);
LightweightVertexOutputUnlit LightweightVertexUnlit(appdata_unlit v)
{
LightweightVertexOutputUnlit o;

ModifyVertex(v);
o.vertex = UnityObjectToClipPos(v.vertex);
o.uv = TRANSFORM_TEX(v.uv, _MainTex);

5
MaterialGraphProject/Assets/SRP/ScriptableRenderPipeline/LightweightPipeline/Shaders/LightweightFastBlinn.shader


#pragma vertex LightweightVertex
#pragma fragment LightweightFragmentFastBlinn
void ModifyVertex(inout LightweightVertexInput v)
{
}
void DefineSurface(LightweightVertexOutput i, inout SurfaceFastBlinn s)
{
// Albedo

5
MaterialGraphProject/Assets/SRP/ScriptableRenderPipeline/LightweightPipeline/Shaders/LightweightPBR.shader


#pragma vertex LightweightVertex
#pragma fragment LightweightFragmentPBR
void ModifyVertex(inout LightweightVertexInput v)
{
}
void DefineSurface(LightweightVertexOutput i, inout SurfacePBR s)
{
// Albedo

5
MaterialGraphProject/Assets/SRP/ScriptableRenderPipeline/LightweightPipeline/Shaders/LightweightUnlit.shader


#pragma vertex LightweightVertexUnlit
#pragma fragment LightweightFragmentUnlit
void ModifyVertex(inout appdata_unlit v)
{
}
void DefineSurface(LightweightVertexOutputUnlit i, inout SurfaceUnlit s)
{
// Albedo

2
MaterialGraphProject/Assets/SRP/ScriptableRenderPipeline/LightweightPipeline/Shaders/MetallicTest.ShaderGraph.meta


fileFormatVersion: 2
guid: 02a3ca69ec995e94aa47105621a17e4c
timeCreated: 1505497637
timeCreated: 1505499381
licenseType: Pro
ShaderImporter:
externalObjects: {}

2
MaterialGraphProject/Assets/SRP/ScriptableRenderPipeline/LightweightPipeline/Shaders/SpecularTest.ShaderGraph.meta


fileFormatVersion: 2
guid: a96bafc6e4c6e7c4ca1fb43c905d7948
timeCreated: 1505498093
timeCreated: 1505499391
licenseType: Pro
ShaderImporter:
externalObjects: {}

34
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Templates/lightweightSubshaderPBR.template


o.normal = normalize(UnityObjectToWorldNormal(v.normal));
${VertexShaderBody}
// TODO - Handle lightmaps
//o.uv01.xy = TRANSFORM_TEX(v.texcoord, _MainTex);
#ifdef LIGHTMAP_ON
//o.uv01.zw = v.lightmapUV * unity_LightmapST.xy + unity_LightmapST.zw;

o.posWS.xyz = worldPos;
o.viewDir.xyz = normalize(_WorldSpaceCameraPos - worldPos);
#if _NORMALMAP
//half sign = v.tangent.w * unity_WorldTransformParams.w;
//o.tangent = normalize(UnityObjectToWorldDir(v.tangent));
//o.binormal = cross(normal, tangent) * v.tangent.w;
// Initialize tangetToWorld in column-major to benefit from better glsl matrix multiplication code
//o.tangentToWorld0 = half3(tangent.x, binormal.x, normal.x);
//o.tangentToWorld1 = half3(tangent.y, binormal.y, normal.y);
//o.tangentToWorld2 = half3(tangent.z, binormal.z, normal.z);
#endif
// TODO: change to only support point lights per vertex. This will greatly simplify shader ALU
#if defined(_VERTEX_LIGHTS) && defined(_MULTIPLE_LIGHTS)

half3 MetallicSetup(SurfacePBR o, out half3 specular, out half smoothness, out half oneMinusReflectivity)
{
smoothness = o.Smoothness;// metallicGloss.g;
smoothness = o.Smoothness;
// We'll need oneMinusReflectivity, so
// 1-reflectivity = 1-lerp(dielectricSpec, 1, metallic) = lerp(1-dielectricSpec, 0, metallic)

DefineSurface(i, o);
o.Albedo = LIGHTWEIGHT_GAMMA_TO_LINEAR(o.Albedo);
//float2 uv = i.uv01.xy;
// TODO - Handle lightmaps
// float2 uv = i.uv01.xy;
float2 lightmapUV = float2(0,0);//i.uv01.zw;
half3 specColor;

// Roughness is (1.0 - smoothness)²
half perceptualRoughness = 1.0h - smoothness;
// TODO - Actually handle normal
half3 normal;
#if _NORMALMAP
half3 tangentToWorld0 = half3(i.tangent.x, i.binormal.x, i.normal.x);

half fresnelTerm = Pow4(1.0 - saturate(dot(normal, i.viewDir.xyz)));
half3 color = LightweightBRDFIndirect(diffColor, specColor, indirectLight, perceptualRoughness * perceptualRoughness, grazingTerm, fresnelTerm);
half3 lightDirection;
#ifdef _SHADOWS
#if _NORMALMAP
half3 vertexNormal = half3(tangentToWorld0.z, tangentToWorld1.z, tangentToWorld2.z); // Fix this
#else
half3 vertexNormal = normal;
#endif
#endif
#ifndef _MULTIPLE_LIGHTS
LightInput light;

#ifdef _SHADOWS
lightAtten *= ComputeShadowAttenuation(i.normal, i.posWS, _ShadowLightDirection.xyz);
lightAtten *= ComputeShadowAttenuation(vertexNormal, i.posWS, _ShadowLightDirection.xyz);
#endif
half NdotL = saturate(dot(normal, lightDirection));

#ifdef _SHADOWS
half shadowAttenuation = ComputeShadowAttenuation(i.normal, i.posWS, _ShadowLightDirection.xyz);
half shadowAttenuation = ComputeShadowAttenuation(vertexNormal, i.posWS, _ShadowLightDirection.xyz);
#endif
int pixelLightCount = min(globalLightCount.x, unity_LightIndicesOffsetAndCount.y);
for (int lightIter = 0; lightIter < pixelLightCount; ++lightIter)

13
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/LightweightPipeline/LightweightMetallicMasterNode.cs


public const string WorkflowName = "Metallic";
//public const string LightFunctionName = "Standard";
//public const string SurfaceOutputStructureName = "SurfaceOutputStandard";
public LightweightMetallicMasterNode()
{
name = "LightweightMetallicMasterNode";

{
return WorkflowName;
}
/*public override string GetSurfaceOutputName()
{
return SurfaceOutputStructureName;
}
public override string GetLightFunction()
{
return LightFunctionName;
}*/
}
}

13
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/LightweightPipeline/LightweightSpecularMasterNode.cs


public const string WorkflowName = "Specular";
//public const string LightFunctionName = "Standard";
//public const string SurfaceOutputStructureName = "SurfaceOutputStandard";
public LightweightSpecularMasterNode()
{
name = "LightweightSpecularMasterNode";

{
return WorkflowName;
}
/*public override string GetSurfaceOutputName()
{
return SurfaceOutputStructureName;
}
public override string GetLightFunction()
{
return LightFunctionName;
}*/
}
}

4
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/LightweightPipeline/ShaderTest.unity


m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 1913430569}
m_LocalRotation: {x: -0.28734982, y: 0.32602012, z: -0.10472839, w: -0.8945239}
m_LocalPosition: {x: -0.2865281, y: 1.3010813, z: -2.3694947}
m_LocalRotation: {x: 0.29880813, y: -0.32938838, z: 0.11073876, w: 0.8887935}
m_LocalPosition: {x: 0.4304604, y: 1.4661161, z: -2.531431}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 0}
正在加载...
取消
保存