mirror of
https://github.com/overte-org/overte.git
synced 2025-04-29 19:02:36 +02:00
97 lines
3.3 KiB
Text
97 lines
3.3 KiB
Text
<@include gpu/Config.slh@>
|
|
<$VERSION_HEADER$>
|
|
// Generated on <$_SCRIBE_DATE$>
|
|
//
|
|
// model_translucent_normal_map.frag
|
|
// fragment shader
|
|
//
|
|
// Created by Olivier Prat on 23/01/2018.
|
|
// Copyright 2018 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 graphics/Material.slh@>
|
|
|
|
<@include DeferredGlobalLight.slh@>
|
|
|
|
<$declareEvalGlobalLightingAlphaBlendedWithHaze()$>
|
|
|
|
<@include LightLocal.slh@>
|
|
|
|
<@include gpu/Transform.slh@>
|
|
<$declareStandardCameraTransform()$>
|
|
|
|
<@include graphics/MaterialTextures.slh@>
|
|
<$declareMaterialTextures(ALBEDO, ROUGHNESS, NORMAL, _SCRIBE_NULL, EMISSIVE, OCCLUSION)$>
|
|
|
|
<@include render-utils/ShaderConstants.h@>
|
|
|
|
layout(location=RENDER_UTILS_ATTR_TEXCOORD01) in vec4 _texCoord01;
|
|
#define _texCoord0 _texCoord01.xy
|
|
#define _texCoord1 _texCoord01.zw
|
|
layout(location=RENDER_UTILS_ATTR_POSITION_ES) in vec4 _positionES;
|
|
layout(location=RENDER_UTILS_ATTR_POSITION_WS) in vec4 _positionWS;
|
|
layout(location=RENDER_UTILS_ATTR_NORMAL_WS) in vec3 _normalWS;
|
|
layout(location=RENDER_UTILS_ATTR_TANGENT_WS) in vec3 _tangentWS;
|
|
layout(location=RENDER_UTILS_ATTR_COLOR) in vec4 _color;
|
|
|
|
layout(location=0) out vec4 _fragColor;
|
|
|
|
void main(void) {
|
|
Material mat = getMaterial();
|
|
int matKey = getMaterialKey(mat);
|
|
<$fetchMaterialTexturesCoord0(matKey, _texCoord0, albedoTex, roughnessTex, normalTex, _SCRIBE_NULL, emissiveTex)$>
|
|
<$fetchMaterialTexturesCoord1(matKey, _texCoord1, occlusionTex)$>
|
|
|
|
float opacity = getMaterialOpacity(mat) * _color.a;
|
|
<$evalMaterialOpacity(albedoTex.a, opacity, matKey, opacity)$>;
|
|
<$discardInvisible(opacity)$>;
|
|
|
|
vec3 albedo = getMaterialAlbedo(mat);
|
|
<$evalMaterialAlbedo(albedoTex, albedo, matKey, albedo)$>;
|
|
albedo *= _color.rgb;
|
|
|
|
float roughness = getMaterialRoughness(mat);
|
|
<$evalMaterialRoughness(roughnessTex, roughness, matKey, roughness)$>;
|
|
|
|
float metallic = getMaterialMetallic(mat);
|
|
vec3 fresnel = getFresnelF0(metallic, albedo);
|
|
|
|
vec3 emissive = getMaterialEmissive(mat);
|
|
<$evalMaterialEmissive(emissiveTex, emissive, matKey, emissive)$>;
|
|
|
|
vec3 fragPositionES = _positionES.xyz;
|
|
vec3 fragPositionWS = _positionWS.xyz;
|
|
// Lighting is done in world space
|
|
vec3 fragNormalWS;
|
|
<$evalMaterialNormalLOD(_positionES, normalTex, _normalWS, _tangentWS, fragNormalWS)$>
|
|
|
|
TransformCamera cam = getTransformCamera();
|
|
vec3 fragToEyeWS = cam._viewInverse[3].xyz - fragPositionWS;
|
|
vec3 fragToEyeDirWS = normalize(fragToEyeWS);
|
|
SurfaceData surfaceWS = initSurfaceData(roughness, fragNormalWS, fragToEyeDirWS);
|
|
|
|
vec4 localLighting = vec4(0.0);
|
|
|
|
<$fetchClusterInfo(_positionWS)$>;
|
|
if (hasLocalLights(numLights, clusterPos, dims)) {
|
|
localLighting = evalLocalLighting(cluster, numLights, fragPositionWS, surfaceWS,
|
|
metallic, fresnel, albedo, 0.0,
|
|
vec4(0), vec4(0), opacity);
|
|
}
|
|
|
|
_fragColor = vec4(evalGlobalLightingAlphaBlendedWithHaze(
|
|
cam._viewInverse,
|
|
1.0,
|
|
occlusionTex,
|
|
fragPositionES,
|
|
fragPositionWS,
|
|
albedo,
|
|
fresnel,
|
|
metallic,
|
|
emissive,
|
|
surfaceWS, opacity, localLighting.rgb),
|
|
opacity);
|
|
}
|