overte-HifiExperiments/libraries/render-utils/src/model_translucent.slf
2015-06-08 18:36:12 +02:00

132 lines
3.8 KiB
Text
Executable file

<@include gpu/Config.slh@>
<$VERSION_HEADER$>
// Generated on <$_SCRIBE_DATE$>
//
// model_translucent.frag
// fragment shader
//
// Created by Andrzej Kapolka on 9/19/14.
// Copyright 2014 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 DeferredBufferWrite.slh@>
<@include model/Material.slh@>
// the diffuse texture
uniform sampler2D diffuseMap;
varying vec4 interpolatedNormal;
varying vec3 color;
void main(void) {
// Fetch diffuse map
vec4 diffuse = texture2D(diffuseMap, gl_TexCoord[0].st);
Material mat = getMaterial();
packDeferredFragmentTranslucent(
normalize(interpolatedNormal.xyz),
getMaterialOpacity(mat) * diffuse.a,
getMaterialDiffuse(mat) * diffuse.rgb * color,
getMaterialSpecular(mat),
getMaterialShininess(mat));
// set the diffuse data
// gl_FragData[0] = gl_Color * texture2D(diffuseMap, gl_TexCoord[0].st);
}*/!>
<@include model/Material.slh@>
// Everything about global lighting
<@include DeferredLighting.slh@>
<@include gpu/Transform.slh@>
<$declareStandardTransform()$>
// Everything about light
<@include model/Light.slh@>
// The view Matrix
//uniform mat4 invViewMat;
vec4 evalNormalColor(vec3 dir, float opacity) {
bool isX = (abs(dir.x) > 0.99);
bool isY = (abs(dir.y) > 0.99);
bool isZ = (abs(dir.z) > 0.99);
if (isX || isY || isZ) {
bool negX = (dir.x < -0.995);
bool negY = (dir.y < -0.995);
bool negZ = (dir.z < -0.995);
if (negX || negY || negZ) {
return vec4(float(isX), float(isY), float(isZ), 0.2);
} else {
return vec4(float(isX), float(isY), float(isZ), 1.0);
}
}
return vec4(0.5 * dir + vec3(0.5), opacity);
}
vec4 evalGlobalColor(float shadowAttenuation, vec3 position, vec3 normal, vec3 diffuse, vec3 specular, float gloss, float opacity) {
// Need the light now
Light light = getLight();
TransformCamera cam = getTransformCamera();
vec3 fragNormal;
<$transformEyeToWorldDir(cam, normal, fragNormal)$>
vec3 fragEyeVectorView = normalize(-position);
vec3 fragEyeDir;
<$transformEyeToWorldDir(cam, fragEyeVectorView, fragEyeDir)$>
vec3 color = opacity * diffuse.rgb * getLightColor(light) * getLightAmbientIntensity(light);
vec4 shading = evalFragShading(fragNormal, -getLightDirection(light), fragEyeDir, specular, gloss);
color += vec3(opacity * diffuse + shading.rgb) * shading.w * shadowAttenuation * getLightColor(light) * getLightIntensity(light);
//return vec4(color, opacity);
return vec4(color, opacity);
//return vec4(diffuse.rgb, opacity);
//return evalNormalColor(fragEyeDir, opacity);
}
// the diffuse texture
uniform sampler2D diffuseMap;
// the interpolated view position
varying vec4 interpolatedPosition;
// the interpolated normal
varying vec4 interpolatedNormal;
varying vec3 color;
void main(void) {
vec3 fragPosition = interpolatedPosition.xyz;
// Fetch diffuse map
vec4 diffuse = texture2D(diffuseMap, gl_TexCoord[0].st);
Material mat = getMaterial();
vec3 fragNormal = normalize(interpolatedNormal.xyz);
float fragOpacity = getMaterialOpacity(mat) * diffuse.a;
vec3 fragDiffuse = getMaterialDiffuse(mat) * diffuse.rgb * color;
vec3 fragSpecular = getMaterialSpecular(mat);
float fragGloss = getMaterialShininess(mat);
vec4 fragColor = evalGlobalColor(1.0,
fragPosition,
fragNormal,
fragDiffuse,
fragSpecular,
fragGloss,
fragOpacity);
gl_FragColor = fragColor;
}