v0.6
This commit is contained in:
1 parent
dff23db2f5
commit
c6c1c77535
70 files changed
+4395
-18
No files matched your search
+38
-2
@@ -133,11 +133,47 @@ Shader "BSDF/URPGradient"
|
||||
output.normalWS = vertexNormalInput.normalWS;
|
||||
return output;
|
||||
}
|
||||
|
||||
|
||||
BRDFData SurfaceDataToBSDFData(SurfaceData surface, InputData inputData){
|
||||
BRDFData bsdf;
|
||||
bsdf.albedo = surface.albedo;//漫反射颜色
|
||||
bsdf.specular = lerp(float3(0.04, 0.04, 0.04), surface.albedo, surface.metallic);//镜面反射颜色
|
||||
bsdf.diffuse = surface.albedo * (1.0 - surface.metallic);//漫反射颜色
|
||||
bsdf.reflectivity = ReflectivitySpecular(bsdf.specular);//反射率
|
||||
bsdf.perceptualRoughness = 1.0 - surface.smoothness;//感知粗糙度
|
||||
bsdf.roughness = bsdf.perceptualRoughness * bsdf.perceptualRoughness;//粗糙度
|
||||
bsdf.roughness2 = bsdf.roughness * bsdf.roughness;//粗糙度平方
|
||||
bsdf.grazingTerm =saturate(surface.smoothness+bsdf.reflectivity);//光滑度+反射率
|
||||
bsdf.normalizationTerm = bsdf.roughness*4.0+2.0;//归一化项
|
||||
bsdf.roughness2MinusOne = bsdf.roughness2 - 1.0;//粗糙度平方-1
|
||||
return bsdf;
|
||||
}
|
||||
|
||||
float3 BRDFToColor(BRDFData bsdf, InputData inputData,float3 positionWS){
|
||||
float3 color = float3(0, 0, 0);
|
||||
//主光源
|
||||
float4 shadowCoord = TransformWorldToShadowCoord(positionWS);//阴影坐标
|
||||
Light mainLight = GetMainLight(shadowCoord);
|
||||
color += LightingPhysicallyBased(bsdf,mainLight, inputData.normalWS, inputData.viewDirectionWS);
|
||||
//附加光源
|
||||
for (int i = 0; i < GetAdditionalLightsCount(); ++i)
|
||||
{
|
||||
half4 shadowMask = CalculateShadowMask(inputData);
|
||||
Light additionalLight = GetAdditionalLight(i, positionWS,shadowMask);
|
||||
color += LightingPhysicallyBased(bsdf, additionalLight, inputData.normalWS, inputData.viewDirectionWS);
|
||||
}
|
||||
//环境光
|
||||
color += inputData.bakedGI.rgb * bsdf.diffuse;//烘焙全局光照
|
||||
return color;
|
||||
}
|
||||
|
||||
float4 MainFragmentShader(Varyings input):SV_TARGET{
|
||||
InputData inputData = InitializeInputData(input);
|
||||
SurfaceData surface = GetSurfaceData(input);
|
||||
float4 color = UniversalFragmentPBR(inputData, surface);
|
||||
color.rgb += surface.emission;//自发光
|
||||
BRDFData bsdf = SurfaceDataToBSDFData(surface, inputData);
|
||||
float3 color = BRDFToColor(bsdf, inputData, inputData.positionWS);
|
||||
|
||||
color.rgb = MixFog(color.rgb, inputData.fogCoord);//混合雾效
|
||||
/* Light mainLight = GetMainLight();
|
||||
float3 normal = normalize(input.normalWS);
|
||||
|
||||
Reference in new issue
Block a user