浏览代码

Removed diffuse GI computation from fragment function. When using shader graph, templates must use the helper GI functions to compute diffuse GI.

/Add-support-for-light-specular-color-tint
Felipe Lira 7 年前
当前提交
e97d8b34
共有 4 个文件被更改,包括 29 次插入65 次删除
  1. 5
      ScriptableRenderPipeline/LightweightPipeline/Shaders/LightweightCore.cginc
  2. 23
      ScriptableRenderPipeline/LightweightPipeline/Shaders/LightweightLighting.cginc
  3. 61
      ScriptableRenderPipeline/LightweightPipeline/Shaders/LightweightPassLit.cginc
  4. 5
      ScriptableRenderPipeline/LightweightPipeline/Shaders/LightweightStandardParticles.shader

5
ScriptableRenderPipeline/LightweightPipeline/Shaders/LightweightCore.cginc


return half3(0.0, 0.0, 0.0);
}
half3 EvaluateSHPerPixel(half3 normalWS)
{
return max(half3(0, 0, 0), ShadeSH9(half4(normalWS, 1.0)));
}
half3 EvaluateSHPerPixel(half3 normalWS, half3 L2Term)
{
#ifdef EVALUATE_SH_MIXED

23
ScriptableRenderPipeline/LightweightPipeline/Shaders/LightweightLighting.cginc


#define UNITY_SPECCUBE_LOD_STEPS 6
#endif
#ifdef NO_LIGHTMAP
#undef LIGHTMAP_ON
#endif
#ifdef NO_ADDITIONAL_LIGHTS
#undef _ADDITIONAL_LIGHTS
#endif

#endif
}
half3 LightweightBRDFIndirect(BRDFData brdfData, half3 indirectDiffuse, half3 indirectSpecular, half roughness2, half fresnelTerm)
half3 LightweightEnvironmentBRDF(BRDFData brdfData, half3 indirectDiffuse, half3 indirectSpecular, half roughness2, half fresnelTerm)
{
half3 c = indirectDiffuse * brdfData.diffuse;
float surfaceReduction = 1.0 / (roughness2 + 1.0);

#endif
return _GlossyEnvironmentColor;
}
half3 DiffuseGI(float2 lightmapUV, half3 ambient, half3 normalWS)
{
#ifdef LIGHTMAP_ON
return SampleLightmap(lightmapUV, normalWS);
#endif
return EvaluateSHPerPixel(normalWS, ambient);
}
half SpotAttenuation(half3 spotDirection, half3 lightDirection, float4 attenuationParams)

#endif
}
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)
half4 LightweightFragmentPBR(float3 positionWS, half3 normalWS, half3 viewDirectionWS, half fogFactor, half3 diffuseGI, half3 albedo, half metallic, half3 specular, half smoothness, half occlusion, half3 emission, half alpha)
{
BRDFData brdfData;
InitializeBRDFData(albedo, metallic, specular, smoothness, alpha, brdfData);

half3 reflectVec = reflect(-viewDirectionWS, normalWS);
half roughness2 = brdfData.roughness * brdfData.roughness;
half3 indirectDiffuse = DiffuseGI(lightmapUV.xy, ambient, normalWS) * ambientOcclusion;
half3 indirectSpecular = GlossyEnvironment(reflectVec, brdfData.perceptualRoughness) * ambientOcclusion;
half3 indirectDiffuse = diffuseGI * occlusion;
half3 indirectSpecular = GlossyEnvironment(reflectVec, brdfData.perceptualRoughness) * occlusion;
half3 color = LightweightBRDFIndirect(brdfData, indirectDiffuse, indirectSpecular, roughness2, fresnelTerm);
half3 color = LightweightEnvironmentBRDF(brdfData, indirectDiffuse, indirectSpecular, roughness2, fresnelTerm);
half3 lightDirectionWS;
LightInput light;

61
ScriptableRenderPipeline/LightweightPipeline/Shaders/LightweightPassLit.cginc


struct LightweightVertexOutput
{
float4 uv01 : TEXCOORD0; // xy: main UV, zw: lightmap UV (directional / non-directional)
float4 posWS : TEXCOORD1;
float3 posWS : TEXCOORD1;
#if _NORMALMAP
half3 tangent : TEXCOORD2;
half3 binormal : TEXCOORD3;

#endif
half4 viewDir : TEXCOORD5; // xyz: viewDir
half3 viewDir : TEXCOORD5;
half4 fogFactorAndVertexLight : TEXCOORD6; // x: fogFactor, yzw: vertex light
#if defined(EVALUATE_SH_VERTEX) || defined(EVALUATE_SH_MIXED)
half4 vertexSH : TEXCOORD7;

};
struct SurfaceInput
{
float4 lightmapUV;
half4 ambient;
half3 normalWS;
half3 tangentWS;
half3 bitangentWS;
float3 positionWS;
half3 viewDirectionWS;
half fogFactor;
};
inline half Alpha(half albedoAlpha)

outSurfaceData.normal = Normal(uv);
outSurfaceData.occlusion = Occlusion(uv);
outSurfaceData.emission = Emission(uv);
outSurfaceData.emission += IN.fogFactorAndVertexLight.yzw;
void InitializeSurfaceInput(LightweightVertexOutput IN, out SurfaceInput outSurfaceInput)
{
#if LIGHTMAP_ON
outSurfaceInput.lightmapUV = float4(IN.uv01.zw, 0.0, 0.0);
outSurfaceInput.ambient = half4(0.0, 0.0, 0.0, 0.0);
#else
outSurfaceInput.lightmapUV = float4(0.0, 0.0, 0.0, 0.0);
outSurfaceInput.ambient = half4(IN.vertexSH);
#endif
#if _NORMALMAP
outSurfaceInput.tangentWS = IN.tangent;
outSurfaceInput.bitangentWS = IN.binormal;
#else
outSurfaceInput.tangentWS = half3(1.0h, 0.0h, 0.0h);
outSurfaceInput.bitangentWS = half3(0.0h, 1.0h, 0.0h);
#endif
outSurfaceInput.normalWS = IN.normal;
outSurfaceInput.positionWS = IN.posWS;
outSurfaceInput.viewDirectionWS = IN.viewDir;
outSurfaceInput.fogFactor = IN.fogFactorAndVertexLight.x;
}
LightweightVertexOutput LitPassVertex(LightweightVertexInput v)
{
LightweightVertexOutput o = (LightweightVertexOutput)0;

#endif
float3 worldPos = mul(unity_ObjectToWorld, v.vertex).xyz;
o.posWS.xyz = worldPos;
o.posWS = worldPos;
o.viewDir.xyz = viewDir;
o.viewDir = viewDir;
#if _NORMALMAP
OutputTangentToWorld(v.tangent, v.normal, o.tangent, o.binormal, o.normal);

SurfaceData surfaceData;
InitializeStandardLitSurfaceData(IN, surfaceData);
SurfaceInput surfaceInput;
InitializeSurfaceInput(IN, surfaceInput);
#if _NORMALMAP
half3 normalWS = TangentToWorldNormal(surfaceData.normal, IN.tangent, IN.binormal, IN.normal);
#else

return LightweightFragmentPBR(surfaceInput.lightmapUV, surfaceInput.positionWS, normalWS, surfaceInput.viewDirectionWS, surfaceInput.fogFactor, surfaceInput.ambient, surfaceData.albedo, surfaceData.metallic, surfaceData.specular, surfaceData.smoothness, surfaceData.occlusion, surfaceData.emission, surfaceData.alpha);
#if LIGHTMAP_ON
half3 diffuseGI = SampleLightmap(IN.uv01.zw, normalWS);
#else
half3 diffuseGI = EvaluateSHPerPixel(normalWS, IN.vertexSH);
#endif
#if _VERTEX_LIGHTS
diffuseGI += IN.fogFactorAndVertexLight.yzw;
#endif
float fogFactor = IN.fogFactorAndVertexLight.x;
return LightweightFragmentPBR(IN.posWS, normalWS, IN.viewDir, fogFactor, diffuseGI, surfaceData.albedo, surfaceData.metallic, surfaceData.specular, surfaceData.smoothness, surfaceData.occlusion, surfaceData.emission, surfaceData.alpha);
}
half4 LitPassFragmentSimple(LightweightVertexOutput IN) : SV_Target

5
ScriptableRenderPipeline/LightweightPipeline/Shaders/LightweightStandardParticles.shader


SurfaceOutputStandard surfaceData;
InitializeSurfaceData(IN, surfaceData);
half4 zero = half4(0.0h, 0.0h, 0.0h, 0.0h);
float3 positionWS = IN.posWS.xyz;
half3 viewDirWS = SafeNormalize(_WorldSpaceCameraPos - positionWS);
half fogFactor = IN.posWS.w;

half3 normalWS = normalize(IN.normal);
#endif
return LightweightFragmentPBR(zero, positionWS, normalWS, viewDirWS, fogFactor, zero, surfaceData.Albedo, surfaceData.Metallic, zero, surfaceData.Smoothness, surfaceData.Occlusion, surfaceData.Emission, surfaceData.Alpha);
half3 zero = half3(0.0, 0.0, 0.0);
return LightweightFragmentPBR(positionWS, normalWS, viewDirWS, fogFactor, /*diffuseGI*/ zero, surfaceData.Albedo,
surfaceData.Metallic, /* specularColor */ zero, surfaceData.Smoothness, surfaceData.Occlusion, surfaceData.Emission, surfaceData.Alpha);
}
ENDCG
}

正在加载...
取消
保存