mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-07-14 02:36:42 +02:00
109 lines
3.2 KiB
Text
109 lines
3.2 KiB
Text
<@include gpu/Config.slh@>
|
|
<$VERSION_HEADER$>
|
|
// Generated on <$_SCRIBE_DATE$>
|
|
//
|
|
// Created by Sam Gateau on 6/8/16.
|
|
// Copyright 2016 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
|
|
//
|
|
|
|
|
|
|
|
<@include DeferredBufferRead.slh@>
|
|
<@include graphics/Light.slh@>
|
|
<$declareLightBuffer()$>
|
|
|
|
<$declareDeferredCurvature()$>
|
|
|
|
<@include SubsurfaceScattering.slh@>
|
|
<$declareSubsurfaceScatteringBRDF()$>
|
|
|
|
in vec2 varTexCoord0;
|
|
out vec4 _fragColor;
|
|
|
|
uniform vec2 uniformCursorTexcoord = vec2(0.5);
|
|
|
|
//uniform vec3 uniformLightVector = vec3(1.0);
|
|
|
|
vec3 evalScatteringBRDF(vec2 texcoord) {
|
|
DeferredFragment fragment = unpackDeferredFragmentNoPosition(texcoord);
|
|
|
|
vec3 normal = fragment.normal; // .getWorldNormal(varTexCoord0);
|
|
vec4 blurredCurvature = fetchCurvature(texcoord);
|
|
vec4 diffusedCurvature = fetchDiffusedCurvature(texcoord);
|
|
vec3 midNormal = normalize((blurredCurvature.xyz - 0.5f) * 2.0f);
|
|
vec3 lowNormal = normalize((diffusedCurvature.xyz - 0.5f) * 2.0f);
|
|
float curvature = unpackCurvature(diffusedCurvature.w);
|
|
|
|
|
|
// Transform directions to worldspace
|
|
vec3 fragNormal = vec3((normal));
|
|
|
|
// Get light
|
|
Light light = getKeyLight();
|
|
vec3 fresnel = vec3(0.028); // Default Di-electric fresnel value for skin
|
|
float metallic = 0.0;
|
|
|
|
vec3 fragLightDir = -normalize(getLightDirection(light));
|
|
|
|
|
|
vec3 brdf = evalSkinBRDF(fragLightDir, fragNormal, midNormal, lowNormal, curvature);
|
|
|
|
return brdf;
|
|
}
|
|
|
|
vec3 drawScatteringTableUV(vec2 cursor, vec2 texcoord) {
|
|
DeferredFragment fragment = unpackDeferredFragmentNoPosition(cursor);
|
|
|
|
vec3 normal = fragment.normal; // .getWorldNormal(varTexCoord0);
|
|
vec4 blurredCurvature = fetchCurvature(cursor);
|
|
vec4 diffusedCurvature = fetchDiffusedCurvature(cursor);
|
|
vec3 midNormal = normalize((blurredCurvature.xyz - 0.5f) * 2.0f);
|
|
vec3 lowNormal = normalize((diffusedCurvature.xyz - 0.5f) * 2.0f);
|
|
float curvature = unpackCurvature(diffusedCurvature.w);
|
|
|
|
// Get light
|
|
Light light = getKeyLight();
|
|
vec3 fresnel = vec3(0.028); // Default Di-electric fresnel value for skin
|
|
|
|
vec3 fragLightDir = -normalize(getLightDirection(light));
|
|
|
|
vec3 bentNdotL = evalScatteringBentNdotL(normal, midNormal, lowNormal, fragLightDir);
|
|
|
|
// return clamp(bentNdotL * 0.5 + 0.5, 0.0, 1.0);
|
|
|
|
vec3 distance = vec3(0.0);
|
|
for (int c = 0; c < 3; c++) {
|
|
vec2 BRDFuv = vec2(clamp(bentNdotL[c] * 0.5 + 0.5, 0.0, 1.0), clamp(2 * curvature, 0.0, 1.0));
|
|
vec2 delta = BRDFuv - texcoord;
|
|
distance[c] = 1.0 - dot(delta, delta);
|
|
}
|
|
|
|
distance *= distance;
|
|
|
|
float threshold = 0.999;
|
|
vec3 color = vec3(0.0);
|
|
bool keep = false;
|
|
for (int c = 0; c < 3; c++) {
|
|
if (distance[c] > threshold) {
|
|
keep = true;
|
|
color[c] += 1.0;
|
|
}
|
|
}
|
|
|
|
if (!keep)
|
|
discard;
|
|
|
|
return color;
|
|
}
|
|
|
|
void main(void) {
|
|
// _fragColor = vec4(evalScatteringBRDF(varTexCoord0), 1.0);
|
|
// _fragColor = vec4(uniformCursorTexcoord, 0.0, 1.0);
|
|
|
|
_fragColor = vec4(drawScatteringTableUV(uniformCursorTexcoord, varTexCoord0), 1.0);
|
|
}
|
|
|
|
|