76 lines · 3.2 KB · Text
RawDownload
<!//  DeferredBufferWrite.slh//  libraries/render-utils/src////  Created by Sam Gateau on 1/12/15.//  Copyright 2013 High Fidelity, Inc.//  Copyright 2024 Overte e.V.////  Distributed under the Apache License, Version 2.0.//  See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html!><@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 / metallicOUTPUT(DEFERRED_NORMAL_SLOT, vec4, _normalRoughness);               // normal / roughnessOUTPUT(DEFERRED_SPECULAR_SLOT, vec4, _scatteringEmissiveOcclusion); // scattering / emissive / occlusionOUTPUT(DEFERRED_VELOCITY_SLOT, vec4, _velocity);                    // velocityOUTPUT(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@>