mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-08-12 12:03:13 +02:00
67 lines
2.4 KiB
Text
67 lines
2.4 KiB
Text
<@include gpu/Config.slh@>
|
|
<$VERSION_HEADER$>
|
|
// Generated on <$_SCRIBE_DATE$>
|
|
// polyvox_fade.frag
|
|
// fragment shader
|
|
//
|
|
// Created by Olivier Prat on 2017-06-08
|
|
// Copyright 2017 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 DeferredBufferWrite.slh@>
|
|
<@include render-utils/ShaderConstants.h@>
|
|
<@include entities-renderer/ShaderConstants.h@>
|
|
|
|
<@include Fade.slh@>
|
|
|
|
layout(location=RENDER_UTILS_ATTR_NORMAL_MS) in vec3 _normal;
|
|
layout(location=RENDER_UTILS_ATTR_POSITION_MS) in vec4 _position;
|
|
layout(location=RENDER_UTILS_ATTR_POSITION_WS) in vec4 _worldPosition;
|
|
layout(location=RENDER_UTILS_ATTR_POSITION_ES) in vec4 _worldFadePosition;
|
|
|
|
layout(binding=ENTITIES_TEXTURE_POLYVOX_XMAP) uniform sampler2D xMap;
|
|
layout(binding=ENTITIES_TEXTURE_POLYVOX_YMAP) uniform sampler2D yMap;
|
|
layout(binding=ENTITIES_TEXTURE_POLYVOX_ZMAP) uniform sampler2D zMap;
|
|
|
|
layout(location=ENTITIES_UNIFORM_POLYVOX_VOXEL_SIZE) uniform vec3 voxelVolumeSize;
|
|
|
|
// Declare after all samplers to prevent sampler location mix up with voxel shading (sampler locations are hardcoded in RenderablePolyVoxEntityItem)
|
|
<$declareFadeFragment()$>
|
|
|
|
void main(void) {
|
|
vec3 emissive;
|
|
FadeObjectParams fadeParams;
|
|
|
|
<$fetchFadeObjectParams(fadeParams)$>
|
|
applyFade(fadeParams, _worldFadePosition.xyz, emissive);
|
|
|
|
vec3 worldNormal = cross(dFdy(_worldPosition.xyz), dFdx(_worldPosition.xyz));
|
|
worldNormal = normalize(worldNormal);
|
|
|
|
float inPositionX = (_worldPosition.x - 0.5) / voxelVolumeSize.x;
|
|
float inPositionY = (_worldPosition.y - 0.5) / voxelVolumeSize.y;
|
|
float inPositionZ = (_worldPosition.z - 0.5) / voxelVolumeSize.z;
|
|
|
|
vec4 xyDiffuse = texture(xMap, vec2(-inPositionX, -inPositionY));
|
|
vec4 xzDiffuse = texture(yMap, vec2(-inPositionX, inPositionZ));
|
|
vec4 yzDiffuse = texture(zMap, vec2(inPositionZ, -inPositionY));
|
|
|
|
vec3 xyDiffuseScaled = xyDiffuse.rgb * abs(worldNormal.z);
|
|
vec3 xzDiffuseScaled = xzDiffuse.rgb * abs(worldNormal.y);
|
|
vec3 yzDiffuseScaled = yzDiffuse.rgb * abs(worldNormal.x);
|
|
vec4 diffuse = vec4(xyDiffuseScaled + xzDiffuseScaled + yzDiffuseScaled, 1.0);
|
|
|
|
packDeferredFragment(
|
|
_normal,
|
|
1.0,
|
|
vec3(diffuse),
|
|
DEFAULT_ROUGHNESS,
|
|
DEFAULT_METALLIC,
|
|
DEFAULT_EMISSIVE+emissive,
|
|
DEFAULT_OCCLUSION,
|
|
DEFAULT_SCATTERING);
|
|
}
|