mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-06-21 05:00:23 +02:00
184 lines
4.9 KiB
Text
184 lines
4.9 KiB
Text
<@include gpu/Config.slh@>
|
|
<$VERSION_HEADER$>
|
|
// <$_SCRIBE_FILENAME$>
|
|
// Generated on <$_SCRIBE_DATE$>
|
|
//
|
|
// Created by Andrzej Kapolka on 9/15/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
|
|
//
|
|
|
|
<@if not HIFI_USE_TRANSLUCENT@>
|
|
<@include DeferredBufferWrite.slh@>
|
|
<@else@>
|
|
<@include DefaultMaterials.slh@>
|
|
|
|
<@include GlobalLight.slh@>
|
|
<$declareEvalGlobalLightingAlphaBlended()$>
|
|
|
|
layout(location=0) out vec4 _fragColor0;
|
|
<@endif@>
|
|
|
|
<@include gpu/Transform.slh@>
|
|
<$declareStandardCameraTransform()$>
|
|
|
|
<@include render-utils/ShaderConstants.h@>
|
|
|
|
layout(location=RENDER_UTILS_ATTR_POSITION_MS) in vec4 _positionMS;
|
|
layout(location=RENDER_UTILS_ATTR_POSITION_ES) in vec4 _positionES;
|
|
layout(location=RENDER_UTILS_ATTR_NORMAL_MS) in vec3 _normalMS;
|
|
layout(location=RENDER_UTILS_ATTR_NORMAL_WS) in vec3 _normalWS;
|
|
layout(location=RENDER_UTILS_ATTR_COLOR) in vec4 _color;
|
|
layout(location=RENDER_UTILS_ATTR_TEXCOORD01) in vec4 _texCoord01;
|
|
#define _texCoord0 _texCoord01.xy
|
|
#define _texCoord1 _texCoord01.zw
|
|
|
|
// For retro-compatibility
|
|
#define _normal _normalWS
|
|
#define _modelNormal _normalMS
|
|
#define _position _positionMS
|
|
#define _eyePosition _positionES
|
|
|
|
<@include procedural/ProceduralCommon.slh@>
|
|
|
|
#line 1001
|
|
//PROCEDURAL_BLOCK_BEGIN
|
|
|
|
vec3 getProceduralColor() {
|
|
return _color.rgb;
|
|
}
|
|
|
|
float getProceduralColors(inout vec3 diffuse, inout vec3 specular, inout float shininess) {
|
|
return 1.0;
|
|
}
|
|
|
|
float getProceduralFragment(inout ProceduralFragment proceduralData) {
|
|
return 1.0;
|
|
}
|
|
|
|
float getProceduralFragmentWithPosition(inout ProceduralFragmentWithPosition proceduralData) {
|
|
return 1.0;
|
|
}
|
|
|
|
//PROCEDURAL_BLOCK_END
|
|
|
|
#line 2030
|
|
void main(void) {
|
|
vec3 normal = normalize(_normalWS.xyz) * (2.0 * float(gl_FrontFacing) - 1.0);
|
|
vec3 diffuse = _color.rgb;
|
|
vec3 fresnel = DEFAULT_FRESNEL;
|
|
float roughness = DEFAULT_ROUGHNESS;
|
|
float metallic = DEFAULT_METALLIC;
|
|
vec3 emissive = DEFAULT_EMISSIVE;
|
|
float occlusion = DEFAULT_OCCLUSION;
|
|
float scattering = DEFAULT_SCATTERING;
|
|
|
|
float emissiveAmount = 0.0;
|
|
|
|
<@if HIFI_USE_TRANSLUCENT@>
|
|
float alpha = _color.a;
|
|
TransformCamera cam = getTransformCamera();
|
|
vec3 posEye = _positionES.xyz;
|
|
<@else@>
|
|
float alpha = 1.0;
|
|
<@endif@>
|
|
|
|
#if defined(PROCEDURAL_V1)
|
|
diffuse = getProceduralColor().rgb;
|
|
emissiveAmount = 1.0;
|
|
emissive = vec3(1.0);
|
|
#elif defined(PROCEDURAL_V2)
|
|
vec3 specular = DEFAULT_SPECULAR;
|
|
float shininess = DEFAULT_SHININESS;
|
|
emissiveAmount = getProceduralColors(diffuse, specular, shininess);
|
|
roughness = max(0.0, 1.0 - shininess / 128.0);
|
|
metallic = length(specular);
|
|
emissive = vec3(clamp(emissiveAmount, 0.0, 1.0));
|
|
#elif defined(PROCEDURAL_V3) || defined(PROCEDURAL_V4)
|
|
#if defined(PROCEDURAL_V3)
|
|
ProceduralFragment proceduralData = ProceduralFragment(
|
|
#else
|
|
TransformCamera cam = getTransformCamera();
|
|
vec4 position = cam._viewInverse * _positionES;
|
|
ProceduralFragmentWithPosition proceduralData = ProceduralFragmentWithPosition(
|
|
position.xyz,
|
|
#endif
|
|
normal,
|
|
diffuse,
|
|
fresnel,
|
|
emissive,
|
|
alpha,
|
|
roughness,
|
|
metallic,
|
|
occlusion,
|
|
scattering
|
|
);
|
|
|
|
#if defined(PROCEDURAL_V3)
|
|
emissiveAmount = getProceduralFragment(proceduralData);
|
|
#else
|
|
emissiveAmount = getProceduralFragmentWithPosition(proceduralData);
|
|
#endif
|
|
normal = proceduralData.normal;
|
|
diffuse = proceduralData.diffuse;
|
|
fresnel = proceduralData.specular;
|
|
roughness = proceduralData.roughness;
|
|
metallic = proceduralData.metallic;
|
|
emissive = proceduralData.emissive;
|
|
occlusion = proceduralData.occlusion;
|
|
scattering = proceduralData.scattering;
|
|
alpha = proceduralData.alpha;
|
|
|
|
#if defined(PROCEDURAL_V4)
|
|
position = vec4(proceduralData.position, 1.0);
|
|
vec4 posEye4 = cam._view * position;
|
|
<@if HIFI_USE_TRANSLUCENT@>
|
|
posEye = posEye4.xyz;
|
|
<@endif@>
|
|
vec4 posClip = cam._projection * posEye4;
|
|
gl_FragDepth = 0.5 * (posClip.z / posClip.w + 1.0);
|
|
#endif
|
|
|
|
#endif
|
|
|
|
<@if not HIFI_USE_TRANSLUCENT@>
|
|
if (emissiveAmount > 0.0) {
|
|
packDeferredFragmentLightmap(
|
|
normal,
|
|
1.0,
|
|
diffuse,
|
|
roughness,
|
|
metallic,
|
|
emissive);
|
|
} else {
|
|
packDeferredFragment(
|
|
normal,
|
|
1.0,
|
|
diffuse,
|
|
roughness,
|
|
metallic,
|
|
emissive,
|
|
occlusion,
|
|
scattering);
|
|
}
|
|
<@else@>
|
|
if (emissiveAmount > 0.0) {
|
|
_fragColor0 = vec4(diffuse, alpha);
|
|
} else {
|
|
_fragColor0 = vec4(evalGlobalLightingAlphaBlended(
|
|
cam._viewInverse,
|
|
1.0,
|
|
occlusion,
|
|
posEye,
|
|
normal,
|
|
diffuse,
|
|
fresnel,
|
|
metallic,
|
|
emissive,
|
|
roughness, alpha),
|
|
alpha);
|
|
}
|
|
<@endif@>
|
|
}
|