您最多选择25个主题
主题必须以中文或者字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
121 行
4.3 KiB
121 行
4.3 KiB
#if SHADERPASS != SHADERPASS_FORWARD
|
|
#error SHADERPASS_is_not_correctly_define
|
|
#endif
|
|
|
|
#include "VertMesh.hlsl"
|
|
|
|
PackedVaryingsType Vert(AttributesMesh inputMesh)
|
|
{
|
|
VaryingsType varyingsType;
|
|
varyingsType.vmesh = VertMesh(inputMesh);
|
|
return PackVaryingsType(varyingsType);
|
|
}
|
|
|
|
#ifdef TESSELLATION_ON
|
|
|
|
PackedVaryingsToPS VertTesselation(VaryingsToDS input)
|
|
{
|
|
VaryingsToPS output;
|
|
output.vmesh = VertMeshTesselation(input.vmesh);
|
|
return PackVaryingsToPS(output);
|
|
}
|
|
|
|
#include "TessellationShare.hlsl"
|
|
|
|
#endif // TESSELLATION_ON
|
|
|
|
void Frag(PackedVaryingsToPS packedInput,
|
|
// YIBING BEGIN
|
|
#ifdef FORWARD_SPLIT_LIGHTING
|
|
out float4 outColor : SV_Target0, // this is outSpecular
|
|
out float4 outDiffuse : SV_Target1,
|
|
out float4 outGbuffer0 : SV_Target2,
|
|
out float4 outGbuffer2 : SV_Target3
|
|
#else
|
|
out float4 outColor : SV_Target0
|
|
#endif
|
|
|
|
//out float4 outColor : SV_Target0
|
|
// YIBING END
|
|
#ifdef _DEPTHOFFSET_ON
|
|
, out float outputDepth : SV_Depth
|
|
#endif
|
|
)
|
|
{
|
|
FragInputs input = UnpackVaryingsMeshToFragInputs(packedInput.vmesh);
|
|
|
|
// input.unPositionSS is SV_Position
|
|
PositionInputs posInput = GetPositionInput(input.unPositionSS.xy, _ScreenSize.zw, uint2(input.unPositionSS.xy) / GetTileSize());
|
|
UpdatePositionInput(input.unPositionSS.z, input.unPositionSS.w, input.positionWS, posInput);
|
|
float3 V = GetWorldSpaceNormalizeViewDir(input.positionWS);
|
|
|
|
SurfaceData surfaceData;
|
|
BuiltinData builtinData;
|
|
GetSurfaceAndBuiltinData(input, V, posInput, surfaceData, builtinData);
|
|
|
|
BSDFData bsdfData = ConvertSurfaceDataToBSDFData(surfaceData);
|
|
|
|
PreLightData preLightData = GetPreLightData(V, posInput, bsdfData);
|
|
|
|
outColor = float4(0.0, 0.0, 0.0, 0.0);
|
|
|
|
// We need to skip lighting when doing debug pass because the debug pass is done before lighting so some buffers may not be properly initialized potentially causing crashes on PS4.
|
|
#ifdef DEBUG_DISPLAY
|
|
if (_DebugLightingMode != DEBUGLIGHTINGMODE_NONE)
|
|
#endif
|
|
{
|
|
#ifdef _SURFACE_TYPE_TRANSPARENT
|
|
uint featureFlags = LIGHT_FEATURE_MASK_FLAGS_TRANSPARENT;
|
|
#else
|
|
uint featureFlags = LIGHT_FEATURE_MASK_FLAGS_OPAQUE;
|
|
#endif
|
|
float3 diffuseLighting;
|
|
float3 specularLighting;
|
|
BakeLightingData bakeLightingData;
|
|
bakeLightingData.bakeDiffuseLighting = GetBakedDiffuseLigthing(surfaceData, builtinData, bsdfData, preLightData);
|
|
#ifdef SHADOWS_SHADOWMASK
|
|
bakeLightingData.bakeShadowMask = float4(builtinData.shadowMask0, builtinData.shadowMask1, builtinData.shadowMask2, builtinData.shadowMask3);
|
|
#endif
|
|
LightLoop(V, posInput, preLightData, bsdfData, bakeLightingData, featureFlags, diffuseLighting, specularLighting);
|
|
|
|
// YIBING BEGIN
|
|
// If we have split lighting it mean we are opaque (no SSS on transparent)
|
|
#ifdef FORWARD_SPLIT_LIGHTING
|
|
outColor = float4(specularLighting, 1.0);
|
|
outDiffuse = float4(diffuseLighting, 1.0);
|
|
outGbuffer0 = EncodeSplitLightingGBuffer0(surfaceData);
|
|
outGbuffer2 = EncodeSplitLightingGBuffer1(surfaceData);
|
|
#else
|
|
outColor = ApplyBlendMode(diffuseLighting, specularLighting, builtinData.opacity);
|
|
outColor = EvaluateAtmosphericScattering(posInput, outColor);
|
|
#endif
|
|
// YIBING END
|
|
}
|
|
|
|
#ifdef _DEPTHOFFSET_ON
|
|
outputDepth = posInput.depthRaw;
|
|
#endif
|
|
|
|
#ifdef DEBUG_DISPLAY
|
|
// Same code in ShaderPassForwardUnlit.shader
|
|
if (_DebugViewMaterial != 0)
|
|
{
|
|
float3 result = float3(1.0, 0.0, 1.0);
|
|
bool needLinearToSRGB = false;
|
|
|
|
GetPropertiesDataDebug(_DebugViewMaterial, result, needLinearToSRGB);
|
|
GetVaryingsDataDebug(_DebugViewMaterial, input, result, needLinearToSRGB);
|
|
GetBuiltinDataDebug(_DebugViewMaterial, builtinData, result, needLinearToSRGB);
|
|
GetSurfaceDataDebug(_DebugViewMaterial, surfaceData, result, needLinearToSRGB);
|
|
GetBSDFDataDebug(_DebugViewMaterial, bsdfData, result, needLinearToSRGB); // TODO: This required to initialize all field from BSDFData...
|
|
|
|
// TEMP!
|
|
// For now, the final blit in the backbuffer performs an sRGB write
|
|
// So in the meantime we apply the inverse transform to linear data to compensate.
|
|
if (!needLinearToSRGB)
|
|
result = SRGBToLinear(max(0, result));
|
|
|
|
outColor = float4(result, 1.0);
|
|
}
|
|
#endif
|
|
}
|