浏览代码

Removed UnityStandardInput and BRDF/Lighting dependencies.

/Add-support-for-light-specular-color-tint
Felipe Lira 7 年前
当前提交
dd386fd1
共有 5 个文件被更改,包括 104 次插入39 次删除
  1. 21
      ScriptableRenderPipeline/LightweightPipeline/Shaders/LightweightCore.cginc
  2. 50
      ScriptableRenderPipeline/LightweightPipeline/Shaders/LightweightLighting.cginc
  3. 33
      ScriptableRenderPipeline/LightweightPipeline/Shaders/LightweightPassLit.cginc
  4. 1
      ScriptableRenderPipeline/LightweightPipeline/Shaders/LightweightStandard.shader
  5. 38
      ScriptableRenderPipeline/LightweightPipeline/Shaders/LightweightStandardSimpleLighting.shader

21
ScriptableRenderPipeline/LightweightPipeline/Shaders/LightweightCore.cginc


#define LIGHTWEIGHT_LINEAR_TO_GAMMA(color) color
#endif
half Pow4(half x)
{
return x * x * x * x;
}
half LerpOneTo(half b, half t)
{
half oneMinusT = 1 - t;
return oneMinusT + b * t;
}
half3 SafeNormalize(half3 inVec)
{
half dp3 = max(1.e-4h, dot(inVec, inVec));
return inVec * rsqrt(dp3);
}
void OutputTangentToWorld(half4 vertexTangent, half3 vertexNormal, out half3 tangentWS, out half3 binormalWS, out half3 normalWS)
{
half sign = vertexTangent.w * unity_WorldTransformParams.w;

half4 OutputColor(half3 color, half alpha)
{
#if defined(_ALPHABLEND_ON) || defined(_ALPHAPREMULTIPLY_ON)
#else
return half4(LIGHTWEIGHT_LINEAR_TO_GAMMA(color), 1);
#endif
}
#endif

50
ScriptableRenderPipeline/LightweightPipeline/Shaders/LightweightLighting.cginc


#define PI 3.14159265359f
#define kDieletricSpec half4(0.04, 0.04, 0.04, 1.0 - 0.04) // standard dielectric reflectivity coef at incident angle (= 4%)
#ifndef UNITY_SPECCUBE_LOD_STEPS
#define UNITY_SPECCUBE_LOD_STEPS 6
#endif
// Main light initialized without indexing
#define INITIALIZE_MAIN_LIGHT(light) \
light.pos = _MainLightPosition; \

half4 unity_LightIndicesOffsetAndCount;
half4 unity_4LightIndices0;
half4 unity_4LightIndices1;
half _Shininess;
CBUFFER_END
CBUFFER_START(_PerCamera)

#endif
}
half3 GlossyEnvironment(UNITY_ARGS_TEXCUBE(tex), half4 hdr, half perceptualRoughness, half3 reflectVec)
{
perceptualRoughness = perceptualRoughness * (1.7 - 0.7 * perceptualRoughness);
half mip = perceptualRoughness * UNITY_SPECCUBE_LOD_STEPS;
half4 rgbm = UNITY_SAMPLE_TEXCUBE_LOD(tex, reflectVec, mip);
return DecodeHDR(rgbm, hdr);
}
inline void InitializeBRDFData(half3 albedo, half metallic, half3 specular, half smoothness, half alpha, out BRDFData outBRDFData)
{
// BRDF SETUP

half3 LightweightBDRF(BRDFData brdfData, half roughness2, half3 normal, half3 lightDirection, half3 viewDir)
{
#ifndef _SPECULARHIGHLIGHTS_OFF
half3 halfDir = Unity_SafeNormalize(lightDirection + viewDir);
half3 halfDir = SafeNormalize(lightDirection + viewDir);
half NoH = saturate(dot(normal, halfDir));
half LoH = saturate(dot(lightDirection, halfDir));

#endif
}
half3 LightweightBRDFIndirect(BRDFData brdfData, UnityIndirect indirect, half roughness2, half fresnelTerm)
half3 LightweightBRDFIndirect(BRDFData brdfData, half3 indirectDiffuse, half3 indirectSpecular, half roughness2, half fresnelTerm)
half3 c = indirect.diffuse * brdfData.diffuse;
half3 c = indirectDiffuse * brdfData.diffuse;
c += surfaceReduction * indirect.specular * lerp(brdfData.specular, brdfData.grazingTerm, fresnelTerm);
c += surfaceReduction * indirectSpecular * lerp(brdfData.specular, brdfData.grazingTerm, fresnelTerm);
UnityIndirect LightweightGI(float4 lightmapUV, half3 normalWorld, half3 reflectVec, half occlusion, half perceptualRoughness)
void LightweightGI(float4 lightmapUV, half3 normalWorld, half3 reflectVec, half occlusion, half perceptualRoughness, out half3 indirectDiffuse, out half3 indirectSpecular)
UnityIndirect o = (UnityIndirect)0;
o.diffuse += (DecodeLightmap(UNITY_SAMPLE_TEX2D(unity_Lightmap, lightmapUV.xy))) * occlusion;
indirectDiffuse = (DecodeLightmap(UNITY_SAMPLE_TEX2D(unity_Lightmap, lightmapUV.xy))) * occlusion;
o.diffuse = ShadeSH9(half4(normalWorld, 1.0)) * occlusion;
indirectDiffuse = ShadeSH9(half4(normalWorld, 1.0)) * occlusion;
Unity_GlossyEnvironmentData g;
g.roughness = perceptualRoughness;
g.reflUVW = reflectVec;
o.specular = Unity_GlossyEnvironment(UNITY_PASS_TEXCUBE(unity_SpecCube0), unity_SpecCube0_HDR, g) * occlusion;
indirectSpecular = GlossyEnvironment(UNITY_PASS_TEXCUBE(unity_SpecCube0), unity_SpecCube0_HDR, perceptualRoughness, reflectVec);
indirectSpecular *= occlusion;
o.specular = _GlossyEnvironmentColor * occlusion;
indirectSpecular = _GlossyEnvironmentColor * occlusion;
return o;
}
half SpotAttenuation(half3 spotDirection, half3 lightDirection, float4 attenuationParams)

return diffuseColor * (NdotL * atten);
}
inline half3 LightingBlinnPhong(half3 diffuseColor, half4 specularGloss, half3 lightDir, half3 normal, half3 viewDir, half atten)
inline half3 LightingBlinnPhong(half3 diffuseColor, half4 specularGloss, half3 lightDir, half3 normal, half3 viewDir, half atten, half shininess)
{
half NdotL = saturate(dot(normal, lightDir));
half3 diffuse = diffuseColor * NdotL;

half3 specular = specularGloss.rgb * pow(NdotH, _Shininess * 128.0) * specularGloss.a;
half3 specular = specularGloss.rgb * pow(NdotH, shininess) * specularGloss.a;
return (diffuse + specular) * atten;
}

half3 reflectVec = reflect(-viewDirectionWS, normalWS);
half roughness2 = brdfData.roughness * brdfData.roughness;
UnityIndirect indirectLight = LightweightGI(lightmapUV, normalWS, reflectVec, ambientOcclusion, brdfData.perceptualRoughness);
half3 indirectDiffuse;
half3 indirectSpecular;
LightweightGI(lightmapUV, normalWS, reflectVec, ambientOcclusion, brdfData.perceptualRoughness, indirectDiffuse, indirectSpecular);
half3 color = LightweightBRDFIndirect(brdfData, indirectLight, roughness2, fresnelTerm);
half3 color = LightweightBRDFIndirect(brdfData, indirectDiffuse, indirectSpecular, roughness2, fresnelTerm);
half3 lightDirectionWS;
LightInput light;

33
ScriptableRenderPipeline/LightweightPipeline/Shaders/LightweightPassLit.cginc


#define SAMPLE_METALLICSPECULAR(uv) tex2D(_MetallicGlossMap, uv)
#endif
half4 _Color;
sampler2D _MainTex; half4 _MainTex_ST;
half _Cutoff;
half _Glossiness;
half _GlossMapScale;
half _SmoothnessTextureChannel;
half _Metallic;
sampler2D _MetallicGlossMap;
half4 _SpecColor;
sampler2D _SpecGlossMap;
sampler2D _BumpMap;
half _OcclusionStrength;
sampler2D _OcclusionMap;
half4 _EmissionColor;
sampler2D _EmissionMap;
half _Shininess;
struct LightweightVertexInput
{
float4 vertex : POSITION;

return specGloss;
}
half OcclusionLW(float2 uv)
half Occlusion(float2 uv)
{
#ifdef _OCCLUSIONMAP
#if (SHADER_TARGET < 30)

#endif
}
half3 EmissionLW(float2 uv)
half3 Emission(float2 uv)
{
#ifndef _EMISSION
return 0;

outSurfaceData.smoothness = specGloss.a;
outSurfaceData.normal = Normal(uv);
outSurfaceData.occlusion = OcclusionLW(uv);
outSurfaceData.emission = EmissionLW(uv);
outSurfaceData.occlusion = Occlusion(uv);
outSurfaceData.emission = Emission(uv);
outSurfaceData.emission += IN.fogFactorAndVertexLight.yzw;
outSurfaceData.alpha = Alpha(albedoAlpha.a);
}

half3 color = (ShadeSH9(half4(normalWorld, 1.0)) + IN.ambientOrLightmapUV.xyz) * diffuse;
#endif
half shininess = _Shininess * 128.0h;
LightInput lightInput;
INITIALIZE_MAIN_LIGHT(lightInput);
half lightAtten = ComputeMainLightAttenuation(lightInput, normalWorld, worldPos, lightDirection);

color += LightingBlinnPhong(diffuse, specularGloss, lightDirection, normalWorld, viewDir, lightAtten) * lightInput.color;
color += LightingBlinnPhong(diffuse, specularGloss, lightDirection, normalWorld, viewDir, lightAtten, shininess) * lightInput.color;
#else
color += LightingLambert(diffuse, lightDirection, normalWorld, lightAtten) * lightInput.color;
#endif

half lightAtten = ComputePixelLightAttenuation(lightData, normalWorld, worldPos, lightDirection);
#if defined(_SPECGLOSSMAP) || defined(_SPECULAR_COLOR)
color += LightingBlinnPhong(diffuse, specularGloss, lightDirection, normalWorld, viewDir, lightAtten) * lightData.color;
color += LightingBlinnPhong(diffuse, specularGloss, lightDirection, normalWorld, viewDir, lightAtten, shininess) * lightData.color;
#else
color += LightingLambert(diffuse, lightDirection, normalWorld, lightAtten) * lightData.color;
#endif

color += EmissionLW(uv);
color += Emission(uv);
color += IN.fogFactorAndVertexLight.yzw;
// Computes Fog Factor per vextex

1
ScriptableRenderPipeline/LightweightPipeline/Shaders/LightweightStandard.shader


#pragma vertex LitPassVertex
#pragma fragment LitPassFragment
#include "UnityStandardInput.cginc"
#include "LightweightPassLit.cginc"
ENDCG
}

38
ScriptableRenderPipeline/LightweightPipeline/Shaders/LightweightStandardSimpleLighting.shader


#pragma vertex LitPassVertex
#pragma fragment LitPassFragmentSimple
#include "UnityStandardInput.cginc"
#include "LightweightPassLit.cginc"
ENDCG
}

CGPROGRAM
#define UNITY_SETUP_BRDF_INPUT SpecularSetup
#pragma vertex vert_meta
#pragma fragment frag_meta_ld
#pragma vertex LightweightVertexMeta
#pragma fragment LightweightFragmentMeta
#pragma shader_feature _EMISSION
#pragma shader_feature _SPECGLOSSMAP

#include "UnityStandardMeta.cginc"
#include "UnityMetaPass.cginc"
struct MetaVertexInput
{
float4 vertex : POSITION;
half3 normal : NORMAL;
float2 uv0 : TEXCOORD0;
float2 uv1 : TEXCOORD1;
float2 uv2 : TEXCOORD2;
#ifdef _TANGENT_TO_WORLD
half4 tangent : TANGENT;
#endif
UNITY_VERTEX_INPUT_INSTANCE_ID
};
fixed4 frag_meta_ld(v2f_meta i) : SV_Target
struct MetaVertexOuput
{
float4 pos : SV_POSITION;
float2 uv : TEXCOORD0;
};
MetaVertexOuput LightweightVertexMeta(MetaVertexInput v)
{
MetaVertexOuput o;
o.pos = UnityMetaVertexPosition(v.vertex, v.uv1.xy, v.uv2.xy, unity_LightmapST, unity_DynamicLightmapST);
o.uv = TRANSFORM_TEX(v.uv0, _MainTex);
return o;
}
fixed4 LightweightFragmentMeta(MetaVertexOuput i) : SV_Target
o.Albedo = Albedo(i.uv);
o.Albedo = _Color.rgb * tex2D(_MainTex, i.uv).rgb;
half4 specularColor;
SpecularGloss(i.uv.xy, 1.0, specularColor);

正在加载...
取消
保存