浏览代码

Due to target hardware restrictions (ALU/bandwidth) LD won't support the same standard shader workflow. Instead a specular limited will be available.

/vr_sandbox
Felipe Lira 8 年前
当前提交
38a9956f
共有 21 个文件被更改,包括 663 次插入604 次删除
  1. 327
      Assets/LowEndRenderLoop/LowEndRenderLoopScene.unity
  2. 2
      Assets/LowEndRenderLoop/LowEndRenderPipeline.cs
  3. 2
      Assets/LowEndRenderLoop/Materials/MobileColors.mat
  4. 264
      Assets/LowEndRenderLoop/Shaders/LDRenderPipe-Specular.shader
  5. 12
      Assets/LowEndRenderLoop/LDMaterialInspector.cs
  6. 12
      Assets/LowEndRenderLoop/LDMaterialInspector.cs.meta
  7. 80
      Assets/LowEndRenderLoop/Materials/LDSpecularSphere0.mat
  8. 9
      Assets/LowEndRenderLoop/Materials/LDSpecularSphere0.mat.meta
  9. 80
      Assets/LowEndRenderLoop/Materials/StandardSpecular.mat
  10. 9
      Assets/LowEndRenderLoop/Materials/StandardSpecular.mat.meta
  11. 9
      Assets/ScriptableRenderLoop.meta
  12. 9
      Assets/ScriptableRenderLoop/HDRenderPipeline.meta
  13. 9
      Assets/ScriptableRenderLoop/HDRenderPipeline/Material.meta
  14. 130
      Assets/LowEndRenderLoop/Shaders/LDRenderPipe-Metallic.shader
  15. 9
      Assets/LowEndRenderLoop/Shaders/LDRenderPipe-Metallic.shader.meta
  16. 277
      Assets/LowEndRenderLoop/Shaders/LDRenderPipeline-Core.cginc
  17. 9
      Assets/LowEndRenderLoop/Shaders/LDRenderPipeline-Core.cginc.meta
  18. 9
      Assets/TestScenes/HDTest/GraphicTest/Two Sided/Prefabs/Materials.meta
  19. 9
      Assets/TestScenes/HDTest/LayeredLitTest/Mesh/Materials.meta

327
Assets/LowEndRenderLoop/LowEndRenderLoopScene.unity


m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 766602296}
m_RootOrder: 10
m_RootOrder: 1
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &240143172
GameObject:

m_LocalScale: {x: 5, y: 1, z: 5}
m_Children: []
m_Father: {fileID: 766602296}
m_RootOrder: 17
m_RootOrder: 8
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &261580742
GameObject:

m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 4
m_IsActive: 0
m_IsActive: 1
--- !u!23 &261580743
MeshRenderer:
m_ObjectHideFlags: 0

m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 261580742}
m_LocalRotation: {x: 0.04534631, y: -0.0067818314, z: -0.99533, w: 0.08494744}
m_LocalPosition: {x: 0.39, y: 0.715, z: 0.576}
m_LocalPosition: {x: -1.21, y: 1.08, z: 7.72}
m_Father: {fileID: 766602296}
m_Father: {fileID: 1592048727}
--- !u!1 &472209899
GameObject:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
serializedVersion: 5
m_Component:
- component: {fileID: 472209901}
- component: {fileID: 472209900}
m_Layer: 0
m_Name: Sphere
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!135 &472209900
SphereCollider:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 472209899}
m_Material: {fileID: 0}
m_IsTrigger: 0
m_Enabled: 1
serializedVersion: 2
m_Radius: 32.4691
m_Center: {x: -5.3164, y: -6.7591, z: 15.734}
--- !u!4 &472209901
Transform:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 472209899}
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 &529372582
GameObject:
m_ObjectHideFlags: 0

m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 766602296}
m_RootOrder: 9
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &531853420
GameObject:

m_LocalPosition: {x: 1.67, y: 1.55, z: 5.57}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 766602296}
m_Father: {fileID: 1592048727}
--- !u!1 &660517135
GameObject:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
serializedVersion: 5
m_Component:
- component: {fileID: 660517136}
- component: {fileID: 660517139}
- component: {fileID: 660517138}
- component: {fileID: 660517137}
m_Layer: 0
m_Name: Sphere
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &660517136
Transform:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 660517135}
m_LocalRotation: {x: -0, y: 0.6952887, z: -0, w: 0.71873057}
m_LocalPosition: {x: -5.98, y: 2.13, z: 7.51}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 1592048727}
m_RootOrder: 8
m_LocalEulerAnglesHint: {x: 0, y: 88.100006, z: 0}
--- !u!23 &660517137
MeshRenderer:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 660517135}
m_Enabled: 1
m_CastShadows: 1
m_ReceiveShadows: 1
m_MotionVectors: 1
m_LightProbeUsage: 1
m_ReflectionProbeUsage: 1
m_Materials:
- {fileID: 2100000, guid: bded62b791643214d8d29703a7813d34, 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_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 &660517138
SphereCollider:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 660517135}
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 &660517139
MeshFilter:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 660517135}
m_Mesh: {fileID: 10207, guid: 0000000000000000e000000000000000, type: 0}
--- !u!1 &689369500
GameObject:
m_ObjectHideFlags: 0

m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 766602296}
m_RootOrder: 11
m_RootOrder: 2
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &717059738
GameObject:

m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 766602296}
m_RootOrder: 12
m_RootOrder: 3
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &722899210
GameObject:

m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children:
- {fileID: 1280249099}
- {fileID: 1714697416}
- {fileID: 531853424}
- {fileID: 1485985481}
- {fileID: 1596459103}
- {fileID: 1749252043}
- {fileID: 2031315349}
- {fileID: 261580746}
- {fileID: 1405931301}
- {fileID: 529372586}
- {fileID: 126291029}
- {fileID: 689369504}

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

m_LocalPosition: {x: -1.892566, y: 0.82283884, z: 4.0344157}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 766602296}
m_Father: {fileID: 1592048727}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &1366180535

m_UseColorTemperature: 0
m_ShadowRadius: 0
m_ShadowAngle: 0
--- !u!1 &1405931297
GameObject:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
serializedVersion: 5
m_Component:
- component: {fileID: 1405931301}
- component: {fileID: 1405931300}
- component: {fileID: 1405931299}
- component: {fileID: 1405931298}
m_Layer: 0
m_Name: Sphere (4)
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 4
m_IsActive: 1
--- !u!23 &1405931298
MeshRenderer:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 1405931297}
m_Enabled: 1
m_CastShadows: 1
m_ReceiveShadows: 1
m_MotionVectors: 1
m_LightProbeUsage: 1
m_ReflectionProbeUsage: 1
m_Materials:
- {fileID: 2100000, guid: 2fee9f51314ef4046b13d8291efdbc6d, 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_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 &1405931299
SphereCollider:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 1405931297}
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 &1405931300
MeshFilter:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 1405931297}
m_Mesh: {fileID: 10207, guid: 0000000000000000e000000000000000, type: 0}
--- !u!4 &1405931301
Transform:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 1405931297}
m_LocalRotation: {x: 0.56518906, y: 0.5003966, z: 0.20066339, w: 0.62441885}
m_LocalPosition: {x: 0.39, y: 0.604, z: 1.205}
m_LocalScale: {x: 2, y: 2, z: 2}
m_Children: []
m_Father: {fileID: 766602296}
m_RootOrder: 8
m_LocalEulerAnglesHint: {x: 30.332, y: -620.687, z: 71.02901}
--- !u!1 &1447851825
GameObject:
m_ObjectHideFlags: 0

m_LocalScale: {x: 1, y: 10, z: 1}
m_Children: []
m_Father: {fileID: 766602296}
m_RootOrder: 18
m_RootOrder: 9
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &1485985477
GameObject:

m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 1485985477}
m_LocalRotation: {x: -0.4545799, y: -0.2491196, z: 0.79480726, w: -0.31556}
m_LocalRotation: {x: -0.45457986, y: -0.24911958, z: 0.7948072, w: -0.31556}
m_Father: {fileID: 766602296}
m_Father: {fileID: 1592048727}
m_RootOrder: 3
m_LocalEulerAnglesHint: {x: 43.071003, y: -50.710003, z: 202.125}
--- !u!1 &1499111012

m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 766602296}
m_RootOrder: 13
m_RootOrder: 4
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &1592048726
GameObject:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
serializedVersion: 5
m_Component:
- component: {fileID: 1592048727}
m_Layer: 0
m_Name: Specular
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &1592048727
Transform:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 1592048726}
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:
- {fileID: 1280249099}
- {fileID: 1714697416}
- {fileID: 531853424}
- {fileID: 1485985481}
- {fileID: 1596459103}
- {fileID: 1749252043}
- {fileID: 2031315349}
- {fileID: 261580746}
- {fileID: 660517136}
m_Father: {fileID: 0}
m_RootOrder: 5
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &1596459099
GameObject:

m_LocalPosition: {x: -4.57, y: 1.09, z: 2.58}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 766602296}
m_Father: {fileID: 1592048727}
m_RootOrder: 4
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &1659249725

m_Father: {fileID: 722899211}
m_RootOrder: 1
m_LocalEulerAnglesHint: {x: 18.036001, y: 49.154003, z: -0.014}
--- !u!1 &1678103613
GameObject:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
serializedVersion: 5
m_Component:
- component: {fileID: 1678103614}
m_Layer: 0
m_Name: Metallic
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &1678103614
Transform:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 1678103613}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: -9.96}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 6
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &1680776005
GameObject:
m_ObjectHideFlags: 0

m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 766602296}
m_RootOrder: 15
m_RootOrder: 6
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &1686436290
GameObject:

m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 766602296}
m_RootOrder: 14
m_RootOrder: 5
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &1714697412
GameObject:

m_LocalPosition: {x: -2.94, y: 1.55, z: 4.034416}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 766602296}
m_Father: {fileID: 1592048727}
m_RootOrder: 1
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &1749252039

m_LocalPosition: {x: -1.89, y: 1.09, z: 3.02}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 766602296}
m_Father: {fileID: 1592048727}
m_RootOrder: 5
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &1761282537

m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 766602296}
m_RootOrder: 16
m_RootOrder: 7
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!23 &1761282539
MeshRenderer:

m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 4
m_IsActive: 0
m_IsActive: 1
--- !u!23 &2031315346
MeshRenderer:
m_ObjectHideFlags: 0

m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 2031315345}
m_LocalRotation: {x: -0.0041517415, y: -0.29575256, z: -0.18984698, w: 0.9362005}
m_LocalPosition: {x: 0.39, y: 0.86, z: 0.275}
m_LocalPosition: {x: -1.21, y: 1.22, z: 6.67}
m_Father: {fileID: 766602296}
m_Father: {fileID: 1592048727}
m_RootOrder: 6
m_LocalEulerAnglesHint: {x: -6.8960004, y: -33.794003, z: -20.829}
--- !u!1 &2054727025

2
Assets/LowEndRenderLoop/LowEndRenderPipeline.cs


SetupShadowShaderVariables(context, camera.nearClipPlane, cullingParameters.shadowDistance, m_ShadowSettings.directionalLightCascadeCount);
// Render Opaques
var settings = new DrawRendererSettings(cull, camera, new ShaderPassName("LowEndForwardBase"));
var settings = new DrawRendererSettings(cull, camera, new ShaderPassName("ForwardBase"));
settings.sorting.flags = SortFlags.CommonOpaque;
settings.inputFilter.SetQueuesOpaque();

2
Assets/LowEndRenderLoop/Materials/MobileColors.mat


m_Colors:
- _Color: {r: 1, g: 1, b: 1, a: 1}
- _EmissionColor: {r: 0, g: 0, b: 0, a: 1}
- _SpecColor: {r: 0.19999996, g: 0.19999996, b: 0.19999996, a: 1}
- _SpecColor: {r: 0.21323532, g: 0.21323532, b: 0.21323532, a: 1}

264
Assets/LowEndRenderLoop/Shaders/LDRenderPipe-Specular.shader


Pass
{
Name "SINGLE_PASS_FORWARD"
Tags { "LightMode" = "LowEndForwardBase" }
Tags { "LightMode" = "ForwardBase" }
// Use same blending / depth states as Standard shader
Blend[_SrcBlend][_DstBlend]

#pragma target 2.0
#pragma vertex vert
#pragma fragment frag
#pragma shader_feature _ _ALPHATEST_ON _ALPHABLEND_ON
#pragma shader_feature _SPECGLOSSMAP
#pragma shader_feature _SMOOTHNESS_TEXTURE_ALBEDO_CHANNEL_A
#pragma shader_feature _NORMALMAP

#define DIFFUSE_AND_SPECULAR_INPUT SpecularInput
#include "LDRenderPipeline-Core.cginc"
#include "UnityCG.cginc"
#include "UnityStandardBRDF.cginc"
#include "UnityStandardInput.cginc"
#include "UnityStandardUtils.cginc"
#define DEBUG_CASCADES 0
#define MAX_SHADOW_CASCADES 4
#define MAX_LIGHTS 8
#define INITIALIZE_LIGHT(light, lightIndex) \
light.pos = globalLightPos[lightIndex]; \
light.color = globalLightColor[lightIndex]; \
light.atten = globalLightAtten[lightIndex]; \
light.spotDir = globalLightSpotDir[lightIndex]
#define FRESNEL_TERM(normal, viewDir) Pow4(1.0 - saturate(dot(normal, viewDir)))
// The variables are very similar to built-in unity_LightColor, unity_LightPosition,
// unity_LightAtten, unity_SpotDirection as used by the VertexLit shaders, except here
// we use world space positions instead of view space.
half4 globalLightColor[MAX_LIGHTS];
float4 globalLightPos[MAX_LIGHTS];
half4 globalLightSpotDir[MAX_LIGHTS];
half4 globalLightAtten[MAX_LIGHTS];
int4 globalLightCount; // x: pixelLightCount, y = totalLightCount (pixel + vert)
sampler2D _ShadowMap;
float _PCFKernel[8];
half4x4 _WorldToShadow[MAX_SHADOW_CASCADES];
half4 _PSSMDistancesAndShadowResolution; // xyz: PSSM Distance for 4 cascades, w: 1 / shadowmap resolution. Used for filtering
struct LowendVertexInput
{
float4 vertex : POSITION;
float3 normal : NORMAL;
float4 tangent : TANGENT;
float3 texcoord : TEXCOORD0;
float2 lightmapUV : TEXCOORD1;
};
struct v2f
{
float4 uv01 : TEXCOORD0; // uv01.xy: uv0, uv01.zw: uv1
float4 posWS : TEXCOORD1; // xyz: posWorld, w: eyeZ
#if _NORMALMAP
half3 tangentToWorld[3] : TEXCOORD2; // tangentToWorld matrix
#else
half3 normal : TEXCOORD2;
#endif
half4 viewDir : TEXCOORD5; // xyz: viewDir, w: grazingTerm;
UNITY_FOG_COORDS_PACKED(6, half4) // x: fogCoord, yzw: vertexColor
float4 hpos : SV_POSITION;
};
struct LightInput
{
half4 pos;
half4 color;
half4 atten;
half4 spotDir;
};
inline half ComputeCascadeIndex(half eyeZ)
{
// PSSMDistance is set to infinity for non active cascades. This way the comparison for unavailable cascades will always be zero.
half3 cascadeCompare = step(_PSSMDistancesAndShadowResolution.xyz, half3(eyeZ, eyeZ, eyeZ));
return dot(cascadeCompare, cascadeCompare);
}
inline half ShadowAttenuation(half2 shadowCoord, half shadowCoordDepth)
{
half depth = tex2D(_ShadowMap, shadowCoord).r;
#if defined(UNITY_REVERSED_Z)
return step(depth, shadowCoordDepth);
#else
return step(shadowCoordDepth, depth);
#endif
}
inline half ShadowPCF(half4 shadowCoord)
{
// GPU Gems 4x4 kernel with 4 taps.
half2 offset = (float)(frac(shadowCoord.xy * 0.5) > 0.25); // mod
offset.y += offset.x; // y ^= x in floating point
offset *= _PSSMDistancesAndShadowResolution.w;
half attenuation = ShadowAttenuation(shadowCoord.xy + half2(_PCFKernel[0], _PCFKernel[1]) + offset, shadowCoord.z) +
ShadowAttenuation(shadowCoord.xy + half2(_PCFKernel[2], _PCFKernel[3]) + offset, shadowCoord.z) +
ShadowAttenuation(shadowCoord.xy + half2(_PCFKernel[4], _PCFKernel[5]) + offset, shadowCoord.z) +
ShadowAttenuation(shadowCoord.xy + half2(_PCFKernel[6], _PCFKernel[7]) + offset, shadowCoord.z);
return attenuation * 0.25;
}
inline half3 EvaluateOneLight(LightInput lightInput, half3 diffuseColor, half4 specularGloss, half3 normal, float3 posWorld, half3 viewDir)
{
float3 posToLight = lightInput.pos.xyz;
posToLight -= posWorld * lightInput.pos.w;
float distanceSqr = max(dot(posToLight, posToLight), 0.001);
float lightAtten = 1.0 / (1.0 + distanceSqr * lightInput.atten.z);
float3 lightDir = posToLight * rsqrt(distanceSqr);
float SdotL = saturate(dot(lightInput.spotDir.xyz, lightDir));
lightAtten *= saturate((SdotL - lightInput.atten.x) / lightInput.atten.y);
float cutoff = step(distanceSqr, lightInput.atten.w);
lightAtten *= cutoff;
float NdotL = saturate(dot(normal, lightDir));
half3 halfVec = normalize(lightDir + viewDir);
half NdotH = saturate(dot(normal, halfVec));
half3 lightColor = lightInput.color.rgb * lightAtten;
half3 diffuse = diffuseColor * lightColor * NdotL;
half3 specular = specularGloss.rgb * lightColor * pow(NdotH, 128.0) * specularGloss.a;
return diffuse + specular;
}
inline half3 EvaluateMainLight(LightInput lightInput, half3 diffuseColor, half4 specularGloss, half3 normal, float4 posWorld, half3 viewDir)
{
int cascadeIndex = ComputeCascadeIndex(posWorld.w);
float4 shadowCoord = mul(_WorldToShadow[cascadeIndex], float4(posWorld.xyz, 1.0));
shadowCoord.z = saturate(shadowCoord.z);
#ifdef SHADOWS_FILTERING_VSM
half shadowAttenuation = ShadowVSM(shadowCoord);
#elif defined(SHADOWS_FILTERING_PCF)
half shadowAttenuation = ShadowPCF(shadowCoord);
#else
half shadowAttenuation = ShadowAttenuation(shadowCoord.xy, shadowCoord.z);
#endif
#if DEBUG_CASCADES
half3 cascadeColors[MAX_SHADOW_CASCADES] = { half3(1.0, 0.0, 0.0), half3(0.0, 1.0, 0.0), half3(0.0, 0.0, 1.0), half3(1.0, 0.0, 1.0) };
return cascadeColors[cascadeIndex] * diffuseColor * max(shadowAttenuation, 0.5);
#endif
half3 color = EvaluateOneLight(lightInput, diffuseColor, specularGloss, normal, posWorld, viewDir);
#ifdef SHADOWS_DEPTH
return color * shadowAttenuation;
#else
return color;
#endif
}
v2f vert(LowendVertexInput v)
{
v2f o;
UNITY_INITIALIZE_OUTPUT(v2f, o);
o.uv01.xy = TRANSFORM_TEX(v.texcoord, _MainTex);
o.uv01.zw = v.lightmapUV * unity_LightmapST.xy + unity_LightmapST.zw;
o.hpos = UnityObjectToClipPos(v.vertex);
o.posWS.xyz = mul(unity_ObjectToWorld, v.vertex).xyz;
o.posWS.w = -UnityObjectToViewPos(v.vertex).z;
o.viewDir.xyz = normalize(_WorldSpaceCameraPos - o.posWS.xyz);
half3 normal = normalize(UnityObjectToWorldNormal(v.normal));
half fresnelTerm = FRESNEL_TERM(normal, o.viewDir.xyz);
#if _NORMALMAP
half sign = v.tangent.w * unity_WorldTransformParams.w;
half3 tangent = normalize(UnityObjectToWorldDir(v.tangent));
half3 binormal = cross(normal, tangent) * v.tangent.w;
// Initialize tangetToWorld in column-major to benefit from better glsl matrix multiplication code
o.tangentToWorld[0] = half3(tangent.x, binormal.x, normal.x);
o.tangentToWorld[1] = half3(tangent.y, binormal.y, normal.y);
o.tangentToWorld[2] = half3(tangent.z, binormal.z, normal.z);
#else
o.normal = normal;
#endif
half4 diffuseAndSpecular = half4(1.0, 1.0, 1.0, 1.0);
for (int lightIndex = globalLightCount.x; lightIndex < globalLightCount.y; ++lightIndex)
{
LightInput lightInput;
INITIALIZE_LIGHT(lightInput, lightIndex);
o.fogCoord.yzw += EvaluateOneLight(lightInput, diffuseAndSpecular.rgb, diffuseAndSpecular, normal, o.posWS.xyz, o.viewDir.xyz);
}
#ifndef LIGHTMAP_ON
o.fogCoord.yzw += max(half3(0, 0, 0), ShadeSH9(half4(normal, 1)));
#endif
o.fogCoord.x = 1.0;
UNITY_TRANSFER_FOG(o, o.hpos);
return o;
}
half4 frag(v2f i) : SV_Target
{
half4 diffuseAlpha = tex2D(_MainTex, i.uv01.xy);
half3 diffuse = diffuseAlpha.rgb;
half alpha = diffuseAlpha.a * _Color.a;
#ifdef _ALPHATEST_ON
clip(alpha - _Cutoff);
#endif
#if _NORMALMAP
half3 normalmap = UnpackNormal(tex2D(_BumpMap, i.uv01.xy));
// glsl compiler will generate underperforming code by using a row-major pre multiplication matrix: mul(normalmap, i.tangentToWorld)
// i.tangetToWorld was initialized as column-major in vs and here dot'ing individual for better performance.
// The code below is similar to post multiply: mul(i.tangentToWorld, normalmap)
half3 normal = half3(dot(normalmap, i.tangentToWorld[0]), dot(normalmap, i.tangentToWorld[1]), dot(normalmap, i.tangentToWorld[2]));
#else
half3 normal = normalize(i.normal);
#endif
#if _SPECGLOSSMAP
half4 specularGloss = tex2d(_SpecGlossMap, i.uv01.xy);
#else
half4 specularGloss = half4(_SpecColor.rgb, _Glossiness);
#endif
float3 posWorld = i.posWS.xyz;
half3 viewDir = i.viewDir.xyz;
// Indirect Light Contribution
half3 indirectDiffuse;
#ifdef LIGHTMAP_ON
indirectDiffuse = DecodeLightmap(UNITY_SAMPLE_TEX2D(unity_Lightmap, i.uv01.zw)) * diffuse;
#else
indirectDiffuse = i.fogCoord.yzw * diffuse;
#endif
// Compute direct contribution from main directional light.
// Only a single directional shadow caster is supported.
LightInput mainLight;
INITIALIZE_LIGHT(mainLight, 0);
#if DEBUG_CASCADES
return half4(EvaluateMainLight(mainLight, diffuse, specularGloss, normal, i.posWS, viewDir), 1.0);
#endif
half3 directColor = EvaluateMainLight(mainLight, diffuse, specularGloss, normal, i.posWS, viewDir);
// Compute direct contribution from additional lights.
for (int lightIndex = 1; lightIndex < globalLightCount.x; ++lightIndex)
{
LightInput additionalLight;
INITIALIZE_LIGHT(additionalLight, lightIndex);
directColor += EvaluateOneLight(additionalLight, diffuse, specularGloss, normal, posWorld, viewDir);
}
half3 color = directColor + indirectDiffuse + _EmissionColor;
UNITY_APPLY_FOG(i.fogCoord, color);
#ifdef _ALPHABLEND_ON
return half4(color, alpha);
#else
return half4(color, 1);
#endif
};
ENDCG
}

#pragma vertex vert
#pragma fragment frag
#pragma multi_compile _ SHADOWS_FILTERING_VSM
float4 _ShadowBias;
#include "UnityCG.cginc"

12
Assets/LowEndRenderLoop/LDMaterialInspector.cs


using UnityEngine;
using UnityEditor;
public class LDMaterialInspector : MaterialEditor
{
public override void OnInspectorGUI()
{
base.OnInspectorGUI();
Material materialTarget = target as Material;
}
}

12
Assets/LowEndRenderLoop/LDMaterialInspector.cs.meta


fileFormatVersion: 2
guid: b4af54958c9ad944a8c9bb428b1d2d38
timeCreated: 1487688270
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

80
Assets/LowEndRenderLoop/Materials/LDSpecularSphere0.mat


%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!21 &2100000
Material:
serializedVersion: 6
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_Name: LDSpecularSphere0
m_Shader: {fileID: 4800000, guid: 8d2bb70cbf9db8d4da26e15b26e74248, type: 3}
m_ShaderKeywords:
m_LightmapFlags: 4
m_EnableInstancingVariants: 0
m_CustomRenderQueue: -1
stringTagMap: {}
disabledShaderPasses: []
m_SavedProperties:
serializedVersion: 3
m_TexEnvs:
- _BumpMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _DetailAlbedoMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _DetailMask:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _DetailNormalMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _EmissionMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _MainTex:
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}
- _OcclusionMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _ParallaxMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _SpecGlossMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
m_Floats:
- _BumpScale: 1
- _Cutoff: 0.5
- _DetailNormalMapScale: 1
- _DstBlend: 0
- _GlossMapScale: 0.186
- _Glossiness: 1
- _GlossyReflections: 1
- _Metallic: 0
- _Mode: 0
- _OcclusionStrength: 1
- _Parallax: 0.02
- _SmoothnessTextureChannel: 0
- _SpecularHighlights: 1
- _SrcBlend: 1
- _UVSec: 0
- _ZWrite: 1
m_Colors:
- _Color: {r: 1, g: 1, b: 1, a: 1}
- _EmissionColor: {r: 0, g: 0, b: 0, a: 1}
- _SpecColor: {r: 0.9705882, g: 0.9705882, b: 0.9705882, a: 1}

9
Assets/LowEndRenderLoop/Materials/LDSpecularSphere0.mat.meta


fileFormatVersion: 2
guid: bded62b791643214d8d29703a7813d34
timeCreated: 1487679711
licenseType: Pro
NativeFormatImporter:
mainObjectFileID: 2100000
userData:
assetBundleName:
assetBundleVariant:

80
Assets/LowEndRenderLoop/Materials/StandardSpecular.mat


%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!21 &2100000
Material:
serializedVersion: 6
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_Name: StandardSpecular
m_Shader: {fileID: 45, guid: 0000000000000000f000000000000000, type: 0}
m_ShaderKeywords:
m_LightmapFlags: 4
m_EnableInstancingVariants: 0
m_CustomRenderQueue: -1
stringTagMap: {}
disabledShaderPasses: []
m_SavedProperties:
serializedVersion: 3
m_TexEnvs:
- _BumpMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _DetailAlbedoMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _DetailMask:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _DetailNormalMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _EmissionMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _MainTex:
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}
- _OcclusionMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _ParallaxMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _SpecGlossMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
m_Floats:
- _BumpScale: 1
- _Cutoff: 0.5
- _DetailNormalMapScale: 1
- _DstBlend: 0
- _GlossMapScale: 1
- _Glossiness: 0.445
- _GlossyReflections: 1
- _Metallic: 0
- _Mode: 0
- _OcclusionStrength: 1
- _Parallax: 0.02
- _SmoothnessTextureChannel: 0
- _SpecularHighlights: 1
- _SrcBlend: 1
- _UVSec: 0
- _ZWrite: 1
m_Colors:
- _Color: {r: 1, g: 1, b: 1, a: 1}
- _EmissionColor: {r: 0, g: 0, b: 0, a: 1}
- _SpecColor: {r: 0.456, g: 0.456, b: 0.448, a: 1}

9
Assets/LowEndRenderLoop/Materials/StandardSpecular.mat.meta


fileFormatVersion: 2
guid: 627793c4ac634cd4385032d3c0ff01ca
timeCreated: 1487680774
licenseType: Pro
NativeFormatImporter:
mainObjectFileID: 2100000
userData:
assetBundleName:
assetBundleVariant:

9
Assets/ScriptableRenderLoop.meta


fileFormatVersion: 2
guid: cea91ab26f9c6774c8bb9af2381b5c71
folderAsset: yes
timeCreated: 1487080089
licenseType: Pro
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

9
Assets/ScriptableRenderLoop/HDRenderPipeline.meta


fileFormatVersion: 2
guid: 1df4b89bb1f5a104e8af51e9d9a90be0
folderAsset: yes
timeCreated: 1487080089
licenseType: Pro
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

9
Assets/ScriptableRenderLoop/HDRenderPipeline/Material.meta


fileFormatVersion: 2
guid: 8253ea9124581554c8a1fe18d4ac4363
folderAsset: yes
timeCreated: 1487080089
licenseType: Pro
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

130
Assets/LowEndRenderLoop/Shaders/LDRenderPipe-Metallic.shader


// Shader targeted for LowEnd mobile devices. Single Pass Forward Rendering. Shader Model 2
//
// The parameters and inspector of the shader are the same as Standard shader,
// for easier experimentation.
Shader "LDRenderPipeline/LowEndMetallic"
{
// Properties is just a copy of Standard (Specular Setup).shader. Our example shader does not use all of them,
// but the inspector UI expects all these to exist.
Properties
{
_Color("Color", Color) = (1,1,1,1)
_MainTex("Albedo", 2D) = "white" {}
_Cutoff("Alpha Cutoff", Range(0.0, 1.0)) = 0.5
_Glossiness("Smoothness", Range(0.0, 1.0)) = 0.5
_GlossMapScale("Smoothness Scale", Range(0.0, 1.0)) = 1.0
[Enum(Metallic Alpha,0,Albedo Alpha,1)] _SmoothnessTextureChannel("Smoothness texture channel", Float) = 0
[Gamma] _Metallic("Metallic", Range(0.0, 1.0)) = 0.0
_MetallicGlossMap("Metallic", 2D) = "white" {}
[ToggleOff] _SpecularHighlights("Specular Highlights", Float) = 1.0
[ToggleOff] _GlossyReflections("Glossy Reflections", Float) = 1.0
_BumpScale("Scale", Float) = 1.0
_BumpMap("Normal Map", 2D) = "bump" {}
_Parallax("Height Scale", Range(0.005, 0.08)) = 0.02
_ParallaxMap("Height Map", 2D) = "black" {}
_OcclusionStrength("Strength", Range(0.0, 1.0)) = 1.0
_OcclusionMap("Occlusion", 2D) = "white" {}
_EmissionColor("Color", Color) = (0,0,0)
_EmissionMap("Emission", 2D) = "white" {}
_DetailMask("Detail Mask", 2D) = "white" {}
_DetailAlbedoMap("Detail Albedo x2", 2D) = "grey" {}
_DetailNormalMapScale("Scale", Float) = 1.0
_DetailNormalMap("Normal Map", 2D) = "bump" {}
[Enum(UV0,0,UV1,1)] _UVSec("UV Set for secondary textures", Float) = 0
// Blending state
[HideInInspector] _Mode("__mode", Float) = 0.0
[HideInInspector] _SrcBlend("__src", Float) = 1.0
[HideInInspector] _DstBlend("__dst", Float) = 0.0
[HideInInspector] _ZWrite("__zw", Float) = 1.0
}
SubShader
{
Tags { "RenderType" = "Opaque" "PerformanceChecks" = "False" "RenderPipeline" = "LDRenderPipeline" }
LOD 300
Pass
{
Name "SINGLE_PASS_FORWARD"
Tags { "LightMode" = "LowEndForwardBase" }
// Use same blending / depth states as Standard shader
Blend[_SrcBlend][_DstBlend]
ZWrite[_ZWrite]
CGPROGRAM
#pragma target 2.0
#pragma vertex vert
#pragma fragment frag
#pragma shader_feature _SPECGLOSSMAP
#pragma shader_feature _SMOOTHNESS_TEXTURE_ALBEDO_CHANNEL_A
#pragma shader_feature _NORMALMAP
#pragma multi_compile _ LIGHTMAP_ON
#pragma multi_compile _ SHADOWS_DEPTH
#pragma multi_compile _ SHADOWS_FILTERING_PCF
#pragma multi_compile_fog
#pragma only_renderers d3d9 d3d11 d3d11_9x glcore gles gles3
#pragma enable_d3d11_debug_symbols
#define DIFFUSE_AND_SPECULAR_INPUT MetallicInput
#include "LDRenderPipeline-Core.cginc"
ENDCG
}
Pass
{
Name "SHADOW_CASTER"
Tags { "Lightmode" = "ShadowCaster" }
ZWrite On ZTest LEqual Cull Front
CGPROGRAM
#pragma target 2.0
#pragma vertex vert
#pragma fragment frag
#pragma multi_compile _ SHADOWS_FILTERING_VSM
float4 _ShadowBias;
#include "UnityCG.cginc"
inline void ApplyLinearBias(half4 clipPos)
{
#if defined(UNITY_REVERSED_Z)
clipPos.z -= _ShadowBias.x;
#else
clipPos.z += _ShadowBias.x;
#endif
}
float4 vert(float4 position : POSITION) : SV_POSITION
{
float4 clipPos = UnityObjectToClipPos(position);
ApplyLinearBias(clipPos);
return clipPos;
}
half4 frag() : SV_TARGET
{
return 0;
}
ENDCG
}
}
Fallback "Standard"
CustomEditor "StandardShaderGUI"
}

9
Assets/LowEndRenderLoop/Shaders/LDRenderPipe-Metallic.shader.meta


fileFormatVersion: 2
guid: d9befd2d052c80d45a4ff7f42034b03d
timeCreated: 1487263524
licenseType: Pro
ShaderImporter:
defaultTextures: []
userData:
assetBundleName:
assetBundleVariant:

277
Assets/LowEndRenderLoop/Shaders/LDRenderPipeline-Core.cginc


#include "UnityCG.cginc"
#include "UnityStandardBRDF.cginc"
#include "UnityStandardInput.cginc"
#include "UnityStandardUtils.cginc"
#define DEBUG_CASCADES 0
#define MAX_SHADOW_CASCADES 4
#define MAX_LIGHTS 8
#define INITIALIZE_LIGHT(light, lightIndex) \
light.pos = globalLightPos[lightIndex]; \
light.color = globalLightColor[lightIndex]; \
light.atten = globalLightAtten[lightIndex]; \
light.spotDir = globalLightSpotDir[lightIndex]
#define FRESNEL_TERM(normal, viewDir) Pow4(1.0 - saturate(dot(normal, viewDir)))
// TODO: Add metallic or specular reflectivity
#define GRAZING_TERM _Glossiness
// The variables are very similar to built-in unity_LightColor, unity_LightPosition,
// unity_LightAtten, unity_SpotDirection as used by the VertexLit shaders, except here
// we use world space positions instead of view space.
half4 globalLightColor[MAX_LIGHTS];
float4 globalLightPos[MAX_LIGHTS];
half4 globalLightSpotDir[MAX_LIGHTS];
half4 globalLightAtten[MAX_LIGHTS];
int4 globalLightCount; // x: pixelLightCount, y = totalLightCount (pixel + vert)
sampler2D _ShadowMap;
float _PCFKernel[8];
half4x4 _WorldToShadow[MAX_SHADOW_CASCADES];
half4 _PSSMDistancesAndShadowResolution; // xyz: PSSM Distance for 4 cascades, w: 1 / shadowmap resolution. Used for filtering
struct LowendVertexInput
{
float4 vertex : POSITION;
float3 normal : NORMAL;
float4 tangent : TANGENT;
float3 texcoord : TEXCOORD0;
float2 lightmapUV : TEXCOORD1;
};
struct v2f
{
float4 uv01 : TEXCOORD0; // uv01.xy: uv0, uv01.zw: uv1
float4 posWS : TEXCOORD1; // xyz: posWorld, w: eyeZ
#if _NORMALMAP
half3 tangentToWorld[3] : TEXCOORD2; // tangentToWorld matrix
#else
half3 normal : TEXCOORD2;
#endif
half4 viewDir : TEXCOORD5; // xyz: viewDir, w: grazingTerm;
UNITY_FOG_COORDS_PACKED(6, half4) // x: fogCoord, yzw: vertexColor
float4 hpos : SV_POSITION;
};
struct LightInput
{
half4 pos;
half4 color;
half4 atten;
half4 spotDir;
};
inline half3 MetallicInput(v2f i, half3 albedo, out half4 specularGloss, out half oneMinusReflectivity)
{
// TODO:
specularGloss = half4(1, 1, 1, 1);
oneMinusReflectivity = 1.0;
return half3(1, 1, 1);
// half2 metalSmooth;
//#ifdef _METALLICGLOSSMAP
// metalSmooth = tex2D(_MetallicGlossMap, i.uv01.xy).ra;
//#else
// metalSmooth.r = _Metallic;
// metalSmooth.g = _Glossiness;
//#endif
//
// half3 diffuse = albedo.rgb * _Color.rgb;
// return DiffuseAndSpecularFromMetallic(diffuse, metalSmooth.r, specularGloss.rgb, oneMinusReflectivity);
}
inline half3 SpecularInput(v2f i, half3 albedo, out half4 specularGloss, out half oneMinusReflectivity)
{
half3 diffuse = albedo.rgb * _Color.rgb;
specularGloss = SpecularGloss(i.uv01.xy);
return EnergyConservationBetweenDiffuseAndSpecular(diffuse, specularGloss.rgb, oneMinusReflectivity);
}
inline half ComputeCascadeIndex(half eyeZ)
{
// PSSMDistance is set to infinity for non active cascades. This way the comparison for unavailable cascades will always be zero.
half3 cascadeCompare = step(_PSSMDistancesAndShadowResolution.xyz, half3(eyeZ, eyeZ, eyeZ));
return dot(cascadeCompare, cascadeCompare);
}
inline half ShadowAttenuation(half2 shadowCoord, half shadowCoordDepth)
{
half depth = tex2D(_ShadowMap, shadowCoord).r;
#if defined(UNITY_REVERSED_Z)
return step(depth, shadowCoordDepth);
#else
return step(shadowCoordDepth, depth);
#endif
}
inline half ShadowPCF(half4 shadowCoord)
{
// GPU Gems 4x4 kernel with 4 taps.
half2 offset = (float)(frac(shadowCoord.xy * 0.5) > 0.25); // mod
offset.y += offset.x; // y ^= x in floating point
offset *= _PSSMDistancesAndShadowResolution.w;
half attenuation = ShadowAttenuation(shadowCoord.xy + half2(_PCFKernel[0], _PCFKernel[1]) + offset, shadowCoord.z) +
ShadowAttenuation(shadowCoord.xy + half2(_PCFKernel[2], _PCFKernel[3]) + offset, shadowCoord.z) +
ShadowAttenuation(shadowCoord.xy + half2(_PCFKernel[4], _PCFKernel[5]) + offset, shadowCoord.z) +
ShadowAttenuation(shadowCoord.xy + half2(_PCFKernel[6], _PCFKernel[7]) + offset, shadowCoord.z);
return attenuation * 0.25;
}
inline half3 EvaluateOneLight(LightInput lightInput, half3 diffuseColor, half4 specularGloss, half3 normal, float3 posWorld, half3 viewDir)
{
float3 posToLight = lightInput.pos.xyz;
posToLight -= posWorld * lightInput.pos.w;
float distanceSqr = max(dot(posToLight, posToLight), 0.001);
float lightAtten = 1.0 / (1.0 + distanceSqr * lightInput.atten.z);
float3 lightDir = posToLight * rsqrt(distanceSqr);
float SdotL = saturate(dot(lightInput.spotDir.xyz, lightDir));
lightAtten *= saturate((SdotL - lightInput.atten.x) / lightInput.atten.y);
float cutoff = step(distanceSqr, lightInput.atten.w);
lightAtten *= cutoff;
float NdotL = saturate(dot(normal, lightDir));
half3 halfVec = normalize(lightDir + viewDir);
half NdotH = saturate(dot(normal, halfVec));
half3 lightColor = lightInput.color.rgb * lightAtten;
half3 diffuse = diffuseColor * lightColor * NdotL;
half3 specular = specularGloss.rgb * lightColor * pow(NdotH, 64.0f) * specularGloss.a;
return diffuse + specular;
}
inline half3 EvaluateMainLight(LightInput lightInput, half3 diffuseColor, half4 specularGloss, half3 normal, float4 posWorld, half3 viewDir)
{
int cascadeIndex = ComputeCascadeIndex(posWorld.w);
float4 shadowCoord = mul(_WorldToShadow[cascadeIndex], float4(posWorld.xyz, 1.0));
shadowCoord.z = saturate(shadowCoord.z);
#ifdef SHADOWS_FILTERING_VSM
half shadowAttenuation = ShadowVSM(shadowCoord);
#elif defined(SHADOWS_FILTERING_PCF)
half shadowAttenuation = ShadowPCF(shadowCoord);
#else
half shadowAttenuation = ShadowAttenuation(shadowCoord.xy, shadowCoord.z);
#endif
#if DEBUG_CASCADES
half3 cascadeColors[MAX_SHADOW_CASCADES] = { half3(1.0, 0.0, 0.0), half3(0.0, 1.0, 0.0), half3(0.0, 0.0, 1.0), half3(1.0, 0.0, 1.0) };
return cascadeColors[cascadeIndex] * diffuseColor * max(shadowAttenuation, 0.5);
#endif
half3 color = EvaluateOneLight(lightInput, diffuseColor, specularGloss, normal, posWorld, viewDir);
#ifdef SHADOWS_DEPTH
return color * shadowAttenuation;
#else
return color;
#endif
}
v2f vert(LowendVertexInput v)
{
v2f o;
UNITY_INITIALIZE_OUTPUT(v2f, o);
o.uv01.xy = TRANSFORM_TEX(v.texcoord, _MainTex);
o.uv01.zw = v.lightmapUV * unity_LightmapST.xy + unity_LightmapST.zw;
o.hpos = UnityObjectToClipPos(v.vertex);
o.posWS.xyz = mul(unity_ObjectToWorld, v.vertex).xyz;
o.posWS.w = -UnityObjectToViewPos(v.vertex).z;
o.viewDir.xyz = normalize(_WorldSpaceCameraPos - o.posWS.xyz);
#if !GLOSSMAP
o.viewDir.w = GRAZING_TERM;
#endif
half3 normal = normalize(UnityObjectToWorldNormal(v.normal));
half fresnelTerm = FRESNEL_TERM(normal, o.viewDir.xyz);
#if _NORMALMAP
half sign = v.tangent.w * unity_WorldTransformParams.w;
half3 tangent = normalize(UnityObjectToWorldDir(v.tangent));
half3 binormal = cross(normal, tangent) * v.tangent.w;
// Initialize tangetToWorld in column-major to benefit from better glsl matrix multiplication code
o.tangentToWorld[0] = half3(tangent.x, binormal.x, normal.x);
o.tangentToWorld[1] = half3(tangent.y, binormal.y, normal.y);
o.tangentToWorld[2] = half3(tangent.z, binormal.z, normal.z);
#else
o.normal = normal;
#endif
half4 diffuseAndSpecular = half4(1.0, 1.0, 1.0, 1.0);
for (int lightIndex = globalLightCount.x; lightIndex < globalLightCount.y; ++lightIndex)
{
LightInput lightInput;
INITIALIZE_LIGHT(lightInput, lightIndex);
o.fogCoord.yzw += EvaluateOneLight(lightInput, diffuseAndSpecular.rgb, diffuseAndSpecular, normal, o.posWS.xyz, o.viewDir.xyz);
}
#ifndef LIGHTMAP_ON
o.fogCoord.yzw += max(half3(0, 0, 0), ShadeSH9(half4(normal, 1)));
#endif
o.fogCoord.x = 1.0;
UNITY_TRANSFER_FOG(o, o.hpos);
return o;
}
half4 frag(v2f i) : SV_Target
{
#if _NORMALMAP
half3 normalmap = UnpackNormal(tex2D(_BumpMap, i.uv01.xy));
// glsl compiler will generate underperforming code by using a row-major pre multiplication matrix: mul(normalmap, i.tangentToWorld)
// i.tangetToWorld was initialized as column-major in vs and here dot'ing individual for better performance.
// The code below is similar to post multiply: mul(i.tangentToWorld, normalmap)
half3 normal = half3(dot(normalmap, i.tangentToWorld[0]), dot(normalmap, i.tangentToWorld[1]), dot(normalmap, i.tangentToWorld[2]));
#else
half3 normal = normalize(i.normal);
#endif
half4 diffuseAlbedo = tex2D(_MainTex, i.uv01.xy);
float3 posWorld = i.posWS.xyz;
half3 viewDir = i.viewDir.xyz;
half alpha = diffuseAlbedo.a * _Color.a;
half oneMinusReflectivity;
half4 specularGloss;
half3 diffuse = DIFFUSE_AND_SPECULAR_INPUT(i, diffuseAlbedo.rgb, specularGloss, oneMinusReflectivity);
// Indirect Light Contribution
half3 indirectDiffuse;
#ifdef LIGHTMAP_ON
indirectDiffuse = DecodeLightmap(UNITY_SAMPLE_TEX2D(unity_Lightmap, i.uv01.zw)) * diffuse;
#else
indirectDiffuse = i.fogCoord.yzw * diffuse;
#endif
// Compute direct contribution from main directional light.
// Only a single directional shadow caster is supported.
LightInput mainLight;
INITIALIZE_LIGHT(mainLight, 0);
#if DEBUG_CASCADES
return half4(EvaluateMainLight(mainLight, diffuse, specularGloss, normal, i.posWS, viewDir), 1.0);
#endif
half3 directColor = EvaluateMainLight(mainLight, diffuse, specularGloss, normal, i.posWS, viewDir);
// Compute direct contribution from additional lights.
for (int lightIndex = 1; lightIndex < globalLightCount.x; ++lightIndex)
{
LightInput additionalLight;
INITIALIZE_LIGHT(additionalLight, lightIndex);
directColor += EvaluateOneLight(additionalLight, diffuse, specularGloss, normal, posWorld, viewDir);
}
half3 color = directColor + indirectDiffuse + _EmissionColor;
UNITY_APPLY_FOG(i.fogCoord, color);
return half4(color, alpha);
};

9
Assets/LowEndRenderLoop/Shaders/LDRenderPipeline-Core.cginc.meta


fileFormatVersion: 2
guid: df4c6be7931e8494da4ac059c41d1dbe
timeCreated: 1487263524
licenseType: Pro
ShaderImporter:
defaultTextures: []
userData:
assetBundleName:
assetBundleVariant:

9
Assets/TestScenes/HDTest/GraphicTest/Two Sided/Prefabs/Materials.meta


fileFormatVersion: 2
guid: 0e2aa881811d0644896d4b5a732945cc
folderAsset: yes
timeCreated: 1485804900
licenseType: Pro
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

9
Assets/TestScenes/HDTest/LayeredLitTest/Mesh/Materials.meta


fileFormatVersion: 2
guid: e8f6ad2e481134b4fa6108a280b52de7
folderAsset: yes
timeCreated: 1484331445
licenseType: Pro
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:
正在加载...
取消
保存