#if SHADERPASS != SHADERPASS_GBUFFER #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, OUTPUT_GBUFFER(outGBuffer) OUTPUT_GBUFFER_SHADOWMASK(outShadowMaskBuffer) OUTPUT_GBUFFER_VELOCITY(outVelocityBuffer) #ifdef _DEPTHOFFSET_ON , out float outputDepth : SV_Depth #endif ) { FragInputs input = UnpackVaryingsMeshToFragInputs(packedInput.vmesh); // input.positionSS is SV_Position PositionInputs posInput = GetPositionInput(input.positionSS.xy, _ScreenSize.zw); UpdatePositionInput(input.positionSS.z, input.positionSS.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); float3 bakeDiffuseLighting = GetBakedDiffuseLigthing(surfaceData, builtinData, bsdfData, preLightData); ENCODE_INTO_GBUFFER(surfaceData, bakeDiffuseLighting, posInput.positionSS, outGBuffer); ENCODE_SHADOWMASK_INTO_GBUFFER(float4(builtinData.shadowMask0, builtinData.shadowMask1, builtinData.shadowMask2, builtinData.shadowMask3), outShadowMaskBuffer); ENCODE_VELOCITY_INTO_GBUFFER(builtinData.velocity, outVelocityBuffer); #ifdef _DEPTHOFFSET_ON outputDepth = posInput.deviceDepth; #endif }