overte-HifiExperiments/libraries/entities-renderer/src/proceduralParticle.slf
2024-10-29 23:30:11 -07:00

176 lines
4.6 KiB
Text

<@include gpu/Config.slh@>
<$VERSION_HEADER$>
// <$_SCRIBE_FILENAME$>
// Generated on <$_SCRIBE_DATE$>
//
// Created by HifiExperiements on 11/21/23
// Copyright 2023 Overte e.V.
//
// 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@>
<@include procedural/ProceduralCommon.slh@>
<@include procedural/ProceduralParticleCommon.slh@>
<$declareProceduralParticleRender()$>
layout(location=0) flat in int particleID;
layout(location=1) in vec4 _positionES;
#line 1001
//PROCEDURAL_BLOCK_BEGIN
vec3 getProceduralColor() {
return vec3(1.0);
}
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 = vec3(0.0, 1.0, 0.0);
vec3 diffuse = vec3(0.0);
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 alpha = 1.0;
float emissiveAmount = 0.0;
<@if HIFI_USE_TRANSLUCENT@>
TransformCamera cam = getTransformCamera();
vec3 posEye = _positionES.xyz;
<@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@>
// Particles have AA disabled so this doesn't matter
vec4 PREV_POSITION_CS = vec4(0.0, 0.0, 0.0, 1.0);
if (emissiveAmount > 0.0) {
packDeferredFragmentLightmap(
PREV_POSITION_CS,
normal,
1.0,
diffuse,
roughness,
metallic,
emissive);
} else {
packDeferredFragment(
PREV_POSITION_CS,
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@>
}