浏览代码

Initial functional PBR master

/main
Matt Dean 7 年前
当前提交
7a860c7c
共有 8 个文件被更改,包括 186 次插入91 次删除
  1. 119
      MaterialGraphProject/Assets/SRP/ScriptableRenderPipeline/LightweightPipeline/Shaders/GraphTest.shader
  2. 14
      MaterialGraphProject/Assets/SRP/ScriptableRenderPipeline/LightweightPipeline/Shaders/TestyTest.ShaderGraph
  3. 2
      MaterialGraphProject/Assets/SRP/ScriptableRenderPipeline/LightweightPipeline/Shaders/TestyTest.ShaderGraph.meta
  4. 8
      MaterialGraphProject/Assets/Test-PBR.mat
  5. 5
      MaterialGraphProject/Assets/TestGraph-PBR.mat
  6. 24
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Templates/lightweightSubshaderPBR.template
  7. 5
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/LightweightPipeline/AbstractLightweightPBRMasterNode.cs
  8. 100
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/LightweightPipeline/ShaderTest.unity

119
MaterialGraphProject/Assets/SRP/ScriptableRenderPipeline/LightweightPipeline/Shaders/GraphTest.shader


#pragma vertex LightweightVertexCustom
#pragma fragment LightweightFragmentPBR
//#pragma glsl
//#pragma debug
#pragma glsl
#pragma debug
#define _GLOSSYREFLECTIONS_ON
float Vector1_Vector1_4B0AEC3F_Uniform;

o.fogCoord.yzw += max(half3(0, 0, 0), ShadeSH9(half4(normal, 1)));
#endif
UNITY_TRANSFER_FOG(o, o.hpos);
//UNITY_TRANSFER_FOG(o, o.hpos);
return o;
}

{
o.Albedo = Color_Color_8256B4E6_Uniform;
o.Specular = Vector1_Vector1_5370E8F3_Uniform;
o.Metallic = Vector1_Vector1_5370E8F3_Uniform;
o.Smoothness = Vector1_Vector1_4B0AEC3F_Uniform;
}

half4 LightweightFragmentPBR(vOutput i) : SV_Target
{
SurfacePBR o = InitializeSurfacePBR();
DefineSurface(i, o);
DefineSurface(i, o);
//float2 uv = i.uv01.xy;
float2 lightmapUV = i.uv01.zw;
//float2 uv = i.uv01.xy;
float2 lightmapUV = i.uv01.zw;
half3 specColor;
half smoothness;
half oneMinusReflectivity;
//#ifdef _METALLIC_SETUP
//half3 diffColor = MetallicSetup(o, specColor, smoothness, oneMinusReflectivity);
//#else
half3 diffColor = SpecularSetup(o, specColor, smoothness, oneMinusReflectivity);
//#endif
half3 specColor;
half smoothness;
half oneMinusReflectivity;
//#ifdef _METALLIC_SETUP
half3 diffColor = MetallicSetup(o, specColor, smoothness, oneMinusReflectivity);
//#else
//half3 diffColor = SpecularSetup(o, specColor, smoothness, oneMinusReflectivity);
//#endif
diffColor = PreMultiplyAlpha(diffColor, o.Alpha, oneMinusReflectivity, /*out*/ o.Alpha);
diffColor = PreMultiplyAlpha(diffColor, o.Alpha, oneMinusReflectivity, /*out*/ o.Alpha);
// Roughness is (1.0 - smoothness)²
half perceptualRoughness = 1.0h - smoothness;
// Roughness is (1.0 - smoothness)²
half perceptualRoughness = 1.0h - smoothness;
// TODO - Actually handle normal
half3 normal;
CalculateNormal(i.normal, normal);
// TODO - Actually handle normal
half3 normal;
CalculateNormal(i.normal, normal);
// TODO: shader keyword for occlusion
// TODO: Reflection Probe blend support.
half3 reflectVec = reflect(-i.viewDir.xyz, normal);
// TODO: shader keyword for occlusion
// TODO: Reflection Probe blend support.
half3 reflectVec = reflect(-i.viewDir.xyz, normal);
UnityIndirect indirectLight = LightweightGI(lightmapUV, i.fogCoord.yzw, reflectVec, o.Occlusion, perceptualRoughness);
UnityIndirect indirectLight = LightweightGI(lightmapUV, i.fogCoord.yzw, reflectVec, o.Occlusion, perceptualRoughness);
// PBS
// grazingTerm = F90
half grazingTerm = saturate(smoothness + (1 - oneMinusReflectivity));
half fresnelTerm = Pow4(1.0 - saturate(dot(normal, i.viewDir.xyz)));
half3 color = LightweightBRDFIndirect(diffColor, specColor, indirectLight, perceptualRoughness * perceptualRoughness, grazingTerm, fresnelTerm);
half3 lightDirection;
// PBS
// grazingTerm = F90
half grazingTerm = saturate(smoothness + (1 - oneMinusReflectivity));
half fresnelTerm = Pow4(1.0 - saturate(dot(normal, i.viewDir.xyz)));
half3 color = LightweightBRDFIndirect(diffColor, specColor, indirectLight, perceptualRoughness * perceptualRoughness, grazingTerm, fresnelTerm);
half3 lightDirection;
#ifndef _MULTIPLE_LIGHTS
LightInput light;
INITIALIZE_MAIN_LIGHT(light);
half lightAtten = ComputeLightAttenuation(light, normal, i.posWS.xyz, lightDirection);
//#ifdef _SHADOWS
lightAtten *= ComputeShadowAttenuation(i.normal, i.posWS, _ShadowLightDirection.xyz);
//#endif
half NdotL = saturate(dot(normal, lightDirection));
half3 radiance = light.color * (lightAtten * NdotL);
color += LightweightBDRF(diffColor, specColor, oneMinusReflectivity, perceptualRoughness, normal, lightDirection, i.viewDir.xyz) * radiance;
#else
//#ifdef _SHADOWS
half shadowAttenuation = ComputeShadowAttenuation(i.normal, i.posWS, _ShadowLightDirection.xyz);
//#endif
int pixelLightCount = min(globalLightCount.x, unity_LightIndicesOffsetAndCount.y);
for (int lightIter = 0; lightIter < pixelLightCount; ++lightIter)
{
#ifndef _MULTIPLE_LIGHTS
int lightIndex = unity_4LightIndices0[lightIter];
INITIALIZE_LIGHT(light, lightIndex);
INITIALIZE_MAIN_LIGHT(light);
lightAtten *= max(shadowAttenuation, half(lightIndex != _ShadowData.x));
lightAtten *= ComputeShadowAttenuation(i.normal, i.posWS, _ShadowLightDirection.xyz);
color += LightweightBDRF(diffColor, specColor, oneMinusReflectivity, perceptualRoughness, normal, lightDirection, i.viewDir.xyz) * radiance;
#else
//#ifdef _SHADOWS
half shadowAttenuation = ComputeShadowAttenuation(i.normal, i.posWS, _ShadowLightDirection.xyz);
//#endif
int pixelLightCount = min(globalLightCount.x, unity_LightIndicesOffsetAndCount.y);
for (int lightIter = 0; lightIter < pixelLightCount; ++lightIter)
{
LightInput light;
int lightIndex = unity_4LightIndices0[lightIter];
INITIALIZE_LIGHT(light, lightIndex);
half lightAtten = ComputeLightAttenuation(light, normal, i.posWS.xyz, lightDirection);
//#ifdef _SHADOWS
lightAtten *= max(shadowAttenuation, half(lightIndex != _ShadowData.x));
//#endif
half NdotL = saturate(dot(normal, lightDirection));
half3 radiance = light.color * (lightAtten * NdotL);
color += LightweightBDRF(diffColor, specColor, oneMinusReflectivity, perceptualRoughness, normal, lightDirection, i.viewDir.xyz) * radiance;
}
#endif
color += LightweightBDRF(diffColor, specColor, oneMinusReflectivity, perceptualRoughness, normal, lightDirection, i.viewDir.xyz) * radiance;
}
#endif
color += o.Emission;
//UNITY_APPLY_FOG(i.fogCoord, color);
return OutputColor(color, o.Alpha);
color += o.Emission;
UNITY_APPLY_FOG(i.fogCoord, color);
return OutputColor(color, o.Alpha);
}
ENDCG

14
MaterialGraphProject/Assets/SRP/ScriptableRenderPipeline/LightweightPipeline/Shaders/TestyTest.ShaderGraph
文件差异内容过多而无法显示
查看文件

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


fileFormatVersion: 2
guid: 02a3ca69ec995e94aa47105621a17e4c
timeCreated: 1505452895
timeCreated: 1505455116
licenseType: Pro
ShaderImporter:
externalObjects: {}

8
MaterialGraphProject/Assets/Test-PBR.mat


m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _MetallicGlossMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _MetallicSpecGlossMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}

- _DetailNormalMapScale: 1
- _DstBlend: 0
- _GlossMapScale: 1
- _Glossiness: 0
- _Glossiness: 0.5
- _Metallic: 0
- _Metallic: 0.5
- _Mode: 0
- _OcclusionStrength: 0.5
- _Parallax: 0.02

5
MaterialGraphProject/Assets/TestGraph-PBR.mat


m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
m_Floats:
- Vector1_Vector1_5370E8F3_Uniform: 0
- Vector1_Vector1_4B0AEC3F_Uniform: 0.5
- Vector1_Vector1_5370E8F3_Uniform: 0.5
- _BumpScale: 1
- _Cutoff: 0.5
- _DetailNormalMapScale: 1

- _GlossinessSource: 0
- _GlossyReflections: 1
- _Metallic: 0
- _Metallic: 1
- _Mode: 0
- _OcclusionStrength: 0.5
- _Parallax: 0.02

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


#pragma fragment LightweightFragmentPBR
#pragma glsl
#pragma debug
${Defines}
${Defines}
${ShaderPropertyUsages}
${ShaderFunctions}

half3 specColor;
half smoothness;
half oneMinusReflectivity;
//#ifdef _METALLIC_SETUP
//half3 diffColor = MetallicSetup(o, specColor, smoothness, oneMinusReflectivity);
//#else
#ifdef _METALLIC_SETUP
half3 diffColor = MetallicSetup(o, specColor, smoothness, oneMinusReflectivity);
#else
//#endif
#endif
diffColor = PreMultiplyAlpha(diffColor, o.Alpha, oneMinusReflectivity, /*out*/ o.Alpha);

INITIALIZE_MAIN_LIGHT(light);
half lightAtten = ComputeLightAttenuation(light, normal, i.posWS.xyz, lightDirection);
//#ifdef _SHADOWS
#ifdef _SHADOWS
//#endif
#endif
half NdotL = saturate(dot(normal, lightDirection));
half3 radiance = light.color * (lightAtten * NdotL);

//#ifdef _SHADOWS
#ifdef _SHADOWS
//#endif
#endif
int pixelLightCount = min(globalLightCount.x, unity_LightIndicesOffsetAndCount.y);
for (int lightIter = 0; lightIter < pixelLightCount; ++lightIter)
{

half lightAtten = ComputeLightAttenuation(light, normal, i.posWS.xyz, lightDirection);
//#ifdef _SHADOWS
#ifdef _SHADOWS
//#endif
#endif
half NdotL = saturate(dot(normal, lightDirection));
half3 radiance = light.color * (lightAtten * NdotL);

5
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/LightweightPipeline/AbstractLightweightPBRMasterNode.cs


public void GetDefines(ShaderGenerator visitor)
{
if(GetWorkflowName() == "Metallic")
visitor.AddShaderChunk("#define _METALLIC_SETUP 1", false);
visitor.AddShaderChunk("#define _METALLIC_SETUP 1", true);
visitor.AddShaderChunk("#define _GLOSSYREFLECTIONS_ON", true);
//visitor.AddShaderChunk("#define _SOFT_SHADOWS", true);
visitor.AddShaderChunk("#define _SPECULARHIGHLIGHTS_ON", true);
}
public override string GetFullShader(GenerationMode mode, string name, out List<PropertyGenerator.TextureInfo> configuredTextures)

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


m_AmbientSkyColor: {r: 0.212, g: 0.227, b: 0.259, a: 1}
m_AmbientEquatorColor: {r: 0.114, g: 0.125, b: 0.133, a: 1}
m_AmbientGroundColor: {r: 0.047, g: 0.043, b: 0.035, a: 1}
m_AmbientIntensity: 1
m_AmbientIntensity: 0
m_AmbientMode: 0
m_SubtractiveShadowColor: {r: 0.42, g: 0.478, b: 0.627, a: 1}
m_SkyboxMaterial: {fileID: 10304, guid: 0000000000000000f000000000000000, type: 0}

debug:
m_Flags: 0
m_NavMeshData: {fileID: 0}
--- !u!1 &250933708
GameObject:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
serializedVersion: 5
m_Component:
- component: {fileID: 250933712}
- component: {fileID: 250933711}
- component: {fileID: 250933710}
- component: {fileID: 250933709}
m_Layer: 0
m_Name: Sphere (3)
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!23 &250933709
MeshRenderer:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 250933708}
m_Enabled: 1
m_CastShadows: 1
m_ReceiveShadows: 1
m_DynamicOccludee: 1
m_MotionVectors: 1
m_LightProbeUsage: 1
m_ReflectionProbeUsage: 1
m_Materials:
- {fileID: 2100000, guid: d6c557b0ad00a7946b27400b33a390ac, type: 2}
m_StaticBatchInfo:
firstSubMesh: 0
subMeshCount: 0
m_StaticBatchRoot: {fileID: 0}
m_ProbeAnchor: {fileID: 0}
m_LightProbeVolumeOverride: {fileID: 0}
m_ScaleInLightmap: 1
m_PreserveUVs: 1
m_IgnoreNormalsForChartDetection: 0
m_ImportantGI: 0
m_StitchLightmapSeams: 0
m_SelectedEditorRenderState: 3
m_MinimumChartSize: 4
m_AutoUVMaxDistance: 0.5
m_AutoUVMaxAngle: 89
m_LightmapParameters: {fileID: 0}
m_SortingLayerID: 0
m_SortingLayer: 0
m_SortingOrder: 0
--- !u!135 &250933710
SphereCollider:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 250933708}
m_Material: {fileID: 0}
m_IsTrigger: 0
m_Enabled: 1
serializedVersion: 2
m_Radius: 0.5
m_Center: {x: 0, y: 0, z: 0}
--- !u!33 &250933711
MeshFilter:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 250933708}
m_Mesh: {fileID: 10207, guid: 0000000000000000e000000000000000, type: 0}
--- !u!4 &250933712
Transform:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 250933708}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 5
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &301674285
GameObject:
m_ObjectHideFlags: 0

m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 301674285}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: -0.782, y: 0.909, z: 1.006}
m_LocalPosition: {x: -2.53, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 0}

m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 1225352826}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: -3.087}
m_LocalPosition: {x: -3.733, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 0}

m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 1225949929}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 1.466}
m_LocalPosition: {x: -1.2700001, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 0}

m_Enabled: 1
serializedVersion: 8
m_Type: 1
m_Color: {r: 1, g: 0.95686275, b: 0.8392157, a: 1}
m_Color: {r: 1, g: 1, b: 1, a: 1}
m_Intensity: 1
m_Range: 10
m_SpotAngle: 30

m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 1641918147}
m_LocalRotation: {x: -0.008174583, y: 0.5575213, z: -0.47586024, w: 0.68019146}
m_LocalRotation: {x: -0.008174582, y: 0.5575212, z: -0.47586018, w: 0.6801914}
m_LocalPosition: {x: 0, y: 3, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []

m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 1913430569}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 1, z: -10}
m_LocalRotation: {x: -0.23384847, y: 0.25512192, z: -0.06373714, w: -0.936037}
m_LocalPosition: {x: -0.034000266, y: 1.0085648, z: -1.8235388}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 0}
正在加载...
取消
保存