70 lines · 2.2 KB · Text
RawDownload
<!//  DeferredBufferWrite.slh//  libraries/render-utils/src////  Created by Sam Gateau on 1/12/15.//  Copyright 2013 High Fidelity, Inc.////  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@> layout(location = 0) out vec4 _fragColor0;layout(location = 1) out vec4 _fragColor1;layout(location = 2) out vec4 _fragColor2;  // the alpha thresholdconst float alphaThreshold = 0.5;float evalOpaqueFinalAlpha(float alpha, float mapAlpha) {    return mix(alpha, 1.0 - alpha, step(mapAlpha, alphaThreshold));} const float DEFAULT_ROUGHNESS = 0.9;const float DEFAULT_SHININESS = 10;const float DEFAULT_METALLIC = 0;const vec3 DEFAULT_SPECULAR = vec3(0.1);const vec3 DEFAULT_EMISSIVE = vec3(0.0);const float DEFAULT_OCCLUSION = 1.0;const vec3 DEFAULT_FRESNEL = DEFAULT_EMISSIVE; void packDeferredFragment(vec3 normal, float alpha, vec3 albedo, float roughness, float metallic, vec3 emissive, float occlusion) {    if (alpha != 1.0) {        discard;    }    _fragColor0 = vec4(albedo, packShadedMetallic(metallic));    _fragColor1 = vec4(packNormal(normal), clamp(roughness, 0.0, 1.0));    _fragColor2 = vec4(emissive, occlusion);}  void packDeferredFragmentLightmap(vec3 normal, float alpha, vec3 albedo, float roughness, float metallic, vec3 fresnel, vec3 emissive) {    if (alpha != 1.0) {        discard;    }    _fragColor0 = vec4(albedo, packLightmappedMetallic(metallic));    _fragColor1 = vec4(packNormal(normal), clamp(roughness, 0.0, 1.0));    _fragColor2 = vec4(emissive, 1.0);} void packDeferredFragmentUnlit(vec3 normal, float alpha, vec3 color) {    if (alpha != 1.0) {        discard;    }    _fragColor0 = vec4(color, packUnlit());    _fragColor1 = vec4(packNormal(normal), 1.0);    //_fragColor2 = vec4(vec3(0.0), 1.0); // If unlit, do not worry about the emissive color target} void packDeferredFragmentTranslucent(vec3 normal, float alpha, vec3 albedo, vec3 fresnel, float roughness) {    if (alpha <= 0.0) {        discard;    }    _fragColor0 = vec4(albedo.rgb, alpha);} <@endif@>