浏览代码

Additive light support

/projects-TheLastStand
John Parsaie 7 年前
当前提交
c46de7ff
共有 2 个文件被更改,包括 16 次插入8 次删除
  1. 7
      ScriptableRenderPipeline/LightweightPipeline/LWRP/LightweightPipeline.cs
  2. 17
      ScriptableRenderPipeline/LightweightPipeline/LWRP/Shaders/Subsurface/Lighting.hlsl

7
ScriptableRenderPipeline/LightweightPipeline/LWRP/LightweightPipeline.cs


private Vector4 kDefaultLightPosition = new Vector4(0.0f, 0.0f, 1.0f, 0.0f);
private Vector4 kDefaultLightColor = Color.black;
private Vector4 kDefaultLightAttenuation = new Vector4(0.0f, 1.0f, 0.0f, 1.0f);
//TLS Note: We need to hijack alpha to easily know when we are at a spot light for some features.
private Vector4 kDefaultLightAttenuation = new Vector4(0.0f, 1.0f, 0.0f, 0.0f);
private Vector4 kDefaultLightSpotDirection = new Vector4(0.0f, 0.0f, 1.0f, 0.0f);
private Vector4 kDefaultLightSpotAttenuation = new Vector4(0.0f, 1.0f, 0.0f, 0.0f);

float smoothAngleRange = Mathf.Max(0.001f, cosInnerAngle - cosOuterAngle);
float invAngleRange = 1.0f / smoothAngleRange;
float add = -cosOuterAngle * invAngleRange;
lightSpotAttenuation = new Vector4(invAngleRange, add, 0.0f);
lightSpotAttenuation = new Vector4(invAngleRange, add, 0.0f, 1f);
}
Light light = lightData.light;

17
ScriptableRenderPipeline/LightweightPipeline/LWRP/Shaders/Subsurface/Lighting.hlsl


half3 color;
half3 attenuation; //NOTE: RGB attenuation for shadow scatter.
half subtractiveModeAttenuation;
int isSpot;
};
///////////////////////////////////////////////////////////////////////////////

light.attenuation = directionAndRealtimeAttenuation.w;
light.subtractiveModeAttenuation = lightInput.distanceAttenuation.w;
light.color = lightInput.color;
light.isSpot = lightInput.spotAttenuation.w;
return light;
}

light.attenuation = directionAndRealtimeAttenuation.w;
light.subtractiveModeAttenuation = lightInput.distanceAttenuation.w;
light.color = lightInput.color;
light.isSpot = lightInput.spotAttenuation.w;
return light;
}

return volumeAlbedo * (exp(-t2 * halfRcpVariance1) * lerpWeight1 + exp(-t2 * halfRcpVariance2) * lerpWeight2);
}
half3 DiffuseScattering(BRDFData brdfData, half3 normalHighWS, half3 normalLowWS, half3 lightDirectionWS)
half3 DiffuseScattering(BRDFData brdfData, half3 normalHighWS, half3 lightDirectionWS, half Attenuation, int isSpot)
NdotL = 0.5 * NdotL + 0.5; //Scale to 0..1 for lookup.
//NOTE: We need to account for spot light attenuation here.
float lookup = (0.5 * NdotL + 0.5) * lerp(1, 0.5 * Attenuation + 0.5, isSpot); //Scale lookup to 0..1
return SAMPLE_TEXTURE2D_ARRAY(_PreintegratedDiffuseScatteringTextures, sampler_PreintegratedDiffuseScatteringTextures, float2(NdotL, brdfData.curvature), _DiffusionProfile).rgb;
return SAMPLE_TEXTURE2D_ARRAY(_PreintegratedDiffuseScatteringTextures, sampler_PreintegratedDiffuseScatteringTextures, float2(lookup, brdfData.curvature), _DiffusionProfile).rgb;
}
half3 ShadowScattering(half shadow, half NdotL)

return lightColor * specularReflection;
}
half3 LightingPhysicallyBased(BRDFData brdfData, half3 lightColor, half3 lightDirectionWS, half3 lightAttenuation, half3 normalWS, half3 viewDirectionWS)
half3 LightingPhysicallyBased(BRDFData brdfData, half3 lightColor, half3 lightDirectionWS, half3 lightAttenuation, int isSpot, half3 normalWS, half3 viewDirectionWS)
half3 NdotL = DiffuseScattering(brdfData, normalWS, normalWS, lightDirectionWS);
half3 NdotL = DiffuseScattering(brdfData, normalWS, lightDirectionWS, lightAttenuation, isSpot);
half3 radiance = lightColor * (lightAttenuation * NdotL);
return DirectBDRF(brdfData, normalWS, lightDirectionWS, viewDirectionWS) * radiance;
}

return LightingPhysicallyBased(brdfData, light.color, light.direction, light.attenuation, normalWS, viewDirectionWS);
return LightingPhysicallyBased(brdfData, light.color, light.direction, light.attenuation, light.isSpot, normalWS, viewDirectionWS);
}
half3 VertexLighting(float3 positionWS, half3 normalWS)

正在加载...
取消
保存