<@if not DEFERRED_BUFFER_WRITE_SLH@> <@def DEFERRED_BUFFER_WRITE_SLH@> <@include DeferredBuffer.slh@> <@include DeferredBufferWrite_shared.slh@> OUTPUT(DEFERRED_COLOR_SLOT, vec4, _albedoMetallic); // albedo / metallic OUTPUT(DEFERRED_NORMAL_SLOT, vec4, _normalRoughness); // normal / roughness OUTPUT(DEFERRED_SPECULAR_SLOT, vec4, _scatteringEmissiveOcclusion); // scattering / emissive / occlusion OUTPUT(DEFERRED_VELOCITY_SLOT, vec4, _velocity); // velocity OUTPUT(DEFERRED_LIGHTING_SLOT, vec4, _lighting); // emissive <@include VelocityWrite.slh@> <@include DefaultMaterials.slh@> <@include LightingModel.slh@> void packDeferredFragment(vec4 prevPositionCS, vec3 normal, float alpha, vec3 albedo, float roughness, float metallic, vec3 emissive, float occlusion, float scattering) { // to reduce texel flickering for floating point error we discard when alpha is "almost one" if (alpha < 0.99999) { discard; } float check = float(scattering > 0.0); _albedoMetallic = vec4(albedo, mix(packShadedMetallic(metallic), packScatteringMetallic(metallic), check)); _normalRoughness = vec4(packNormal(normal), clamp(roughness, 0.0, 1.0)); _scatteringEmissiveOcclusion = vec4(mix(emissive, vec3(scattering), check), occlusion); _velocity = vec4(packVelocity(prevPositionCS), 0.0, 0.0); _lighting = vec4(isEmissiveEnabled() * emissive, 1.0); } void packDeferredFragmentLightmap(vec4 prevPositionCS, vec3 normal, float alpha, vec3 albedo, float roughness, float metallic, vec3 lightmap) { // to reduce texel flickering for floating point error we discard when alpha is "almost one" if (alpha < 0.99999) { discard; } _albedoMetallic = vec4(albedo, packLightmappedMetallic(metallic)); _normalRoughness = vec4(packNormal(normal), clamp(roughness, 0.0, 1.0)); _scatteringEmissiveOcclusion = vec4(isLightmapEnabled() * lightmap, 1.0); _velocity = vec4(packVelocity(prevPositionCS), 0.0, 0.0); _lighting = vec4(isLightmapEnabled() * lightmap * albedo, 1.0); } void packDeferredFragmentUnlit(vec4 prevPositionCS, vec3 normal, float alpha, vec3 color) { // to reduce texel flickering for floating point error we discard when alpha is "almost one" if (alpha < 0.999999) { discard; } _albedoMetallic = vec4(color, packUnlit()); _normalRoughness = vec4(packNormal(normal), 1.0); _scatteringEmissiveOcclusion = vec4(vec3(0.0), 1.0); _velocity = vec4(packVelocity(prevPositionCS), 0.0, 0.0); _lighting = vec4(color, 1.0); } void packDeferredFragmentTranslucentUnlit(float alpha, vec3 color) { if (alpha <= 0.0) { discard; } // There's only one attachment here, and _albedoMetallic is actually _lighting, // since transparencies are drawn using forward rendering, not deferred. _albedoMetallic = vec4(color, alpha); } <@endif@>