mirror of
https://github.com/overte-org/overte.git
synced 2025-05-08 01:48:54 +02:00
80 lines
2.5 KiB
Text
80 lines
2.5 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;
|
|
layout(location = 1) out vec4 _fragColor1;
|
|
layout(location = 2) out vec4 _fragColor2;
|
|
|
|
layout(location = 3) out vec4 _fragColor3;
|
|
|
|
// the alpha threshold
|
|
const 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.0;
|
|
const float DEFAULT_METALLIC = 0.0;
|
|
const vec3 DEFAULT_SPECULAR = vec3(0.1);
|
|
const vec3 DEFAULT_EMISSIVE = vec3(0.0);
|
|
const float DEFAULT_OCCLUSION = 1.0;
|
|
const float DEFAULT_SCATTERING = 0.0;
|
|
const vec3 DEFAULT_FRESNEL = DEFAULT_EMISSIVE;
|
|
|
|
void packDeferredFragment(vec3 normal, float alpha, vec3 albedo, float roughness, float metallic, vec3 emissive, float occlusion, float scattering) {
|
|
if (alpha != 1.0) {
|
|
discard;
|
|
}
|
|
_fragColor0 = vec4(albedo, ((scattering > 0.0) ? packScatteringMetallic(metallic) : packShadedMetallic(metallic)));
|
|
_fragColor1 = vec4(packNormal(normal), clamp(roughness, 0.0, 1.0));
|
|
_fragColor2 = vec4(((scattering > 0.0) ? vec3(scattering) : emissive), occlusion);
|
|
|
|
_fragColor3 = vec4(emissive, 1.0);
|
|
}
|
|
|
|
void packDeferredFragmentLightmap(vec3 normal, float alpha, vec3 albedo, float roughness, float metallic, vec3 fresnel, vec3 lightmap) {
|
|
if (alpha != 1.0) {
|
|
discard;
|
|
}
|
|
|
|
_fragColor0 = vec4(albedo, packLightmappedMetallic(metallic));
|
|
_fragColor1 = vec4(packNormal(normal), clamp(roughness, 0.0, 1.0));
|
|
_fragColor2 = vec4(lightmap, 1.0);
|
|
|
|
_fragColor3 = vec4(lightmap * albedo, 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);
|
|
_fragColor3 = vec4(color, 1.0);
|
|
}
|
|
|
|
void packDeferredFragmentTranslucent(vec3 normal, float alpha, vec3 albedo, vec3 fresnel, float roughness) {
|
|
if (alpha <= 0.0) {
|
|
discard;
|
|
}
|
|
_fragColor0 = vec4(albedo.rgb, alpha);
|
|
_fragColor1 = vec4(packNormal(normal), clamp(roughness, 0.0, 1.0));
|
|
|
|
}
|
|
|
|
<@endif@>
|