mirror of
https://github.com/overte-org/overte.git
synced 2025-07-26 09:18:26 +02:00
75 lines
2.6 KiB
Text
75 lines
2.6 KiB
Text
<!
|
|
// 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; // albedo / metallic
|
|
layout(location=1) out vec4 _fragColor1; // Normal
|
|
layout(location=2) out vec4 _fragColor2; // scattering / emissive / occlusion
|
|
layout(location=3) out vec4 _fragColor3; // emissive
|
|
|
|
// the alpha threshold
|
|
const float alphaThreshold = 0.5;
|
|
float evalOpaqueFinalAlpha(float alpha, float mapAlpha) {
|
|
return mix(alpha, 1.0 - alpha, step(mapAlpha, alphaThreshold));
|
|
}
|
|
|
|
<@include DefaultMaterials.slh@>
|
|
<@include LightingModel.slh@>
|
|
|
|
void packDeferredFragment(vec3 normal, float alpha, vec3 albedo, float roughness, float metallic, vec3 emissive, float occlusion, float scattering) {
|
|
if (alpha < 1.0) {
|
|
discard;
|
|
}
|
|
|
|
float check = float(scattering > 0.0);
|
|
_fragColor0 = vec4(albedo, mix(packShadedMetallic(metallic), packScatteringMetallic(metallic), check));
|
|
_fragColor1 = vec4(packNormal(normal), clamp(roughness, 0.0, 1.0));
|
|
_fragColor2 = vec4(mix(emissive, vec3(scattering), check), occlusion);
|
|
_fragColor3 = vec4(isEmissiveEnabled() * emissive, 1.0);
|
|
}
|
|
|
|
void packDeferredFragmentLightmap(vec3 normal, float alpha, vec3 albedo, float roughness, float metallic, vec3 lightmap) {
|
|
if (alpha < 1.0) {
|
|
discard;
|
|
}
|
|
|
|
_fragColor0 = vec4(albedo, packLightmappedMetallic(metallic));
|
|
_fragColor1 = vec4(packNormal(normal), clamp(roughness, 0.0, 1.0));
|
|
_fragColor2 = vec4(isLightmapEnabled() * lightmap, 1.0);
|
|
_fragColor3 = vec4(isLightmapEnabled() * lightmap * albedo, 1.0);
|
|
}
|
|
|
|
void packDeferredFragmentUnlit(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;
|
|
}
|
|
_fragColor0 = vec4(color, packUnlit());
|
|
_fragColor1 = vec4(packNormal(normal), 1.0);
|
|
_fragColor2 = vec4(vec3(0.0), 1.0);
|
|
_fragColor3 = vec4(color, 1.0);
|
|
}
|
|
|
|
void packDeferredFragmentTranslucent(vec3 normal, float alpha, vec3 albedo, float roughness) {
|
|
if (alpha <= 0.0) {
|
|
discard;
|
|
}
|
|
_fragColor0 = vec4(albedo.rgb, alpha);
|
|
_fragColor1 = vec4(packNormal(normal), clamp(roughness, 0.0, 1.0));
|
|
_fragColor2 = vec4(vec3(0.0), 1.0);
|
|
_fragColor3 = vec4(0.0);
|
|
}
|
|
|
|
<@endif@>
|