113 lines · 3.2 KB · Text
RawDownload
<@include gpu/Config.slh@><$VERSION_HEADER$>//  Generated on <$_SCRIBE_DATE$>////  subsurfaceScattering_drawScattering.frag////  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 gpu/ShaderConstants.h@> <@include DeferredBufferRead.slh@><@include graphics/Light.slh@><$declareLightBuffer()$> <$declareDeferredCurvature()$> <@include SubsurfaceScattering.slh@><$declareSubsurfaceScatteringBRDF()$> INPUT(0, vec2, varTexCoord0);OUTPUT(0, vec4, _fragColor); struct SSSDebugParams {    vec4 cursorTexCoordSpare2;}; // Deferred frame transform uses slot 0UNIFORM_BUFFER(1, sssDebugParamsBuffer) {    SSSDebugParams sssDebugParams;}; 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);     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.0 * 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++) {        bool check = distance[c] > threshold;        keep = keep || check;        color[c] += float(check);    }     if (!keep) {        discard;    }     return color;} void main(void) {    vec2 cursorTexcoord = sssDebugParams.cursorTexCoordSpare2.xy;    _fragColor = vec4(drawScatteringTableUV(cursorTexcoord, varTexCoord0), 1.0);}