浏览代码

Added initial prototype version of Lightweight PBS shader. Started moving away from legacy shader library.

/RenderPassXR_Sandbox
Felipe Lira 7 年前
当前提交
6959ac25
共有 12 个文件被更改,包括 523 次插入134 次删除
  1. 5
      Assets/ScriptableRenderPipeline/LightweightPipeline/LightweightPipeline.cs
  2. 14
      Assets/ScriptableRenderPipeline/LightweightPipeline/Shaders/LightweightPipeline.shader
  3. 158
      Assets/ScriptableRenderPipeline/LightweightPipeline/Shaders/LightweightPipelineCore.cginc
  4. 2
      Assets/ScriptableRenderPipeline/LightweightPipeline/Shaders/LightweightPipelineShadows.cginc
  5. 26
      Assets/ScriptableRenderPipeline/LightweightPipeline/Shaders/LightweightPipelineBRDF.cginc
  6. 9
      Assets/ScriptableRenderPipeline/LightweightPipeline/Shaders/LightweightPipelineBRDF.cginc.meta
  7. 145
      Assets/ScriptableRenderPipeline/LightweightPipeline/Shaders/LightweightPipelineInput.cginc
  8. 9
      Assets/ScriptableRenderPipeline/LightweightPipeline/Shaders/LightweightPipelineInput.cginc.meta
  9. 49
      Assets/ScriptableRenderPipeline/LightweightPipeline/Shaders/LightweightPipelineLighting.cginc
  10. 9
      Assets/ScriptableRenderPipeline/LightweightPipeline/Shaders/LightweightPipelineLighting.cginc.meta
  11. 221
      Assets/ScriptableRenderPipeline/LightweightPipeline/Shaders/LightweightStandardShader.shader
  12. 10
      Assets/ScriptableRenderPipeline/LightweightPipeline/Shaders/LightweightStandardShader.shader.meta

5
Assets/ScriptableRenderPipeline/LightweightPipeline/LightweightPipeline.cs


litSettings.sorting.flags = SortFlags.CommonTransparent;
litSettings.inputFilter.SetQueuesTransparent();
RenderStateBlock renderStateBlock = new RenderStateBlock();
context.DrawRenderers(ref litSettings, renderStateBlock);
context.DrawRenderers(ref litSettings);
context.DrawRenderers(ref unlitSettings);

EndForwardRendering(ref context, stereoEnabled, postProcessEnabled);
// Release temporary RT
var discardRT = CommandBufferPool.Get();
discardRT.ReleaseTemporaryRT(m_ShadowMapProperty);

14
Assets/ScriptableRenderPipeline/LightweightPipeline/Shaders/LightweightPipeline.shader


#pragma shader_feature _EMISSION
#pragma shader_feature _ _REFLECTION_CUBEMAP _REFLECTION_PROBE
#pragma multi_compile _ LIGHTWEIGHT_LINEAR
#pragma multi_compile _ LIGHTWEIGHT_LINEAR
#pragma multi_compile _ UNITY_SINGLE_PASS_STEREO STEREO_INSTANCING_ON STEREO_MULTIVIEW_ON
#pragma multi_compile _ _SINGLE_DIRECTIONAL_LIGHT
#pragma multi_compile _ LIGHTMAP_ON

#pragma multi_compile_fog
#pragma only_renderers d3d9 d3d11 d3d11_9x glcore gles gles3 metal
#include "UnityStandardBRDF.cginc"
#include "UnityStandardUtils.cginc"
#include "LightweightPipelineLighting.cginc"
v2f vert(LightweightVertexInput v)
LightweightVertexOutputSimple vert(LightweightVertexInput v)
v2f o = (v2f)0;
LightweightVertexOutputSimple o = (LightweightVertexOutputSimple)0;
#ifdef LIGHTMAP_ON
#endif
o.hpos = UnityObjectToClipPos(v.vertex);
o.posWS = mul(unity_ObjectToWorld, v.vertex).xyz;

return o;
}
half4 frag(v2f i) : SV_Target
half4 frag(LightweightVertexOutputSimple i) : SV_Target
{
half4 diffuseAlpha = tex2D(_MainTex, i.uv01.xy);
half3 diffuse = LIGHTWEIGHT_GAMMA_TO_LINEAR(diffuseAlpha.rgb) * _Color.rgb;

158
Assets/ScriptableRenderPipeline/LightweightPipeline/Shaders/LightweightPipelineCore.cginc


#define MAX_VISIBLE_LIGHTS 16
#ifndef LIGHTWEIGHT_PIPELINE_CORE_INCLUDED
#define LIGHTWEIGHT_PIPELINE_CORE_INCLUDED
#define INITIALIZE_LIGHT(light, lightIndex) \
light.pos = globalLightPos[lightIndex]; \
light.color = globalLightColor[lightIndex]; \
light.atten = globalLightAtten[lightIndex]; \
light.spotDir = globalLightSpotDir[lightIndex]
#include "LightweightPipelineInput.cginc"
#if defined(_HARD_SHADOWS) || defined(_SOFT_SHADOWS) || defined(_HARD_SHADOWS_CASCADES) || defined(_SOFT_SHADOWS_CASCADES)
#define _SHADOWS

#define LIGHTWEIGHT_LINEAR_TO_GAMMA(color) color
#endif
struct LightInput
{
half4 pos;
half4 color;
half4 atten;
half4 spotDir;
};
struct LightweightVertexInput
{
float4 vertex : POSITION;
float3 normal : NORMAL;
float4 tangent : TANGENT;
float3 texcoord : TEXCOORD0;
float2 lightmapUV : TEXCOORD1;
UNITY_VERTEX_INPUT_INSTANCE_ID
};
struct v2f
{
float4 uv01 : TEXCOORD0; // uv01.xy: uv0, uv01.zw: uv1
float3 posWS : TEXCOORD1;
#if _NORMALMAP
half3 tangentToWorld0 : TEXCOORD2; // tangentToWorld matrix
half3 tangentToWorld1 : TEXCOORD3; // tangentToWorld matrix
half3 tangentToWorld2 : TEXCOORD4; // tangentToWorld matrix
#else
half3 normal : TEXCOORD2;
#endif
half4 viewDir : TEXCOORD5; // xyz: viewDir
UNITY_FOG_COORDS_PACKED(6, half4) // x: fogCoord, yzw: vertexColor
float4 hpos : SV_POSITION;
UNITY_VERTEX_OUTPUT_STEREO
};
// Per object light list data
#ifndef _SINGLE_DIRECTIONAL_LIGHT
half4 unity_LightIndicesOffsetAndCount;
half4 unity_4LightIndices0;
// 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 globalLightCount;
half4 globalLightColor[MAX_VISIBLE_LIGHTS];
float4 globalLightPos[MAX_VISIBLE_LIGHTS];
half4 globalLightSpotDir[MAX_VISIBLE_LIGHTS];
half4 globalLightAtten[MAX_VISIBLE_LIGHTS];
#else
float4 _LightPosition0;
#endif
half _Shininess;
samplerCUBE _Cube;
half4 _ReflectColor;
inline void NormalMap(v2f i, out half3 normal)
{
#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)
normal = half3(dot(normalmap, i.tangentToWorld0), dot(normalmap, i.tangentToWorld1), dot(normalmap, i.tangentToWorld2));
#else
normal = normalize(i.normal);
#endif
}
// Does not support: _PARALLAXMAP, DIRLIGHTMAP_COMBINED
#define GLOSSMAP (defined(_SPECGLOSSMAP) || defined(_METALLICGLOSSMAP))
inline void SpecularGloss(half2 uv, half alpha, out half4 specularGloss)
{
#ifdef _SPECGLOSSMAP
specularGloss = tex2D(_SpecGlossMap, uv);
#if defined(UNITY_COLORSPACE_GAMMA) && defined(LIGHTWEIGHT_LINEAR)
specularGloss.rgb = LIGHTWEIGHT_GAMMA_TO_LINEAR(specularGloss.rgb);
#endif
#elif defined(_SPECGLOSSMAP_BASE_ALPHA)
specularGloss = LIGHTWEIGHT_GAMMA_TO_LINEAR(tex2D(_SpecGlossMap, uv).rgb) * _SpecColor.rgb;
specularGloss.a = alpha;
#else
specularGloss = _SpecColor;
#ifndef SPECULAR_HIGHLIGHTS
#define SPECULAR_HIGHLIGHTS (!defined(_SPECULAR_HIGHLIGHTS_OFF))
}
half4 OutputColor(half3 color, half alpha)
{

#endif
}
inline half3 EvaluateDirectionalLight(half3 diffuseColor, half4 specularGloss, half3 normal, half3 lightDir, half3 viewDir)
half MetallicSetup_Reflectivity()
half NdotL = saturate(dot(normal, lightDir));
half3 diffuse = diffuseColor * NdotL;
return 1.0h - OneMinusReflectivityFromMetallic(_Metallic);
}
#if defined(_SPECGLOSSMAP_BASE_ALPHA) || defined(_SPECGLOSSMAP) || defined(_SPECULAR_COLOR)
half3 halfVec = normalize(lightDir + viewDir);
half NdotH = saturate(dot(normal, halfVec));
half3 specular = specularGloss.rgb * pow(NdotH, _Shininess * 128.0) * specularGloss.a;
return diffuse + specular;
#ifdef _NORMALMAP
half3 TransformToTangentSpace(half3 tangent, half3 binormal, half3 normal, half3 v)
{
// Mali400 shader compiler prefers explicit dot product over using a half3x3 matrix
return half3(dot(tangent, v), dot(binormal, v), dot(normal, v));
}
void TangentSpaceLightingInput(half3 normalWorld, half4 vTangent, half3 lightDirWorld, half3 eyeVecWorld, out half3 tangentSpaceLightDir, out half3 tangentSpaceEyeVec)
{
half3 tangentWorld = UnityObjectToWorldDir(vTangent.xyz);
half sign = half(vTangent.w) * half(unity_WorldTransformParams.w);
half3 binormalWorld = cross(normalWorld, tangentWorld) * sign;
tangentSpaceLightDir = TransformToTangentSpace(tangentWorld, binormalWorld, normalWorld, lightDirWorld);
#if SPECULAR_HIGHLIGHTS
tangentSpaceEyeVec = normalize(TransformToTangentSpace(tangentWorld, binormalWorld, normalWorld, eyeVecWorld));
return diffuse;
tangentSpaceEyeVec = 0;
inline half3 EvaluateOneLight(LightInput lightInput, half3 diffuseColor, half4 specularGloss, half3 normal, float3 posWorld, half3 viewDir)
#endif // _NORMALMAP
half3 LightDirForSpecular(LightweightVertexOutput i, UnityLight mainLight)
float3 posToLight = lightInput.pos.xyz;
posToLight -= posWorld * lightInput.pos.w;
#if SPECULAR_HIGHLIGHTS && defined(_NORMALMAP)
return i.tangentSpaceLightDir;
#else
return mainLight.dir;
#endif
}
float distanceSqr = max(dot(posToLight, posToLight), 0.001);
float lightAtten = 1.0 / (1.0 + distanceSqr * lightInput.atten.z);
float3 lightDir = posToLight * rsqrt(distanceSqr);
half SdotL = saturate(dot(lightInput.spotDir.xyz, lightDir));
lightAtten *= saturate((SdotL - lightInput.atten.x) / lightInput.atten.y);
half cutoff = step(distanceSqr, lightInput.atten.w);
lightAtten *= cutoff;
half NdotL = saturate(dot(normal, lightDir));
half3 lightColor = lightInput.color.rgb * lightAtten;
half3 diffuse = diffuseColor * lightColor * NdotL;
#if defined(_SPECGLOSSMAP_BASE_ALPHA) || defined(_SPECGLOSSMAP) || defined(_SPECULAR_COLOR)
half3 halfVec = normalize(lightDir + viewDir);
half NdotH = saturate(dot(normal, halfVec));
half3 specular = specularGloss.rgb * lightColor * pow(NdotH, _Shininess * 128.0) * specularGloss.a;
return diffuse + specular;
#else
return diffuse;
}

2
Assets/ScriptableRenderPipeline/LightweightPipeline/Shaders/LightweightPipelineShadows.cginc


return attenuation * 0.25;
}
inline half ComputeShadowAttenuation(v2f i, half3 shadowDir)
inline half ComputeShadowAttenuation(LightweightVertexOutputSimple i, half3 shadowDir)
{
#if _NORMALMAP
half3 vertexNormal = half3(i.tangentToWorld0.z, i.tangentToWorld1.z, i.tangentToWorld2.z);

26
Assets/ScriptableRenderPipeline/LightweightPipeline/Shaders/LightweightPipelineBRDF.cginc


#ifndef LIGHTWEIGHT_BRDF_INCLUDED
#define LIGHTWEIGHT_BRDF_INCLUDED
//sampler2D unity_NHxRoughness;
half3 LightweightBRDFDirect(half3 diffColor, half3 specColor, half smoothness, half RdotL)
{
#if SPECULAR_HIGHLIGHTS
half RdotLPow4 = Pow4(RdotL);
half LUT_RANGE = 16.0; // must match range in NHxRoughness() function in GeneratedTextures.cpp
// Lookup texture to save instructions
half perceptualRoughness = 1.0 - smoothness;
half specular = tex2D(unity_NHxRoughness, half2(RdotLPow4, perceptualRoughness)).UNITY_ATTEN_CHANNEL * LUT_RANGE;
return diffColor + specular * specColor;
#else
return diffColor;
#endif
}
half3 LightweightBRDFIndirect(half3 diffColor, half3 specColor, UnityIndirect indirect, half grazingTerm, half fresnelTerm)
{
half3 c = indirect.diffuse * diffColor;
c += indirect.specular * lerp(specColor, grazingTerm, fresnelTerm);
return c;
}
#endif

9
Assets/ScriptableRenderPipeline/LightweightPipeline/Shaders/LightweightPipelineBRDF.cginc.meta


fileFormatVersion: 2
guid: 3fabaacd5d91c384fbef81b95e495816
timeCreated: 1488965025
licenseType: Pro
ShaderImporter:
defaultTextures: []
userData:
assetBundleName:
assetBundleVariant:

145
Assets/ScriptableRenderPipeline/LightweightPipeline/Shaders/LightweightPipelineInput.cginc


#ifndef LIGHTWEIGHT_INPUT_INCLUDED
#define LIGHTWEIGHT_INPUT_INCLUDED
#define MAX_VISIBLE_LIGHTS 16
#define INITIALIZE_LIGHT(light, lightIndex) \
light.pos = globalLightPos[lightIndex]; \
light.color = globalLightColor[lightIndex]; \
light.atten = globalLightAtten[lightIndex]; \
light.spotDir = globalLightSpotDir[lightIndex]
struct LightInput
{
half4 pos;
half4 color;
half4 atten;
half4 spotDir;
};
// Per object light list data
#ifndef _SINGLE_DIRECTIONAL_LIGHT
half4 unity_LightIndicesOffsetAndCount;
half4 unity_4LightIndices0;
// 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 globalLightCount;
half4 globalLightColor[MAX_VISIBLE_LIGHTS];
float4 globalLightPos[MAX_VISIBLE_LIGHTS];
half4 globalLightSpotDir[MAX_VISIBLE_LIGHTS];
half4 globalLightAtten[MAX_VISIBLE_LIGHTS];
#else
float4 _LightPosition0;
#endif
half _Shininess;
samplerCUBE _Cube;
half4 _ReflectColor;
struct LightweightVertexInput
{
float4 vertex : POSITION;
float3 normal : NORMAL;
float4 tangent : TANGENT;
float2 texcoord : TEXCOORD0;
float2 lightmapUV : TEXCOORD1;
UNITY_VERTEX_INPUT_INSTANCE_ID
};
struct LightweightVertexOutputSimple
{
float4 uv01 : TEXCOORD0; // uv01.xy: uv0, uv01.zw: uv1
float3 posWS : TEXCOORD1;
#if _NORMALMAP
half3 tangentToWorld0 : TEXCOORD2; // tangentToWorld matrix
half3 tangentToWorld1 : TEXCOORD3; // tangentToWorld matrix
half3 tangentToWorld2 : TEXCOORD4; // tangentToWorld matrix
#else
half3 normal : TEXCOORD2;
#endif
half4 viewDir : TEXCOORD5; // xyz: viewDir
half4 fogCoord : TEXCOORD6; // x: fogCoord, yzw: vertexColor
float4 hpos : SV_POSITION;
UNITY_VERTEX_OUTPUT_STEREO
};
struct LightweightVertexOutput
{
UNITY_POSITION(pos);
float4 uv01 : TEXCOORD0;
half4 eyeVec : TEXCOORD1; // w: grazingTerm
//SHADOW_COORDS(2)
half4 fogCoord : TEXCOORD3;
half4 normalWorld : TEXCOORD4;
#ifdef _NORMALMAP
half3 tangentSpaceLightDir : TEXCOORD5;
#if SPECULAR_HIGHLIGHTS
half3 tangentSpaceEyeVec : TEXCOORD6;
#endif
#endif
UNITY_VERTEX_OUTPUT_STEREO
};
inline void NormalMap(LightweightVertexOutputSimple i, out half3 normal)
{
#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)
normal = half3(dot(normalmap, i.tangentToWorld0), dot(normalmap, i.tangentToWorld1), dot(normalmap, i.tangentToWorld2));
#else
normal = normalize(i.normal);
#endif
}
inline void SpecularGloss(half2 uv, half alpha, out half4 specularGloss)
{
#ifdef _SPECGLOSSMAP
specularGloss = tex2D(_SpecGlossMap, uv);
#if defined(UNITY_COLORSPACE_GAMMA) && defined(LIGHTWEIGHT_LINEAR)
specularGloss.rgb = LIGHTWEIGHT_GAMMA_TO_LINEAR(specularGloss.rgb);
#endif
#elif defined(_SPECGLOSSMAP_BASE_ALPHA)
specularGloss = LIGHTWEIGHT_GAMMA_TO_LINEAR(tex2D(_SpecGlossMap, uv).rgb) * _SpecColor.rgb;
specularGloss.a = alpha;
#else
specularGloss = _SpecColor;
#endif
}
half2 MetallicGloss(float2 uv, half glossiness)
{
half2 mg;
#ifdef _METALLICGLOSSMAP
#ifdef _SMOOTHNESS_TEXTURE_ALBEDO_CHANNEL_A
mg.r = tex2D(_MetallicGlossMap, uv).r;
mg.g = glossiness;
#else
mg = tex2D(_MetallicGlossMap, uv).ra;
#endif
mg.g *= _GlossMapScale;
#else // _METALLICGLOSSMAP
mg.r = _Metallic;
#ifdef _SMOOTHNESS_TEXTURE_ALBEDO_CHANNEL_A
mg.g = glossiness * _GlossMapScale;
#else
mg.g = glossiness;
#endif
#endif
return mg;
}
#endif

9
Assets/ScriptableRenderPipeline/LightweightPipeline/Shaders/LightweightPipelineInput.cginc.meta


fileFormatVersion: 2
guid: 926949d7f34e3e143a1acbf6270e42e0
timeCreated: 1488965025
licenseType: Pro
ShaderImporter:
defaultTextures: []
userData:
assetBundleName:
assetBundleVariant:

49
Assets/ScriptableRenderPipeline/LightweightPipeline/Shaders/LightweightPipelineLighting.cginc


#ifndef LIGHTWEIGHT_LIGHTING_INCLUDED
#define LIGHTWEIGHT_LIGHTING_INCLUDED
inline half3 EvaluateDirectionalLight(half3 diffuseColor, half4 specularGloss, half3 normal, half3 lightDir, half3 viewDir)
{
half NdotL = saturate(dot(normal, lightDir));
half3 diffuse = diffuseColor * NdotL;
#if defined(_SPECGLOSSMAP_BASE_ALPHA) || defined(_SPECGLOSSMAP) || defined(_SPECULAR_COLOR)
half3 halfVec = normalize(lightDir + viewDir);
half NdotH = saturate(dot(normal, halfVec));
half3 specular = specularGloss.rgb * pow(NdotH, _Shininess * 128.0) * specularGloss.a;
return diffuse + specular;
#else
return diffuse;
#endif
}
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);
half SdotL = saturate(dot(lightInput.spotDir.xyz, lightDir));
lightAtten *= saturate((SdotL - lightInput.atten.x) / lightInput.atten.y);
half cutoff = step(distanceSqr, lightInput.atten.w);
lightAtten *= cutoff;
half NdotL = saturate(dot(normal, lightDir));
half3 lightColor = lightInput.color.rgb * lightAtten;
half3 diffuse = diffuseColor * lightColor * NdotL;
#if defined(_SPECGLOSSMAP_BASE_ALPHA) || defined(_SPECGLOSSMAP) || defined(_SPECULAR_COLOR)
half3 halfVec = normalize(lightDir + viewDir);
half NdotH = saturate(dot(normal, halfVec));
half3 specular = specularGloss.rgb * lightColor * pow(NdotH, _Shininess * 128.0) * specularGloss.a;
return diffuse + specular;
#else
return diffuse;
#endif
}
#endif

9
Assets/ScriptableRenderPipeline/LightweightPipeline/Shaders/LightweightPipelineLighting.cginc.meta


fileFormatVersion: 2
guid: 762f0a4829f44584ba01e2f0661150d9
timeCreated: 1488965025
licenseType: Pro
ShaderImporter:
defaultTextures: []
userData:
assetBundleName:
assetBundleVariant:

221
Assets/ScriptableRenderPipeline/LightweightPipeline/Shaders/LightweightStandardShader.shader


Shader "ScriptableRenderPipeline/LightweightPipeline/Standard"
{
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" "RenderPipeline" = "LightweightPipeline"}
LOD 300
// ------------------------------------------------------------------
// Base forward pass (directional light, emission, lightmaps, ...)
Pass
{
Tags{"LightMode" = "LightweightForward"}
Blend[_SrcBlend][_DstBlend]
ZWrite[_ZWrite]
CGPROGRAM
#pragma target 3.0
// -------------------------------------
#pragma shader_feature _NORMALMAP
#pragma shader_feature _ _ALPHATEST_ON _ALPHABLEND_ON _ALPHAPREMULTIPLY_ON
#pragma shader_feature _EMISSION
#pragma shader_feature _METALLICGLOSSMAP
#pragma shader_feature ___ _DETAIL_MULX2
#pragma shader_feature _ _SMOOTHNESS_TEXTURE_ALBEDO_CHANNEL_A
#pragma shader_feature _ _SPECULARHIGHLIGHTS_OFF
#pragma shader_feature _ _GLOSSYREFLECTIONS_OFF
#pragma shader_feature _PARALLAXMAP
#pragma multi_compile _ _SINGLE_DIRECTIONAL_LIGHT
#pragma multi_compile_fog
#pragma multi_compile_instancing
#pragma vertex LightweightVertex
#pragma fragment LightweightFragment
#include "UnityCG.cginc"
#include "UnityStandardInput.cginc"
#include "LightweightPipelineCore.cginc"
#include "LightweightPipelineLighting.cginc"
#include "LightweightPipelineBRDF.cginc"
LightweightVertexOutput LightweightVertex(LightweightVertexInput v)
{
UNITY_SETUP_INSTANCE_ID(v);
LightweightVertexOutput o = (LightweightVertexOutput)0;
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o);
float4 posWorld = mul(unity_ObjectToWorld, v.vertex);
o.pos = UnityObjectToClipPos(v.vertex);
o.uv01.xy = TRANSFORM_TEX(v.texcoord, _MainTex);
#ifdef LIGHTMAP_ON
o.uv01.zw = v.lightmapUV * unity_LightmapST.xy + unityLightmapST.wz;
#endif
half3 eyeVec = normalize(_WorldSpaceCameraPos - posWorld.xyz);
half3 normalWorld = UnityObjectToWorldNormal(v.normal);
o.normalWorld.xyz = normalWorld;
o.eyeVec.xyz = eyeVec;
#ifdef _NORMALMAP
half3 tangentSpaceEyeVec;
TangentSpaceLightingInput(normalWorld, v.tangent, _WorldSpaceLightPos0.xyz, eyeVec, o.tangentSpaceLightDir, tangentSpaceEyeVec);
#if SPECULAR_HIGHLIGHTS
o.tangentSpaceEyeVec = tangentSpaceEyeVec;
#endif
#endif
// TODO:
//TRANSFER_SHADOW(o);
o.fogCoord.yzw = max(half3(0, 0, 0), ShadeSH9(half4(normalWorld, 1)));
o.normalWorld.w = Pow4(1 - saturate(dot(normalWorld, eyeVec))); // fresnel term
#if !GLOSSMAP
o.eyeVec.w = saturate(_Glossiness + MetallicSetup_Reflectivity()); // grazing term
#endif
UNITY_TRANSFER_FOG(o, o.pos);
return o;
}
half4 LightweightFragment(LightweightVertexOutput i) : SV_Target
{
float2 uv = i.uv01.xy;
float2 lightmapUV = i.uv01.zw;
half4 albedoTex = tex2D(_MainTex, i.uv01.xy);
half3 albedo = albedoTex.rgb * _Color.rgb;
#if defined(_SMOOTHNESS_TEXTURE_ALBEDO_CHANNEL_A)
half alpha = _Color.a;
half glossiness = albedorTex.a;
#else
half alpha = albedoTex.a * _Color.a;
half glossiness = _Glossiness;
#endif
#if defined(_ALPHATEST_ON)
clip(alpha - _Cutoff);
#endif
half2 metallicGloss = MetallicGloss(uv, glossiness);
half metallic = metallicGloss.x;
half smoothness = metallicGloss.y;
half oneMinusReflectivity;
half3 specColor;
half3 diffColor = DiffuseAndSpecularFromMetallic(albedo, metallicGloss.x, /*out*/ specColor, /*out*/ oneMinusReflectivity);
#if defined(_NORMALMAP)
half3 tangentSpaceNormal = NormalInTangentSpace(i.uv01.xy);
half3 reflectVec = reflect(-i.tangentSpaceEyeVec, tangentSpaceNormal);
#else
half3 reflectVec = reflect(-i.eyeVec, i.normalWorld.xyz);
#endif
// perceptualRoughness
Unity_GlossyEnvironmentData g;
g.roughness = 1 - smoothness;
g.reflUVW = reflectVec;
// TODO: shader keyword for occlusion
// TODO: Reflection Probe blend support.
// GI
UnityIndirect indirectLight;
half occlusion = Occlusion(uv);
indirectLight.diffuse = (DecodeLightmap(UNITY_SAMPLE_TEX2D(unity_Lightmap, lightmapUV)) + i.fogCoord.yzw) * occlusion;
indirectLight.specular = Unity_GlossyEnvironment(UNITY_PASS_TEXCUBE(unity_SpecCube0), unity_SpecCube0_HDR, g) * occlusion;
// PBS
#if GLOSSMAP
half grazingTerm = saturate(smoothness + (1 - oneMinusReflectivity));
#else
half grazingTerm = i.eyeVec.w;
#endif
half perVertexFresnelTerm = i.normalWorld.w;
half3 color = LightweightBRDFIndirect(diffColor, specColor, indirectLight, grazingTerm, perVertexFresnelTerm);
// TODO: SPOT & POINT keywords
#ifdef _SINGLE_DIRECTIONAL_LIGHT
UnityLight mainLight;
mainLight.color = _LightColor0.rgb;
mainLight.dir = _LightPosition0.xyz;
#if defined(_NORMALMAP)
half NdotL = saturate(dot(s.tangentSpaceNormal, i.tangentSpaceLightDir));
#else
half NdotL = saturate(dot(i.normalWorld.xyz, mainLight.dir));
#endif
// TODO: Atten/Shadow
half atten = 1;
half RdotL = dot(reflectVec, mainLight.dir);
half3 attenuatedLightColor = mainLight.color * NdotL;
color += LightweightBRDFDirect(diffColor, specColor, smoothness, RdotL) * attenuatedLightColor;
#else
// TODO: LIGHTLOOP
color = half3(0, 1, 0);
#endif
color += Emission(uv);
UNITY_APPLY_FOG(i.fogCoord, color);
return OutputColor(color, alpha);
}
ENDCG
}
}
FallBack "VertexLit"
CustomEditor "StandardShaderGUI"
}

10
Assets/ScriptableRenderPipeline/LightweightPipeline/Shaders/LightweightStandardShader.shader.meta


fileFormatVersion: 2
guid: 933532a4fcc9baf4fa0491de14d08ed7
timeCreated: 1503472755
licenseType: Pro
ShaderImporter:
externalObjects: {}
defaultTextures: []
userData:
assetBundleName:
assetBundleVariant:
正在加载...
取消
保存