浏览代码

Added support to directional lightmaps.

/Add-support-for-light-specular-color-tint
Felipe Lira 7 年前
当前提交
27111431
共有 6 个文件被更改,包括 367 次插入795 次删除
  1. 999
      ImageTemplates/LightweightPipeline/Scenes/010_MultiplePointLights.unity.png
  2. 21
      ScriptableRenderPipeline/LightweightPipeline/Shaders/LightweightCore.cginc
  3. 91
      ScriptableRenderPipeline/LightweightPipeline/Shaders/LightweightLighting.cginc
  4. 49
      ScriptableRenderPipeline/LightweightPipeline/Shaders/LightweightPassLit.cginc
  5. 1
      ScriptableRenderPipeline/LightweightPipeline/Shaders/LightweightStandard.shader
  6. 1
      ScriptableRenderPipeline/LightweightPipeline/Shaders/LightweightStandardSimpleLighting.shader

999
ImageTemplates/LightweightPipeline/Scenes/010_MultiplePointLights.unity.png
文件差异内容过多而无法显示
查看文件

21
ScriptableRenderPipeline/LightweightPipeline/Shaders/LightweightCore.cginc


half3 EvaluateSHPerVertex(half3 normalWS)
{
#if defined(EVALUATE_SH_FULLY_VERTEX)
#if defined(EVALUATE_SH_VERTEX)
#else
#endif
#endif
}
half3 EvaluateSHPerPixel(half3 normalWS, half3 L2Term)

#else
#endif
}
half3 SampleLightmap(float2 lightmapUV, half3 normalWS)
{
half4 encodedBakedColor = UNITY_SAMPLE_TEX2D(unity_Lightmap, lightmapUV);
half3 bakedColor = DecodeLightmap(encodedBakedColor);
#if DIRLIGHTMAP_COMBINED
half4 bakedDirection = UNITY_SAMPLE_TEX2D_SAMPLER(unity_LightmapInd, unity_Lightmap, lightmapUV);
bakedColor += DecodeDirectionalLightmap(bakedColor, bakedDirection, normalWS);
return bakedColor;
}
void OutputTangentToWorld(half4 vertexTangent, half3 vertexNormal, out half3 tangentWS, out half3 binormalWS, out half3 normalWS)

91
ScriptableRenderPipeline/LightweightPipeline/Shaders/LightweightLighting.cginc


#define UNITY_SPECCUBE_LOD_STEPS 6
#endif
#if SHADER_TARGET < 30
#define EVALUATE_SH_FULLY_VERTEX
#else
#define EVALUATE_SH_MIXED
#endif
#ifdef NO_LIGHTMAP
#undef LIGHTMAP_ON
#endif

#endif
// If lightmap is not defined than we evaluate GI (ambient + probes) from SH
// We might do it fully or partially in vertex to save shader ALU
#if !defined(LIGHTMAP_ON)
#if SHADER_TARGET < 30
// Evaluates SH fully in vertex
#define EVALUATE_SH_VERTEX
#else
// Evaluates L2 SH in vertex and L0L1 in pixel
#define EVALUATE_SH_MIXED
#endif
#endif
// Main light initialized without indexing

#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)
{
#ifdef _SPECULAR_SETUP

return c;
}
void LightweightGI(float4 lightmapUV, half4 ambient, half3 normalWS, half3 reflectVec, half occlusion, half perceptualRoughness, out half3 indirectDiffuse, out half3 indirectSpecular)
half3 GlossyEnvironment(half3 reflectVector, half perceptualRoughness)
{
#if !defined(_GLOSSYREFLECTIONS_OFF)
half roughness = perceptualRoughness * (1.7 - 0.7 * perceptualRoughness);
half mip = roughness * UNITY_SPECCUBE_LOD_STEPS;
half4 rgbm = UNITY_SAMPLE_TEXCUBE_LOD(unity_SpecCube0, reflectVector, mip);
return DecodeHDR(rgbm, unity_SpecCube0_HDR);
#endif
return _GlossyEnvironmentColor;
}
half3 DiffuseGI(float2 lightmapUV, half3 ambient, half3 normalWS)
indirectDiffuse = (DecodeLightmap(UNITY_SAMPLE_TEX2D(unity_Lightmap, lightmapUV.xy))) * occlusion;
#else
indirectDiffuse = EvaluateSHPerPixel(normalWS, ambient) * occlusion;
return SampleLightmap(lightmapUV, normalWS);
#ifndef _GLOSSYREFLECTIONS_OFF
indirectSpecular = GlossyEnvironment(UNITY_PASS_TEXCUBE(unity_SpecCube0), unity_SpecCube0_HDR, perceptualRoughness, reflectVec);
indirectSpecular *= occlusion;
#else
indirectSpecular = _GlossyEnvironmentColor * occlusion;
#endif
return EvaluateSHPerPixel(normalWS, ambient);
}
half SpotAttenuation(half3 spotDirection, half3 lightDirection, float4 attenuationParams)

#else
return ComputePixelLightAttenuation(lightInput, normal, worldPos, lightDirection);
#endif
}
inline half3 LightingLambert(half3 diffuseColor, half3 lightDir, half3 normal, half atten)
{
half NdotL = saturate(dot(normal, lightDir));
return diffuseColor * (NdotL * 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 halfVec = normalize(lightDir + viewDir);
half NdotH = saturate(dot(normal, halfVec));
half3 specular = specularGloss.rgb * pow(NdotH, shininess) * specularGloss.a;
return (diffuse + specular) * atten;
}
half4 LightweightFragmentPBR(half4 lightmapUV, float3 positionWS, half3 normalWS, half3 viewDirectionWS, half fogFactor, half4 ambient, half3 albedo, half metallic, half3 specular, half smoothness, half ambientOcclusion, half3 emission, half alpha)

half3 vertexNormal = normalWS;
half3 reflectVec = reflect(-viewDirectionWS, normalWS);
half roughness2 = brdfData.roughness * brdfData.roughness;
half3 indirectDiffuse;
half3 indirectSpecular;
LightweightGI(lightmapUV, ambient, normalWS, reflectVec, ambientOcclusion, brdfData.perceptualRoughness, indirectDiffuse, indirectSpecular);
half3 indirectDiffuse = DiffuseGI(lightmapUV.xy, ambient, normalWS) * ambientOcclusion;
half3 indirectSpecular = GlossyEnvironment(reflectVec, brdfData.perceptualRoughness) * ambientOcclusion;
// PBS
half fresnelTerm = _Pow4(1.0 - saturate(dot(normalWS, viewDirectionWS)));

// Computes fog factor per-vertex
ApplyFog(color, fogFactor);
return OutputColor(color, alpha);
}
inline half3 LightingLambert(half3 diffuseColor, half3 lightDir, half3 normal, half atten)
{
half NdotL = saturate(dot(normal, lightDir));
return diffuseColor * (NdotL * 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 halfVec = normalize(lightDir + viewDir);
half NdotH = saturate(dot(normal, halfVec));
half3 specular = specularGloss.rgb * pow(NdotH, shininess) * specularGloss.a;
return (diffuse + specular) * atten;
}
#endif

49
ScriptableRenderPipeline/LightweightPipeline/Shaders/LightweightPassLit.cginc


struct LightweightVertexOutput
{
float2 uv : TEXCOORD0;
float4 ambientOrLightmapUV : TEXCOORD1; // xy: lightmapUV, zw: dynamicLightmapUV OR color from SH
float4 posWS : TEXCOORD2;
float4 uv01 : TEXCOORD0; // xy: main UV, zw: lightmap UV (directional / non-directional)
float4 posWS : TEXCOORD1;
half3 tangent : TEXCOORD3;
half3 binormal : TEXCOORD4;
half3 normal : TEXCOORD5;
half3 tangent : TEXCOORD2;
half3 binormal : TEXCOORD3;
half3 normal : TEXCOORD4;
half3 normal : TEXCOORD3;
half3 normal : TEXCOORD2;
half4 viewDir : TEXCOORD6; // xyz: viewDir
half4 fogFactorAndVertexLight : TEXCOORD7; // x: fogFactor, yzw: vertex light
half4 viewDir : TEXCOORD5; // xyz: viewDir
half4 fogFactorAndVertexLight : TEXCOORD6; // x: fogFactor, yzw: vertex light
#if defined(EVALUATE_SH_VERTEX) || defined(EVALUATE_SH_MIXED)
half4 vertexSH : TEXCOORD7;
#endif
float4 clipPos : SV_POSITION;
UNITY_VERTEX_OUTPUT_STEREO
};

inline void InitializeStandardLitSurfaceData(LightweightVertexOutput IN, out SurfaceData outSurfaceData)
{
float2 uv = IN.uv;
float2 uv = IN.uv01.xy;
half4 albedoAlpha = tex2D(_MainTex, uv);
half4 specGloss = MetallicSpecGloss(uv, albedoAlpha);

void InitializeSurfaceInput(LightweightVertexOutput IN, out SurfaceInput outSurfaceInput)
{
#if LIGHTMAP_ON
outSurfaceInput.lightmapUV = float4(IN.ambientOrLightmapUV.xy, 0.0, 0.0);
outSurfaceInput.lightmapUV = float4(IN.uv01.zw, 0.0, 0.0);
outSurfaceInput.ambient = half4(IN.ambientOrLightmapUV);
outSurfaceInput.ambient = half4(IN.vertexSH);
#endif
#if _NORMALMAP

UNITY_SETUP_INSTANCE_ID(v);
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o);
o.uv = TRANSFORM_TEX(v.texcoord, _MainTex);
o.uv01.xy = TRANSFORM_TEX(v.texcoord, _MainTex);
#ifdef LIGHTMAP_ON
o.uv01.zw = v.lightmapUV * unity_LightmapST.xy + unity_LightmapST.zw;
#endif
float3 worldPos = mul(unity_ObjectToWorld, v.vertex).xyz;
o.posWS.xyz = worldPos;

o.normal = normalize(UnityObjectToWorldNormal(v.normal));
#endif
#ifdef LIGHTMAP_ON
o.ambientOrLightmapUV.xy = v.lightmapUV * unity_LightmapST.xy + unity_LightmapST.zw;
// TODO: Dynamic Lightmap
o.ambientOrLightmapUV.zw = float2(0.0, 0.0);
#else
o.ambientOrLightmapUV = half4(EvaluateSHPerVertex(o.normal), 0.0);
#if defined(EVALUATE_SH_VERTEX) || defined(EVALUATE_SH_MIXED)
o.vertexSH = half4(EvaluateSHPerVertex(o.normal), 0.0);
#endif
o.fogFactorAndVertexLight.yzw = half3(0.0h, 0.0h, 0.0h);

half4 LitPassFragmentSimple(LightweightVertexOutput IN) : SV_Target
{
float2 uv = IN.uv;
float2 uv = IN.uv01.xy;
float2 lightmapUV = IN.uv01.zw;
half4 diffuseAlpha = tex2D(_MainTex, uv);
half3 diffuse = LIGHTWEIGHT_GAMMA_TO_LINEAR(diffuseAlpha.rgb) * _Color.rgb;

half alpha = diffuseAlpha.a * _Color.a;
#endif
// Keep for compatibility reasons. Shader Inpector throws a warning when using cutoff
// due overdraw performance impact.
#ifdef _ALPHATEST_ON
clip(alpha - _Cutoff);
#endif

half3 lightDirection;
#if defined(LIGHTMAP_ON)
half3 color = DecodeLightmap(UNITY_SAMPLE_TEX2D(unity_Lightmap, IN.ambientOrLightmapUV.xy)) * diffuse;
half3 color = SampleLightmap(lightmapUV, normalWorld) * diffuse;
half3 ambient = IN.ambientOrLightmapUV.xyz;
half3 color = EvaluateSHPerPixel(normalWorld, ambient) * diffuse;
half3 color = EvaluateSHPerPixel(normalWorld, IN.vertexSH) * diffuse;
#endif
half shininess = _Shininess * 128.0h;

1
ScriptableRenderPipeline/LightweightPipeline/Shaders/LightweightStandard.shader


#pragma multi_compile _ _ADDITIONAL_LIGHTS
#pragma multi_compile _ UNITY_SINGLE_PASS_STEREO STEREO_INSTANCING_ON STEREO_MULTIVIEW_ON
#pragma multi_compile _ LIGHTMAP_ON
#pragma multi_compile _ DIRLIGHTMAP_COMBINED
#pragma multi_compile _ _HARD_SHADOWS _SOFT_SHADOWS _HARD_SHADOWS_CASCADES _SOFT_SHADOWS_CASCADES
#pragma multi_compile _ _VERTEX_LIGHTS

1
ScriptableRenderPipeline/LightweightPipeline/Shaders/LightweightStandardSimpleLighting.shader


#pragma multi_compile _ _ADDITIONAL_LIGHTS
#pragma multi_compile _ UNITY_SINGLE_PASS_STEREO STEREO_INSTANCING_ON STEREO_MULTIVIEW_ON
#pragma multi_compile _ LIGHTMAP_ON
#pragma multi_compile _ DIRLIGHTMAP_COMBINED
#pragma multi_compile _ _HARD_SHADOWS _SOFT_SHADOWS _HARD_SHADOWS_CASCADES _SOFT_SHADOWS_CASCADES
#pragma multi_compile _ _VERTEX_LIGHTS
#pragma multi_compile_fog

正在加载...
取消
保存