浏览代码
Merge branch 'LWRP' into lw/multipass
Merge branch 'LWRP' into lw/multipass
# Conflicts: # ScriptableRenderPipeline/LightweightPipeline/LWRP/LightweightPipeline.cs # ScriptableRenderPipeline/LightweightPipeline/LWRP/ShaderLibrary/LightweightPassLit.hlsl # ScriptableRenderPipeline/LightweightPipeline/LWRP/ShaderLibrary/LightweightPassLitSimple.hlsl # ScriptableRenderPipeline/LightweightPipeline/LWRP/ShaderLibrary/LightweightPassLitSimple.hlsl.meta # ScriptableRenderPipeline/LightweightPipeline/LWRP/Shaders/LightweightStandardSimpleLighting.shader/main
Felipe Lira
7 年前
当前提交
de8adb82
共有 39 个文件被更改,包括 599 次插入 和 352 次删除
-
16ScriptableRenderPipeline/Core/CoreRP/Editor/Debugging/DebugWindow.cs
-
51ScriptableRenderPipeline/Core/CoreRP/Editor/MaterialUpgrader.cs
-
7ScriptableRenderPipeline/LightweightPipeline/LWRP/Editor/ShaderGraph/lightweightPBRExtraPasses.template
-
4ScriptableRenderPipeline/LightweightPipeline/LWRP/Editor/ShaderGraph/lightweightUnlitExtraPasses.template
-
4ScriptableRenderPipeline/LightweightPipeline/LWRP/Editor/ShaderGraph/lightweightUnlitPass.template
-
2ScriptableRenderPipeline/LightweightPipeline/LWRP/LightweightConstantBuffer.cs
-
103ScriptableRenderPipeline/LightweightPipeline/LWRP/LightweightPipeline.cs
-
5ScriptableRenderPipeline/LightweightPipeline/LWRP/ShaderLibrary/Core.hlsl
-
2ScriptableRenderPipeline/LightweightPipeline/LWRP/ShaderLibrary/Input.hlsl
-
5ScriptableRenderPipeline/LightweightPipeline/LWRP/ShaderLibrary/LightweightPassDepthOnly.hlsl
-
9ScriptableRenderPipeline/LightweightPipeline/LWRP/ShaderLibrary/LightweightPassLit.hlsl
-
16ScriptableRenderPipeline/LightweightPipeline/LWRP/ShaderLibrary/LightweightPassLitSimple.hlsl
-
5ScriptableRenderPipeline/LightweightPipeline/LWRP/ShaderLibrary/LightweightPassShadow.hlsl
-
84ScriptableRenderPipeline/LightweightPipeline/LWRP/ShaderLibrary/Particles.hlsl
-
30ScriptableRenderPipeline/LightweightPipeline/LWRP/ShaderLibrary/LightweightPassMetaCommon.hlsl
-
10ScriptableRenderPipeline/LightweightPipeline/LWRP/Shaders/LightweightStandard.shader
-
4ScriptableRenderPipeline/LightweightPipeline/LWRP/Shaders/LightweightStandardParticles.shader
-
13ScriptableRenderPipeline/LightweightPipeline/LWRP/Shaders/LightweightStandardParticlesSimpleLighting.shader
-
8ScriptableRenderPipeline/LightweightPipeline/LWRP/Shaders/LightweightStandardParticlesUnlit.shader
-
11ScriptableRenderPipeline/LightweightPipeline/LWRP/Shaders/LightweightStandardSimpleLighting.shader
-
2ScriptableRenderPipeline/LightweightPipeline/LWRP/Shaders/LightweightStandardTerrain.shader
-
39ScriptableRenderPipeline/LightweightPipeline/LWRP/Shaders/LightweightStandardUnlit.shader
-
71ScriptableRenderPipeline/LightweightPipeline/LWRP/ShaderLibrary/InputSurfaceCommon.hlsl
-
97ScriptableRenderPipeline/LightweightPipeline/LWRP/ShaderLibrary/InputSurfacePBR.hlsl
-
9ScriptableRenderPipeline/LightweightPipeline/LWRP/ShaderLibrary/InputSurfacePBR.hlsl.meta
-
33ScriptableRenderPipeline/LightweightPipeline/LWRP/ShaderLibrary/InputSurfaceSimple.hlsl
-
9ScriptableRenderPipeline/LightweightPipeline/LWRP/ShaderLibrary/InputSurfaceSimple.hlsl.meta
-
15ScriptableRenderPipeline/LightweightPipeline/LWRP/ShaderLibrary/InputSurfaceUnlit.hlsl
-
9ScriptableRenderPipeline/LightweightPipeline/LWRP/ShaderLibrary/InputSurfaceUnlit.hlsl.meta
-
22ScriptableRenderPipeline/LightweightPipeline/LWRP/ShaderLibrary/LightweightPassMetaPBR.hlsl
-
9ScriptableRenderPipeline/LightweightPipeline/LWRP/ShaderLibrary/LightweightPassMetaPBR.hlsl.meta
-
17ScriptableRenderPipeline/LightweightPipeline/LWRP/ShaderLibrary/LightweightPassMetaSimple.hlsl
-
9ScriptableRenderPipeline/LightweightPipeline/LWRP/ShaderLibrary/LightweightPassMetaSimple.hlsl.meta
-
33ScriptableRenderPipeline/LightweightPipeline/LWRP/ShaderLibrary/ParticlesPBR.hlsl
-
9ScriptableRenderPipeline/LightweightPipeline/LWRP/ShaderLibrary/ParticlesPBR.hlsl.meta
-
179ScriptableRenderPipeline/LightweightPipeline/LWRP/ShaderLibrary/InputSurface.hlsl
-
0/ScriptableRenderPipeline/LightweightPipeline/LWRP/ShaderLibrary/LightweightPassMetaCommon.hlsl.meta
-
0/ScriptableRenderPipeline/LightweightPipeline/LWRP/ShaderLibrary/LightweightPassMetaCommon.hlsl
-
0/ScriptableRenderPipeline/LightweightPipeline/LWRP/ShaderLibrary/InputSurfaceCommon.hlsl.meta
|
|||
#ifndef LIGHTWEIGHT_INPUT_SURFACE_COMMON_INCLUDED |
|||
#define LIGHTWEIGHT_INPUT_SURFACE_COMMON_INCLUDED |
|||
|
|||
#include "Core.hlsl" |
|||
#include "CoreRP/ShaderLibrary/Packing.hlsl" |
|||
#include "CoreRP/ShaderLibrary/CommonMaterial.hlsl" |
|||
|
|||
TEXTURE2D(_MainTex); SAMPLER(sampler_MainTex); |
|||
TEXTURE2D(_BumpMap); SAMPLER(sampler_BumpMap); |
|||
TEXTURE2D(_EmissionMap); SAMPLER(sampler_EmissionMap); |
|||
|
|||
// Must match Lightweigth ShaderGraph master node |
|||
struct SurfaceData |
|||
{ |
|||
half3 albedo; |
|||
half3 specular; |
|||
half metallic; |
|||
half smoothness; |
|||
half3 normalTS; |
|||
half3 emission; |
|||
half occlusion; |
|||
half alpha; |
|||
}; |
|||
|
|||
/////////////////////////////////////////////////////////////////////////////// |
|||
// Material Property Helpers // |
|||
/////////////////////////////////////////////////////////////////////////////// |
|||
half Alpha(half albedoAlpha, half4 color, half cutoff) |
|||
{ |
|||
#if !defined(_SMOOTHNESS_TEXTURE_ALBEDO_CHANNEL_A) && !defined(_GLOSSINESS_FROM_BASE_ALPHA) |
|||
half alpha = albedoAlpha * color.a; |
|||
#else |
|||
half alpha = color.a; |
|||
#endif |
|||
|
|||
#if defined(_ALPHATEST_ON) |
|||
clip(alpha - cutoff); |
|||
#endif |
|||
|
|||
return alpha; |
|||
} |
|||
|
|||
half4 SampleAlbedoAlpha(float2 uv, TEXTURE2D_ARGS(albedoAlphaMap, sampler_albedoAlphaMap)) |
|||
{ |
|||
return SAMPLE_TEXTURE2D(albedoAlphaMap, sampler_albedoAlphaMap, uv); |
|||
} |
|||
|
|||
half3 SampleNormal(float2 uv, TEXTURE2D_ARGS(bumpMap, sampler_bumpMap), half scale = 1.0h) |
|||
{ |
|||
#if _NORMALMAP |
|||
half4 n = SAMPLE_TEXTURE2D(bumpMap, sampler_bumpMap, uv); |
|||
#if BUMP_SCALE_NOT_SUPPORTED |
|||
return UnpackNormal(n); |
|||
#else |
|||
return UnpackNormalScale(n, scale); |
|||
#endif |
|||
#else |
|||
return half3(0.0h, 0.0h, 1.0h); |
|||
#endif |
|||
} |
|||
|
|||
half3 SampleEmission(float2 uv, half3 emissionColor, TEXTURE2D_ARGS(emissionMap, sampler_emissionMap)) |
|||
{ |
|||
#ifndef _EMISSION |
|||
return 0; |
|||
#else |
|||
return SAMPLE_TEXTURE2D(emissionMap, sampler_emissionMap, uv).rgb * emissionColor; |
|||
#endif |
|||
} |
|||
|
|||
#endif // LIGHTWEIGHT_INPUT_SURFACE_COMMON_INCLUDED |
|
|||
#ifndef LIGHTWEIGHT_INPUT_SURFACE_PBR_INCLUDED |
|||
#define LIGHTWEIGHT_INPUT_SURFACE_PBR_INCLUDED |
|||
|
|||
#include "Core.hlsl" |
|||
#include "CoreRP/ShaderLibrary/CommonMaterial.hlsl" |
|||
#include "InputSurfaceCommon.hlsl" |
|||
|
|||
CBUFFER_START(UnityPerMaterial) |
|||
float4 _MainTex_ST; |
|||
half4 _Color; |
|||
half4 _SpecColor; |
|||
half4 _EmissionColor; |
|||
half _Cutoff; |
|||
half _Glossiness; |
|||
half _GlossMapScale; |
|||
half _Metallic; |
|||
half _BumpScale; |
|||
half _OcclusionStrength; |
|||
CBUFFER_END |
|||
|
|||
TEXTURE2D(_OcclusionMap); SAMPLER(sampler_OcclusionMap); |
|||
TEXTURE2D(_MetallicGlossMap); SAMPLER(sampler_MetallicGlossMap); |
|||
TEXTURE2D(_SpecGlossMap); SAMPLER(sampler_SpecGlossMap); |
|||
|
|||
#ifdef _SPECULAR_SETUP |
|||
#define SAMPLE_METALLICSPECULAR(uv) SAMPLE_TEXTURE2D(_SpecGlossMap, sampler_SpecGlossMap, uv) |
|||
#else |
|||
#define SAMPLE_METALLICSPECULAR(uv) SAMPLE_TEXTURE2D(_MetallicGlossMap, sampler_MetallicGlossMap, uv) |
|||
#endif |
|||
|
|||
half4 SampleMetallicSpecGloss(float2 uv, half albedoAlpha) |
|||
{ |
|||
half4 specGloss; |
|||
|
|||
#ifdef _METALLICSPECGLOSSMAP |
|||
specGloss = SAMPLE_METALLICSPECULAR(uv); |
|||
#ifdef _SMOOTHNESS_TEXTURE_ALBEDO_CHANNEL_A |
|||
specGloss.a = albedoAlpha * _GlossMapScale; |
|||
#else |
|||
specGloss.a *= _GlossMapScale; |
|||
#endif |
|||
#else // _METALLICSPECGLOSSMAP |
|||
#if _SPECULAR_SETUP |
|||
specGloss.rgb = _SpecColor.rgb; |
|||
#else |
|||
specGloss.rgb = _Metallic.rrr; |
|||
#endif |
|||
|
|||
#ifdef _SMOOTHNESS_TEXTURE_ALBEDO_CHANNEL_A |
|||
specGloss.a = albedoAlpha * _GlossMapScale; |
|||
#else |
|||
specGloss.a = _Glossiness; |
|||
#endif |
|||
#endif |
|||
|
|||
return specGloss; |
|||
} |
|||
|
|||
half SampleOcclusion(float2 uv) |
|||
{ |
|||
#ifdef _OCCLUSIONMAP |
|||
#if (SHADER_TARGET < 30) |
|||
// SM20: instruction count limitation |
|||
// SM20: simpler occlusion |
|||
return SAMPLE_TEXTURE2D(_OcclusionMap, sampler_OcclusionMap, uv).g; |
|||
#else |
|||
half occ = SAMPLE_TEXTURE2D(_OcclusionMap, sampler_OcclusionMap, uv).g; |
|||
return LerpWhiteTo(occ, _OcclusionStrength); |
|||
#endif |
|||
#else |
|||
return 1.0; |
|||
#endif |
|||
} |
|||
|
|||
inline void InitializeStandardLitSurfaceData(float2 uv, out SurfaceData outSurfaceData) |
|||
{ |
|||
half4 albedoAlpha = SampleAlbedoAlpha(uv, TEXTURE2D_PARAM(_MainTex, sampler_MainTex)); |
|||
outSurfaceData.alpha = Alpha(albedoAlpha.a, _Color, _Cutoff); |
|||
|
|||
half4 specGloss = SampleMetallicSpecGloss(uv, albedoAlpha.a); |
|||
outSurfaceData.albedo = albedoAlpha.rgb * _Color.rgb; |
|||
|
|||
#if _SPECULAR_SETUP |
|||
outSurfaceData.metallic = 1.0h; |
|||
outSurfaceData.specular = specGloss.rgb; |
|||
#else |
|||
outSurfaceData.metallic = specGloss.r; |
|||
outSurfaceData.specular = half3(0.0h, 0.0h, 0.0h); |
|||
#endif |
|||
|
|||
outSurfaceData.smoothness = specGloss.a; |
|||
outSurfaceData.normalTS = SampleNormal(uv, TEXTURE2D_PARAM(_BumpMap, sampler_BumpMap), _BumpScale); |
|||
outSurfaceData.occlusion = SampleOcclusion(uv); |
|||
outSurfaceData.emission = SampleEmission(uv, _EmissionColor.rgb, TEXTURE2D_PARAM(_EmissionMap, sampler_EmissionMap)); |
|||
} |
|||
|
|||
#endif // LIGHTWEIGHT_INPUT_SURFACE_PBR_INCLUDED |
|
|||
fileFormatVersion: 2 |
|||
guid: c46f85bf266d7496d9b3659acfbdc711 |
|||
ShaderImporter: |
|||
externalObjects: {} |
|||
defaultTextures: [] |
|||
nonModifiableTextures: [] |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
#ifndef LIGHTWEIGHT_INPUT_SURFACE_SIMPLE_INCLUDED |
|||
#define LIGHTWEIGHT_INPUT_SURFACE_SIMPLE_INCLUDED |
|||
|
|||
#include "Core.hlsl" |
|||
#include "InputSurfaceCommon.hlsl" |
|||
|
|||
CBUFFER_START(UnityPerMaterial) |
|||
float4 _MainTex_ST; |
|||
half4 _Color; |
|||
half4 _SpecColor; |
|||
half4 _EmissionColor; |
|||
half _Cutoff; |
|||
half _Shininess; |
|||
CBUFFER_END |
|||
|
|||
TEXTURE2D(_SpecGlossMap); SAMPLER(sampler_SpecGlossMap); |
|||
|
|||
half4 SampleSpecularGloss(half2 uv, half alpha, half4 specColor, TEXTURE2D_ARGS(specGlossMap, sampler_specGlossMap)) |
|||
{ |
|||
half4 specularGloss = half4(0.0h, 0.0h, 0.0h, 1.0h); |
|||
#ifdef _SPECGLOSSMAP |
|||
specularGloss = SAMPLE_TEXTURE2D(TEXTURE2D_PARAM(specGlossMap, sampler_specGlossMap), uv); |
|||
#elif defined(_SPECULAR_COLOR) |
|||
specularGloss = specColor; |
|||
#endif |
|||
|
|||
#ifdef _GLOSSINESS_FROM_BASE_ALPHA |
|||
specularGloss.a = alpha; |
|||
#endif |
|||
return specularGloss; |
|||
} |
|||
|
|||
#endif // LIGHTWEIGHT_INPUT_SURFACE_SIMPLE_INCLUDED |
|
|||
fileFormatVersion: 2 |
|||
guid: ad863d097888f42c6bcf419efb2946c5 |
|||
ShaderImporter: |
|||
externalObjects: {} |
|||
defaultTextures: [] |
|||
nonModifiableTextures: [] |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
#ifndef LIGHTWEIGHT_INPUT_SURFACE_UNLIT_INCLUDED |
|||
#define LIGHTWEIGHT_INPUT_SURFACE_UNLIT_INCLUDED |
|||
|
|||
#include "Core.hlsl" |
|||
#include "InputSurfaceCommon.hlsl" |
|||
|
|||
CBUFFER_START(UnityPerMaterial) |
|||
float4 _MainTex_ST; |
|||
half4 _Color; |
|||
half _Cutoff; |
|||
half _Glossiness; |
|||
half _Metallic; |
|||
CBUFFER_END |
|||
|
|||
#endif // LIGHTWEIGHT_INPUT_SURFACE_UNLIT_INCLUDED |
|
|||
fileFormatVersion: 2 |
|||
guid: e7ba75cc852b14b7f934978b5697bf1b |
|||
ShaderImporter: |
|||
externalObjects: {} |
|||
defaultTextures: [] |
|||
nonModifiableTextures: [] |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
#ifndef LIGHTWEIGHT_PASS_META_PBR_INCLUDED |
|||
#define LIGHTWEIGHT_PASS_META_PBR_INCLUDED |
|||
|
|||
#include "LightweightPassMetaCommon.hlsl" |
|||
|
|||
half4 LightweightFragmentMeta(MetaVertexOuput i) : SV_Target |
|||
{ |
|||
SurfaceData surfaceData; |
|||
InitializeStandardLitSurfaceData(i.uv, surfaceData); |
|||
|
|||
BRDFData brdfData; |
|||
InitializeBRDFData(surfaceData.albedo, surfaceData.metallic, surfaceData.specular, surfaceData.smoothness, surfaceData.alpha, brdfData); |
|||
|
|||
MetaInput o; |
|||
o.Albedo = brdfData.diffuse + brdfData.specular * brdfData.roughness * 0.5; |
|||
o.SpecularColor = surfaceData.specular; |
|||
o.Emission = surfaceData.emission; |
|||
|
|||
return MetaFragment(o); |
|||
} |
|||
|
|||
#endif // LIGHTWEIGHT_PASS_META_PBR_INCLUDED |
|
|||
fileFormatVersion: 2 |
|||
guid: dcf4e762d48204e33b575f8007e3d563 |
|||
ShaderImporter: |
|||
externalObjects: {} |
|||
defaultTextures: [] |
|||
nonModifiableTextures: [] |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
#ifndef LIGHTWEIGHT_PASS_META_SIMPLE_INCLUDED |
|||
#define LIGHTWEIGHT_PASS_META_SIMPLE_INCLUDED |
|||
|
|||
#include "LightweightPassMetaCommon.hlsl" |
|||
|
|||
half4 LightweightFragmentMetaSimple(MetaVertexOuput i) : SV_Target |
|||
{ |
|||
float2 uv = i.uv; |
|||
MetaInput o; |
|||
o.Albedo = _Color.rgb * SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, uv).rgb; |
|||
o.SpecularColor = SampleSpecularGloss(uv, 1.0h, _SpecColor, TEXTURE2D_PARAM(_SpecGlossMap, sampler_SpecGlossMap)).xyz; |
|||
o.Emission = SampleEmission(uv, _EmissionColor.rgb, TEXTURE2D_PARAM(_EmissionMap, sampler_EmissionMap)); |
|||
|
|||
return MetaFragment(o); |
|||
} |
|||
|
|||
#endif // LIGHTWEIGHT_PASS_META_SIMPLE_INCLUDED |
|
|||
fileFormatVersion: 2 |
|||
guid: ffc632d1e38ef4682807a89afb2b966f |
|||
ShaderImporter: |
|||
externalObjects: {} |
|||
defaultTextures: [] |
|||
nonModifiableTextures: [] |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
#ifndef LIGHTWEIGHT_PARTICLES_PBR_INCLUDED |
|||
#define LIGHTWEIGHT_PARTICLES_PBR_INCLUDED |
|||
|
|||
#include "Particles.hlsl" |
|||
|
|||
TEXTURE2D(_MetallicGlossMap); SAMPLER(sampler_MetallicGlossMap); |
|||
|
|||
void InitializeSurfaceData(VertexOutputLit IN, out SurfaceData surfaceData) |
|||
{ |
|||
half4 albedo = SampleAlbedo(IN, TEXTURE2D_PARAM(_MainTex, sampler_MainTex)); |
|||
|
|||
#if defined(_METALLICGLOSSMAP) |
|||
half2 metallicGloss = readTexture(TEXTURE2D_PARAM(_MetallicGlossMap, sampler_MetallicGlossMap), IN).ra * half2(1.0, _Glossiness); |
|||
#else |
|||
half2 metallicGloss = half2(_Metallic, _Glossiness); |
|||
#endif |
|||
|
|||
half3 normalTS = SampleNormalTS(IN, TEXTURE2D_PARAM(_BumpMap, sampler_BumpMap), _BumpScale); |
|||
half3 emission = SampleEmission(IN, _EmissionColor.rgb, TEXTURE2D_PARAM(_EmissionMap, sampler_EmissionMap)); |
|||
|
|||
surfaceData.albedo = albedo.rgb; |
|||
surfaceData.specular = half3(0.0h, 0.0h, 0.0h); |
|||
surfaceData.normalTS = normalTS; |
|||
surfaceData.emission = emission; |
|||
surfaceData.metallic = metallicGloss.r; |
|||
surfaceData.smoothness = metallicGloss.g; |
|||
surfaceData.occlusion = 1.0; |
|||
|
|||
surfaceData.alpha = AlphaBlendAndTest(albedo.a, _Cutoff); |
|||
surfaceData.albedo = AlphaModulate(surfaceData.albedo, surfaceData.alpha); |
|||
} |
|||
|
|||
#endif // LIGHTWEIGHT_PARTICLES_PBR_INCLUDED |
|
|||
fileFormatVersion: 2 |
|||
guid: a3129e299d0744bb7bd42c2cea7cea2b |
|||
ShaderImporter: |
|||
externalObjects: {} |
|||
defaultTextures: [] |
|||
nonModifiableTextures: [] |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
#ifndef LIGHTWEIGHT_SURFACE_INPUT_INCLUDED |
|||
#define LIGHTWEIGHT_SURFACE_INPUT_INCLUDED |
|||
|
|||
#include "Core.hlsl" |
|||
#include "CoreRP/ShaderLibrary/Packing.hlsl" |
|||
#include "CoreRP/ShaderLibrary/CommonMaterial.hlsl" |
|||
|
|||
#ifdef _SPECULAR_SETUP |
|||
#define SAMPLE_METALLICSPECULAR(uv) SAMPLE_TEXTURE2D(_SpecGlossMap, sampler_SpecGlossMap, uv) |
|||
#else |
|||
#define SAMPLE_METALLICSPECULAR(uv) SAMPLE_TEXTURE2D(_MetallicGlossMap, sampler_MetallicGlossMap, uv) |
|||
#endif |
|||
|
|||
CBUFFER_START(UnityPerMaterial) |
|||
float4 _MainTex_ST; |
|||
half4 _Color; |
|||
half4 _SpecColor; |
|||
half4 _EmissionColor; |
|||
half _Cutoff; |
|||
half _Glossiness; |
|||
half _GlossMapScale; |
|||
half _Metallic; |
|||
half _BumpScale; |
|||
half _OcclusionStrength; |
|||
half _Shininess; |
|||
CBUFFER_END |
|||
|
|||
TEXTURE2D(_MainTex); SAMPLER(sampler_MainTex); |
|||
TEXTURE2D(_MetallicGlossMap); SAMPLER(sampler_MetallicGlossMap); |
|||
TEXTURE2D(_SpecGlossMap); SAMPLER(sampler_SpecGlossMap); |
|||
TEXTURE2D(_BumpMap); SAMPLER(sampler_BumpMap); |
|||
TEXTURE2D(_OcclusionMap); SAMPLER(sampler_OcclusionMap); |
|||
TEXTURE2D(_EmissionMap); SAMPLER(sampler_EmissionMap); |
|||
|
|||
// Must match Lightweigth ShaderGraph master node |
|||
struct SurfaceData |
|||
{ |
|||
half3 albedo; |
|||
half3 specular; |
|||
half metallic; |
|||
half smoothness; |
|||
half3 normalTS; |
|||
half3 emission; |
|||
half occlusion; |
|||
half alpha; |
|||
}; |
|||
|
|||
/////////////////////////////////////////////////////////////////////////////// |
|||
// Material Property Helpers // |
|||
/////////////////////////////////////////////////////////////////////////////// |
|||
float2 TransformMainTextureCoord(float2 uv) |
|||
{ |
|||
return TRANSFORM_TEX(uv, _MainTex); |
|||
} |
|||
|
|||
half Alpha(half albedoAlpha) |
|||
{ |
|||
#if !defined(_SMOOTHNESS_TEXTURE_ALBEDO_CHANNEL_A) && !defined(_GLOSSINESS_FROM_BASE_ALPHA) |
|||
half alpha = albedoAlpha * _Color.a; |
|||
#else |
|||
half alpha = _Color.a; |
|||
#endif |
|||
|
|||
#if defined(_ALPHATEST_ON) |
|||
clip(alpha - _Cutoff); |
|||
#endif |
|||
|
|||
return alpha; |
|||
} |
|||
|
|||
half4 MainTexture(float2 uv) |
|||
{ |
|||
return SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, uv); |
|||
} |
|||
|
|||
half3 Normal(float2 uv) |
|||
{ |
|||
#if _NORMALMAP |
|||
#if BUMP_SCALE_NOT_SUPPORTED |
|||
return UnpackNormal(SAMPLE_TEXTURE2D(_BumpMap, sampler_BumpMap, uv)); |
|||
#else |
|||
return UnpackNormalScale(SAMPLE_TEXTURE2D(_BumpMap, sampler_BumpMap, uv), _BumpScale); |
|||
#endif |
|||
#else |
|||
return half3(0.0h, 0.0h, 1.0h); |
|||
#endif |
|||
} |
|||
|
|||
half4 SpecularGloss(half2 uv, half alpha) |
|||
{ |
|||
half4 specularGloss = half4(0, 0, 0, 1); |
|||
#ifdef _SPECGLOSSMAP |
|||
specularGloss = SAMPLE_TEXTURE2D(_SpecGlossMap, sampler_SpecGlossMap, uv); |
|||
#elif defined(_SPECULAR_COLOR) |
|||
specularGloss = _SpecColor; |
|||
#endif |
|||
|
|||
#ifdef _GLOSSINESS_FROM_BASE_ALPHA |
|||
specularGloss.a = alpha; |
|||
#endif |
|||
return specularGloss; |
|||
} |
|||
|
|||
half4 MetallicSpecGloss(float2 uv, half albedoAlpha) |
|||
{ |
|||
half4 specGloss; |
|||
|
|||
#ifdef _METALLICSPECGLOSSMAP |
|||
specGloss = SAMPLE_METALLICSPECULAR(uv); |
|||
#ifdef _SMOOTHNESS_TEXTURE_ALBEDO_CHANNEL_A |
|||
specGloss.a = albedoAlpha * _GlossMapScale; |
|||
#else |
|||
specGloss.a *= _GlossMapScale; |
|||
#endif |
|||
#else // _METALLICSPECGLOSSMAP |
|||
#if _SPECULAR_SETUP |
|||
specGloss.rgb = _SpecColor.rgb; |
|||
#else |
|||
specGloss.rgb = _Metallic.rrr; |
|||
#endif |
|||
|
|||
#ifdef _SMOOTHNESS_TEXTURE_ALBEDO_CHANNEL_A |
|||
specGloss.a = albedoAlpha * _GlossMapScale; |
|||
#else |
|||
specGloss.a = _Glossiness; |
|||
#endif |
|||
#endif |
|||
|
|||
return specGloss; |
|||
} |
|||
|
|||
half Occlusion(float2 uv) |
|||
{ |
|||
#ifdef _OCCLUSIONMAP |
|||
#if (SHADER_TARGET < 30) |
|||
// SM20: instruction count limitation |
|||
// SM20: simpler occlusion |
|||
return SAMPLE_TEXTURE2D(_OcclusionMap, sampler_OcclusionMap, uv).g; |
|||
#else |
|||
half occ = SAMPLE_TEXTURE2D(_OcclusionMap, sampler_OcclusionMap, uv).g; |
|||
return LerpWhiteTo(occ, _OcclusionStrength); |
|||
#endif |
|||
#else |
|||
return 1.0; |
|||
#endif |
|||
} |
|||
|
|||
half3 Emission(float2 uv) |
|||
{ |
|||
#ifndef _EMISSION |
|||
return 0; |
|||
#else |
|||
return SAMPLE_TEXTURE2D(_EmissionMap, sampler_EmissionMap, uv).rgb * _EmissionColor.rgb; |
|||
#endif |
|||
} |
|||
|
|||
inline void InitializeStandardLitSurfaceData(float2 uv, out SurfaceData outSurfaceData) |
|||
{ |
|||
half4 albedoAlpha = MainTexture(uv); |
|||
|
|||
half4 specGloss = MetallicSpecGloss(uv, albedoAlpha.a); |
|||
outSurfaceData.albedo = albedoAlpha.rgb * _Color.rgb; |
|||
|
|||
#if _SPECULAR_SETUP |
|||
outSurfaceData.metallic = 1.0h; |
|||
outSurfaceData.specular = specGloss.rgb; |
|||
#else |
|||
outSurfaceData.metallic = specGloss.r; |
|||
outSurfaceData.specular = half3(0.0h, 0.0h, 0.0h); |
|||
#endif |
|||
|
|||
outSurfaceData.smoothness = specGloss.a; |
|||
outSurfaceData.normalTS = Normal(uv); |
|||
outSurfaceData.occlusion = Occlusion(uv); |
|||
outSurfaceData.emission = Emission(uv); |
|||
outSurfaceData.alpha = Alpha(albedoAlpha.a); |
|||
} |
|||
|
|||
#endif |
撰写
预览
正在加载...
取消
保存
Reference in new issue