Matt Dean
7 年前
当前提交
316a1125
共有 28 个文件被更改,包括 784 次插入 和 781 次删除
-
20MaterialGraphProject/Assets/SRP/ScriptableRenderPipeline/LightweightPipeline/Shaders/LightweightPBR.shader
-
5MaterialGraphProject/Assets/SRP/ScriptableRenderPipeline/LightweightPipeline/Shaders/CGIncludes/LightweightShadows.cginc
-
10MaterialGraphProject/Assets/SRP/ScriptableRenderPipeline/LightweightPipeline/Shaders/CGIncludes.meta
-
213MaterialGraphProject/Assets/SRP/ScriptableRenderPipeline/LightweightPipeline/Shaders/LightweightFastBlinn.shader
-
116MaterialGraphProject/Assets/SRP/ScriptableRenderPipeline/LightweightPipeline/Shaders/CGIncludes/LightweightCore.cginc
-
114MaterialGraphProject/Assets/SRP/ScriptableRenderPipeline/LightweightPipeline/Shaders/CGIncludes/LightweightFastBlinn.cginc
-
9MaterialGraphProject/Assets/SRP/ScriptableRenderPipeline/LightweightPipeline/Shaders/CGIncludes/LightweightFastBlinn.cginc.meta
-
102MaterialGraphProject/Assets/SRP/ScriptableRenderPipeline/LightweightPipeline/Shaders/CGIncludes/LightweightInput.cginc
-
144MaterialGraphProject/Assets/SRP/ScriptableRenderPipeline/LightweightPipeline/Shaders/CGIncludes/LightweightPBR.cginc
-
9MaterialGraphProject/Assets/SRP/ScriptableRenderPipeline/LightweightPipeline/Shaders/CGIncludes/LightweightPBR.cginc.meta
-
53MaterialGraphProject/Assets/SRP/ScriptableRenderPipeline/LightweightPipeline/Shaders/CGIncludes/LightweightPass.cginc
-
53MaterialGraphProject/Assets/SRP/ScriptableRenderPipeline/LightweightPipeline/Shaders/LightweightPipelinePass.cginc
-
189MaterialGraphProject/Assets/SRP/ScriptableRenderPipeline/LightweightPipeline/Shaders/LightweightPipeline.shader
-
330MaterialGraphProject/Assets/SRP/ScriptableRenderPipeline/LightweightPipeline/Shaders/LightweightPipelineCore.cginc
-
198MaterialGraphProject/Assets/SRP/ScriptableRenderPipeline/LightweightPipeline/Shaders/LightweightPipelineInput.cginc
-
0/MaterialGraphProject/Assets/SRP/ScriptableRenderPipeline/LightweightPipeline/Shaders/LightweightFastBlinn.shader.meta
-
0/MaterialGraphProject/Assets/SRP/ScriptableRenderPipeline/LightweightPipeline/Shaders/LightweightPBR.shader.meta
-
0/MaterialGraphProject/Assets/SRP/ScriptableRenderPipeline/LightweightPipeline/Shaders/LightweightPBR.shader
-
0/MaterialGraphProject/Assets/SRP/ScriptableRenderPipeline/LightweightPipeline/Shaders/CGIncludes/LightweightBRDF.cginc
-
0/MaterialGraphProject/Assets/SRP/ScriptableRenderPipeline/LightweightPipeline/Shaders/CGIncludes/LightweightBRDF.cginc.meta
-
0/MaterialGraphProject/Assets/SRP/ScriptableRenderPipeline/LightweightPipeline/Shaders/CGIncludes/LightweightCore.cginc.meta
-
0/MaterialGraphProject/Assets/SRP/ScriptableRenderPipeline/LightweightPipeline/Shaders/CGIncludes/LightweightInput.cginc.meta
-
0/MaterialGraphProject/Assets/SRP/ScriptableRenderPipeline/LightweightPipeline/Shaders/CGIncludes/LightweightLighting.cginc
-
0/MaterialGraphProject/Assets/SRP/ScriptableRenderPipeline/LightweightPipeline/Shaders/CGIncludes/LightweightLighting.cginc.meta
-
0/MaterialGraphProject/Assets/SRP/ScriptableRenderPipeline/LightweightPipeline/Shaders/CGIncludes/LightweightShadows.cginc
-
0/MaterialGraphProject/Assets/SRP/ScriptableRenderPipeline/LightweightPipeline/Shaders/CGIncludes/LightweightShadows.cginc.meta
-
0/MaterialGraphProject/Assets/SRP/ScriptableRenderPipeline/LightweightPipeline/Shaders/CGIncludes/LightweightPass.cginc.meta
|
|||
fileFormatVersion: 2 |
|||
guid: 2376bae6f236e5842972372c576a8645 |
|||
folderAsset: yes |
|||
timeCreated: 1505346231 |
|||
licenseType: Pro |
|||
DefaultImporter: |
|||
externalObjects: {} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
// Shader targeted for low end devices. Single Pass Forward Rendering. Shader Model 2 |
|||
Shader "ScriptableRenderPipeline/LightweightPipeline/FastBlinn" |
|||
{ |
|||
// Keep properties of StandardSpecular shader for upgrade reasons. |
|||
Properties |
|||
{ |
|||
_Color("Color", Color) = (1,1,1,1) |
|||
_MainTex("Base (RGB) Glossiness / Alpha (A)", 2D) = "white" {} |
|||
|
|||
_Cutoff("Alpha Cutoff", Range(0.0, 1.0)) = 0.5 |
|||
|
|||
_Shininess("Shininess", Range(0.01, 1.0)) = 1.0 |
|||
_GlossMapScale("Smoothness Factor", Range(0.0, 1.0)) = 1.0 |
|||
|
|||
_Glossiness("Glossiness", Range(0.0, 1.0)) = 0.5 |
|||
[Enum(Specular Alpha,0,Albedo Alpha,1)] _SmoothnessTextureChannel("Smoothness texture channel", Float) = 0 |
|||
|
|||
_Cube ("Reflection Cubemap", CUBE) = "" {} |
|||
_ReflectionSource("Reflection Source", Float) = 0 |
|||
|
|||
[HideInInspector] _SpecSource("Specular Color Source", Float) = 0.0 |
|||
_SpecColor("Specular", Color) = (1.0, 1.0, 1.0) |
|||
_SpecGlossMap("Specular", 2D) = "white" {} |
|||
[HideInInspector] _GlossinessSource("Glossiness Source", Float) = 0.0 |
|||
[ToggleOff] _SpecularHighlights("Specular Highlights", Float) = 1.0 |
|||
[ToggleOff] _GlossyReflections("Glossy Reflections", Float) = 1.0 |
|||
|
|||
[HideInInspector] _BumpScale("Scale", Float) = 1.0 |
|||
[NoScaleOffset] _BumpMap("Normal Map", 2D) = "bump" {} |
|||
|
|||
_Parallax("Height Scale", Range(0.005, 0.08)) = 0.02 |
|||
_ParallaxMap("Height Map", 2D) = "black" {} |
|||
|
|||
_EmissionColor("Emission 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 |
|||
|
|||
Pass |
|||
{ |
|||
Tags { "LightMode" = "LightweightForward" } |
|||
|
|||
// Use same blending / depth states as Standard shader |
|||
Blend[_SrcBlend][_DstBlend] |
|||
ZWrite[_ZWrite] |
|||
|
|||
CGPROGRAM |
|||
#pragma target 3.0 |
|||
|
|||
#pragma shader_feature _ _ALPHATEST_ON _ALPHABLEND_ON |
|||
#pragma shader_feature _ _SPECGLOSSMAP _SPECGLOSSMAP_BASE_ALPHA _SPECULAR_COLOR |
|||
#pragma shader_feature _NORMALMAP |
|||
#pragma shader_feature _EMISSION |
|||
#pragma shader_feature _ _REFLECTION_CUBEMAP _REFLECTION_PROBE |
|||
|
|||
#pragma multi_compile _ LIGHTWEIGHT_LINEAR |
|||
#pragma multi_compile _ UNITY_SINGLE_PASS_STEREO STEREO_INSTANCING_ON STEREO_MULTIVIEW_ON |
|||
#pragma multi_compile _ _SINGLE_DIRECTIONAL_LIGHT _SINGLE_SPOT_LIGHT _SINGLE_POINT_LIGHT |
|||
#pragma multi_compile _ LIGHTMAP_ON |
|||
#pragma multi_compile _ _LIGHT_PROBES_ON |
|||
#pragma multi_compile _ _HARD_SHADOWS _SOFT_SHADOWS _HARD_SHADOWS_CASCADES _SOFT_SHADOWS_CASCADES |
|||
#pragma multi_compile _ _VERTEX_LIGHTS |
|||
#pragma multi_compile _ _ATTENUATION_TEXTURE |
|||
#pragma multi_compile_fog |
|||
#pragma multi_compile_instancing |
|||
|
|||
#include "UnityCG.cginc" |
|||
#include "CGIncludes/LightweightFastBlinn.cginc" |
|||
|
|||
#pragma vertex LightweightVertex |
|||
#pragma fragment LightweightFragmentFastBlinn |
|||
|
|||
void DefineSurface(LightweightVertexOutput i, inout SurfaceFastBlinn s) |
|||
{ |
|||
// Albedo |
|||
float4 c = tex2D(_MainTex, i.uv01.xy); |
|||
s.Diffuse = LIGHTWEIGHT_GAMMA_TO_LINEAR(c.rgb) * _Color.rgb; |
|||
// Specular |
|||
#ifdef _SPECGLOSSMAP |
|||
half4 specularMap = tex2D(_SpecGlossMap, i.uv01.xy); |
|||
#if defined(UNITY_COLORSPACE_GAMMA) && defined(LIGHTWEIGHT_LINEAR) |
|||
s.Specular = LIGHTWEIGHT_GAMMA_TO_LINEAR(specularGloss.rgb); |
|||
#endif |
|||
#elif defined(_SPECGLOSSMAP_BASE_ALPHA) |
|||
s.Specular.rgb = LIGHTWEIGHT_GAMMA_TO_LINEAR(tex2D(_SpecGlossMap, i.uv01.xy).rgb) * _SpecColor.rgb; |
|||
s.Glossiness = s.Alpha; |
|||
#else |
|||
s.Specular = _SpecColor.rgb; |
|||
s.Glossiness = _SpecColor.a; |
|||
#endif |
|||
// Normal |
|||
#if _NORMALMAP |
|||
s.Normal = UnpackNormal(tex2D(_BumpMap, i.uv01.xy)); |
|||
#endif |
|||
// Emission |
|||
#ifndef _EMISSION |
|||
s.Emission = _EmissionColor.rgb; |
|||
#else |
|||
s.Emission = LIGHTWEIGHT_GAMMA_TO_LINEAR(tex2D(_EmissionMap, uv).rgb) * _EmissionColor.rgb; |
|||
#endif |
|||
// Alpha |
|||
#ifdef _SMOOTHNESS_TEXTURE_ALBEDO_CHANNEL_A |
|||
s.Alpha = _Color.a; |
|||
#else |
|||
s.Alpha = c.a * _Color.a; |
|||
#endif |
|||
|
|||
#ifdef _ALPHATEST_ON |
|||
clip(s.Alpha - _Cutoff); |
|||
#endif |
|||
} |
|||
|
|||
ENDCG |
|||
} |
|||
|
|||
Pass |
|||
{ |
|||
Tags { "Lightmode" = "ShadowCaster" } |
|||
ZWrite On ZTest LEqual |
|||
|
|||
CGPROGRAM |
|||
#pragma target 2.0 |
|||
#include "UnityCG.cginc" |
|||
#include "CGIncludes/LightweightPass.cginc" |
|||
#pragma vertex shadowVert |
|||
#pragma fragment shadowFrag |
|||
ENDCG |
|||
} |
|||
|
|||
Pass |
|||
{ |
|||
Tags{"Lightmode" = "DepthOnly"} |
|||
ZWrite On |
|||
|
|||
CGPROGRAM |
|||
#pragma target 2.0 |
|||
#include "CGIncludes/LightweightPass.cginc" |
|||
#pragma vertex depthVert |
|||
#pragma fragment depthFrag |
|||
ENDCG |
|||
} |
|||
|
|||
// This pass it not used during regular rendering, only for lightmap baking. |
|||
Pass |
|||
{ |
|||
Tags{ "LightMode" = "Meta" } |
|||
|
|||
Cull Off |
|||
|
|||
CGPROGRAM |
|||
#define UNITY_SETUP_BRDF_INPUT SpecularSetup |
|||
|
|||
#pragma shader_feature _EMISSION |
|||
#pragma shader_feature _SPECGLOSSMAP |
|||
#pragma shader_feature _ _SMOOTHNESS_TEXTURE_ALBEDO_CHANNEL_A |
|||
#pragma shader_feature ___ _DETAIL_MULX2 |
|||
#pragma shader_feature EDITOR_VISUALIZATION |
|||
|
|||
#include "UnityCG.cginc" |
|||
#include "CGIncludes/LightweightPass.cginc" |
|||
#pragma vertex vert_meta |
|||
#pragma fragment frag_meta_ld |
|||
|
|||
void DefineSurfaceMeta(v2f_meta i, inout SurfaceFastBlinn s) |
|||
{ |
|||
// Albedo |
|||
float4 c = tex2D(_MainTex, i.uv.xy); |
|||
s.Diffuse = c.rgb; |
|||
// Specular |
|||
#ifdef _SPECGLOSSMAP |
|||
half4 specularMap = tex2D(_SpecGlossMap, i.uv.xy); |
|||
#if defined(UNITY_COLORSPACE_GAMMA) && defined(LIGHTWEIGHT_LINEAR) |
|||
s.Specular = LIGHTWEIGHT_GAMMA_TO_LINEAR(specularGloss.rgb); |
|||
#endif |
|||
#elif defined(_SPECGLOSSMAP_BASE_ALPHA) |
|||
s.Specular.rgb = LIGHTWEIGHT_GAMMA_TO_LINEAR(tex2D(_SpecGlossMap, i.uv.xy).rgb) * _SpecColor.rgb; |
|||
s.Glossiness = s.Alpha; |
|||
#else |
|||
s.Specular = _SpecColor.rgb; |
|||
s.Glossiness = _SpecColor.a; |
|||
#endif |
|||
// Emission |
|||
#ifndef _EMISSION |
|||
s.Emission = _EmissionColor.rgb; |
|||
#else |
|||
s.Emission = LIGHTWEIGHT_GAMMA_TO_LINEAR(tex2D(_EmissionMap, uv).rgb) * _EmissionColor.rgb; |
|||
#endif |
|||
} |
|||
|
|||
ENDCG |
|||
} |
|||
} |
|||
Fallback "Standard (Specular setup)" |
|||
CustomEditor "LightweightPipelineMaterialEditor" |
|||
} |
|
|||
#ifndef LIGHTWEIGHT_CORE_INCLUDED |
|||
#define LIGHTWEIGHT_CORE_INCLUDED |
|||
|
|||
// ------------------------------------- |
|||
|
|||
#include "LightweightInput.cginc" |
|||
#include "LightweightLighting.cginc" |
|||
|
|||
#if defined(_HARD_SHADOWS) || defined(_SOFT_SHADOWS) || defined(_HARD_SHADOWS_CASCADES) || defined(_SOFT_SHADOWS_CASCADES) |
|||
#define _SHADOWS |
|||
#endif |
|||
|
|||
#if defined(_HARD_SHADOWS_CASCADES) || defined(_SOFT_SHADOWS_CASCADES) |
|||
#define _SHADOW_CASCADES |
|||
#endif |
|||
|
|||
#ifdef _SHADOWS |
|||
#include "LightweightShadows.cginc" |
|||
#endif |
|||
|
|||
#if defined(_SPECGLOSSMAP_BASE_ALPHA) || defined(_SPECGLOSSMAP) || defined(_SPECULAR_COLOR) |
|||
#define LIGHTWEIGHT_SPECULAR_HIGHLIGHTS |
|||
#endif |
|||
|
|||
#define _DieletricSpec half4(0.04, 0.04, 0.04, 1.0 - 0.04) // standard dielectric reflectivity coef at incident angle (= 4%) |
|||
|
|||
half SpecularReflectivity(half3 specular) |
|||
{ |
|||
#if (SHADER_TARGET < 30) |
|||
// SM2.0: instruction count limitation |
|||
// SM2.0: simplified SpecularStrength |
|||
return specular.r; // Red channel - because most metals are either monocrhome or with redish/yellowish tint |
|||
#else |
|||
return max(max(specular.r, specular.g), specular.b); |
|||
#endif |
|||
} |
|||
|
|||
inline void CalculateNormal(half3 normalMap, LightweightVertexOutput i, out half3 normal) |
|||
{ |
|||
#if _NORMALMAP |
|||
normal = normalize(half3(dot(normalMap, i.tangentToWorld0), dot(normalMap, i.tangentToWorld1), dot(normalMap, i.tangentToWorld2))); |
|||
#else |
|||
normal = normalize(i.normal); |
|||
#endif |
|||
} |
|||
|
|||
half4 OutputColor(half3 color, half alpha) |
|||
{ |
|||
#if defined(_ALPHABLEND_ON) || defined(_ALPHAPREMULTIPLY_ON) |
|||
return LIGHTWEIGHT_LINEAR_TO_GAMMA(half4(color, alpha)); |
|||
#else |
|||
return half4(LIGHTWEIGHT_LINEAR_TO_GAMMA(color), 1); |
|||
#endif |
|||
} |
|||
|
|||
LightweightVertexOutput LightweightVertex(LightweightVertexInput v) |
|||
{ |
|||
LightweightVertexOutput o = (LightweightVertexOutput)0; |
|||
|
|||
UNITY_SETUP_INSTANCE_ID(v); |
|||
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o); |
|||
|
|||
o.uv01.xy = TRANSFORM_TEX(v.texcoord, _MainTex); |
|||
#ifdef LIGHTMAP_ON |
|||
o.uv01.zw = v.lightmapUV * unity_LightmapST.xy + unity_LightmapST.zw; |
|||
#endif |
|||
o.hpos = UnityObjectToClipPos(v.vertex); |
|||
|
|||
float3 worldPos = mul(unity_ObjectToWorld, v.vertex).xyz; |
|||
o.posWS.xyz = worldPos; |
|||
|
|||
o.viewDir.xyz = normalize(_WorldSpaceCameraPos - worldPos); |
|||
half3 normal = normalize(UnityObjectToWorldNormal(v.normal)); |
|||
|
|||
#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.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); |
|||
#else |
|||
o.normal = normal; |
|||
#endif |
|||
|
|||
// TODO: change to only support point lights per vertex. This will greatly simplify shader ALU |
|||
#if defined(_VERTEX_LIGHTS) && defined(_MULTIPLE_LIGHTS) |
|||
half3 diffuse = half3(1.0, 1.0, 1.0); |
|||
// pixel lights shaded = min(pixelLights, perObjectLights) |
|||
// vertex lights shaded = min(vertexLights, perObjectLights) - pixel lights shaded |
|||
// Therefore vertexStartIndex = pixelLightCount; vertexEndIndex = min(vertexLights, perObjectLights) |
|||
int vertexLightStart = min(globalLightCount.x, unity_LightIndicesOffsetAndCount.y); |
|||
int vertexLightEnd = min(globalLightCount.y, unity_LightIndicesOffsetAndCount.y); |
|||
for (int lightIter = vertexLightStart; lightIter < vertexLightEnd; ++lightIter) |
|||
{ |
|||
int lightIndex = unity_4LightIndices0[lightIter]; |
|||
LightInput lightInput; |
|||
INITIALIZE_LIGHT(lightInput, lightIndex); |
|||
|
|||
half3 lightDirection; |
|||
half atten = ComputeLightAttenuationVertex(lightInput, normal, worldPos, lightDirection); |
|||
o.fogCoord.yzw += LightingLambert(diffuse, lightDirection, normal, atten); |
|||
} |
|||
#endif |
|||
|
|||
#if defined(_LIGHT_PROBES_ON) && !defined(LIGHTMAP_ON) |
|||
o.fogCoord.yzw += max(half3(0, 0, 0), ShadeSH9(half4(normal, 1))); |
|||
#endif |
|||
|
|||
UNITY_TRANSFER_FOG(o, o.hpos); |
|||
return o; |
|||
} |
|||
|
|||
#endif |
|
|||
#ifndef LIGHTWEIGHT_FASTBLINN_INCLUDED |
|||
#define LIGHTWEIGHT_FASTBLINN_INCLUDED |
|||
|
|||
#include "UnityStandardInput.cginc" |
|||
#include "LightweightCore.cginc" |
|||
|
|||
struct SurfaceFastBlinn |
|||
{ |
|||
float3 Diffuse; // diffuse color |
|||
float3 Specular; // specular color |
|||
float3 Normal; // tangent space normal, if written |
|||
half3 Emission; |
|||
half Glossiness; // 0=rough, 1=smooth |
|||
float Alpha; // alpha for transparencies |
|||
}; |
|||
|
|||
SurfaceFastBlinn InitializeSurfaceFastBlinn() |
|||
{ |
|||
SurfaceFastBlinn s; |
|||
s.Diffuse = float3(0.5, 0.5, 0.5); |
|||
s.Specular = float3(0, 0, 0); |
|||
s.Normal = float3(.5, .5, 1); |
|||
s.Emission = 0; |
|||
s.Glossiness = 0; |
|||
s.Alpha = 1; |
|||
return s; |
|||
} |
|||
|
|||
void DefineSurface(LightweightVertexOutput i, inout SurfaceFastBlinn s); |
|||
|
|||
half4 LightweightFragmentFastBlinn(LightweightVertexOutput i) : SV_Target |
|||
{ |
|||
SurfaceFastBlinn s = InitializeSurfaceFastBlinn(); |
|||
DefineSurface(i, s); |
|||
|
|||
// Keep for compatibility reasons. Shader Inpector throws a warning when using cutoff |
|||
// due overdraw performance impact. |
|||
#ifdef _ALPHATEST_ON |
|||
clip(s.Alpha - _Cutoff); |
|||
#endif |
|||
|
|||
half3 normal; |
|||
CalculateNormal(s.Normal, i, normal); |
|||
|
|||
half3 viewDir = i.viewDir.xyz; |
|||
float3 worldPos = i.posWS.xyz; |
|||
|
|||
half3 lightDirection; |
|||
|
|||
half4 specularGloss = half4(s.Specular, s.Glossiness); |
|||
#ifndef _MULTIPLE_LIGHTS |
|||
LightInput lightInput; |
|||
INITIALIZE_MAIN_LIGHT(lightInput); |
|||
half lightAtten = ComputeLightAttenuation(lightInput, normal, worldPos, lightDirection); |
|||
#ifdef _SHADOWS |
|||
lightAtten *= ComputeShadowAttenuation(i, _ShadowLightDirection.xyz); |
|||
#endif |
|||
|
|||
#ifdef LIGHTWEIGHT_SPECULAR_HIGHLIGHTS |
|||
half3 color = LightingBlinnPhong(s.Diffuse, specularGloss, lightDirection, normal, viewDir, lightAtten) * lightInput.color; |
|||
#else |
|||
half3 color = LightingLambert(s.Diffuse, lightDirection, normal, lightAtten) * lightInput.color; |
|||
#endif |
|||
|
|||
#else |
|||
half3 color = half3(0, 0, 0); |
|||
|
|||
#ifdef _SHADOWS |
|||
half shadowAttenuation = ComputeShadowAttenuation(i, _ShadowLightDirection.xyz); |
|||
#endif |
|||
int pixelLightCount = min(globalLightCount.x, unity_LightIndicesOffsetAndCount.y); |
|||
for (int lightIter = 0; lightIter < pixelLightCount; ++lightIter) |
|||
{ |
|||
LightInput lightData; |
|||
int lightIndex = unity_4LightIndices0[lightIter]; |
|||
INITIALIZE_LIGHT(lightData, lightIndex); |
|||
half lightAtten = ComputeLightAttenuation(lightData, normal, worldPos, lightDirection); |
|||
#ifdef _SHADOWS |
|||
lightAtten *= max(shadowAttenuation, half(lightIndex != _ShadowData.x)); |
|||
#endif |
|||
|
|||
#ifdef LIGHTWEIGHT_SPECULAR_HIGHLIGHTS |
|||
color += LightingBlinnPhong(s.Diffuse, specularGloss, lightDirection, normal, viewDir, lightAtten) * lightData.color; |
|||
#else |
|||
color += LightingLambert(s.Diffuse, lightDirection, normal, lightAtten) * lightData.color; |
|||
#endif |
|||
} |
|||
|
|||
#endif // _MULTIPLE_LIGHTS |
|||
|
|||
color += s.Emission; |
|||
|
|||
#if defined(LIGHTMAP_ON) |
|||
color += (DecodeLightmap(UNITY_SAMPLE_TEX2D(unity_Lightmap, i.uv01.zw)) + i.fogCoord.yzw) * s.Diffuse; |
|||
#elif defined(_VERTEX_LIGHTS) || defined(_LIGHT_PROBES_ON) |
|||
color += i.fogCoord.yzw * s.Diffuse; |
|||
#endif |
|||
|
|||
#if _REFLECTION_CUBEMAP |
|||
// TODO: we can use reflect vec to compute specular instead of half when computing cubemap reflection |
|||
half3 reflectVec = reflect(-i.viewDir.xyz, normal); |
|||
color += texCUBE(_Cube, reflectVec).rgb * s.Specular; |
|||
#elif defined(_REFLECTION_PROBE) |
|||
half3 reflectVec = reflect(-i.viewDir.xyz, normal); |
|||
half4 reflectionProbe = UNITY_SAMPLE_TEXCUBE(unity_SpecCube0, reflectVec); |
|||
color += reflectionProbe.rgb * (reflectionProbe.a * unity_SpecCube0_HDR.x) * s.Specular; |
|||
#endif |
|||
|
|||
UNITY_APPLY_FOG(i.fogCoord, color); |
|||
|
|||
return OutputColor(color, s.Alpha); |
|||
}; |
|||
|
|||
#endif |
|
|||
fileFormatVersion: 2 |
|||
guid: 34f60d15edc79b040ba710e07e9582a8 |
|||
timeCreated: 1488965025 |
|||
licenseType: Pro |
|||
ShaderImporter: |
|||
defaultTextures: [] |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
#ifndef LIGHTWEIGHT_INPUT_INCLUDED |
|||
#define LIGHTWEIGHT_INPUT_INCLUDED |
|||
|
|||
#include "UnityCG.cginc" |
|||
|
|||
#define MAX_VISIBLE_LIGHTS 16 |
|||
|
|||
// Main light initialized without indexing |
|||
#define INITIALIZE_MAIN_LIGHT(light) \ |
|||
light.pos = _LightPosition; \ |
|||
light.color = _LightColor; \ |
|||
light.atten = _LightAttenuationParams; \ |
|||
light.spotDir = _LightSpotDir; |
|||
|
|||
// Indexing might have a performance hit for old mobile hardware |
|||
#define INITIALIZE_LIGHT(light, lightIndex) \ |
|||
light.pos = globalLightPos[lightIndex]; \ |
|||
light.color = globalLightColor[lightIndex]; \ |
|||
light.atten = globalLightAtten[lightIndex]; \ |
|||
light.spotDir = globalLightSpotDir[lightIndex] |
|||
|
|||
#if !(defined(_SINGLE_DIRECTIONAL_LIGHT) || defined(_SINGLE_SPOT_LIGHT) || defined(_SINGLE_POINT_LIGHT)) |
|||
#define _MULTIPLE_LIGHTS |
|||
#endif |
|||
|
|||
#if defined(UNITY_COLORSPACE_GAMMA) && defined(LIGHTWEIGHT_LINEAR) |
|||
// Ideally we want an approximation of gamma curve 2.0 to save ALU on GPU but as off now it won't match the GammaToLinear conversion of props in engine |
|||
//#define LIGHTWEIGHT_GAMMA_TO_LINEAR(gammaColor) gammaColor * gammaColor |
|||
//#define LIGHTWEIGHT_LINEAR_TO_GAMMA(linColor) sqrt(color) |
|||
#define LIGHTWEIGHT_GAMMA_TO_LINEAR(sRGB) sRGB * (sRGB * (sRGB * 0.305306011h + 0.682171111h) + 0.012522878h) |
|||
#define LIGHTWEIGHT_LINEAR_TO_GAMMA(linRGB) max(1.055h * pow(max(linRGB, 0.h), 0.416666667h) - 0.055h, 0.h) |
|||
#else |
|||
#define LIGHTWEIGHT_GAMMA_TO_LINEAR(color) color |
|||
#define LIGHTWEIGHT_LINEAR_TO_GAMMA(color) color |
|||
#endif |
|||
|
|||
|
|||
struct LightInput |
|||
{ |
|||
float4 pos; |
|||
half4 color; |
|||
float4 atten; |
|||
half4 spotDir; |
|||
}; |
|||
|
|||
sampler2D _AttenuationTexture; |
|||
|
|||
// Per object light list data |
|||
#ifdef _MULTIPLE_LIGHTS |
|||
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]; |
|||
float4 globalLightAtten[MAX_VISIBLE_LIGHTS]; |
|||
#else |
|||
float4 _LightPosition; |
|||
half4 _LightColor; |
|||
float4 _LightAttenuationParams; |
|||
half4 _LightSpotDir; |
|||
#endif |
|||
|
|||
sampler2D _MetallicSpecGlossMap; |
|||
|
|||
half4 _DieletricSpec; |
|||
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 LightweightVertexOutput |
|||
{ |
|||
float4 uv01 : TEXCOORD0; // uv01.xy: uv0, uv01.zw: uv1 |
|||
float4 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 |
|||
}; |
|||
|
|||
#endif |
|
|||
#ifndef LIGHTWEIGHT_PBR_INCLUDED |
|||
#define LIGHTWEIGHT_PBR_INCLUDED |
|||
|
|||
#include "UnityStandardInput.cginc" |
|||
#include "LightweightBRDF.cginc" |
|||
#include "LightweightCore.cginc" |
|||
|
|||
struct SurfacePBR |
|||
{ |
|||
float3 Albedo; // diffuse color |
|||
float3 Specular; // specular color |
|||
float Metallic; // metallic |
|||
float3 Normal; // tangent space normal, if written |
|||
half3 Emission; |
|||
half Smoothness; // 0=rough, 1=smooth |
|||
half Occlusion; // occlusion (default 1) |
|||
float Alpha; // alpha for transparencies |
|||
}; |
|||
|
|||
SurfacePBR InitializeSurfacePBR() |
|||
{ |
|||
SurfacePBR s; |
|||
s.Albedo = float3(0.5, 0.5, 0.5); |
|||
s.Specular = float3(0, 0, 0); |
|||
s.Metallic = 0; |
|||
s.Normal = float3(.5, .5, 1); |
|||
s.Emission = 0; |
|||
s.Smoothness = 0; |
|||
s.Occlusion = 1; |
|||
s.Alpha = 1; |
|||
return s; |
|||
} |
|||
|
|||
void DefineSurface(LightweightVertexOutput i, inout SurfacePBR s); |
|||
|
|||
half3 MetallicSetup(float2 uv, SurfacePBR s, out half3 specular, out half smoothness, out half oneMinusReflectivity) |
|||
{ |
|||
smoothness = s.Smoothness;// metallicGloss.g; |
|||
|
|||
// We'll need oneMinusReflectivity, so |
|||
// 1-reflectivity = 1-lerp(dielectricSpec, 1, metallic) = lerp(1-dielectricSpec, 0, metallic) |
|||
// store (1-dielectricSpec) in unity_ColorSpaceDielectricSpec.a, then |
|||
// 1-reflectivity = lerp(alpha, 0, metallic) = alpha + metallic*(0 - alpha) = |
|||
// = alpha - metallic * alpha |
|||
half oneMinusDielectricSpec = _DieletricSpec.a; |
|||
oneMinusReflectivity = oneMinusDielectricSpec - s.Metallic * oneMinusDielectricSpec; |
|||
specular = lerp(_DieletricSpec.rgb, s.Albedo, s.Metallic); |
|||
|
|||
return s.Albedo * oneMinusReflectivity; |
|||
} |
|||
|
|||
half3 SpecularSetup(float2 uv, SurfacePBR s, out half3 specular, out half smoothness, out half oneMinusReflectivity) |
|||
{ |
|||
half4 specGloss = float4(s.Specular, s.Smoothness); |
|||
|
|||
#if defined(UNITY_COLORSPACE_GAMMA) && defined(LIGHTWEIGHT_LINEAR) |
|||
specGloss.rgb = LIGHTWEIGHT_GAMMA_TO_LINEAR(specGloss.rgb); |
|||
#endif |
|||
|
|||
specular = specGloss.rgb; |
|||
smoothness = specGloss.a; |
|||
oneMinusReflectivity = 1.0h - SpecularReflectivity(specular); |
|||
return s.Albedo * (half3(1, 1, 1) - specular); |
|||
} |
|||
|
|||
half4 LightweightFragmentPBR(LightweightVertexOutput i) : SV_Target |
|||
{ |
|||
SurfacePBR s = InitializeSurfacePBR(); |
|||
DefineSurface(i, s); |
|||
|
|||
float2 uv = i.uv01.xy; |
|||
float2 lightmapUV = i.uv01.zw; |
|||
|
|||
half3 specColor; |
|||
half smoothness; |
|||
half oneMinusReflectivity; |
|||
#ifdef _METALLIC_SETUP |
|||
half3 diffColor = MetallicSetup(uv, s, specColor, smoothness, oneMinusReflectivity); |
|||
#else |
|||
half3 diffColor = SpecularSetup(uv, s, specColor, smoothness, oneMinusReflectivity); |
|||
#endif |
|||
|
|||
diffColor = PreMultiplyAlpha(diffColor, s.Alpha, oneMinusReflectivity, /*out*/ s.Alpha); |
|||
|
|||
// Roughness is (1.0 - smoothness)² |
|||
half perceptualRoughness = 1.0h - smoothness; |
|||
|
|||
// TODO - Actually handle normal |
|||
half3 normal; |
|||
CalculateNormal(s.Normal, i, 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, s.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; |
|||
|
|||
#ifndef _MULTIPLE_LIGHTS |
|||
LightInput light; |
|||
INITIALIZE_MAIN_LIGHT(light); |
|||
half lightAtten = ComputeLightAttenuation(light, normal, i.posWS.xyz, lightDirection); |
|||
|
|||
#ifdef _SHADOWS |
|||
lightAtten *= ComputeShadowAttenuation(i, _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, _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 += s.Emission; |
|||
UNITY_APPLY_FOG(i.fogCoord, color); |
|||
return OutputColor(color, s.Alpha); |
|||
} |
|||
|
|||
#endif |
|
|||
fileFormatVersion: 2 |
|||
guid: 7cfc2533f15ff004ca757daee1df2c37 |
|||
timeCreated: 1488965025 |
|||
licenseType: Pro |
|||
ShaderImporter: |
|||
defaultTextures: [] |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
#ifndef LIGHTWEIGHT_PASS_INCLUDED |
|||
#define LIGHTWEIGHT_PASS_INCLUDED |
|||
|
|||
float4 shadowVert(float4 pos : POSITION) : SV_POSITION |
|||
{ |
|||
float4 clipPos = UnityObjectToClipPos(pos); |
|||
#if defined(UNITY_REVERSED_Z) |
|||
clipPos.z = min(clipPos.z, UNITY_NEAR_CLIP_VALUE); |
|||
#else |
|||
clipPos.z = max(clipPos.z, UNITY_NEAR_CLIP_VALUE); |
|||
#endif |
|||
return clipPos; |
|||
} |
|||
|
|||
half4 shadowFrag() : SV_TARGET |
|||
{ |
|||
return 0; |
|||
} |
|||
|
|||
float4 depthVert(float4 pos : POSITION) : SV_POSITION |
|||
{ |
|||
return UnityObjectToClipPos(pos); |
|||
} |
|||
|
|||
half4 depthFrag() : SV_TARGET |
|||
{ |
|||
return 0; |
|||
} |
|||
|
|||
// -------------------------------- |
|||
// Meta |
|||
|
|||
#include "UnityStandardMeta.cginc" |
|||
#include "LightweightFastBlinn.cginc" |
|||
|
|||
void DefineSurfaceMeta(v2f_meta i, inout SurfaceFastBlinn s); |
|||
|
|||
fixed4 frag_meta_ld(v2f_meta i) : SV_Target |
|||
{ |
|||
UnityMetaInput o; |
|||
UNITY_INITIALIZE_OUTPUT(UnityMetaInput, o); |
|||
|
|||
SurfaceFastBlinn s = InitializeSurfaceFastBlinn(); |
|||
DefineSurfaceMeta(i, s); |
|||
|
|||
o.Albedo = s.Diffuse; |
|||
o.SpecularColor = s.Specular; |
|||
o.Emission = s.Emission; |
|||
|
|||
return UnityMetaFragment(o); |
|||
} |
|||
|
|||
#endif |
|
|||
#ifndef LIGHTWEIGHT_PASS_INCLUDED |
|||
#define LIGHTWEIGHT_PASS_INCLUDED |
|||
|
|||
float4 shadowVert(float4 pos : POSITION) : SV_POSITION |
|||
{ |
|||
float4 clipPos = UnityObjectToClipPos(pos); |
|||
#if defined(UNITY_REVERSED_Z) |
|||
clipPos.z = min(clipPos.z, UNITY_NEAR_CLIP_VALUE); |
|||
#else |
|||
clipPos.z = max(clipPos.z, UNITY_NEAR_CLIP_VALUE); |
|||
#endif |
|||
return clipPos; |
|||
} |
|||
|
|||
half4 shadowFrag() : SV_TARGET |
|||
{ |
|||
return 0; |
|||
} |
|||
|
|||
float4 depthVert(float4 pos : POSITION) : SV_POSITION |
|||
{ |
|||
return UnityObjectToClipPos(pos); |
|||
} |
|||
|
|||
half4 depthFrag() : SV_TARGET |
|||
{ |
|||
return 0; |
|||
} |
|||
|
|||
#include "UnityStandardMeta.cginc" |
|||
#include "LightweightPipelineInput.cginc" |
|||
|
|||
fixed4 frag_meta_ld(v2f_meta i) : SV_Target |
|||
{ |
|||
UnityMetaInput o; |
|||
UNITY_INITIALIZE_OUTPUT(UnityMetaInput, o); |
|||
|
|||
o.Albedo = Albedo(i.uv); |
|||
|
|||
half4 specularColor; |
|||
SpecularGloss(i.uv.xy, 1.0, specularColor); |
|||
o.SpecularColor = specularColor; |
|||
|
|||
#ifdef _EMISSION |
|||
o.Emission += LIGHTWEIGHT_GAMMA_TO_LINEAR(tex2D(_EmissionMap, i.uv).rgb) * _EmissionColor; |
|||
#else |
|||
o.Emission += _EmissionColor; |
|||
#endif |
|||
|
|||
return UnityMetaFragment(o); |
|||
} |
|||
|
|||
#endif |
|
|||
// Shader targeted for low end devices. Single Pass Forward Rendering. Shader Model 2 |
|||
Shader "ScriptableRenderPipeline/LightweightPipeline/FastBlinn" |
|||
{ |
|||
// Keep properties of StandardSpecular shader for upgrade reasons. |
|||
Properties |
|||
{ |
|||
_Color("Color", Color) = (1,1,1,1) |
|||
_MainTex("Base (RGB) Glossiness / Alpha (A)", 2D) = "white" {} |
|||
|
|||
_Cutoff("Alpha Cutoff", Range(0.0, 1.0)) = 0.5 |
|||
|
|||
_Shininess("Shininess", Range(0.01, 1.0)) = 1.0 |
|||
_GlossMapScale("Smoothness Factor", Range(0.0, 1.0)) = 1.0 |
|||
|
|||
_Glossiness("Glossiness", Range(0.0, 1.0)) = 0.5 |
|||
[Enum(Specular Alpha,0,Albedo Alpha,1)] _SmoothnessTextureChannel("Smoothness texture channel", Float) = 0 |
|||
|
|||
_Cube ("Reflection Cubemap", CUBE) = "" {} |
|||
_ReflectionSource("Reflection Source", Float) = 0 |
|||
|
|||
[HideInInspector] _SpecSource("Specular Color Source", Float) = 0.0 |
|||
_SpecColor("Specular", Color) = (1.0, 1.0, 1.0) |
|||
_SpecGlossMap("Specular", 2D) = "white" {} |
|||
[HideInInspector] _GlossinessSource("Glossiness Source", Float) = 0.0 |
|||
[ToggleOff] _SpecularHighlights("Specular Highlights", Float) = 1.0 |
|||
[ToggleOff] _GlossyReflections("Glossy Reflections", Float) = 1.0 |
|||
|
|||
[HideInInspector] _BumpScale("Scale", Float) = 1.0 |
|||
[NoScaleOffset] _BumpMap("Normal Map", 2D) = "bump" {} |
|||
|
|||
_Parallax("Height Scale", Range(0.005, 0.08)) = 0.02 |
|||
_ParallaxMap("Height Map", 2D) = "black" {} |
|||
|
|||
_EmissionColor("Emission 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 |
|||
|
|||
Pass |
|||
{ |
|||
Tags { "LightMode" = "LightweightForward" } |
|||
|
|||
// Use same blending / depth states as Standard shader |
|||
Blend[_SrcBlend][_DstBlend] |
|||
ZWrite[_ZWrite] |
|||
|
|||
CGPROGRAM |
|||
#pragma target 3.0 |
|||
|
|||
#pragma shader_feature _ _ALPHATEST_ON _ALPHABLEND_ON |
|||
#pragma shader_feature _ _SPECGLOSSMAP _SPECGLOSSMAP_BASE_ALPHA _SPECULAR_COLOR |
|||
#pragma shader_feature _NORMALMAP |
|||
#pragma shader_feature _EMISSION |
|||
#pragma shader_feature _ _REFLECTION_CUBEMAP _REFLECTION_PROBE |
|||
|
|||
#pragma multi_compile _ LIGHTWEIGHT_LINEAR |
|||
#pragma multi_compile _ UNITY_SINGLE_PASS_STEREO STEREO_INSTANCING_ON STEREO_MULTIVIEW_ON |
|||
#pragma multi_compile _ _SINGLE_DIRECTIONAL_LIGHT _SINGLE_SPOT_LIGHT _SINGLE_POINT_LIGHT |
|||
#pragma multi_compile _ LIGHTMAP_ON |
|||
#pragma multi_compile _ _LIGHT_PROBES_ON |
|||
#pragma multi_compile _ _HARD_SHADOWS _SOFT_SHADOWS _HARD_SHADOWS_CASCADES _SOFT_SHADOWS_CASCADES |
|||
#pragma multi_compile _ _VERTEX_LIGHTS |
|||
#pragma multi_compile _ _ATTENUATION_TEXTURE |
|||
#pragma multi_compile_fog |
|||
#pragma multi_compile_instancing |
|||
|
|||
#include "UnityCG.cginc" |
|||
#include "UnityStandardInput.cginc" |
|||
#include "LightweightPipelineCore.cginc" |
|||
//#include "LightweightPipelineLighting.cginc" |
|||
|
|||
#pragma vertex LightweightVertex |
|||
#pragma fragment LightweightFragmentFastBlinn |
|||
|
|||
void DefineSurface(LightweightVertexOutput i, inout SurfaceFastBlinn s) |
|||
{ |
|||
// Albedo |
|||
float4 c = tex2D(_MainTex, i.uv01.xy); |
|||
s.Diffuse = LIGHTWEIGHT_GAMMA_TO_LINEAR(c.rgb) * _Color.rgb; |
|||
|
|||
// Specular |
|||
#ifdef _SPECGLOSSMAP |
|||
half4 specularMap = tex2D(_SpecGlossMap, i.uv01.xy); |
|||
#if defined(UNITY_COLORSPACE_GAMMA) && defined(LIGHTWEIGHT_LINEAR) |
|||
s.Specular = LIGHTWEIGHT_GAMMA_TO_LINEAR(specularGloss.rgb); |
|||
#endif |
|||
#elif defined(_SPECGLOSSMAP_BASE_ALPHA) |
|||
s.Specular.rgb = LIGHTWEIGHT_GAMMA_TO_LINEAR(tex2D(_SpecGlossMap, i.uv01.xy).rgb) * _SpecColor.rgb; |
|||
s.Glossiness = s.Alpha; |
|||
#else |
|||
s.Specular = _SpecColor.rgb; |
|||
s.Glossiness = _SpecColor.a; |
|||
#endif |
|||
|
|||
// Normal |
|||
#if _NORMALMAP |
|||
s.Normal = UnpackNormal(tex2D(_BumpMap, i.uv01.xy)); |
|||
#endif |
|||
|
|||
// Emission |
|||
s.Emission = CalculateEmission(i.uv01.xy); |
|||
|
|||
// Alpha |
|||
#ifdef _SMOOTHNESS_TEXTURE_ALBEDO_CHANNEL_A |
|||
s.Alpha = _Color.a; |
|||
#else |
|||
s.Alpha = c.a * _Color.a; |
|||
#endif |
|||
|
|||
#ifdef _ALPHATEST_ON |
|||
clip(s.Alpha - _Cutoff); |
|||
#endif |
|||
|
|||
} |
|||
|
|||
ENDCG |
|||
} |
|||
|
|||
Pass |
|||
{ |
|||
Tags { "Lightmode" = "ShadowCaster" } |
|||
ZWrite On ZTest LEqual |
|||
|
|||
CGPROGRAM |
|||
#pragma target 2.0 |
|||
#include "UnityCG.cginc" |
|||
#include "LightweightPipelinePass.cginc" |
|||
#pragma vertex shadowVert |
|||
#pragma fragment shadowFrag |
|||
ENDCG |
|||
} |
|||
|
|||
Pass |
|||
{ |
|||
Tags{"Lightmode" = "DepthOnly"} |
|||
ZWrite On |
|||
|
|||
CGPROGRAM |
|||
#pragma target 2.0 |
|||
#include "LightweightPipelinePass.cginc" |
|||
#pragma vertex depthVert |
|||
#pragma fragment depthFrag |
|||
ENDCG |
|||
} |
|||
|
|||
// This pass it not used during regular rendering, only for lightmap baking. |
|||
Pass |
|||
{ |
|||
Tags{ "LightMode" = "Meta" } |
|||
|
|||
Cull Off |
|||
|
|||
CGPROGRAM |
|||
#define UNITY_SETUP_BRDF_INPUT SpecularSetup |
|||
|
|||
#pragma shader_feature _EMISSION |
|||
#pragma shader_feature _SPECGLOSSMAP |
|||
#pragma shader_feature _ _SMOOTHNESS_TEXTURE_ALBEDO_CHANNEL_A |
|||
#pragma shader_feature ___ _DETAIL_MULX2 |
|||
#pragma shader_feature EDITOR_VISUALIZATION |
|||
|
|||
#include "UnityCG.cginc" |
|||
#include "LightweightPipelinePass.cginc" |
|||
#pragma vertex vert_meta |
|||
#pragma fragment frag_meta_ld |
|||
ENDCG |
|||
} |
|||
} |
|||
Fallback "Standard (Specular setup)" |
|||
CustomEditor "LightweightPipelineMaterialEditor" |
|||
} |
|
|||
#ifndef LIGHTWEIGHT_PIPELINE_CORE_INCLUDED |
|||
#define LIGHTWEIGHT_PIPELINE_CORE_INCLUDED |
|||
|
|||
// ------------------------------------- |
|||
|
|||
#include "LightweightPipelineInput.cginc" |
|||
#include "LightweightPipelineLighting.cginc" |
|||
#include "LightweightPipelineBRDF.cginc" |
|||
|
|||
#if defined(_HARD_SHADOWS) || defined(_SOFT_SHADOWS) || defined(_HARD_SHADOWS_CASCADES) || defined(_SOFT_SHADOWS_CASCADES) |
|||
#define _SHADOWS |
|||
#endif |
|||
|
|||
#if defined(_HARD_SHADOWS_CASCADES) || defined(_SOFT_SHADOWS_CASCADES) |
|||
#define _SHADOW_CASCADES |
|||
#endif |
|||
|
|||
#ifdef _SHADOWS |
|||
#include "LightweightPipelineShadows.cginc" |
|||
#endif |
|||
|
|||
#if defined(_SPECGLOSSMAP_BASE_ALPHA) || defined(_SPECGLOSSMAP) || defined(_SPECULAR_COLOR) |
|||
#define LIGHTWEIGHT_SPECULAR_HIGHLIGHTS |
|||
#endif |
|||
|
|||
#define _DieletricSpec half4(0.04, 0.04, 0.04, 1.0 - 0.04) // standard dielectric reflectivity coef at incident angle (= 4%) |
|||
|
|||
half SpecularReflectivity(half3 specular) |
|||
{ |
|||
#if (SHADER_TARGET < 30) |
|||
// SM2.0: instruction count limitation |
|||
// SM2.0: simplified SpecularStrength |
|||
return specular.r; // Red channel - because most metals are either monocrhome or with redish/yellowish tint |
|||
#else |
|||
return max(max(specular.r, specular.g), specular.b); |
|||
#endif |
|||
} |
|||
|
|||
half3 MetallicSetup(float2 uv, SurfacePBR s, /*half3 albedo, half albedoAlpha, */out half3 specular, out half smoothness, out half oneMinusReflectivity) |
|||
{ |
|||
//half2 metallicGloss = MetallicSpecGloss(uv, albedoAlpha).ra; |
|||
//half metallic = metallicGloss.r; |
|||
smoothness = s.Smoothness;// metallicGloss.g; |
|||
|
|||
// We'll need oneMinusReflectivity, so |
|||
// 1-reflectivity = 1-lerp(dielectricSpec, 1, metallic) = lerp(1-dielectricSpec, 0, metallic) |
|||
// store (1-dielectricSpec) in unity_ColorSpaceDielectricSpec.a, then |
|||
// 1-reflectivity = lerp(alpha, 0, metallic) = alpha + metallic*(0 - alpha) = |
|||
// = alpha - metallic * alpha |
|||
half oneMinusDielectricSpec = _DieletricSpec.a; |
|||
oneMinusReflectivity = oneMinusDielectricSpec - s.Metallic * oneMinusDielectricSpec; |
|||
specular = lerp(_DieletricSpec.rgb, s.Albedo, s.Metallic); |
|||
|
|||
return s.Albedo * oneMinusReflectivity; |
|||
} |
|||
|
|||
half3 SpecularSetup(float2 uv, SurfacePBR s, /*half3 albedo, half albedoAlpha, */out half3 specular, out half smoothness, out half oneMinusReflectivity) |
|||
{ |
|||
half4 specGloss = float4(s.Specular, s.Smoothness);// MetallicSpecGloss(uv, albedoAlpha); |
|||
|
|||
#if defined(UNITY_COLORSPACE_GAMMA) && defined(LIGHTWEIGHT_LINEAR) |
|||
specGloss.rgb = LIGHTWEIGHT_GAMMA_TO_LINEAR(specGloss.rgb); |
|||
#endif |
|||
|
|||
specular = specGloss.rgb; |
|||
smoothness = specGloss.a; |
|||
oneMinusReflectivity = 1.0h - SpecularReflectivity(specular); |
|||
return s.Albedo * (half3(1, 1, 1) - specular); |
|||
} |
|||
|
|||
half4 OutputColor(half3 color, half alpha) |
|||
{ |
|||
#if defined(_ALPHABLEND_ON) || defined(_ALPHAPREMULTIPLY_ON) |
|||
return LIGHTWEIGHT_LINEAR_TO_GAMMA(half4(color, alpha)); |
|||
#else |
|||
return half4(LIGHTWEIGHT_LINEAR_TO_GAMMA(color), 1); |
|||
#endif |
|||
} |
|||
|
|||
LightweightVertexOutput LightweightVertex(LightweightVertexInput v) |
|||
{ |
|||
LightweightVertexOutput o = (LightweightVertexOutput)0; |
|||
|
|||
UNITY_SETUP_INSTANCE_ID(v); |
|||
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o); |
|||
|
|||
o.uv01.xy = TRANSFORM_TEX(v.texcoord, _MainTex); |
|||
#ifdef LIGHTMAP_ON |
|||
o.uv01.zw = v.lightmapUV * unity_LightmapST.xy + unity_LightmapST.zw; |
|||
#endif |
|||
o.hpos = UnityObjectToClipPos(v.vertex); |
|||
|
|||
float3 worldPos = mul(unity_ObjectToWorld, v.vertex).xyz; |
|||
o.posWS.xyz = worldPos; |
|||
|
|||
o.viewDir.xyz = normalize(_WorldSpaceCameraPos - worldPos); |
|||
half3 normal = normalize(UnityObjectToWorldNormal(v.normal)); |
|||
|
|||
#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.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); |
|||
#else |
|||
o.normal = normal; |
|||
#endif |
|||
|
|||
// TODO: change to only support point lights per vertex. This will greatly simplify shader ALU |
|||
#if defined(_VERTEX_LIGHTS) && defined(_MULTIPLE_LIGHTS) |
|||
half3 diffuse = half3(1.0, 1.0, 1.0); |
|||
// pixel lights shaded = min(pixelLights, perObjectLights) |
|||
// vertex lights shaded = min(vertexLights, perObjectLights) - pixel lights shaded |
|||
// Therefore vertexStartIndex = pixelLightCount; vertexEndIndex = min(vertexLights, perObjectLights) |
|||
int vertexLightStart = min(globalLightCount.x, unity_LightIndicesOffsetAndCount.y); |
|||
int vertexLightEnd = min(globalLightCount.y, unity_LightIndicesOffsetAndCount.y); |
|||
for (int lightIter = vertexLightStart; lightIter < vertexLightEnd; ++lightIter) |
|||
{ |
|||
int lightIndex = unity_4LightIndices0[lightIter]; |
|||
LightInput lightInput; |
|||
INITIALIZE_LIGHT(lightInput, lightIndex); |
|||
|
|||
half3 lightDirection; |
|||
half atten = ComputeLightAttenuationVertex(lightInput, normal, worldPos, lightDirection); |
|||
o.fogCoord.yzw += LightingLambert(diffuse, lightDirection, normal, atten); |
|||
} |
|||
#endif |
|||
|
|||
#if defined(_LIGHT_PROBES_ON) && !defined(LIGHTMAP_ON) |
|||
o.fogCoord.yzw += max(half3(0, 0, 0), ShadeSH9(half4(normal, 1))); |
|||
#endif |
|||
|
|||
UNITY_TRANSFER_FOG(o, o.hpos); |
|||
return o; |
|||
} |
|||
|
|||
SurfacePBR InitializeSurfacePBR() |
|||
{ |
|||
SurfacePBR s; |
|||
s.Albedo = float3(0.5, 0.5, 0.5); |
|||
s.Specular = float3(0, 0, 0); |
|||
s.Metallic = 0; |
|||
s.Normal = float3(.5, .5, 1); |
|||
s.Emission = 0; |
|||
s.Smoothness = 0; |
|||
s.Occlusion = 1; |
|||
s.Alpha = 1; |
|||
return s; |
|||
} |
|||
|
|||
SurfaceFastBlinn InitializeSurfaceFastBlinn() |
|||
{ |
|||
SurfaceFastBlinn s; |
|||
s.Diffuse = float3(0.5, 0.5, 0.5); |
|||
s.Specular = float3(0, 0, 0); |
|||
s.Normal = float3(.5, .5, 1); |
|||
s.Emission = 0; |
|||
s.Glossiness = 0; |
|||
s.Alpha = 1; |
|||
return s; |
|||
} |
|||
|
|||
void DefineSurface(LightweightVertexOutput i, inout SurfacePBR s); |
|||
void DefineSurface(LightweightVertexOutput i, inout SurfaceFastBlinn s); |
|||
|
|||
half4 LightweightFragmentPBR(LightweightVertexOutput i) : SV_Target |
|||
{ |
|||
SurfacePBR s = InitializeSurfacePBR(); |
|||
DefineSurface(i, s); |
|||
|
|||
float2 uv = i.uv01.xy; |
|||
float2 lightmapUV = i.uv01.zw; |
|||
|
|||
half3 specColor; |
|||
half smoothness; |
|||
half oneMinusReflectivity; |
|||
#ifdef _METALLIC_SETUP |
|||
half3 diffColor = MetallicSetup(uv, s, specColor, smoothness, oneMinusReflectivity); |
|||
#else |
|||
half3 diffColor = SpecularSetup(uv, s, specColor, smoothness, oneMinusReflectivity); |
|||
#endif |
|||
|
|||
diffColor = PreMultiplyAlpha(diffColor, s.Alpha, oneMinusReflectivity, /*out*/ s.Alpha); |
|||
|
|||
// Roughness is (1.0 - smoothness)� |
|||
half perceptualRoughness = 1.0h - smoothness; |
|||
|
|||
// TODO - Actually handle normal |
|||
half3 normal; |
|||
CalculateNormal(s.Normal, i, 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, s.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; |
|||
|
|||
#ifndef _MULTIPLE_LIGHTS |
|||
LightInput light; |
|||
INITIALIZE_MAIN_LIGHT(light); |
|||
half lightAtten = ComputeLightAttenuation(light, normal, i.posWS.xyz, lightDirection); |
|||
|
|||
#ifdef _SHADOWS |
|||
lightAtten *= ComputeShadowAttenuation(i, _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, _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 += s.Emission; |
|||
UNITY_APPLY_FOG(i.fogCoord, color); |
|||
return OutputColor(color, s.Alpha); |
|||
} |
|||
|
|||
half4 LightweightFragmentFastBlinn(LightweightVertexOutput i) : SV_Target |
|||
{ |
|||
SurfaceFastBlinn s = InitializeSurfaceFastBlinn(); |
|||
DefineSurface(i, s); |
|||
|
|||
// Keep for compatibility reasons. Shader Inpector throws a warning when using cutoff |
|||
// due overdraw performance impact. |
|||
#ifdef _ALPHATEST_ON |
|||
clip(s.Alpha - _Cutoff); |
|||
#endif |
|||
|
|||
half3 normal; |
|||
CalculateNormal(s.Normal, i, normal); |
|||
|
|||
half3 viewDir = i.viewDir.xyz; |
|||
float3 worldPos = i.posWS.xyz; |
|||
|
|||
half3 lightDirection; |
|||
|
|||
half4 specularGloss = half4(s.Specular, s.Glossiness); |
|||
#ifndef _MULTIPLE_LIGHTS |
|||
LightInput lightInput; |
|||
INITIALIZE_MAIN_LIGHT(lightInput); |
|||
half lightAtten = ComputeLightAttenuation(lightInput, normal, worldPos, lightDirection); |
|||
#ifdef _SHADOWS |
|||
lightAtten *= ComputeShadowAttenuation(i, _ShadowLightDirection.xyz); |
|||
#endif |
|||
|
|||
#ifdef LIGHTWEIGHT_SPECULAR_HIGHLIGHTS |
|||
half3 color = LightingBlinnPhong(s.Diffuse, specularGloss, lightDirection, normal, viewDir, lightAtten) * lightInput.color; |
|||
#else |
|||
half3 color = LightingLambert(s.Diffuse, lightDirection, normal, lightAtten) * lightInput.color; |
|||
#endif |
|||
|
|||
#else |
|||
half3 color = half3(0, 0, 0); |
|||
|
|||
#ifdef _SHADOWS |
|||
half shadowAttenuation = ComputeShadowAttenuation(i, _ShadowLightDirection.xyz); |
|||
#endif |
|||
int pixelLightCount = min(globalLightCount.x, unity_LightIndicesOffsetAndCount.y); |
|||
for (int lightIter = 0; lightIter < pixelLightCount; ++lightIter) |
|||
{ |
|||
LightInput lightData; |
|||
int lightIndex = unity_4LightIndices0[lightIter]; |
|||
INITIALIZE_LIGHT(lightData, lightIndex); |
|||
half lightAtten = ComputeLightAttenuation(lightData, normal, worldPos, lightDirection); |
|||
#ifdef _SHADOWS |
|||
lightAtten *= max(shadowAttenuation, half(lightIndex != _ShadowData.x)); |
|||
#endif |
|||
|
|||
#ifdef LIGHTWEIGHT_SPECULAR_HIGHLIGHTS |
|||
color += LightingBlinnPhong(s.Diffuse, specularGloss, lightDirection, normal, viewDir, lightAtten) * lightData.color; |
|||
#else |
|||
color += LightingLambert(s.Diffuse, lightDirection, normal, lightAtten) * lightData.color; |
|||
#endif |
|||
} |
|||
|
|||
#endif // _MULTIPLE_LIGHTS |
|||
|
|||
color += CalculateEmissionFastBlinn(i.uv01.xy); |
|||
|
|||
#if defined(LIGHTMAP_ON) |
|||
color += (DecodeLightmap(UNITY_SAMPLE_TEX2D(unity_Lightmap, i.uv01.zw)) + i.fogCoord.yzw) * s.Diffuse; |
|||
#elif defined(_VERTEX_LIGHTS) || defined(_LIGHT_PROBES_ON) |
|||
color += i.fogCoord.yzw * s.Diffuse; |
|||
#endif |
|||
|
|||
#if _REFLECTION_CUBEMAP |
|||
// TODO: we can use reflect vec to compute specular instead of half when computing cubemap reflection |
|||
half3 reflectVec = reflect(-i.viewDir.xyz, normal); |
|||
color += texCUBE(_Cube, reflectVec).rgb * s.Specular; |
|||
#elif defined(_REFLECTION_PROBE) |
|||
half3 reflectVec = reflect(-i.viewDir.xyz, normal); |
|||
half4 reflectionProbe = UNITY_SAMPLE_TEXCUBE(unity_SpecCube0, reflectVec); |
|||
color += reflectionProbe.rgb * (reflectionProbe.a * unity_SpecCube0_HDR.x) * s.Specular; |
|||
#endif |
|||
|
|||
UNITY_APPLY_FOG(i.fogCoord, color); |
|||
|
|||
return OutputColor(color, s.Alpha); |
|||
}; |
|||
|
|||
#endif |
|
|||
#ifndef LIGHTWEIGHT_INPUT_INCLUDED |
|||
#define LIGHTWEIGHT_INPUT_INCLUDED |
|||
|
|||
#include "UnityCG.cginc" |
|||
#include "UnityStandardInput.cginc" |
|||
|
|||
#define MAX_VISIBLE_LIGHTS 16 |
|||
|
|||
// Main light initialized without indexing |
|||
#define INITIALIZE_MAIN_LIGHT(light) \ |
|||
light.pos = _LightPosition; \ |
|||
light.color = _LightColor; \ |
|||
light.atten = _LightAttenuationParams; \ |
|||
light.spotDir = _LightSpotDir; |
|||
|
|||
// Indexing might have a performance hit for old mobile hardware |
|||
#define INITIALIZE_LIGHT(light, lightIndex) \ |
|||
light.pos = globalLightPos[lightIndex]; \ |
|||
light.color = globalLightColor[lightIndex]; \ |
|||
light.atten = globalLightAtten[lightIndex]; \ |
|||
light.spotDir = globalLightSpotDir[lightIndex] |
|||
|
|||
#if !(defined(_SINGLE_DIRECTIONAL_LIGHT) || defined(_SINGLE_SPOT_LIGHT) || defined(_SINGLE_POINT_LIGHT)) |
|||
#define _MULTIPLE_LIGHTS |
|||
#endif |
|||
|
|||
#if defined(UNITY_COLORSPACE_GAMMA) && defined(LIGHTWEIGHT_LINEAR) |
|||
// Ideally we want an approximation of gamma curve 2.0 to save ALU on GPU but as off now it won't match the GammaToLinear conversion of props in engine |
|||
//#define LIGHTWEIGHT_GAMMA_TO_LINEAR(gammaColor) gammaColor * gammaColor |
|||
//#define LIGHTWEIGHT_LINEAR_TO_GAMMA(linColor) sqrt(color) |
|||
#define LIGHTWEIGHT_GAMMA_TO_LINEAR(sRGB) sRGB * (sRGB * (sRGB * 0.305306011h + 0.682171111h) + 0.012522878h) |
|||
#define LIGHTWEIGHT_LINEAR_TO_GAMMA(linRGB) max(1.055h * pow(max(linRGB, 0.h), 0.416666667h) - 0.055h, 0.h) |
|||
#else |
|||
#define LIGHTWEIGHT_GAMMA_TO_LINEAR(color) color |
|||
#define LIGHTWEIGHT_LINEAR_TO_GAMMA(color) color |
|||
#endif |
|||
|
|||
|
|||
struct LightInput |
|||
{ |
|||
float4 pos; |
|||
half4 color; |
|||
float4 atten; |
|||
half4 spotDir; |
|||
}; |
|||
|
|||
sampler2D _AttenuationTexture; |
|||
|
|||
// Per object light list data |
|||
#ifdef _MULTIPLE_LIGHTS |
|||
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]; |
|||
float4 globalLightAtten[MAX_VISIBLE_LIGHTS]; |
|||
#else |
|||
float4 _LightPosition; |
|||
half4 _LightColor; |
|||
float4 _LightAttenuationParams; |
|||
half4 _LightSpotDir; |
|||
#endif |
|||
|
|||
sampler2D _MetallicSpecGlossMap; |
|||
|
|||
half4 _DieletricSpec; |
|||
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 LightweightVertexOutput |
|||
{ |
|||
float4 uv01 : TEXCOORD0; // uv01.xy: uv0, uv01.zw: uv1 |
|||
float4 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 SurfacePBR |
|||
{ |
|||
float3 Albedo; // diffuse color |
|||
float3 Specular; // specular color |
|||
float Metallic; // metallic |
|||
float3 Normal; // tangent space normal, if written |
|||
half3 Emission; |
|||
half Smoothness; // 0=rough, 1=smooth |
|||
half Occlusion; // occlusion (default 1) |
|||
float Alpha; // alpha for transparencies |
|||
}; |
|||
|
|||
struct SurfaceFastBlinn |
|||
{ |
|||
float3 Diffuse; // diffuse color |
|||
float3 Specular; // specular color |
|||
float3 Normal; // tangent space normal, if written |
|||
half3 Emission; |
|||
half Glossiness; // 0=rough, 1=smooth |
|||
float Alpha; // alpha for transparencies |
|||
}; |
|||
|
|||
inline void CalculateNormal(half3 normalMap, LightweightVertexOutput i, out half3 normal) |
|||
{ |
|||
#if _NORMALMAP |
|||
normal = normalize(half3(dot(normalMap, i.tangentToWorld0), dot(normalMap, i.tangentToWorld1), dot(normalMap, i.tangentToWorld2))); |
|||
#else |
|||
normal = normalize(i.normal); |
|||
#endif |
|||
} |
|||
|
|||
inline half3 CalculateEmission(half2 uv) |
|||
{ |
|||
#ifndef _EMISSION |
|||
return 0; |
|||
#else |
|||
return LIGHTWEIGHT_GAMMA_TO_LINEAR(tex2D(_EmissionMap, uv).rgb) * _EmissionColor.rgb; |
|||
#endif |
|||
} |
|||
|
|||
inline half3 CalculateEmissionFastBlinn(half2 uv) |
|||
{ |
|||
#ifndef _EMISSION |
|||
return _EmissionColor.rgb; |
|||
#else |
|||
return LIGHTWEIGHT_GAMMA_TO_LINEAR(tex2D(_EmissionMap, uv).rgb) * _EmissionColor.rgb; |
|||
#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.rgb = LIGHTWEIGHT_GAMMA_TO_LINEAR(tex2D(_SpecGlossMap, uv).rgb) * _SpecColor.rgb; |
|||
specularGloss.a = alpha; |
|||
#else |
|||
specularGloss = _SpecColor; |
|||
#endif |
|||
} |
|||
|
|||
half4 MetallicSpecGloss(float2 uv, half albedoAlpha) |
|||
{ |
|||
half4 specGloss; |
|||
|
|||
#ifdef _METALLICSPECGLOSSMAP |
|||
#ifdef _SMOOTHNESS_TEXTURE_ALBEDO_CHANNEL_A |
|||
specGloss.rgb = tex2D(_MetallicSpecGlossMap, uv).rgb; |
|||
specGloss.a = albedoAlpha; |
|||
#else |
|||
specGloss = tex2D(_MetallicSpecGlossMap, uv).rgba; |
|||
#endif |
|||
specGloss.a *= _GlossMapScale; |
|||
|
|||
#else // _METALLICSPECGLOSSMAP |
|||
|
|||
#if _METALLIC_SETUP |
|||
specGloss.r = _Metallic; |
|||
#else |
|||
specGloss.rgb = _SpecColor.rgb; |
|||
#endif |
|||
|
|||
#ifdef _SMOOTHNESS_TEXTURE_ALBEDO_CHANNEL_A |
|||
specGloss.a = albedoAlpha * _GlossMapScale; |
|||
#else |
|||
specGloss.a = _Glossiness; |
|||
#endif |
|||
#endif |
|||
|
|||
return specGloss; |
|||
} |
|||
|
|||
#endif |
撰写
预览
正在加载...
取消
保存
Reference in new issue