1
0
Fork 0

HDR: Complete refactoring of shader style and naming

See https://wiki.flightgear.org/Shader_Style_Guide.
This commit is contained in:
Fernando García Liñán 2023-04-07 08:17:37 +02:00
parent c64130fc4c
commit 8af67bfb2f
162 changed files with 2642 additions and 2843 deletions

View file

@ -8,14 +8,15 @@
<!--
G-Buffer layout
..........................................................................
...........................................................................
: : Red : Green : Blue : Alpha :
:.......................:...........:.........:............:.............:
:........................:...........:.........:............:.............:
: G-Buffer 0 (RGB10_A2) : Normal : Roughness : Material ID :
: G-Buffer 1 (RGBA8) : Base Color : Metallic :
: G-Buffer 2 (RGBA8) : Material specific params : Occlusion :
: G-Buffer 3 (R11G11B10) : Emission : - :
: Depth/Stencil : DEPTH32F_STENCIL8 (Reversed depth) :
:.......................:............:.........:...........:.............:
:........................:............:.........:...........:.............:
Notes:
- Two 10-bit channels is enough for normals, as long as we are using
@ -51,6 +52,13 @@
<height>screen</height>
<format>rgba8</format>
</buffer>
<buffer>
<name>gbuffer3</name>
<type>2d</type>
<width>screen</width>
<height>screen</height>
<format>r11f-g11f-b10f</format>
</buffer>
<buffer>
<name>depth-stencil</name>
<type>2d</type>
@ -59,7 +67,7 @@
<format>depth32f-stencil</format>
</buffer>
<!-- HDR lighting result -->
<!-- HDR shading result -->
<buffer>
<name>hdr-result</name>
<type>2d</type>
@ -290,6 +298,10 @@
<component>color2</component>
<buffer>gbuffer2</buffer>
</attachment>
<attachment>
<component>color3</component>
<buffer>gbuffer3</buffer>
</attachment>
</pass>
<!--
@ -640,6 +652,10 @@
<component>color2</component>
<buffer>gbuffer2</buffer>
</attachment>
<attachment>
<component>color3</component>
<buffer>gbuffer3</buffer>
</attachment>
<attachment>
<component>depth</component>
<buffer>depth-stencil</buffer>
@ -737,14 +753,14 @@
</pass>
<!--
Main lighting pass
Main shading pass (for opaque objects)
Combine the G-Buffer and other buffers to compute the final shading value
of the pixel in HDR.
-->
<pass>
<name>lighting</name>
<name>shading</name>
<type>quad</type>
<effect>Effects/HDR/lighting</effect>
<effect>Effects/HDR/shading-opaque</effect>
<use-shadow-pass>csm0</use-shadow-pass>
<use-shadow-pass>csm1</use-shadow-pass>
<use-shadow-pass>csm2</use-shadow-pass>
@ -770,6 +786,10 @@
</binding>
<binding>
<unit>3</unit>
<buffer>gbuffer3</buffer>
</binding>
<binding>
<unit>4</unit>
<buffer>depth-stencil</buffer>
</binding>
<binding>
@ -808,7 +828,7 @@
<pass>
<name>water</name>
<type>quad</type>
<effect>Effects/HDR/water-lighting</effect>
<effect>Effects/HDR/water-shading</effect>
<binding>
<unit>0</unit>
<buffer>gbuffer0</buffer>

View file

@ -1,34 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<PropertyList>
<name>Effects/Fallback/hdr-geometry</name>
<technique n="110">
<scheme>hdr-geometry</scheme>
<pass>
<!-- Reverse floating point depth buffer -->
<depth>
<function>gequal</function>
<near>1.0</near>
<far>0.0</far>
</depth>
<texture-unit>
<unit>0</unit>
<type><use>texture[0]/type</use></type>
<image><use>texture[0]/image</use></image>
<filter><use>texture[0]/filter</use></filter>
<wrap-s><use>texture[0]/wrap-s</use></wrap-s>
<wrap-t><use>texture[0]/wrap-t</use></wrap-t>
</texture-unit>
<cull-face>back</cull-face>
<program>
<vertex-shader>Shaders/HDR/geometry.vert</vertex-shader>
<fragment-shader>Shaders/HDR/geometry.frag</fragment-shader>
<fragment-shader>Shaders/HDR/gbuffer-include.frag</fragment-shader>
</program>
<uniform>
<name>color_tex</name>
<type>sampler-2d</type>
<value type="int">0</value>
</uniform>
</pass>
</technique>
</PropertyList>

View file

@ -1,35 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<PropertyList>
<name>Effects/Fallback/hdr-shadow</name>
<technique n="120">
<scheme>hdr-shadow</scheme>
<pass>
<texture-unit>
<unit>0</unit>
<type><use>texture[0]/type</use></type>
<image><use>texture[0]/image</use></image>
<filter><use>texture[0]/filter</use></filter>
<wrap-s><use>texture[0]/wrap-s</use></wrap-s>
<wrap-t><use>texture[0]/wrap-t</use></wrap-t>
</texture-unit>
<color-mask type="vec4d">0 0 0 0</color-mask>
<cull-face>back</cull-face>
<blend>
<active>false</active>
</blend>
<polygon-offset>
<factor>1.1</factor>
<units>4.0</units>
</polygon-offset>
<program>
<vertex-shader>Shaders/HDR/geometry-shadow.vert</vertex-shader>
<fragment-shader>Shaders/HDR/geometry-shadow.frag</fragment-shader>
</program>
<uniform>
<name>color_tex</name>
<type>sampler-2d</type>
<value type="int">0</value>
</uniform>
</pass>
</technique>
</PropertyList>

View file

@ -1,23 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<PropertyList>
<name>Effects/HDR/ao</name>
<technique n="1">
<pass>
<program>
<vertex-shader>Shaders/HDR/trivial.vert</vertex-shader>
<fragment-shader>Shaders/HDR/ao.frag</fragment-shader>
<fragment-shader>Shaders/HDR/gbuffer-include.frag</fragment-shader>
</program>
<uniform>
<name>gbuffer0_tex</name>
<type>sampler-2d</type>
<value type="int">0</value>
</uniform>
<uniform>
<name>depth_tex</name>
<type>sampler-2d</type>
<value type="int">1</value>
</uniform>
</pass>
</technique>
</PropertyList>

View file

@ -4,10 +4,12 @@
<technique n="1">
<pass>
<program>
<vertex-shader>Shaders/HDR/trivial.vert</vertex-shader>
<fragment-shader>Shaders/HDR/atmos-aerial-perspective.frag</fragment-shader>
<fragment-shader>Shaders/HDR/atmos-include.frag</fragment-shader>
<fragment-shader>Shaders/HDR/gbuffer-include.frag</fragment-shader>
<vertex-shader>Shaders/HDR/quad.vert</vertex-shader>
<fragment-shader>Shaders/HDR/atmos_aerial_perspective.frag</fragment-shader>
<fragment-shader>Shaders/HDR/math.glsl</fragment-shader>
<fragment-shader>Shaders/HDR/pos_from_depth.glsl</fragment-shader>
<fragment-shader>Shaders/HDR/atmos.glsl</fragment-shader>
<fragment-shader>Shaders/HDR/atmos_spectral.glsl</fragment-shader>
</program>
<uniform>
<name>transmittance_lut</name>

View file

@ -4,9 +4,10 @@
<technique n="1">
<pass>
<program>
<vertex-shader>Shaders/HDR/trivial.vert</vertex-shader>
<fragment-shader>Shaders/HDR/atmos-sky-view.frag</fragment-shader>
<fragment-shader>Shaders/HDR/atmos-include.frag</fragment-shader>
<vertex-shader>Shaders/HDR/quad.vert</vertex-shader>
<fragment-shader>Shaders/HDR/atmos_sky_view.frag</fragment-shader>
<fragment-shader>Shaders/HDR/math.glsl</fragment-shader>
<fragment-shader>Shaders/HDR/atmos.glsl</fragment-shader>
</program>
<uniform>
<name>transmittance_lut</name>

View file

@ -4,9 +4,10 @@
<technique n="1">
<pass>
<program>
<vertex-shader>Shaders/HDR/trivial.vert</vertex-shader>
<fragment-shader>Shaders/HDR/atmos-transmittance.frag</fragment-shader>
<fragment-shader>Shaders/HDR/atmos-include.frag</fragment-shader>
<vertex-shader>Shaders/HDR/quad.vert</vertex-shader>
<fragment-shader>Shaders/HDR/atmos_transmittance.frag</fragment-shader>
<fragment-shader>Shaders/HDR/math.glsl</fragment-shader>
<fragment-shader>Shaders/HDR/atmos.glsl</fragment-shader>
</program>
</pass>
</technique>

View file

@ -2,17 +2,17 @@
<PropertyList>
<name>Effects/HDR/bloom-threshold</name>
<parameters>
<bloom-threshold><use>/sim/rendering/hdr/bloom-threshold</use></bloom-threshold>
<exposure-compensation>
<use>/sim/rendering/hdr/exposure-compensation</use>
</exposure-compensation>
<bloom-threshold><use>/sim/rendering/hdr/bloom-threshold</use></bloom-threshold>
</parameters>
<technique n="1">
<pass>
<program>
<vertex-shader>Shaders/HDR/trivial.vert</vertex-shader>
<fragment-shader>Shaders/HDR/bloom-threshold.frag</fragment-shader>
<fragment-shader>Shaders/HDR/exposure-include.frag</fragment-shader>
<vertex-shader>Shaders/HDR/quad.vert</vertex-shader>
<fragment-shader>Shaders/HDR/bloom_threshold.frag</fragment-shader>
<fragment-shader>Shaders/HDR/exposure.glsl</fragment-shader>
</program>
<uniform>
<name>hdr_tex</name>
@ -24,16 +24,17 @@
<type>sampler-2d</type>
<value type="int">1</value>
</uniform>
<uniform>
<name>exposure_compensation</name>
<type>float</type>
<value><use>exposure-compensation</use></value>
</uniform>
<uniform>
<name>bloom_threshold</name>
<type>float</type>
<value><use>bloom-threshold</use></value>
</uniform>
<!-- exposure.glsl -->
<uniform>
<name>exposure_compensation</name>
<type>float</type>
<value><use>exposure-compensation</use></value>
</uniform>
</pass>
</technique>
</PropertyList>

View file

@ -7,7 +7,7 @@
<technique n="1">
<pass>
<program>
<vertex-shader>Shaders/HDR/trivial.vert</vertex-shader>
<vertex-shader>Shaders/HDR/quad.vert</vertex-shader>
<fragment-shader>Shaders/HDR/blur.frag</fragment-shader>
</program>
<uniform>

View file

@ -4,11 +4,11 @@
<technique n="1">
<pass>
<program>
<vertex-shader>Shaders/HDR/trivial-notexcoord.vert</vertex-shader>
<fragment-shader>Shaders/HDR/copy-prev-luminance.frag</fragment-shader>
<vertex-shader>Shaders/HDR/quad_notexcoord.vert</vertex-shader>
<fragment-shader>Shaders/HDR/copy_prev_luminance.frag</fragment-shader>
</program>
<uniform>
<name>tex</name>
<name>lum_tex</name>
<type>sampler-2d</type>
<value type="int">0</value>
</uniform>

View file

@ -4,11 +4,11 @@
<technique n="1">
<pass>
<program>
<vertex-shader>Shaders/HDR/envmap-prefilter.vert</vertex-shader>
<fragment-shader>Shaders/HDR/envmap-copy.frag</fragment-shader>
<vertex-shader>Shaders/HDR/envmap.vert</vertex-shader>
<fragment-shader>Shaders/HDR/envmap_copy.frag</fragment-shader>
</program>
<uniform>
<name>envmap</name>
<name>envmap_tex</name>
<type>sampler-cube</type>
<value type="int">0</value>
</uniform>

View file

@ -4,15 +4,17 @@
<parameters>
<roughness type="float">0.0</roughness>
<num-samples type="int">1</num-samples>
<mip-count type="int">4</mip-count>
</parameters>
<technique n="1">
<pass>
<program>
<vertex-shader>Shaders/HDR/envmap-prefilter.vert</vertex-shader>
<fragment-shader>Shaders/HDR/envmap-prefilter.frag</fragment-shader>
<vertex-shader>Shaders/HDR/envmap.vert</vertex-shader>
<fragment-shader>Shaders/HDR/envmap_prefilter.frag</fragment-shader>
<fragment-shader>Shaders/HDR/math.glsl</fragment-shader>
</program>
<uniform>
<name>envmap</name>
<name>envmap_tex</name>
<type>sampler-cube</type>
<value type="int">0</value>
</uniform>
@ -26,6 +28,11 @@
<type>int</type>
<value><use>num-samples</use></value>
</uniform>
<uniform>
<name>mip_count</name>
<type>int</type>
<value><use>mip-count</use></value>
</uniform>
</pass>
</technique>
</PropertyList>

View file

@ -4,8 +4,8 @@
<technique n="1">
<pass>
<program>
<vertex-shader>Shaders/HDR/trivial.vert</vertex-shader>
<fragment-shader>Shaders/HDR/gbuffer-debug-clear.frag</fragment-shader>
<vertex-shader>Shaders/HDR/quad.vert</vertex-shader>
<fragment-shader>Shaders/HDR/debug_gbuffer_clear.frag</fragment-shader>
</program>
</pass>
</technique>

View file

@ -4,8 +4,8 @@
<technique n="1">
<pass>
<program>
<vertex-shader>Shaders/HDR/trivial-quad.vert</vertex-shader>
<fragment-shader>Shaders/HDR/gbuffer-debug-color.frag</fragment-shader>
<vertex-shader>Shaders/HDR/quad_matrix.vert</vertex-shader>
<fragment-shader>Shaders/HDR/debug_gbuffer_color.frag</fragment-shader>
</program>
<uniform>
<name>gbuffer1_tex</name>

View file

@ -4,9 +4,9 @@
<technique n="1">
<pass>
<program>
<vertex-shader>Shaders/HDR/trivial-quad.vert</vertex-shader>
<fragment-shader>Shaders/HDR/gbuffer-debug-depth.frag</fragment-shader>
<fragment-shader>Shaders/HDR/gbuffer-include.frag</fragment-shader>
<vertex-shader>Shaders/HDR/quad_matrix.vert</vertex-shader>
<fragment-shader>Shaders/HDR/debug_gbuffer_orm.frag</fragment-shader>
<fragment-shader>Shaders/HDR/pos_from_depth.glsl</fragment-shader>
</program>
<uniform>
<name>depth_tex</name>

View file

@ -4,8 +4,8 @@
<technique n="1">
<pass>
<program>
<vertex-shader>Shaders/HDR/trivial-quad.vert</vertex-shader>
<fragment-shader>Shaders/HDR/gbuffer-debug-matid.frag</fragment-shader>
<vertex-shader>Shaders/HDR/quad_matrix.vert</vertex-shader>
<fragment-shader>Shaders/HDR/debug_gbuffer_matid.frag</fragment-shader>
</program>
<uniform>
<name>gbuffer0_tex</name>

View file

@ -4,8 +4,8 @@
<technique n="1">
<pass>
<program>
<vertex-shader>Shaders/HDR/trivial-quad.vert</vertex-shader>
<fragment-shader>Shaders/HDR/gbuffer-debug-normal.frag</fragment-shader>
<vertex-shader>Shaders/HDR/quad_matrix.vert</vertex-shader>
<fragment-shader>Shaders/HDR/debug_gbuffer_normal.frag</fragment-shader>
</program>
<uniform>
<name>gbuffer0_tex</name>

View file

@ -4,8 +4,8 @@
<technique n="1">
<pass>
<program>
<vertex-shader>Shaders/HDR/trivial-quad.vert</vertex-shader>
<fragment-shader>Shaders/HDR/gbuffer-debug-orm.frag</fragment-shader>
<vertex-shader>Shaders/HDR/quad_matrix.vert</vertex-shader>
<fragment-shader>Shaders/HDR/debug_gbuffer_orm.frag</fragment-shader>
</program>
<uniform>
<name>gbuffer0_tex</name>

View file

@ -4,8 +4,8 @@
<technique n="1">
<pass>
<program>
<vertex-shader>Shaders/HDR/trivial-notexcoord.vert</vertex-shader>
<fragment-shader>Shaders/HDR/gtao-denoiser.frag</fragment-shader>
<vertex-shader>Shaders/HDR/quad_notexcoord.vert</vertex-shader>
<fragment-shader>Shaders/HDR/gtao_denoiser.frag</fragment-shader>
</program>
<uniform>
<name>ao_tex</name>

View file

@ -13,9 +13,11 @@
<value>8</value>
</stencil>
<program>
<vertex-shader>Shaders/HDR/trivial.vert</vertex-shader>
<vertex-shader>Shaders/HDR/quad.vert</vertex-shader>
<fragment-shader>Shaders/HDR/gtao.frag</fragment-shader>
<fragment-shader>Shaders/HDR/gbuffer-include.frag</fragment-shader>
<fragment-shader>Shaders/HDR/math.glsl</fragment-shader>
<fragment-shader>Shaders/HDR/normal_encoding.glsl</fragment-shader>
<fragment-shader>Shaders/HDR/pos_from_depth.glsl</fragment-shader>
</program>
<uniform>
<name>gbuffer0_tex</name>

View file

@ -4,8 +4,8 @@
<technique n="1">
<pass>
<program>
<vertex-shader>Shaders/HDR/trivial-notexcoord.vert</vertex-shader>
<fragment-shader>Shaders/HDR/histogram-aggregate.frag</fragment-shader>
<vertex-shader>Shaders/HDR/quad_notexcoord.vert</vertex-shader>
<fragment-shader>Shaders/HDR/histogram_aggregate.frag</fragment-shader>
</program>
<uniform>
<name>partial_histogram_tex</name>

View file

@ -4,9 +4,10 @@
<technique n="1">
<pass>
<program>
<vertex-shader>Shaders/HDR/trivial-notexcoord.vert</vertex-shader>
<fragment-shader>Shaders/HDR/histogram-column.frag</fragment-shader>
<fragment-shader>Shaders/HDR/histogram-include.frag</fragment-shader>
<vertex-shader>Shaders/HDR/quad_notexcoord.vert</vertex-shader>
<fragment-shader>Shaders/HDR/histogram_column.frag</fragment-shader>
<fragment-shader>Shaders/HDR/color.glsl</fragment-shader>
<fragment-shader>Shaders/HDR/histogram.glsl</fragment-shader>
</program>
<uniform>
<name>hdr_tex</name>

View file

@ -4,9 +4,9 @@
<technique n="1">
<pass>
<program>
<vertex-shader>Shaders/HDR/trivial-notexcoord.vert</vertex-shader>
<fragment-shader>Shaders/HDR/histogram-luminance.frag</fragment-shader>
<fragment-shader>Shaders/HDR/histogram-include.frag</fragment-shader>
<vertex-shader>Shaders/HDR/quad_notexcoord.vert</vertex-shader>
<fragment-shader>Shaders/HDR/histogram_luminance.frag</fragment-shader>
<fragment-shader>Shaders/HDR/histogram.glsl</fragment-shader>
</program>
<uniform>
<name>histogram_tex</name>

View file

@ -2,18 +2,20 @@
<PropertyList>
<name>Effects/HDR/postprocess</name>
<parameters>
<bloom-magnitude><use>/sim/rendering/hdr/bloom-magnitude</use></bloom-magnitude>
<debug-ev100><use>/sim/rendering/hdr/debug/display-ev100</use></debug-ev100>
<exposure-compensation>
<use>/sim/rendering/hdr/exposure-compensation</use>
</exposure-compensation>
<bloom-magnitude><use>/sim/rendering/hdr/bloom-magnitude</use></bloom-magnitude>
<debug-ev100><use>/sim/rendering/hdr/debug/display-ev100</use></debug-ev100>
</parameters>
<technique n="1">
<pass>
<program>
<vertex-shader>Shaders/HDR/trivial.vert</vertex-shader>
<vertex-shader>Shaders/HDR/quad.vert</vertex-shader>
<fragment-shader>Shaders/HDR/postprocess.frag</fragment-shader>
<fragment-shader>Shaders/HDR/exposure-include.frag</fragment-shader>
<fragment-shader>Shaders/HDR/exposure.glsl</fragment-shader>
<fragment-shader>Shaders/HDR/aces.glsl</fragment-shader>
<fragment-shader>Shaders/HDR/color.glsl</fragment-shader>
</program>
<uniform>
<name>hdr_tex</name>
@ -30,11 +32,6 @@
<type>sampler-2d</type>
<value type="int">4</value>
</uniform>
<uniform>
<name>exposure_compensation</name>
<type>float</type>
<value><use>exposure-compensation</use></value>
</uniform>
<uniform>
<name>bloom_magnitude</name>
<type>float</type>
@ -45,6 +42,12 @@
<type>bool</type>
<value><use>debug-ev100</use></value>
</uniform>
<!-- exposure.glsl -->
<uniform>
<name>exposure_compensation</name>
<type>float</type>
<value><use>exposure-compensation</use></value>
</uniform>
</pass>
</technique>
</PropertyList>

View file

@ -1,7 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<PropertyList>
<name>Effects/HDR/lighting</name>
<name>Effects/HDR/shading-opaque</name>
<parameters>
<!-- ibl.glsl -->
<texture n="8">
<image>Textures/PBR/dfg_lut.dds</image>
<type>2d</type>
@ -11,9 +12,11 @@
<wrap-t>clamp-to-edge</wrap-t>
<internal-format>normalized</internal-format>
</texture>
<!-- gtao.glsl -->
<ambient-occlusion-enabled>
<use>/sim/rendering/hdr/ambient-occlusion/enabled</use>
</ambient-occlusion-enabled>
<!-- shadows.glsl -->
<show-shadow-cascades>
<use>/sim/rendering/hdr/debug/show-shadow-cascades</use>
</show-shadow-cascades>
@ -35,14 +38,22 @@
<internal-format><use>texture[8]/internal-format</use></internal-format>
</texture-unit>
<program>
<vertex-shader>Shaders/HDR/trivial.vert</vertex-shader>
<fragment-shader>Shaders/HDR/lighting.frag</fragment-shader>
<fragment-shader>Shaders/HDR/gbuffer-include.frag</fragment-shader>
<fragment-shader>Shaders/HDR/shadows-include.frag</fragment-shader>
<fragment-shader>Shaders/HDR/lighting-include.frag</fragment-shader>
<fragment-shader>Shaders/HDR/aerial-perspective-include.frag</fragment-shader>
<fragment-shader>Shaders/HDR/clustered-include.frag</fragment-shader>
<vertex-shader>Shaders/HDR/quad.vert</vertex-shader>
<fragment-shader>Shaders/HDR/shading_opaque.frag</fragment-shader>
<fragment-shader>Shaders/HDR/gbuffer_unpack.glsl</fragment-shader>
<fragment-shader>Shaders/HDR/normal_encoding.glsl</fragment-shader>
<fragment-shader>Shaders/HDR/pos_from_depth.glsl</fragment-shader>
<fragment-shader>Shaders/HDR/math.glsl</fragment-shader>
<fragment-shader>Shaders/HDR/shading_opaque.glsl</fragment-shader>
<fragment-shader>Shaders/HDR/surface.glsl</fragment-shader>
<fragment-shader>Shaders/HDR/ibl.glsl</fragment-shader>
<fragment-shader>Shaders/HDR/shadows.glsl</fragment-shader>
<fragment-shader>Shaders/HDR/gtao.glsl</fragment-shader>
<fragment-shader>Shaders/HDR/aerial_perspective.glsl</fragment-shader>
<fragment-shader>Shaders/HDR/atmos_spectral.glsl</fragment-shader>
<fragment-shader>Shaders/HDR/clustered.glsl</fragment-shader>
</program>
<!-- gbuffer_unpack.glsl -->
<uniform>
<name>gbuffer0_tex</name>
<type>sampler-2d</type>
@ -59,10 +70,20 @@
<value type="int">2</value>
</uniform>
<uniform>
<name>depth_tex</name>
<name>gbuffer3_tex</name>
<type>sampler-2d</type>
<value type="int">3</value>
</uniform>
<!--
shadows.glsl
pos_from_depth.glsl
-->
<uniform>
<name>depth_tex</name>
<type>sampler-2d</type>
<value type="int">4</value>
</uniform>
<!-- gtao.glsl -->
<uniform>
<name>ao_tex</name>
<type>sampler-2d</type>
@ -73,36 +94,36 @@
<type>bool</type>
<value><use>ambient-occlusion-enabled</use></value>
</uniform>
<uniform>
<name>debug_shadow_cascades</name>
<type>bool</type>
<value><use>show-shadow-cascades</use></value>
</uniform>
<!-- Shadows include -->
<!-- shadows.glsl -->
<uniform>
<name>shadow_tex</name>
<type>sampler-2d-shadow</type>
<value type="int">10</value>
</uniform>
<!-- Lighting include -->
<uniform>
<name>dfg_lut</name>
<name>debug_shadow_cascades</name>
<type>bool</type>
<value><use>show-shadow-cascades</use></value>
</uniform>
<!-- ibl.glsl -->
<uniform>
<name>dfg_tex</name>
<type>sampler-2d</type>
<value type="int">8</value>
</uniform>
<uniform>
<name>prefiltered_envmap</name>
<name>prefiltered_envmap_tex</name>
<type>sampler-cube</type>
<value type="int">9</value>
</uniform>
<!-- Aerial perspective include -->
<!-- aerial_perspective.glsl -->
<uniform>
<name>aerial_perspective_lut</name>
<name>aerial_perspective_tex</name>
<type>sampler-2d</type>
<value type="int">11</value>
</uniform>
<uniform>
<name>transmittance_lut</name>
<name>transmittance_tex</name>
<type>sampler-2d</type>
<value type="int">12</value>
</uniform>

View file

@ -48,8 +48,8 @@
<internal-format><use>texture[2]/internal-format</use></internal-format>
</texture-unit>
<program>
<vertex-shader>Shaders/HDR/smaa-blending-weight-calculation.vert</vertex-shader>
<fragment-shader>Shaders/HDR/smaa-blending-weight-calculation.frag</fragment-shader>
<vertex-shader>Shaders/HDR/smaa_blending_weight_calculation.vert</vertex-shader>
<fragment-shader>Shaders/HDR/smaa_blending_weight_calculation.frag</fragment-shader>
</program>
<uniform>
<name>edges_tex</name>

View file

@ -9,8 +9,8 @@
<pass>replace</pass>
</stencil>
<program>
<vertex-shader>Shaders/HDR/smaa-edge-detection.vert</vertex-shader>
<fragment-shader>Shaders/HDR/smaa-edge-detection.frag</fragment-shader>
<vertex-shader>Shaders/HDR/smaa_edge_detection.vert</vertex-shader>
<fragment-shader>Shaders/HDR/smaa_edge_detection.frag</fragment-shader>
</program>
<uniform>
<name>color_tex</name>

View file

@ -4,8 +4,8 @@
<technique n="1">
<pass>
<program>
<vertex-shader>Shaders/HDR/smaa-neighborhood-blending.vert</vertex-shader>
<fragment-shader>Shaders/HDR/smaa-neighborhood-blending.frag</fragment-shader>
<vertex-shader>Shaders/HDR/smaa_neighborhood_blending.vert</vertex-shader>
<fragment-shader>Shaders/HDR/smaa_neighborhood_blending.frag</fragment-shader>
</program>
<uniform>
<name>color_tex</name>

View file

@ -4,8 +4,8 @@
<technique n="1">
<pass>
<program>
<vertex-shader>Shaders/HDR/trivial.vert</vertex-shader>
<fragment-shader>Shaders/HDR/trivial.frag</fragment-shader>
<vertex-shader>Shaders/HDR/quad.vert</vertex-shader>
<fragment-shader>Shaders/HDR/quad.frag</fragment-shader>
</program>
<uniform>
<name>tex</name>

View file

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<PropertyList>
<name>Effects/HDR/water-lighting</name>
<name>Effects/HDR/water-shading</name>
<technique n="1">
<pass>
<stencil>
@ -8,10 +8,13 @@
<value>3</value>
</stencil>
<program>
<vertex-shader>Shaders/HDR/trivial.vert</vertex-shader>
<fragment-shader>Shaders/HDR/water-lighting.frag</fragment-shader>
<fragment-shader>Shaders/HDR/gbuffer-include.frag</fragment-shader>
<fragment-shader>Shaders/HDR/aerial-perspective-include.frag</fragment-shader>
<vertex-shader>Shaders/HDR/quad.vert</vertex-shader>
<fragment-shader>Shaders/HDR/water_shading.frag</fragment-shader>
<fragment-shader>Shaders/HDR/math.glsl</fragment-shader>
<fragment-shader>Shaders/HDR/normal_encoding.glsl</fragment-shader>
<fragment-shader>Shaders/HDR/pos_from_depth.glsl</fragment-shader>
<fragment-shader>Shaders/HDR/aerial_perspective.glsl</fragment-shader>
<fragment-shader>Shaders/HDR/atmos_spectral.glsl</fragment-shader>
</program>
<uniform>
<name>gbuffer0_tex</name>
@ -23,24 +26,25 @@
<type>sampler-2d</type>
<value type="int">1</value>
</uniform>
<uniform>
<name>prefiltered_envmap_tex</name>
<type>sampler-cube</type>
<value type="int">9</value>
</uniform>
<!-- pos_from_depth.glsl -->
<uniform>
<name>depth_tex</name>
<type>sampler-2d</type>
<value type="int">3</value>
</uniform>
<!-- aerial_perspective.glsl -->
<uniform>
<name>prefiltered_envmap</name>
<type>sampler-cube</type>
<value type="int">9</value>
</uniform>
<!-- Aerial perspective include -->
<uniform>
<name>aerial_perspective_lut</name>
<name>aerial_perspective_tex</name>
<type>sampler-2d</type>
<value type="int">11</value>
</uniform>
<uniform>
<name>transmittance_lut</name>
<name>transmittance_tex</name>
<type>sampler-2d</type>
<value type="int">12</value>
</uniform>

View file

@ -83,12 +83,14 @@
<rendering-hint>opaque</rendering-hint>
<cull-face><use>cull-face</use></cull-face>
<program>
<vertex-shader>Shaders/HDR/geometry-chrome.vert</vertex-shader>
<fragment-shader>Shaders/HDR/geometry-chrome.frag</fragment-shader>
<fragment-shader>Shaders/HDR/gbuffer-include.frag</fragment-shader>
<vertex-shader>Shaders/HDR/model_chrome.vert</vertex-shader>
<fragment-shader>Shaders/HDR/model_chrome.frag</fragment-shader>
<fragment-shader>Shaders/HDR/gbuffer_pack.glsl</fragment-shader>
<fragment-shader>Shaders/HDR/normal_encoding.glsl</fragment-shader>
</program>
</pass>
</technique>
<technique n="119">
<scheme>hdr-shadow</scheme>
<pass>
@ -100,9 +102,10 @@
<units>4.0</units>
</polygon-offset>
<program>
<vertex-shader>Shaders/HDR/geometry-shadow.vert</vertex-shader>
<fragment-shader>Shaders/HDR/geometry-shadow.frag</fragment-shader>
<vertex-shader>Shaders/HDR/model_shadow.vert</vertex-shader>
<fragment-shader>Shaders/HDR/model_shadow.frag</fragment-shader>
</program>
</pass>
</technique>
</PropertyList>

View file

@ -258,23 +258,25 @@
<blend>1</blend>
<rendering-hint>transparent</rendering-hint>
<program>
<vertex-shader>Shaders/HDR/cloud-static.vert</vertex-shader>
<vertex-shader>Shaders/HDR/aerial-perspective-include.frag</vertex-shader>
<vertex-shader>Shaders/HDR/cloud_static.vert</vertex-shader>
<vertex-shader>Shaders/HDR/aerial_perspective.glsl</vertex-shader>
<vertex-shader>Shaders/HDR/atmos_spectral.glsl</vertex-shader>
<fragment-shader>Shaders/HDR/3dcloud.frag</fragment-shader>
<fragment-shader>Shaders/HDR/aerial_perspective.glsl</fragment-shader>
</program>
<uniform>
<name>baseTexture</name>
<name>base_tex</name>
<type>sampler-2d</type>
<value type="int">0</value>
</uniform>
<!-- Aerial perspective include -->
<!-- aerial_perspective.glsl -->
<uniform>
<name>aerial_perspective_lut</name>
<name>aerial_perspective_tex</name>
<type>sampler-2d</type>
<value type="int">11</value>
</uniform>
<uniform>
<name>transmittance_lut</name>
<name>transmittance_tex</name>
<type>sampler-2d</type>
<value type="int">12</value>
</uniform>

View file

@ -178,23 +178,25 @@
<blend>1</blend>
<rendering-hint>transparent</rendering-hint>
<program>
<vertex-shader>Shaders/HDR/cloud-static.vert</vertex-shader>
<vertex-shader>Shaders/HDR/aerial-perspective-include.frag</vertex-shader>
<vertex-shader>Shaders/HDR/cloud_static.vert</vertex-shader>
<vertex-shader>Shaders/HDR/aerial_perspective.glsl</vertex-shader>
<vertex-shader>Shaders/HDR/atmos_spectral.glsl</vertex-shader>
<fragment-shader>Shaders/HDR/3dcloud.frag</fragment-shader>
<fragment-shader>Shaders/HDR/aerial_perspective.glsl</fragment-shader>
</program>
<uniform>
<name>baseTexture</name>
<name>base_tex</name>
<type>sampler-2d</type>
<value type="int">0</value>
</uniform>
<!-- Aerial perspective include -->
<!-- aerial_perspective.glsl -->
<uniform>
<name>aerial_perspective_lut</name>
<name>aerial_perspective_tex</name>
<type>sampler-2d</type>
<value type="int">11</value>
</uniform>
<uniform>
<name>transmittance_lut</name>
<name>transmittance_tex</name>
<type>sampler-2d</type>
<value type="int">12</value>
</uniform>

View file

@ -386,23 +386,25 @@
<blend>1</blend>
<rendering-hint>transparent</rendering-hint>
<program>
<vertex-shader>Shaders/HDR/cloud-static.vert</vertex-shader>
<vertex-shader>Shaders/HDR/aerial-perspective-include.frag</vertex-shader>
<vertex-shader>Shaders/HDR/cloud_static.vert</vertex-shader>
<vertex-shader>Shaders/HDR/aerial_perspective.glsl</vertex-shader>
<vertex-shader>Shaders/HDR/atmos_spectral.glsl</vertex-shader>
<fragment-shader>Shaders/HDR/3dcloud.frag</fragment-shader>
<fragment-shader>Shaders/HDR/aerial_perspective.glsl</fragment-shader>
</program>
<uniform>
<name>baseTexture</name>
<name>base_tex</name>
<type>sampler-2d</type>
<value type="int">0</value>
</uniform>
<!-- Aerial perspective include -->
<!-- aerial_perspective.glsl -->
<uniform>
<name>aerial_perspective_lut</name>
<name>aerial_perspective_tex</name>
<type>sampler-2d</type>
<value type="int">11</value>
</uniform>
<uniform>
<name>transmittance_lut</name>
<name>transmittance_tex</name>
<type>sampler-2d</type>
<value type="int">12</value>
</uniform>

View file

@ -500,8 +500,10 @@
<rendering-hint>transparent</rendering-hint>
<program>
<vertex-shader>Shaders/HDR/3dcloud.vert</vertex-shader>
<vertex-shader>Shaders/HDR/aerial-perspective-include.frag</vertex-shader>
<vertex-shader>Shaders/HDR/aerial_perspective.glsl</vertex-shader>
<vertex-shader>Shaders/HDR/atmos_spectral.glsl</vertex-shader>
<fragment-shader>Shaders/HDR/3dcloud.frag</fragment-shader>
<fragment-shader>Shaders/HDR/aerial_perspective.glsl</fragment-shader>
<attribute>
<name>usrAttr1</name>
<index>10</index>
@ -512,7 +514,7 @@
</attribute>
</program>
<uniform>
<name>baseTexture</name>
<name>base_tex</name>
<type>sampler-2d</type>
<value type="int">0</value>
</uniform>
@ -526,14 +528,14 @@
<type>float</type>
<value><use>detail</use></value>
</uniform>
<!-- Aerial perspective include -->
<!-- aerial_perspective.glsl -->
<uniform>
<name>aerial_perspective_lut</name>
<name>aerial_perspective_tex</name>
<type>sampler-2d</type>
<value type="int">11</value>
</uniform>
<uniform>
<name>transmittance_lut</name>
<name>transmittance_tex</name>
<type>sampler-2d</type>
<value type="int">12</value>
</uniform>

View file

@ -120,9 +120,11 @@
<rendering-hint>opaque</rendering-hint>
<cull-face>back</cull-face>
<program>
<vertex-shader>Shaders/HDR/geometry-lfeat.vert</vertex-shader>
<fragment-shader>Shaders/HDR/geometry-lfeat.frag</fragment-shader>
<fragment-shader>Shaders/HDR/gbuffer-include.frag</fragment-shader>
<vertex-shader>Shaders/HDR/terrain_lfeat.vert</vertex-shader>
<fragment-shader>Shaders/HDR/terrain_lfeat.frag</fragment-shader>
<fragment-shader>Shaders/HDR/gbuffer_pack.glsl</fragment-shader>
<fragment-shader>Shaders/HDR/normal_encoding.glsl</fragment-shader>
<fragment-shader>Shaders/HDR/color.glsl</fragment-shader>
</program>
<uniform>
<name>color_tex</name>

View file

@ -1338,9 +1338,11 @@ please see Docs/README.model-combined.eff for documentation
</texture-unit>
<cull-face>back</cull-face>
<program>
<vertex-shader>Shaders/HDR/geometry-combined.vert</vertex-shader>
<fragment-shader>Shaders/HDR/geometry-combined.frag</fragment-shader>
<fragment-shader>Shaders/HDR/gbuffer-include.frag</fragment-shader>
<vertex-shader>Shaders/HDR/model_combined.vert</vertex-shader>
<fragment-shader>Shaders/HDR/model_combined.frag</fragment-shader>
<fragment-shader>Shaders/HDR/gbuffer_pack.glsl</fragment-shader>
<fragment-shader>Shaders/HDR/normal_encoding.glsl</fragment-shader>
<fragment-shader>Shaders/HDR/color.glsl</fragment-shader>
</program>
<uniform>
<name>color_tex</name>

View file

@ -692,9 +692,11 @@
<rendering-hint>opaque</rendering-hint>
<cull-face><use>cull-face</use></cull-face>
<program>
<vertex-shader>Shaders/HDR/geometry.vert</vertex-shader>
<fragment-shader>Shaders/HDR/geometry.frag</fragment-shader>
<fragment-shader>Shaders/HDR/gbuffer-include.frag</fragment-shader>
<vertex-shader>Shaders/HDR/model_default.vert</vertex-shader>
<fragment-shader>Shaders/HDR/model_default.frag</fragment-shader>
<fragment-shader>Shaders/HDR/gbuffer_pack.glsl</fragment-shader>
<fragment-shader>Shaders/HDR/normal_encoding.glsl</fragment-shader>
<fragment-shader>Shaders/HDR/color.glsl</fragment-shader>
</program>
<uniform>
<name>color_tex</name>
@ -725,8 +727,8 @@
<units>4.0</units>
</polygon-offset>
<program>
<vertex-shader>Shaders/HDR/geometry-shadow.vert</vertex-shader>
<fragment-shader>Shaders/HDR/geometry-shadow.frag</fragment-shader>
<vertex-shader>Shaders/HDR/model_shadow.vert</vertex-shader>
<fragment-shader>Shaders/HDR/model_shadow.frag</fragment-shader>
</program>
</pass>
</technique>

View file

@ -5,6 +5,10 @@
<inherits-from>Effects/model-pbr</inherits-from>
<parameters>
<!-- Alpha Coverage -->
<blend>1</blend>
<alpha-cutoff>-1.0</alpha-cutoff>
<!-- ibl.glsl -->
<texture n="8">
<image>Textures/PBR/dfg_lut.dds</image>
<type>2d</type>
@ -14,9 +18,6 @@
<wrap-t>clamp-to-edge</wrap-t>
<internal-format>normalized</internal-format>
</texture>
<!-- Alpha Coverage -->
<blend>1</blend>
<alpha-cutoff>-1.0</alpha-cutoff>
</parameters>
<technique n="108">
@ -87,12 +88,18 @@
<rendering-hint>transparent</rendering-hint>
<cull-face><use>cull-face</use></cull-face>
<program>
<vertex-shader>Shaders/HDR/geometry-pbr-transparent.vert</vertex-shader>
<fragment-shader>Shaders/HDR/geometry-pbr-transparent.frag</fragment-shader>
<fragment-shader>Shaders/HDR/gbuffer-include.frag</fragment-shader>
<fragment-shader>Shaders/HDR/shadows-include.frag</fragment-shader>
<fragment-shader>Shaders/HDR/lighting-include.frag</fragment-shader>
<fragment-shader>Shaders/HDR/aerial-perspective-include.frag</fragment-shader>
<vertex-shader>Shaders/HDR/model_pbr_transparent.vert</vertex-shader>
<vertex-shader>Shaders/HDR/aerial_perspective.glsl</vertex-shader>
<fragment-shader>Shaders/HDR/model_pbr_transparent.frag</fragment-shader>
<fragment-shader>Shaders/HDR/color.glsl</fragment-shader>
<fragment-shader>Shaders/HDR/math.glsl</fragment-shader>
<fragment-shader>Shaders/HDR/shading_transparent.glsl</fragment-shader>
<fragment-shader>Shaders/HDR/surface.glsl</fragment-shader>
<fragment-shader>Shaders/HDR/ibl.glsl</fragment-shader>
<fragment-shader>Shaders/HDR/shadows.glsl</fragment-shader>
<fragment-shader>Shaders/HDR/aerial_perspective.glsl</fragment-shader>
<fragment-shader>Shaders/HDR/atmos_spectral.glsl</fragment-shader>
<fragment-shader>Shaders/HDR/clustered.glsl</fragment-shader>
<attribute>
<name>tangent</name>
<index>6</index>
@ -152,36 +159,36 @@
<type>float</type>
<value><use>alpha-cutoff</use></value>
</uniform>
<!-- Shadows include -->
<uniform>
<name>depth_tex</name>
<type>sampler-2d</type>
<value type="int">7</value>
</uniform>
<!-- shadows.glsl -->
<uniform>
<name>shadow_tex</name>
<type>sampler-2d-shadow</type>
<value type="int">10</value>
</uniform>
<!-- Lighting include -->
<uniform>
<name>dfg_lut</name>
<name>debug_shadow_cascades</name>
<type>bool</type>
<value><use>show-shadow-cascades</use></value>
</uniform>
<!-- ibl.glsl -->
<uniform>
<name>dfg_tex</name>
<type>sampler-2d</type>
<value type="int">8</value>
</uniform>
<uniform>
<name>prefiltered_envmap</name>
<name>prefiltered_envmap_tex</name>
<type>sampler-cube</type>
<value type="int">9</value>
</uniform>
<!-- Aerial perspective include -->
<!-- aerial_perspective.glsl -->
<uniform>
<name>aerial_perspective_lut</name>
<name>aerial_perspective_tex</name>
<type>sampler-2d</type>
<value type="int">11</value>
</uniform>
<uniform>
<name>transmittance_lut</name>
<name>transmittance_tex</name>
<type>sampler-2d</type>
<value type="int">12</value>
</uniform>

View file

@ -89,9 +89,11 @@
<rendering-hint>opaque</rendering-hint>
<cull-face><use>cull-face</use></cull-face>
<program>
<vertex-shader>Shaders/HDR/geometry-pbr.vert</vertex-shader>
<fragment-shader>Shaders/HDR/geometry-pbr.frag</fragment-shader>
<fragment-shader>Shaders/HDR/gbuffer-include.frag</fragment-shader>
<vertex-shader>Shaders/HDR/model_pbr.vert</vertex-shader>
<fragment-shader>Shaders/HDR/model_pbr.frag</fragment-shader>
<fragment-shader>Shaders/HDR/gbuffer_pack.glsl</fragment-shader>
<fragment-shader>Shaders/HDR/normal_encoding.glsl</fragment-shader>
<fragment-shader>Shaders/HDR/color.glsl</fragment-shader>
<attribute>
<name>tangent</name>
<index>6</index>
@ -160,8 +162,8 @@
<units>4.0</units>
</polygon-offset>
<program>
<vertex-shader>Shaders/HDR/geometry-shadow.vert</vertex-shader>
<fragment-shader>Shaders/HDR/geometry-shadow.frag</fragment-shader>
<vertex-shader>Shaders/HDR/model_shadow.vert</vertex-shader>
<fragment-shader>Shaders/HDR/model_shadow.frag</fragment-shader>
</program>
</pass>
</technique>

View file

@ -9,7 +9,8 @@
<bin-name>DepthSortedBin</bin-name>
</render-bin>
<write-depth type="bool">false</write-depth>
<rendering-hint>transparent</rendering-hint>
<!-- ibl.glsl -->
<texture n="8">
<image>Textures/PBR/dfg_lut.dds</image>
<type>2d</type>
@ -19,11 +20,6 @@
<wrap-t>clamp-to-edge</wrap-t>
<internal-format>normalized</internal-format>
</texture>
<rendering-hint>transparent</rendering-hint>
<render-bin>
<bin-number>111</bin-number>
<bin-name>DepthSortedBin</bin-name>
</render-bin>
</parameters>
<!-- Place objects in render bin 111 (frontmost transparent objects).
@ -97,12 +93,18 @@
<rendering-hint>transparent</rendering-hint>
<cull-face><use>cull-face</use></cull-face>
<program>
<vertex-shader>Shaders/HDR/geometry-transparent.vert</vertex-shader>
<fragment-shader>Shaders/HDR/geometry-transparent.frag</fragment-shader>
<fragment-shader>Shaders/HDR/gbuffer-include.frag</fragment-shader>
<fragment-shader>Shaders/HDR/shadows-include.frag</fragment-shader>
<fragment-shader>Shaders/HDR/lighting-include.frag</fragment-shader>
<fragment-shader>Shaders/HDR/aerial-perspective-include.frag</fragment-shader>
<vertex-shader>Shaders/HDR/model_transparent.vert</vertex-shader>
<vertex-shader>Shaders/HDR/aerial_perspective.glsl</vertex-shader>
<fragment-shader>Shaders/HDR/model_transparent.frag</fragment-shader>
<fragment-shader>Shaders/HDR/color.glsl</fragment-shader>
<fragment-shader>Shaders/HDR/math.glsl</fragment-shader>
<fragment-shader>Shaders/HDR/shading_transparent.glsl</fragment-shader>
<fragment-shader>Shaders/HDR/surface.glsl</fragment-shader>
<fragment-shader>Shaders/HDR/ibl.glsl</fragment-shader>
<fragment-shader>Shaders/HDR/shadows.glsl</fragment-shader>
<fragment-shader>Shaders/HDR/aerial_perspective.glsl</fragment-shader>
<fragment-shader>Shaders/HDR/atmos_spectral.glsl</fragment-shader>
<fragment-shader>Shaders/HDR/clustered.glsl</fragment-shader>
</program>
<uniform>
<name>color_tex</name>
@ -119,36 +121,36 @@
<type>float-vec4</type>
<value><use>material/diffuse</use></value>
</uniform>
<!-- Shadows include -->
<uniform>
<name>depth_tex</name>
<type>sampler-2d</type>
<value type="int">7</value>
</uniform>
<!-- shadows.glsl -->
<uniform>
<name>shadow_tex</name>
<type>sampler-2d-shadow</type>
<value type="int">10</value>
</uniform>
<!-- Lighting include -->
<uniform>
<name>dfg_lut</name>
<name>debug_shadow_cascades</name>
<type>bool</type>
<value><use>show-shadow-cascades</use></value>
</uniform>
<!-- ibl.glsl -->
<uniform>
<name>dfg_tex</name>
<type>sampler-2d</type>
<value type="int">8</value>
</uniform>
<uniform>
<name>prefiltered_envmap</name>
<name>prefiltered_envmap_tex</name>
<type>sampler-cube</type>
<value type="int">9</value>
</uniform>
<!-- Aerial perspective include -->
<!-- aerial_perspective.glsl -->
<uniform>
<name>aerial_perspective_lut</name>
<name>aerial_perspective_tex</name>
<type>sampler-2d</type>
<value type="int">11</value>
</uniform>
<uniform>
<name>transmittance_lut</name>
<name>transmittance_tex</name>
<type>sampler-2d</type>
<value type="int">12</value>
</uniform>

View file

@ -1437,9 +1437,11 @@
</texture-unit>
<cull-face>back</cull-face>
<program>
<vertex-shader>Shaders/HDR/geometry-combined.vert</vertex-shader>
<fragment-shader>Shaders/HDR/geometry-combined.frag</fragment-shader>
<fragment-shader>Shaders/HDR/gbuffer-include.frag</fragment-shader>
<vertex-shader>Shaders/HDR/model_combined.vert</vertex-shader>
<fragment-shader>Shaders/HDR/model_combined.frag</fragment-shader>
<fragment-shader>Shaders/HDR/gbuffer_pack.glsl</fragment-shader>
<fragment-shader>Shaders/HDR/normal_encoding.glsl</fragment-shader>
<fragment-shader>Shaders/HDR/color.glsl</fragment-shader>
</program>
<uniform>
<name>color_tex</name>
@ -1466,7 +1468,6 @@
<type>float</type>
<value><use>normalmap-tiling</use></value>
</uniform>
</pass>
</technique>

View file

@ -925,9 +925,11 @@
<rendering-hint>opaque</rendering-hint>
<cull-face>back</cull-face>
<program>
<vertex-shader>Shaders/HDR/geometry-runway.vert</vertex-shader>
<fragment-shader>Shaders/HDR/geometry-runway.frag</fragment-shader>
<fragment-shader>Shaders/HDR/gbuffer-include.frag</fragment-shader>
<vertex-shader>Shaders/HDR/terrain_runway.vert</vertex-shader>
<fragment-shader>Shaders/HDR/terrain_runway.frag</fragment-shader>
<fragment-shader>Shaders/HDR/gbuffer_pack.glsl</fragment-shader>
<fragment-shader>Shaders/HDR/normal_encoding.glsl</fragment-shader>
<fragment-shader>Shaders/HDR/color.glsl</fragment-shader>
</program>
<uniform>
<name>color_tex</name>

View file

@ -314,6 +314,8 @@
<program>
<vertex-shader>Shaders/HDR/skydome.vert</vertex-shader>
<fragment-shader>Shaders/HDR/skydome.frag</fragment-shader>
<fragment-shader>Shaders/HDR/math.glsl</fragment-shader>
<fragment-shader>Shaders/HDR/atmos_spectral.glsl</fragment-shader>
</program>
<uniform>
<name>sun_disk</name>
@ -321,12 +323,12 @@
<value type="bool">true</value>
</uniform>
<uniform>
<name>transmittance_lut</name>
<name>transmittance_tex</name>
<type>sampler-2d</type>
<value type="int">12</value>
</uniform>
<uniform>
<name>sky_view_lut</name>
<name>sky_view_tex</name>
<type>sampler-2d</type>
<value type="int">13</value>
</uniform>
@ -342,6 +344,8 @@
<program>
<vertex-shader>Shaders/HDR/skydome.vert</vertex-shader>
<fragment-shader>Shaders/HDR/skydome.frag</fragment-shader>
<fragment-shader>Shaders/HDR/math.glsl</fragment-shader>
<fragment-shader>Shaders/HDR/atmos_spectral.glsl</fragment-shader>
</program>
<uniform>
<name>sun_disk</name>
@ -349,12 +353,12 @@
<value type="bool">false</value>
</uniform>
<uniform>
<name>transmittance_lut</name>
<name>transmittance_tex</name>
<type>sampler-2d</type>
<value type="int">12</value>
</uniform>
<uniform>
<name>sky_view_lut</name>
<name>sky_view_tex</name>
<type>sampler-2d</type>
<value type="int">13</value>
</uniform>

View file

@ -1695,9 +1695,11 @@
<rendering-hint>opaque</rendering-hint>
<cull-face>back</cull-face>
<program>
<vertex-shader>Shaders/HDR/geometry-terrain.vert</vertex-shader>
<fragment-shader>Shaders/HDR/geometry-terrain.frag</fragment-shader>
<fragment-shader>Shaders/HDR/gbuffer-include.frag</fragment-shader>
<vertex-shader>Shaders/HDR/terrain_default.vert</vertex-shader>
<fragment-shader>Shaders/HDR/terrain_default.frag</fragment-shader>
<fragment-shader>Shaders/HDR/gbuffer_pack.glsl</fragment-shader>
<fragment-shader>Shaders/HDR/normal_encoding.glsl</fragment-shader>
<fragment-shader>Shaders/HDR/color.glsl</fragment-shader>
</program>
<uniform>
<name>color_tex</name>

View file

@ -1550,9 +1550,10 @@
<internal-format><use>texture[8]/internal-format</use></internal-format>
</texture-unit>
<program>
<vertex-shader>Shaders/HDR/geometry-water.vert</vertex-shader>
<fragment-shader>Shaders/HDR/geometry-water.frag</fragment-shader>
<fragment-shader>Shaders/HDR/gbuffer-include.frag</fragment-shader>
<vertex-shader>Shaders/HDR/water.vert</vertex-shader>
<fragment-shader>Shaders/HDR/water.frag</fragment-shader>
<fragment-shader>Shaders/HDR/normal_encoding.glsl</fragment-shader>
<fragment-shader>Shaders/HDR/color.glsl</fragment-shader>
</program>
<uniform>
<name>water_normalmap</name>

View file

@ -1874,100 +1874,4 @@
</pass>
</technique>
<technique n="109">
<scheme>hdr-geometry</scheme>
<pass>
<!-- Reverse floating point depth buffer -->
<depth>
<function>gequal</function>
<near>1.0</near>
<far>0.0</far>
</depth>
<stencil>
<function>always</function>
<value>9</value>
<pass>replace</pass>
</stencil>
<blend><use>transparent</use></blend>
<alpha-test><use>transparent</use></alpha-test>
<shade-model>smooth</shade-model>
<cull-face>back</cull-face>
<render-bin>
<bin-number><use>render-bin/bin-number</use></bin-number>
<bin-name><use>render-bin/bin-name</use></bin-name>
</render-bin>
<!-- texture unit 0 direct from VPBBuilder.cxx -->
<texture-unit>
<unit>1</unit>
<image><use>texture[1]/image</use></image>
<filter>nearest-mipmap-nearest</filter>
<mag-filter>nearest-mipmap-nearest</mag-filter>
<wrap-s><use>texture[0]/wrap-s</use></wrap-s>
<wrap-t><use>texture[0]/wrap-t</use></wrap-t>
<internal-format><use>texture[0]/internal-format</use></internal-format>
</texture-unit>
<texture-unit>
<unit>2</unit>
<image><use>texture[2]/image</use></image>
<filter><use>texture[2]/filter</use></filter>
<wrap-s><use>texture[2]/wrap-s</use></wrap-s>
<wrap-t><use>texture[2]/wrap-t</use></wrap-t>
<internal-format><use>texture[2]/internal-format</use></internal-format>
</texture-unit>
<texture-unit>
<unit>3</unit>
<image><use>texture[3]/image</use></image>
<filter><use>texture[3]/filter</use></filter>
<wrap-s><use>texture[3]/wrap-s</use></wrap-s>
<wrap-t><use>texture[3]/wrap-t</use></wrap-t>
<internal-format><use>texture[3]/internal-format</use></internal-format>
</texture-unit>
<texture-unit>
<unit>4</unit>
<image><use>texture[4]/image</use></image>
<filter><use>texture[4]/filter</use></filter>
<wrap-s><use>texture[4]/wrap-s</use></wrap-s>
<wrap-t><use>texture[4]/wrap-t</use></wrap-t>
<internal-format><use>texture[4]/internal-format</use></internal-format>
</texture-unit>
<texture-unit>
<unit>6</unit>
<image><use>texture[6]/image</use></image>
<filter><use>texture[6]/filter</use></filter>
<wrap-s><use>texture[6]/wrap-s</use></wrap-s>
<wrap-t><use>texture[6]/wrap-t</use></wrap-t>
<internal-format><use>texture[6]/internal-format</use></internal-format>
</texture-unit>
<program>
<vertex-shader>Shaders/HDR/geometry.vert</vertex-shader>
<fragment-shader>Shaders/HDR/ws30.frag</fragment-shader>
<fragment-shader>Shaders/HDR/gbuffer-include.frag</fragment-shader>
</program>
<uniform>
<name>landclass</name>
<type>sampler-2d</type>
<value type="int">0</value>
</uniform>
<uniform>
<name>atlas</name>
<type>sampler-2d</type>
<value type="int">1</value>
</uniform>
<uniform>
<name>perlin</name>
<type>sampler-2d</type>
<value type="int">6</value>
</uniform>
</pass>
</technique>
</PropertyList>

View file

@ -1,24 +1,28 @@
#version 330 core
out vec4 fragColor;
layout(location = 0) out vec4 fragColor;
in vec2 texCoord;
in vec4 cloudColor;
in vec2 texcoord;
in vec4 cloud_color;
in vec4 ap_color;
uniform sampler2D baseTexture;
uniform sampler2D base_tex;
uniform mat4 osg_ProjectionMatrix;
uniform vec4 fg_Viewport;
uniform vec3 fg_SunDirection;
const int STEPS = 8;
uniform float density = 30.0;
uniform float max_sample_dist = 0.05;
const int STEPS = 8;
// aerial_perspective.glsl
vec3 mix_aerial_perspective(vec3 color, vec4 ap);
void main()
{
vec4 base = texture(baseTexture, texCoord);
vec4 base = texture(base_tex, texcoord);
// Directly discard fragments below a threshold
if (base.a < 0.02)
@ -43,8 +47,8 @@ void main()
float T = 1.0;
for (int i = 0; i < STEPS; ++i) {
float t = (float(i) + 0.5) * dt;
vec2 uv_t = texCoord - sun_dir * t;
vec4 texel = texture(baseTexture, uv_t);
vec2 uv_t = texcoord - sun_dir * t;
vec4 texel = texture(base_tex, uv_t);
// Beer-Lambert's law
T *= exp(-texel.a * dt * density);
}
@ -54,8 +58,10 @@ void main()
// the perpendicular.
float fade = smoothstep(0.1, 0.5, dot(vec3(0.0, 0.0, -1.0), fg_SunDirection));
vec4 color = base * cloudColor;
vec4 color = base * cloud_color;
color.rgb *= base.a * mix(1.0, T, fade);
color.rgb = mix_aerial_perspective(color.rgb, ap_color);
fragColor = color;
}

View file

@ -1,13 +1,14 @@
#version 330 core
layout(location = 0) in vec4 pos;
layout(location = 2) in vec4 vertexColor;
layout(location = 3) in vec4 multiTexCoord0;
layout(location = 2) in vec4 vertex_color;
layout(location = 3) in vec4 multitexcoord0;
layout(location = 10) in vec4 usrAttr1;
layout(location = 11) in vec4 usrAttr2;
out vec2 texCoord;
out vec4 cloudColor;
out vec2 texcoord;
out vec4 cloud_color;
out vec4 ap_color;
uniform float range;
uniform float detail_range;
@ -17,8 +18,8 @@ uniform mat4 osg_ModelViewProjectionMatrix;
uniform mat4 osg_ViewMatrixInverse;
uniform vec3 fg_SunDirectionWorld;
// aerial-perspective-include.frag
vec3 add_aerial_perspective(vec3 color, vec2 coord, float depth);
// aerial_perspective.glsl
vec4 get_aerial_perspective(vec2 coord, float depth);
vec3 get_sun_radiance(vec3 p);
void main()
@ -30,7 +31,7 @@ void main()
float middle_factor = usrAttr2.g;
float top_factor = usrAttr2.b;
texCoord = multiTexCoord0.st;
texcoord = multitexcoord0.st;
// XXX: Should be sent as an uniform
mat4 inverseModelViewMatrix = inverse(osg_ModelViewMatrix);
@ -52,20 +53,20 @@ void main()
final_pos.xyz += pos.y * r;
final_pos.xyz += pos.z * w;
// Apply Z scaling to allow sprites to be squashed in the z-axis
final_pos.z = final_pos.z * vertexColor.w;
final_pos.z = final_pos.z * vertex_color.w;
// Now shift the sprite to the correct position in the cloud.
final_pos.xyz += vertexColor.xyz;
final_pos.xyz += vertex_color.xyz;
// Determine the position - used for fog and shading calculations
float fogCoord = length(vec3(osg_ModelViewMatrix * vec4(vertexColor.xyz, 1.0)));
float fogCoord = length(vec3(osg_ModelViewMatrix * vec4(vertex_color.xyz, 1.0)));
float center_dist = length(vec3(osg_ModelViewMatrix * vec4(0.0, 0.0, 0.0, 1.0)));
if ((fogCoord > detail_range) && (fogCoord > center_dist) && (shade_factor < 0.7)) {
// More than detail_range away, so discard all sprites on opposite side of
// cloud center by shifting them beyond the view fustrum
gl_Position = vec4(0.0, 0.0, 10.0, 1.0);
cloudColor = vec4(0.0);
cloud_color = vec4(0.0);
} else {
gl_Position = osg_ModelViewProjectionMatrix * final_pos;
@ -91,26 +92,25 @@ void main()
final_pos.z * 2.0 / cloud_height - 1.0));
}
cloudColor.rgb = shade * get_sun_radiance(final_world_pos.xyz);
cloud_color.rgb = shade * get_sun_radiance(final_world_pos.xyz);
// Perspective division and scale to [0, 1] to get the screen position
// of the vertex.
vec2 coord = (gl_Position.xy / gl_Position.w) * 0.5 + 0.5;
cloudColor.rgb = add_aerial_perspective(
cloudColor.rgb, coord, length(final_view_pos));
ap_color = get_aerial_perspective(coord, length(final_view_pos));
if ((fogCoord > (0.9 * detail_range))
&& (fogCoord > center_dist)
&& (shade_factor < 0.7)) {
// cloudlet is almost at the detail range, so fade it out.
cloudColor.a = 1.0 - smoothstep(0.9 * detail_range, detail_range, fogCoord);
cloud_color.a = 1.0 - smoothstep(0.9 * detail_range, detail_range, fogCoord);
} else {
// As we get within 100m of the sprite, it is faded out.
// Equally at large distances it also fades out.
cloudColor.a = min(smoothstep(10.0, 100.0, fogCoord),
cloud_color.a = min(smoothstep(10.0, 100.0, fogCoord),
1.0 - smoothstep(0.9 * range, range, fogCoord));
}
cloudColor.a *= alpha_factor;
cloud_color.a *= alpha_factor;
}
}

28
Shaders/HDR/aces.glsl Normal file
View file

@ -0,0 +1,28 @@
/*
* ACES tone mapping
* From 'Baking Lab' by MJP and David Neubelt
* Original by Stephen Hill
* https://github.com/TheRealMJP/BakingLab/blob/master/BakingLab/ACES.hlsl
* Licensed under the MIT license
*/
#version 330 core
// sRGB => XYZ => D65_2_D60 => AP1 => RRT_SAT
const mat3 ACESInputMat = mat3(
0.59719, 0.07600, 0.02840,
0.35458, 0.90834, 0.13383,
0.04823, 0.01566, 0.83777);
// ODT_SAT => XYZ => D60_2_D65 => sRGB
const mat3 ACESOutputMat = mat3(
1.60475, -0.10208, -0.00327,
-0.53108, 1.10813, -0.07276,
-0.07367, -0.00605, 1.07602);
vec3 aces_fitted(vec3 color)
{
vec3 v = ACESInputMat * color;
vec3 a = v * (v + 0.0245786) - 0.000090537;
vec3 b = v * (0.983729 * v + 0.4329510) + 0.238081;
return clamp(ACESOutputMat * (a / b), 0.0, 1.0);
}

View file

@ -1,7 +1,7 @@
#version 330 core
uniform sampler2D aerial_perspective_lut;
uniform sampler2D transmittance_lut;
uniform sampler2D aerial_perspective_tex;
uniform sampler2D transmittance_tex;
uniform vec3 fg_SunDirectionWorld;
uniform float fg_CameraDistanceToEarthCenter;
@ -16,25 +16,9 @@ const float AP_TEXEL_WIDTH = 1.0 / (AP_SLICE_COUNT * AP_SLICE_WIDTH_PIXELS);
const float ATMOSPHERE_RADIUS = 6471e3;
//-- BEGIN spectral include
// Extraterrestial Solar Irradiance Spectra, units W * m^-2 * nm^-1
// https://www.nrel.gov/grid/solar-resource/spectra.html
const vec4 sun_spectral_irradiance = vec4(1.679, 1.828, 1.986, 1.307);
const mat4x3 M = mat4x3(
137.672389239975, -8.632904716299537, -1.7181567391931372,
32.549094028629234, 91.29801417199785, -12.005406444382531,
-38.91428392614275, 34.31665471469816, 29.89044807197628,
8.572844237945445, -11.103384660054624, 117.47585277566478
);
vec3 linear_srgb_from_spectral_samples(vec4 L)
{
return M * L;
}
//-- END spectral include
// atmos_spectral.glsl
vec4 get_sun_spectral_irradiance();
vec3 linear_srgb_from_spectral_samples(vec4 L);
vec4 sample_aerial_perspective_slice(sampler2D lut, vec2 coord, float slice)
{
@ -64,10 +48,19 @@ vec4 sample_aerial_perspective(sampler2D lut, vec2 coord, float depth)
return color;
}
vec4 get_aerial_perspective(vec2 coord, float depth)
{
return sample_aerial_perspective(aerial_perspective_tex, coord, depth);
}
vec3 mix_aerial_perspective(vec3 color, vec4 ap)
{
return color * ap.a + ap.rgb;
}
vec3 add_aerial_perspective(vec3 color, vec2 coord, float depth)
{
vec4 ap = sample_aerial_perspective(aerial_perspective_lut, coord, depth);
return color * ap.a + ap.rgb;
return mix_aerial_perspective(color, get_aerial_perspective(coord, depth));
}
/*
@ -86,8 +79,16 @@ vec3 get_sun_radiance(vec3 p)
float u = sun_cos_theta * 0.5 + 0.5;
float v = clamp(normalized_altitude, 0.0, 1.0);
vec4 transmittance = texture(transmittance_lut, vec2(u, v));
vec4 transmittance = texture(transmittance_tex, vec2(u, v));
vec4 L = sun_spectral_irradiance * transmittance;
vec4 L = get_sun_spectral_irradiance() * transmittance;
return linear_srgb_from_spectral_samples(L);
}
vec3 get_sun_radiance_sea_level()
{
vec2 uv = vec2(fg_SunZenithCosTheta * 0.5 + 0.5, 0.0);
vec4 transmittance = texture(transmittance_tex, uv);
vec4 L = get_sun_spectral_irradiance() * transmittance;
return linear_srgb_from_spectral_samples(L);
}

View file

@ -1,73 +0,0 @@
#version 330 core
#pragma optionNV (unroll all)
out float fragColor;
in vec2 texCoord;
uniform sampler2D gbuffer0_tex;
uniform sampler2D depth_tex;
uniform mat4 fg_ProjectionMatrix;
const float RADIUS = 0.04;
const float BIAS = 0.05;
const float SCALE = 3.0;
const float MAX_DISTANCE = 0.08;
const float INTENSITY = 1.5;
const vec2 kernel[4] = vec2[](
vec2( 0.0, 1.0), // top
vec2( 1.0, 0.0), // right
vec2( 0.0, -1.0), // bottom
vec2(-1.0, 0.0)); // left
vec3 decodeNormal(vec2 f);
vec3 positionFromDepth(vec2 pos, float depth);
float rand(vec2 co) {
return fract(sin(dot(co.xy, vec2(12.9898,78.233))) * 43758.5453);
}
float sampleAO(vec3 fragPos, vec3 normal, vec2 coords)
{
float sampleDepth = texture(depth_tex, coords).r;
vec3 samplePoint = positionFromDepth(coords, sampleDepth);
vec3 diff = samplePoint - fragPos;
float l = length(diff);
vec3 v = diff / l;
float d = l * SCALE;
float ao = max(0.0, dot(normal, v) - BIAS) * (1.0 / (1.0 + d));
ao *= smoothstep(MAX_DISTANCE, MAX_DISTANCE * 0.5, l);
return ao;
}
void main()
{
vec4 gbuffer0 = texture(gbuffer0_tex, texCoord);
float depth = texture(depth_tex, texCoord).r;
vec3 normal = decodeNormal(gbuffer0.rg);
vec3 fragPos = positionFromDepth(texCoord, depth);
vec2 randomVec = normalize(vec2(rand(texCoord) * 2.0 - 1.0,
rand(texCoord+1.0) * 2.0 - 1.0));
const float sin45 = 0.707107;
float occlusion = 0.0;
for (int i = 0; i < 4; ++i) {
vec2 k1 = reflect(kernel[i], randomVec) * RADIUS;
vec2 k2 = vec2(k1.x * sin45 - k1.y * sin45, k1.x * sin45 + k1.y * sin45);
occlusion += sampleAO(fragPos, normal, texCoord + k1);
occlusion += sampleAO(fragPos, normal, texCoord + k2 * 0.75);
occlusion += sampleAO(fragPos, normal, texCoord + k1 * 0.5);
occlusion += sampleAO(fragPos, normal, texCoord + k2 * 0.25);
}
occlusion /= 16.0;
fragColor = clamp(1.0 - occlusion * INTENSITY, 0.0, 1.0);
}

View file

@ -1,14 +1,13 @@
#version 330 core
const float PI = 3.14159265358979323846;
const float INV_PI = 0.31830988618379067154;
const float INV_4PI = 0.25 * INV_PI;
const float PHASE_ISOTROPIC = INV_4PI;
const float RAYLEIGH_PHASE_SCALE = (3.0 / 16.0) * INV_PI;
const float g = 0.8;
const float gg = g*g;
// math.glsl
float M_PI();
float M_1_PI();
float M_1_4PI();
const float ATMOSPHERE_RADIUS = 6471e3;
const float RAYLEIGH_PHASE_SCALE = 0.05968310365946075091; // 3/(16*pi)
const float HENYEY_ASYMMETRY = 0.8;
const float HENYEY_ASYMMETRY2 = HENYEY_ASYMMETRY*HENYEY_ASYMMETRY;
// Rayleigh scattering coefficient at sea level, units m^-1
// "Rayleigh-scattering calculations for the terrestrial atmosphere"
@ -77,9 +76,19 @@ uniform float fg_EarthRadius;
//------------------------------------------------------------------------------
float get_earth_radius()
{
return fg_EarthRadius;
}
float get_atmosphere_radius()
{
return 6471e3; // m
}
/*
* Helper function to obtain the transmittance to the top of the atmosphere
* from Buffer A.
* from the precomputed transmittance LUT.
*/
vec4 transmittance_from_lut(sampler2D lut, float cos_theta, float normalized_altitude)
{
@ -117,8 +126,8 @@ float molecular_phase_function(float cos_theta)
*/
float aerosol_phase_function(float cos_theta)
{
float den = 1.0 + gg + 2.0 * g * cos_theta;
return INV_4PI * (1.0 - gg) / (den * sqrt(den));
float den = 1.0 + HENYEY_ASYMMETRY2 + 2.0 * HENYEY_ASYMMETRY * cos_theta;
return M_1_4PI() * (1.0 - HENYEY_ASYMMETRY2) / (den * sqrt(den));
}
/*
@ -132,7 +141,7 @@ vec4 get_multiple_scattering(sampler2D transmittance_lut,
{
// Solid angle subtended by the planet from a point at d distance
// from the planet center.
float omega = 2.0 * PI * (1.0 - sqrt(d*d - fg_EarthRadius*fg_EarthRadius) / d);
float omega = 2.0 * M_PI() * (1.0 - sqrt(d*d - get_earth_radius()*fg_EarthRadius) / d);
omega = max(0.0, omega);
vec4 T_to_ground = transmittance_from_lut(transmittance_lut, cos_theta, 0.0);
@ -142,7 +151,7 @@ vec4 get_multiple_scattering(sampler2D transmittance_lut,
transmittance_from_lut(transmittance_lut, 1.0, normalized_height);
// 2nd order scattering from the ground
vec4 L_ground = PHASE_ISOTROPIC * omega * (ground_albedo * INV_PI)
vec4 L_ground = M_1_4PI() * omega * (ground_albedo * M_1_PI())
* T_to_ground * T_ground_to_sample * max(0.0, cos_theta);
// Fit of Earth's multiple scattering coming from other points in the atmosphere
@ -230,11 +239,11 @@ vec4 compute_inscattering(in vec3 ray_origin,
// 3. Any object within the atmosphere.
float ray_altitude = length(ray_origin);
// Handle the camera being underground
float earth_radius = min(ray_altitude, fg_EarthRadius);
float atmos_dist = ray_sphere_intersection(ray_origin, ray_dir, ATMOSPHERE_RADIUS);
float earth_radius = min(ray_altitude, get_earth_radius());
float atmos_dist = ray_sphere_intersection(ray_origin, ray_dir, get_atmosphere_radius());
float ground_dist = ray_sphere_intersection(ray_origin, ray_dir, earth_radius);
float t_d;
if (ray_altitude < ATMOSPHERE_RADIUS) {
if (ray_altitude < get_atmosphere_radius()) {
// We are inside the atmosphere
if (ground_dist < 0.0) {
// No ground collision, use the distance to the outer atmosphere
@ -269,8 +278,8 @@ vec4 compute_inscattering(in vec3 ray_origin,
float distance_to_earth_center = length(x_t);
vec3 zenith_dir = x_t / distance_to_earth_center;
float altitude = distance_to_earth_center - fg_EarthRadius;
float normalized_altitude = altitude / (ATMOSPHERE_RADIUS - fg_EarthRadius);
float altitude = distance_to_earth_center - get_earth_radius();
float normalized_altitude = altitude / (get_atmosphere_radius() - get_earth_radius());
float sample_cos_theta = dot(zenith_dir, sun_dir);

View file

@ -1,17 +1,19 @@
// Render the aerial perspective LUT, similar to
// "A Scalable and Production Ready Sky and Atmosphere Rendering Technique"
// by Sébastien Hillaire (2020).
//
// Unlike the paper, we are using a tiled 2D texture instead of a true 3D
// texture. For some reason the overhead of rendering to a texture many times
// (the depth of the 3D texture) seems to be too high, probably because OSG is
// not sharing state between those passes.
/*
* Render the aerial perspective LUT, similar to
* "A Scalable and Production Ready Sky and Atmosphere Rendering Technique"
* by Sébastien Hillaire (2020).
*
* Unlike the paper, we are using a tiled 2D texture instead of a true 3D
* texture. For some reason the overhead of rendering to a texture many times
* (the depth of the 3D texture) seems to be too high, probably because OSG is
* not sharing state between those passes.
*/
#version 330 core
out vec4 fragColor;
layout(location = 0) out vec4 fragColor;
in vec2 texCoord;
in vec2 texcoord;
uniform sampler2D transmittance_lut;
@ -23,10 +25,9 @@ const float AP_SLICE_COUNT = 32.0;
const float AP_MAX_DEPTH = 128000.0;
const int AERIAL_PERSPECTIVE_STEPS = 20;
// gbuffer-include.frag
vec3 positionFromDepth(vec2 pos, float depth);
// atmos-include.frag
// pos_from_depth.glsl
vec3 get_view_space_from_depth(vec2 uv, float depth);
// atmos.glsl
vec4 compute_inscattering(in vec3 ray_origin,
in vec3 ray_dir,
in float t_max,
@ -34,41 +35,23 @@ vec4 compute_inscattering(in vec3 ray_origin,
in int steps,
in sampler2D transmittance_lut,
out vec4 transmittance);
//-- BEGIN spectral include
// Extraterrestial Solar Irradiance Spectra, units W * m^-2 * nm^-1
// https://www.nrel.gov/grid/solar-resource/spectra.html
const vec4 sun_spectral_irradiance = vec4(1.679, 1.828, 1.986, 1.307);
const mat4x3 M = mat4x3(
137.672389239975, -8.632904716299537, -1.7181567391931372,
32.549094028629234, 91.29801417199785, -12.005406444382531,
-38.91428392614275, 34.31665471469816, 29.89044807197628,
8.572844237945445, -11.103384660054624, 117.47585277566478
);
vec3 linear_srgb_from_spectral_samples(vec4 L)
{
return M * L;
}
//-- END spectral include
// atmos_spectral.glsl
vec4 get_sun_spectral_irradiance();
vec3 linear_srgb_from_spectral_samples(vec4 L);
void main()
{
// Account for the depth slice we are currently in. Depth goes from 0 to
// DEPTH_RANGE in a squared distribution. The first slice is not 0 since
// that would waste a slice.
float x = texCoord.x * AP_SLICE_COUNT;
float x = texcoord.x * AP_SLICE_COUNT;
float slice = ceil(x);
float w = slice / AP_SLICE_COUNT; // [0,1]
float depth = w*w * AP_MAX_DEPTH;
vec2 coord = vec2(fract(x), texCoord.y);
vec2 coord = vec2(fract(x), texcoord.y);
vec3 frag_pos = positionFromDepth(coord, 1.0);
vec3 frag_pos = get_view_space_from_depth(coord, 1.0);
vec3 ray_dir = vec4(fg_ViewMatrixInverse * vec4(normalize(frag_pos), 0.0)).xyz;
vec4 transmittance;
@ -80,7 +63,8 @@ void main()
transmittance_lut,
transmittance);
// In-scattering
fragColor.rgb = linear_srgb_from_spectral_samples(L * sun_spectral_irradiance);
fragColor.rgb = linear_srgb_from_spectral_samples(
L * get_sun_spectral_irradiance());
// Transmittance
fragColor.a = dot(transmittance, vec4(0.25));
}

View file

@ -1,17 +1,20 @@
#version 330 core
out vec4 fragColor;
layout(location = 0) out vec4 fragColor;
in vec2 texCoord;
in vec2 texcoord;
uniform sampler2D transmittance_lut;
uniform float fg_SunZenithCosTheta;
uniform float fg_CameraDistanceToEarthCenter;
const float PI = 3.14159265358979323846;
const int SKY_STEPS = 32;
// atmos-include.frag
// math.glsl
float M_2PI();
float M_PI_2();
// atmos.glsl
vec4 compute_inscattering(in vec3 ray_origin,
in vec3 ray_dir,
in float t_max,
@ -30,11 +33,11 @@ void main()
0.0,
fg_SunZenithCosTheta);
float azimuth = 2.0 * PI * texCoord.x; // [0, 2pi]
float azimuth = M_2PI() * texcoord.x; // [0, 2pi]
// Apply a non-linear transformation to the elevation to dedicate more
// texels to the horizon, where having more detail matters.
float l = texCoord.y * 2.0 - 1.0;
float elev = l*l * sign(l) * PI * 0.5; // [-pi/2, pi/2]
float l = texcoord.y * 2.0 - 1.0;
float elev = l*l * sign(l) * M_PI_2(); // [-pi/2, pi/2]
vec3 ray_dir = vec3(cos(elev) * cos(azimuth),
cos(elev) * sin(azimuth),

View file

@ -0,0 +1,22 @@
#version 330 core
// Extraterrestial Solar Irradiance Spectra, units W * m^-2 * nm^-1
// https://www.nrel.gov/grid/solar-resource/spectra.html
const vec4 sun_spectral_irradiance = vec4(1.679, 1.828, 1.986, 1.307);
const mat4x3 M = mat4x3(
137.672389239975, -8.632904716299537, -1.7181567391931372,
32.549094028629234, 91.29801417199785, -12.005406444382531,
-38.91428392614275, 34.31665471469816, 29.89044807197628,
8.572844237945445, -11.103384660054624, 117.47585277566478
);
vec4 get_sun_spectral_irradiance()
{
return sun_spectral_irradiance;
}
vec3 linear_srgb_from_spectral_samples(vec4 L)
{
return M * L;
}

View file

@ -1,15 +1,14 @@
#version 330 core
out vec4 fragColor;
layout(location = 0) out vec4 fragColor;
in vec2 texCoord;
in vec2 texcoord;
uniform float fg_EarthRadius;
const float ATMOSPHERE_RADIUS = 6471e3;
const int TRANSMITTANCE_STEPS = 40;
// atmos-include.frag
// atmos.glsl
float get_earth_radius();
float get_atmosphere_radius();
float ray_sphere_intersection(vec3 ro, vec3 rd, float radius);
void get_atmosphere_collision_coefficients(in float h,
out vec4 aerosol_absorption,
@ -20,13 +19,15 @@ void get_atmosphere_collision_coefficients(in float h,
void main()
{
float sun_cos_theta = texCoord.x * 2.0 - 1.0;
float sun_cos_theta = texcoord.x * 2.0 - 1.0;
vec3 sun_dir = vec3(-sqrt(1.0 - sun_cos_theta*sun_cos_theta), 0.0, sun_cos_theta);
float distance_to_earth_center = mix(fg_EarthRadius, ATMOSPHERE_RADIUS, texCoord.y);
float distance_to_earth_center = mix(get_earth_radius(),
get_atmosphere_radius(),
texcoord.y);
vec3 ray_origin = vec3(0.0, 0.0, distance_to_earth_center);
float t_d = ray_sphere_intersection(ray_origin, sun_dir, ATMOSPHERE_RADIUS);
float t_d = ray_sphere_intersection(ray_origin, sun_dir, get_atmosphere_radius());
float dt = t_d / float(TRANSMITTANCE_STEPS);
vec4 result = vec4(0.0);
@ -35,7 +36,7 @@ void main()
float t = (float(i) + 0.5) * dt;
vec3 x_t = ray_origin + sun_dir * t;
float altitude = length(x_t) - fg_EarthRadius;
float altitude = length(x_t) - get_earth_radius();
vec4 aerosol_absorption, aerosol_scattering;
vec4 molecular_absorption, molecular_scattering;

View file

@ -1,24 +0,0 @@
#version 330 core
out vec3 fragColor;
in vec2 texCoord;
uniform sampler2D hdr_tex;
uniform sampler2D lum_tex;
uniform float bloom_threshold;
vec3 applyExposure(vec3 color, float avgLuminance, float threshold);
void main()
{
vec3 hdrColor = texture(hdr_tex, texCoord).rgb;
float avgLuminance = texelFetch(lum_tex, ivec2(0), 0).r;
vec3 exposedHdrColor = applyExposure(hdrColor, avgLuminance, bloom_threshold);
if (dot(exposedHdrColor, vec3(0.333)) <= 0.001)
fragColor = vec3(0.0);
else
fragColor = exposedHdrColor;
}

View file

@ -0,0 +1,25 @@
#version 330 core
layout(location = 0) out vec3 fragColor;
in vec2 texcoord;
uniform sampler2D hdr_tex;
uniform sampler2D lum_tex;
uniform float bloom_threshold;
// exposure.glsl
vec3 apply_exposure(vec3 color, float avg_lum, float threshold);
void main()
{
vec3 hdr_color = texture(hdr_tex, texcoord).rgb;
float avg_lum = texelFetch(lum_tex, ivec2(0), 0).r;
vec3 exposed_hdr_color = apply_exposure(hdr_color, avg_lum, bloom_threshold);
if (dot(exposed_hdr_color, vec3(0.333)) <= 0.001)
fragColor = vec3(0.0);
else
fragColor = exposed_hdr_color;
}

View file

@ -1,8 +1,8 @@
#version 330 core
out vec4 fragColor;
layout(location = 0) out vec4 fragColor;
in vec2 texCoord;
in vec2 texcoord;
uniform sampler2D tex;
uniform sampler2D prev_pass_tex;
@ -15,19 +15,19 @@ void main()
if (vertical) offset.x = 0.0;
else offset.y = 0.0;
vec4 sum = texture(prev_pass_tex, texCoord);
vec4 sum = texture(prev_pass_tex, texcoord);
sum += texture(tex, texCoord - 4.0 * offset) * 0.0162162162;
sum += texture(tex, texCoord - 3.0 * offset) * 0.0540540541;
sum += texture(tex, texCoord - 2.0 * offset) * 0.1216216216;
sum += texture(tex, texCoord - 1.0 * offset) * 0.1945945946;
sum += texture(tex, texcoord - 4.0 * offset) * 0.0162162162;
sum += texture(tex, texcoord - 3.0 * offset) * 0.0540540541;
sum += texture(tex, texcoord - 2.0 * offset) * 0.1216216216;
sum += texture(tex, texcoord - 1.0 * offset) * 0.1945945946;
sum += texture(tex, texCoord) * 0.2270270270;
sum += texture(tex, texcoord) * 0.2270270270;
sum += texture(tex, texCoord + 1.0 * offset) * 0.1945945946;
sum += texture(tex, texCoord + 2.0 * offset) * 0.1216216216;
sum += texture(tex, texCoord + 3.0 * offset) * 0.0540540541;
sum += texture(tex, texCoord + 4.0 * offset) * 0.0162162162;
sum += texture(tex, texcoord + 1.0 * offset) * 0.1945945946;
sum += texture(tex, texcoord + 2.0 * offset) * 0.1216216216;
sum += texture(tex, texcoord + 3.0 * offset) * 0.0540540541;
sum += texture(tex, texcoord + 4.0 * offset) * 0.0162162162;
fragColor = sum;
}

View file

@ -1,11 +1,12 @@
#version 330 core
layout(location = 0) in vec4 pos;
layout(location = 2) in vec4 vertexColor;
layout(location = 3) in vec4 multiTexCoord0;
layout(location = 2) in vec4 vertex_color;
layout(location = 3) in vec4 multitexcoord0;
out vec2 texCoord;
out vec4 cloudColor;
out vec2 texcoord;
out vec4 cloud_color;
out vec4 ap_color;
uniform mat4 osg_ModelViewMatrix;
uniform mat4 osg_ModelViewProjectionMatrix;
@ -15,13 +16,13 @@ uniform vec3 fg_SunDirectionWorld;
const float shade = 0.8;
const float cloud_height = 1000.0;
// aerial-perspective-include.frag
vec3 add_aerial_perspective(vec3 color, vec2 coord, float depth);
// aerial_perspective.glsl
vec4 get_aerial_perspective(vec2 coord, float depth);
vec3 get_sun_radiance(vec3 p);
void main()
{
texCoord = multiTexCoord0.st;
texcoord = multitexcoord0.st;
// XXX: Should be sent as an uniform
mat4 inverseModelViewMatrix = inverse(osg_ModelViewMatrix);
@ -34,7 +35,7 @@ void main()
final_pos.x = pos.x;
final_pos.y = pos.y;
final_pos.z = pos.z;
final_pos.xyz += vertexColor.xyz;
final_pos.xyz += vertex_color.xyz;
gl_Position = osg_ModelViewProjectionMatrix * final_pos;
@ -59,16 +60,15 @@ void main()
// Determine the shading based on a mixture from the backlight to the front
vec3 backlight = shade * sun_radiance;
cloudColor.rgb = mix(backlight, sun_radiance, NdotL);
cloud_color.rgb = mix(backlight, sun_radiance, NdotL);
// Perspective division and scale to [0, 1] to get the screen position
// of the vertex.
vec2 coord = (gl_Position.xy / gl_Position.w) * 0.5 + 0.5;
cloudColor.rgb = add_aerial_perspective(
cloudColor.rgb, coord, length(final_view_pos));
ap_color = get_aerial_perspective(coord, length(final_view_pos));
// As we get within 100m of the sprite, it is faded out. Equally at large
// distances it also fades out.
cloudColor.a = min(smoothstep(100.0, 250.0, fogCoord),
cloud_color.a = min(smoothstep(100.0, 250.0, fogCoord),
1.0 - smoothstep(70000.0, 75000.0, fogCoord));
}

View file

@ -15,19 +15,11 @@ uniform float fg_ClusteredSliceBias;
uniform int fg_ClusteredHorizontalTiles;
uniform int fg_ClusteredVerticalTiles;
// lighting-include.frag
vec3 evaluateLight(
vec3 baseColor,
float metallic,
float roughness,
vec3 f0,
vec3 intensity,
float visibility,
vec3 n,
vec3 l,
vec3 v,
float NdotL,
float NdotV);
// surface.glsl
vec3 surface_eval_analytical(
vec3 base_color, float metallic, float roughness, vec3 f0,
vec3 light_intensity, float occlusion,
vec3 N, vec3 L, vec3 V);
struct PointLight {
vec3 position;
@ -105,37 +97,31 @@ float get_spot_angle_attenuation(vec3 l, vec3 light_dir,
return pow(cd, exponent);
}
vec3 get_contribution_from_scene_lights(
vec3 p,
vec3 base_color,
float metallic,
float roughness,
vec3 f0,
vec3 n,
vec3 v)
vec3 eval_scene_lights(vec3 base_color, float metallic, float roughness, vec3 f0,
vec3 P, vec3 N, vec3 V)
{
int slice = int(max(log2(-p.z) * fg_ClusteredSliceScale
int slice = int(max(log2(-P.z) * fg_ClusteredSliceScale
+ fg_ClusteredSliceBias, 0.0));
vec3 clusterCoords = vec3(floor(gl_FragCoord.xy / fg_ClusteredTileSize),
vec3 cluster_coords = vec3(floor(gl_FragCoord.xy / fg_ClusteredTileSize),
slice) + vec3(0.5); // Pixel center
// Normalize
clusterCoords /= vec3(fg_ClusteredHorizontalTiles,
cluster_coords /= vec3(fg_ClusteredHorizontalTiles,
fg_ClusteredVerticalTiles,
fg_ClusteredDepthSlices);
vec3 cluster = texture(fg_Clusters, clusterCoords).rgb;
int lightIndex = int(cluster.r);
int pointCount = int(cluster.g);
int spotCount = int(cluster.b);
vec3 cluster = texture(fg_Clusters, cluster_coords).rgb;
int light_index = int(cluster.r);
int point_count = int(cluster.g);
int spot_count = int(cluster.b);
vec3 color = vec3(0.0);
for (int i = 0; i < pointCount; ++i) {
int index = getIndex(lightIndex++);
for (int i = 0; i < point_count; ++i) {
int index = getIndex(light_index++);
PointLight light = unpackPointLight(index);
vec3 to_light = light.position - p;
vec3 l = normalize(to_light);
vec3 to_light = light.position - P;
vec3 L = normalize(to_light);
float attenuation = get_square_falloff_attenuation(
to_light, 1.0 / light.range);
@ -144,46 +130,32 @@ vec3 get_contribution_from_scene_lights(
vec3 intensity = light.color * light.intensity * attenuation;
float NdotL = max(dot(n, l), 0.0);
float NdotV = clamp(abs(dot(n, v)), 0.001, 1.0);
color += evaluateLight(base_color,
metallic,
roughness,
f0,
intensity,
1.0,
n, l, v,
NdotL, NdotV);
color += surface_eval_analytical(
base_color, metallic, roughness, f0,
intensity, 1.0,
N, L, V);
}
for (int i = 0; i < spotCount; ++i) {
int index = getIndex(lightIndex++);
for (int i = 0; i < spot_count; ++i) {
int index = getIndex(light_index++);
SpotLight light = unpackSpotLight(index);
vec3 to_light = light.position - p;
vec3 l = normalize(to_light);
vec3 to_light = light.position - P;
vec3 L = normalize(to_light);
float attenuation = get_square_falloff_attenuation(
to_light, 1.0 / light.range);
attenuation *= get_spot_angle_attenuation(
l, light.direction, light.cos_cutoff, light.exponent);
L, light.direction, light.cos_cutoff, light.exponent);
if (attenuation <= 0.0)
continue;
vec3 intensity = light.color * light.intensity * attenuation;
float NdotL = max(dot(n, l), 0.0);
float NdotV = clamp(abs(dot(n, v)), 0.001, 1.0);
color += evaluateLight(base_color,
metallic,
roughness,
f0,
intensity,
1.0,
n, l, v,
NdotL, NdotV);
color += surface_eval_analytical(
base_color, metallic, roughness, f0,
intensity, 1.0,
N, L, V);
}
return color;

28
Shaders/HDR/color.glsl Normal file
View file

@ -0,0 +1,28 @@
#version 330 core
float linear_srgb_to_luminance(vec3 color)
{
return dot(color, vec3(0.2125, 0.7154, 0.0721));
}
/*
* Transform an sRGB color to linear sRGB.
*/
vec3 eotf_inverse_sRGB(vec3 srgb)
{
vec3 a = srgb / 12.92;
vec3 b = pow((srgb + 0.055) / 1.055, vec3(2.4));
vec3 c = step(vec3(0.04045), srgb);
return mix(a, b, c);
}
/*
* Transform a linear sRGB color to sRGB (gamma correction).
*/
vec3 eotf_sRGB(vec3 linear_srgb)
{
vec3 a = 12.92 * linear_srgb;
vec3 b = 1.055 * pow(linear_srgb, vec3(1.0 / 2.4)) - 0.055;
vec3 c = step(vec3(0.0031308), linear_srgb);
return mix(a, b, c);
}

View file

@ -1,10 +0,0 @@
#version 330 core
out float prevLum;
uniform sampler2D tex;
void main()
{
prevLum = texelFetch(tex, ivec2(0), 0).r;
}

View file

@ -0,0 +1,10 @@
#version 330 core
layout(location = 0) out float fragColor;
uniform sampler2D lum_tex;
void main()
{
fragColor = texelFetch(lum_tex, ivec2(0), 0).r;
}

View file

@ -0,0 +1,14 @@
#version 330 core
layout(location = 0) out vec4 out_gbuffer0;
layout(location = 1) out vec4 out_gbuffer1;
layout(location = 2) out vec4 out_gbuffer2;
layout(location = 3) out vec4 out_gbuffer3;
void main()
{
out_gbuffer0 = vec4(0.0);
out_gbuffer1 = vec4(0.0);
out_gbuffer2 = vec4(0.0);
out_gbuffer3 = vec4(0.0);
}

View file

@ -0,0 +1,12 @@
#version 330 core
layout(location = 0) out vec4 fragColor;
in vec2 texcoord;
uniform sampler2D gbuffer1_tex;
void main()
{
fragColor = vec4(texture(gbuffer1_tex, texcoord).rgb, 1.0);
}

View file

@ -0,0 +1,16 @@
#version 330 core
layout(location = 0) out vec4 fragColor;
in vec2 texcoord;
uniform sampler2D depth_tex;
// pos_from_depth.glsl
float linearize_depth(float depth);
void main()
{
float depth = texture(depth_tex, texcoord).r;
fragColor = vec4(vec3(linearize_depth(depth)), 1.0);
}

View file

@ -0,0 +1,12 @@
#version 330 core
layout(location = 0) out vec4 fragColor;
in vec2 texcoord;
uniform sampler2D gbuffer0_tex;
void main()
{
fragColor = vec4(vec3(texture(gbuffer0_tex, texcoord).a), 1.0);
}

View file

@ -0,0 +1,12 @@
#version 330 core
layout(location = 0) out vec4 fragColor;
in vec2 texcoord;
uniform sampler2D gbuffer0_tex;
void main()
{
fragColor = vec4(texture(gbuffer0_tex, texcoord).rg, 0.0, 1.0);
}

View file

@ -0,0 +1,17 @@
#version 330 core
layout(location = 0) out vec4 fragColor;
in vec2 texcoord;
uniform sampler2D gbuffer0_tex;
uniform sampler2D gbuffer1_tex;
uniform sampler2D gbuffer2_tex;
void main()
{
fragColor = vec4(texture(gbuffer2_tex, texcoord).a,
texture(gbuffer0_tex, texcoord).b,
texture(gbuffer1_tex, texcoord).a,
1.0);
}

View file

@ -1,27 +0,0 @@
#version 330 core
layout(location = 0) out vec3 fragColor0;
layout(location = 1) out vec3 fragColor1;
layout(location = 2) out vec3 fragColor2;
layout(location = 3) out vec3 fragColor3;
layout(location = 4) out vec3 fragColor4;
layout(location = 5) out vec3 fragColor5;
in vec3 cubemapCoord0;
in vec3 cubemapCoord1;
in vec3 cubemapCoord2;
in vec3 cubemapCoord3;
in vec3 cubemapCoord4;
in vec3 cubemapCoord5;
uniform samplerCube envmap;
void main()
{
fragColor0 = textureLod(envmap, cubemapCoord0, 0.0).rgb;
fragColor1 = textureLod(envmap, cubemapCoord1, 0.0).rgb;
fragColor2 = textureLod(envmap, cubemapCoord2, 0.0).rgb;
fragColor3 = textureLod(envmap, cubemapCoord3, 0.0).rgb;
fragColor4 = textureLod(envmap, cubemapCoord4, 0.0).rgb;
fragColor5 = textureLod(envmap, cubemapCoord5, 0.0).rgb;
}

View file

@ -1,107 +0,0 @@
// Mostly based on 'Moving Frostbite to Physically Based Rendering'
// https://seblagarde.files.wordpress.com/2015/07/course_notes_moving_frostbite_to_pbr_v32.pdf
#version 330 core
layout(location = 0) out vec3 fragColor0;
layout(location = 1) out vec3 fragColor1;
layout(location = 2) out vec3 fragColor2;
layout(location = 3) out vec3 fragColor3;
layout(location = 4) out vec3 fragColor4;
layout(location = 5) out vec3 fragColor5;
in vec3 cubemapCoord0;
in vec3 cubemapCoord1;
in vec3 cubemapCoord2;
in vec3 cubemapCoord3;
in vec3 cubemapCoord4;
in vec3 cubemapCoord5;
uniform samplerCube envmap;
uniform float roughness;
uniform int num_samples;
const float PI = 3.14159265359;
const float ENVMAP_SIZE = 128.0;
const float ENVMAP_MIP_COUNT = 4.0;
float RadicalInverse_VdC(uint bits)
{
bits = (bits << 16u) | (bits >> 16u);
bits = ((bits & 0x55555555u) << 1u) | ((bits & 0xAAAAAAAAu) >> 1u);
bits = ((bits & 0x33333333u) << 2u) | ((bits & 0xCCCCCCCCu) >> 2u);
bits = ((bits & 0x0F0F0F0Fu) << 4u) | ((bits & 0xF0F0F0F0u) >> 4u);
bits = ((bits & 0x00FF00FFu) << 8u) | ((bits & 0xFF00FF00u) >> 8u);
return float(bits) * 2.3283064365386963e-10; // / 0x100000000
}
vec2 Hammersley(uint i, uint N)
{
return vec2(float(i)/float(N), RadicalInverse_VdC(i));
}
vec3 ImportanceSampleGGX(vec2 Xi, vec3 n, float a)
{
float phi = 2.0 * PI * Xi.x;
float cosTheta = sqrt((1.0 - Xi.y) / (1.0 + (a*a - 1.0) * Xi.y));
float sinTheta = sqrt(1.0 - cosTheta*cosTheta);
vec3 h;
h.x = sinTheta * cos(phi);
h.y = sinTheta * sin(phi);
h.z = cosTheta;
return h;
}
float D_GGX(float NdotH, float a2)
{
float f = (NdotH * a2 - NdotH) * NdotH + 1.0;
return a2 / (PI * f * f);
}
vec3 prefilter(vec3 n)
{
vec3 v = n; // n = v simplification
float a = roughness*roughness;
vec3 prefilteredColor = vec3(0.0);
float totalWeight = 0.0;
vec3 up = abs(n.z) < 0.999f ? vec3(0.0, 0.0, 1.0) : vec3(1.0, 0.0, 0.0);
vec3 tangent = normalize(cross(up, n));
vec3 bitangent = cross(n, tangent);
mat3 tangentToWorld = mat3(tangent, bitangent, n);
uint sample_count = uint(num_samples);
for (uint i = 0u; i < sample_count; ++i) {
vec2 Xi = Hammersley(i, sample_count);
vec3 h = tangentToWorld * ImportanceSampleGGX(Xi, n, a);
vec3 l = normalize(2.0 * dot(v, h) * h - v);
float NdotL = max(dot(n, l), 0.0);
if (NdotL > 0.0) {
float NdotH = clamp(dot(n, h), 0.0, 1.0);
float VdotH = clamp(dot(v, h), 0.0, 1.0);
float pdf = D_GGX(NdotH, a) * NdotH / (4.0 * VdotH);
float omegaS = 1.0 / (float(sample_count) * pdf);
float omegaP = 4.0 * PI / (6.0 * ENVMAP_SIZE * ENVMAP_SIZE);
float mipLevel = clamp(0.5 * log2(omegaS / omegaP) + 1.0,
0.0, ENVMAP_MIP_COUNT);
prefilteredColor += textureLod(envmap, l, mipLevel).rgb * NdotL;
totalWeight += NdotL;
}
}
return prefilteredColor / totalWeight;
}
void main()
{
fragColor0 = prefilter(normalize(cubemapCoord0));
fragColor1 = prefilter(normalize(cubemapCoord1));
fragColor2 = prefilter(normalize(cubemapCoord2));
fragColor3 = prefilter(normalize(cubemapCoord3));
fragColor4 = prefilter(normalize(cubemapCoord4));
fragColor5 = prefilter(normalize(cubemapCoord5));
}

View file

@ -1,24 +0,0 @@
#version 330 core
out vec3 cubemapCoord0;
out vec3 cubemapCoord1;
out vec3 cubemapCoord2;
out vec3 cubemapCoord3;
out vec3 cubemapCoord4;
out vec3 cubemapCoord5;
void main()
{
vec2 pos = vec2(gl_VertexID % 2, gl_VertexID / 2) * 4.0 - 1.0;
gl_Position = vec4(pos, 0.0, 1.0);
// Map the quad texture coordinates to a direction vector to sample
// the cubemap. This assumes that we are using the weird left-handed
// orientations given by the OpenGL spec.
// See https://www.khronos.org/opengl/wiki/Cubemap_Texture#Upload_and_orientation
cubemapCoord0 = vec3(1.0, -pos.y, -pos.x);
cubemapCoord1 = vec3(-1.0, -pos.y, pos.x);
cubemapCoord2 = vec3(pos.x, 1.0, pos.y);
cubemapCoord3 = vec3(pos.x, -1.0, -pos.y);
cubemapCoord4 = vec3(pos.x, -pos.y, 1.0);
cubemapCoord5 = vec3(-pos.x, -pos.y, -1.0);
}

25
Shaders/HDR/envmap.vert Normal file
View file

@ -0,0 +1,25 @@
#version 330 core
out vec3 cubemap_coord0;
out vec3 cubemap_coord1;
out vec3 cubemap_coord2;
out vec3 cubemap_coord3;
out vec3 cubemap_coord4;
out vec3 cubemap_coord5;
void main()
{
vec2 pos = vec2(gl_VertexID % 2, gl_VertexID / 2) * 4.0 - 1.0;
gl_Position = vec4(pos, 0.0, 1.0);
// Map the quad texture coordinates to a direction vector to sample
// the cubemap. This assumes that we are using the weird left-handed
// orientations given by the OpenGL spec.
// See https://www.khronos.org/opengl/wiki/Cubemap_Texture#Upload_and_orientation
cubemap_coord0 = vec3( 1.0, -pos.y, -pos.x);
cubemap_coord1 = vec3(- 1.0, -pos.y, pos.x);
cubemap_coord2 = vec3( pos.x, 1.0, pos.y);
cubemap_coord3 = vec3( pos.x, - 1.0, -pos.y);
cubemap_coord4 = vec3( pos.x, -pos.y, 1.0);
cubemap_coord5 = vec3(-pos.x, -pos.y, - 1.0);
}

View file

@ -0,0 +1,27 @@
#version 330 core
layout(location = 0) out vec3 fragColor0;
layout(location = 1) out vec3 fragColor1;
layout(location = 2) out vec3 fragColor2;
layout(location = 3) out vec3 fragColor3;
layout(location = 4) out vec3 fragColor4;
layout(location = 5) out vec3 fragColor5;
in vec3 cubemap_coord0;
in vec3 cubemap_coord1;
in vec3 cubemap_coord2;
in vec3 cubemap_coord3;
in vec3 cubemap_coord4;
in vec3 cubemap_coord5;
uniform samplerCube envmap_tex;
void main()
{
fragColor0 = textureLod(envmap_tex, cubemap_coord0, 0.0).rgb;
fragColor1 = textureLod(envmap_tex, cubemap_coord1, 0.0).rgb;
fragColor2 = textureLod(envmap_tex, cubemap_coord2, 0.0).rgb;
fragColor3 = textureLod(envmap_tex, cubemap_coord3, 0.0).rgb;
fragColor4 = textureLod(envmap_tex, cubemap_coord4, 0.0).rgb;
fragColor5 = textureLod(envmap_tex, cubemap_coord5, 0.0).rgb;
}

View file

@ -0,0 +1,110 @@
/*
* Mostly based on 'Moving Frostbite to Physically Based Rendering'
* https://seblagarde.files.wordpress.com/2015/07/course_notes_moving_frostbite_to_pbr_v32.pdf
*/
#version 330 core
layout(location = 0) out vec3 fragColor0;
layout(location = 1) out vec3 fragColor1;
layout(location = 2) out vec3 fragColor2;
layout(location = 3) out vec3 fragColor3;
layout(location = 4) out vec3 fragColor4;
layout(location = 5) out vec3 fragColor5;
in vec3 cubemap_coord0;
in vec3 cubemap_coord1;
in vec3 cubemap_coord2;
in vec3 cubemap_coord3;
in vec3 cubemap_coord4;
in vec3 cubemap_coord5;
uniform samplerCube envmap_tex;
uniform float roughness;
uniform int num_samples;
uniform int mip_count;
// math.glsl
float M_PI();
float M_2PI();
float M_4PI();
float sqr(float x);
float RadicalInverse_VdC(uint bits)
{
bits = (bits << 16u) | (bits >> 16u);
bits = ((bits & 0x55555555u) << 1u) | ((bits & 0xAAAAAAAAu) >> 1u);
bits = ((bits & 0x33333333u) << 2u) | ((bits & 0xCCCCCCCCu) >> 2u);
bits = ((bits & 0x0F0F0F0Fu) << 4u) | ((bits & 0xF0F0F0F0u) >> 4u);
bits = ((bits & 0x00FF00FFu) << 8u) | ((bits & 0xFF00FF00u) >> 8u);
return float(bits) * 2.3283064365386963e-10; // / 0x100000000
}
vec2 Hammersley(uint i, uint N)
{
return vec2(float(i) / float(N), RadicalInverse_VdC(i));
}
vec3 ImportanceSampleGGX(vec2 Xi, vec3 n, float a)
{
float phi = M_2PI() * Xi.x;
float cos_theta = sqrt((1.0 - Xi.y) / (1.0 + (sqr(a) - 1.0) * Xi.y));
float sin_theta = sqrt(1.0 - sqr(cos_theta));
return vec3(sin_theta * cos(phi), sin_theta * sin(phi), cos_theta);
}
float D_GGX(float NdotH, float a2)
{
float f = (NdotH * a2 - NdotH) * NdotH + 1.0;
return a2 / (M_PI() * f * f);
}
vec3 prefilter(vec3 N)
{
vec3 V = N; // n = v simplification
float a = sqr(roughness);
float envmap_size = float(textureSize(envmap_tex, 0).x);
vec3 result = vec3(0.0);
float weight = 0.0;
vec3 up = abs(N.z) < 0.999f ? vec3(0.0, 0.0, 1.0) : vec3(1.0, 0.0, 0.0);
vec3 T = normalize(cross(up, N));
vec3 B = cross(N, T);
mat3 TBN = mat3(T, B, N);
uint sample_count = uint(num_samples);
for (uint i = 0u; i < sample_count; ++i) {
vec2 Xi = Hammersley(i, sample_count);
vec3 H = TBN * ImportanceSampleGGX(Xi, N, a);
vec3 L = normalize(2.0 * dot(V, H) * H - V);
float NdotL = max(dot(N, L), 0.0);
if (NdotL > 0.0) {
float NdotH = clamp(dot(N, H), 0.0, 1.0);
float VdotH = clamp(dot(V, H), 0.0, 1.0);
float pdf = D_GGX(NdotH, a) * NdotH / (4.0 * VdotH);
float omega_s = 1.0 / (float(sample_count) * pdf);
float omega_p = M_4PI() / (6.0 * envmap_size * envmap_size);
float miplevel = clamp(0.5 * log2(omega_s / omega_p) + 1.0,
0.0, float(mip_count));
result += textureLod(envmap_tex, L, miplevel).rgb * NdotL;
weight += NdotL;
}
}
return result / weight;
}
void main()
{
fragColor0 = prefilter(normalize(cubemap_coord0));
fragColor1 = prefilter(normalize(cubemap_coord1));
fragColor2 = prefilter(normalize(cubemap_coord2));
fragColor3 = prefilter(normalize(cubemap_coord3));
fragColor4 = prefilter(normalize(cubemap_coord4));
fragColor5 = prefilter(normalize(cubemap_coord5));
}

View file

@ -1,26 +0,0 @@
#version 330 core
uniform float exposure_compensation;
const float one_over_log10 = 1.0 / log(10.0);
float log10(float x)
{
return one_over_log10 * log(x);
}
// Exposure curve from 'Perceptual Effects in Real-time Tone Mapping'.
// http://resources.mpi-inf.mpg.de/hdr/peffects/krawczyk05sccg.pdf
float keyValue(float L)
{
return 1.0 - 2.0 / (log10(L + 1.0) + 2.0);
}
vec3 applyExposure(vec3 color, float avgLuminance, float threshold)
{
avgLuminance = max(avgLuminance, 0.001);
float linearExposure = keyValue(avgLuminance) / avgLuminance;
float exposure = log2(max(linearExposure, 0.0001));
exposure += exposure_compensation - threshold;
return color * exp2(exposure);
}

28
Shaders/HDR/exposure.glsl Normal file
View file

@ -0,0 +1,28 @@
#version 330 core
uniform float exposure_compensation;
const float one_over_log10 = 1.0 / log(10.0);
float log10(float x)
{
return one_over_log10 * log(x);
}
/*
* Exposure curve from 'Perceptual Effects in Real-time Tone Mapping'.
* http://resources.mpi-inf.mpg.de/hdr/peffects/krawczyk05sccg.pdf
*/
float key_value(float L)
{
return 1.0 - 2.0 / (log10(L + 1.0) + 2.0);
}
vec3 apply_exposure(vec3 color, float avg_lum, float threshold)
{
avg_lum = max(avg_lum, 0.001);
float linear_exposure = key_value(avg_lum) / avg_lum;
float exposure = log2(max(linear_exposure, 0.0001));
exposure += exposure_compensation - threshold;
return color * exp2(exposure);
}

View file

@ -1,13 +0,0 @@
#version 330 core
layout(location = 0) out vec4 fragColor;
in vec3 normalVS;
in vec2 texCoord;
uniform sampler2D color_tex;
void main()
{
fragColor = texture(color_tex, texCoord);
}

View file

@ -1,18 +0,0 @@
#version 330 core
layout(location = 0) in vec4 pos;
layout(location = 1) in vec3 normal;
layout(location = 3) in vec4 multiTexCoord0;
out vec3 normalVS;
out vec2 texCoord;
uniform mat4 osg_ModelViewProjectionMatrix;
uniform mat3 osg_NormalMatrix;
void main()
{
gl_Position = osg_ModelViewProjectionMatrix * pos;
normalVS = normalize(osg_NormalMatrix * normal);
texCoord = multiTexCoord0.st;
}

View file

@ -1,9 +1,9 @@
#version 330 core
out vec4 fragColor;
layout(location = 0) out vec4 fragColor;
in vec2 texCoord;
in vec4 posPos;
in vec2 texcoord;
in vec4 pos_pos;
uniform sampler2D color_tex;
@ -15,11 +15,11 @@ void main()
{
vec2 rcpFrame = 1.0 / textureSize(color_tex, 0);
vec3 rgbNW = textureLod(color_tex, posPos.zw, 0.0).xyz;
vec3 rgbNE = textureLodOffset(color_tex, posPos.zw, 0.0, ivec2(1,0)).xyz;
vec3 rgbSW = textureLodOffset(color_tex, posPos.zw, 0.0, ivec2(0,1)).xyz;
vec3 rgbSE = textureLodOffset(color_tex, posPos.zw, 0.0, ivec2(1,1)).xyz;
vec3 rgbM = textureLod(color_tex, posPos.xy, 0.0).xyz;
vec3 rgbNW = textureLod(color_tex, pos_pos.zw, 0.0).xyz;
vec3 rgbNE = textureLodOffset(color_tex, pos_pos.zw, 0.0, ivec2(1,0)).xyz;
vec3 rgbSW = textureLodOffset(color_tex, pos_pos.zw, 0.0, ivec2(0,1)).xyz;
vec3 rgbSE = textureLodOffset(color_tex, pos_pos.zw, 0.0, ivec2(1,1)).xyz;
vec3 rgbM = textureLod(color_tex, pos_pos.xy, 0.0).xyz;
const vec3 luma = vec3(0.299, 0.587, 0.114);
float lumaNW = dot(rgbNW, luma);
@ -43,11 +43,11 @@ void main()
dir * rcpDirMin)) * rcpFrame.xy;
vec3 rgbA = 0.5 * (
textureLod(color_tex, posPos.xy + dir * (1.0/3.0 - 0.5), 0.0).xyz +
textureLod(color_tex, posPos.xy + dir * (2.0/3.0 - 0.5), 0.0).xyz);
textureLod(color_tex, pos_pos.xy + dir * (1.0/3.0 - 0.5), 0.0).xyz +
textureLod(color_tex, pos_pos.xy + dir * (2.0/3.0 - 0.5), 0.0).xyz);
vec3 rgbB = rgbA * 0.5 + 0.25 * (
textureLod(color_tex, posPos.xy + dir * (0.0/3.0 - 0.5), 0.0).xyz +
textureLod(color_tex, posPos.xy + dir * (3.0/3.0 - 0.5), 0.0).xyz);
textureLod(color_tex, pos_pos.xy + dir * (0.0/3.0 - 0.5), 0.0).xyz +
textureLod(color_tex, pos_pos.xy + dir * (3.0/3.0 - 0.5), 0.0).xyz);
float lumaB = dot(rgbB, luma);
if((lumaB < lumaMin) || (lumaB > lumaMax))

View file

@ -1,7 +1,7 @@
#version 330 core
out vec2 texCoord;
out vec4 posPos;
out vec2 texcoord;
out vec4 pos_pos;
uniform sampler2D color_tex;
@ -10,11 +10,11 @@ const float FXAA_SUBPIX_SHIFT = 1.0/4.0;
void main()
{
vec2 pos = vec2(gl_VertexID % 2, gl_VertexID / 2) * 4.0 - 1.0;
texCoord = pos * 0.5 + 0.5;
texcoord = pos * 0.5 + 0.5;
vec2 rcpFrame = 1.0 / textureSize(color_tex, 0);
posPos.xy = texCoord;
posPos.zw = texCoord - (rcpFrame * (0.5 + FXAA_SUBPIX_SHIFT));
pos_pos.xy = texcoord;
pos_pos.zw = texcoord - (rcpFrame * (0.5 + FXAA_SUBPIX_SHIFT));
gl_Position = vec4(pos, 0.0, 1.0);
}

View file

@ -1,12 +0,0 @@
#version 330 core
layout(location = 0) out vec4 outGBuffer0;
layout(location = 1) out vec4 outGBuffer1;
layout(location = 2) out vec4 outGBuffer2;
void main()
{
outGBuffer0 = vec4(0.0);
outGBuffer1 = vec4(0.0);
outGBuffer2 = vec4(0.0);
}

View file

@ -1,12 +0,0 @@
#version 330 core
out vec4 fragColor;
in vec2 texCoord;
uniform sampler2D gbuffer1_tex;
void main()
{
fragColor = vec4(texture(gbuffer1_tex, texCoord).rgb, 1.0);
}

View file

@ -1,15 +0,0 @@
#version 330 core
out vec4 fragColor;
in vec2 texCoord;
uniform sampler2D depth_tex;
float linearizeDepth(float depth);
void main()
{
float depth = texture(depth_tex, texCoord).r;
fragColor = vec4(vec3(linearizeDepth(depth)), 1.0);
}

View file

@ -1,12 +0,0 @@
#version 330 core
out vec4 fragColor;
in vec2 texCoord;
uniform sampler2D gbuffer0_tex;
void main()
{
fragColor = vec4(vec3(texture(gbuffer0_tex, texCoord).a), 1.0);
}

View file

@ -1,12 +0,0 @@
#version 330 core
out vec4 fragColor;
in vec2 texCoord;
uniform sampler2D gbuffer0_tex;
void main()
{
fragColor = vec4(texture(gbuffer0_tex, texCoord).rg, 0.0, 1.0);
}

View file

@ -1,17 +0,0 @@
#version 330 core
out vec4 fragColor;
in vec2 texCoord;
uniform sampler2D gbuffer0_tex;
uniform sampler2D gbuffer1_tex;
uniform sampler2D gbuffer2_tex;
void main()
{
fragColor = vec4(texture(gbuffer2_tex, texCoord).a,
texture(gbuffer0_tex, texCoord).b,
texture(gbuffer1_tex, texCoord).a,
1.0);
}

View file

@ -1,65 +0,0 @@
#version 330 core
uniform mat4 fg_ProjectionMatrixInverse;
uniform vec2 fg_NearFar;
// Octahedron normal encoding
// https://knarkowicz.wordpress.com/2014/04/16/octahedron-normal-vector-encoding/
vec2 msign(vec2 v)
{
return vec2((v.x >= 0.0) ? 1.0 : -1.0,
(v.y >= 0.0) ? 1.0 : -1.0);
}
vec2 encodeNormal(vec3 n)
{
n /= (abs(n.x) + abs(n.y) + abs(n.z));
n.xy = (n.z >= 0) ? n.xy : (1.0 - abs(n.yx)) * msign(n.xy);
n.xy = n.xy * 0.5 + 0.5;
return n.xy;
}
vec3 decodeNormal(vec2 f)
{
f = f * 2.0 - 1.0;
vec3 n = vec3(f, 1.0 - abs(f.x) - abs(f.y));
float t = max(-n.z, 0.0);
n.x += (n.x > 0.0) ? -t : t;
n.y += (n.y > 0.0) ? -t : t;
return normalize(n);
}
// Given a 2D coordinate in the range [0,1] and a depth value from a depth
// buffer, also in the [0,1] range, return the view space position.
vec3 positionFromDepth(vec2 pos, float depth, mat4 projMatrixInverse)
{
// We are using a reversed depth buffer. 1.0 corresponds to the near plane
// and 0.0 to the far plane. We convert this back to clip space by doing
// 1.0 - depth to undo the depth reversal
// 2.0 * depth - 1.0 to transform it to clip space [-1,1]
vec4 clipSpacePos = vec4(pos * 2.0 - 1.0, 1.0 - depth * 2.0, 1.0);
vec4 viewSpacePos = projMatrixInverse * clipSpacePos;
viewSpacePos.xyz /= viewSpacePos.w;
return viewSpacePos.xyz;
}
vec3 positionFromDepth(vec2 pos, float depth)
{
return positionFromDepth(pos, depth, fg_ProjectionMatrixInverse);
}
// http://www.geeks3d.com/20091216/geexlab-how-to-visualize-the-depth-buffer-in-glsl/
float linearizeDepth(float depth)
{
float z = 1.0 - depth; // Undo the depth reversal
return 2.0 * fg_NearFar.x
/ (fg_NearFar.y + fg_NearFar.x - z * (fg_NearFar.y - fg_NearFar.x));
}
vec3 decodeSRGB(vec3 screenRGB)
{
vec3 a = screenRGB / 12.92;
vec3 b = pow((screenRGB + 0.055) / 1.055, vec3(2.4));
vec3 c = step(vec3(0.04045), screenRGB);
return mix(a, b, c);
}

View file

@ -0,0 +1,27 @@
#version 330 core
layout(location = 0) out vec4 out_gbuffer0;
layout(location = 1) out vec4 out_gbuffer1;
layout(location = 2) out vec4 out_gbuffer2;
layout(location = 3) out vec3 out_gbuffer3;
// normal_encoding.glsl
vec2 encode_normal(vec3 n);
/*
* Write the given surface properties to the G-buffer.
* See the HDR pipeline definition in $FG_ROOT/Compositor/HDR/hdr.xml for the
* G-buffer layout.
*/
void gbuffer_pack(vec3 normal, vec3 base_color, float metallic, float roughness,
float occlusion, vec3 emissive, uint mat_id)
{
out_gbuffer0.rg = encode_normal(normal);
out_gbuffer0.b = roughness;
out_gbuffer0.a = float(mat_id) * (1.0 / 3.0);
out_gbuffer1.rgb = base_color;
out_gbuffer1.a = metallic;
out_gbuffer2.rgb = vec3(0.0); // unused
out_gbuffer2.a = occlusion;
out_gbuffer3.rgb = emissive;
}

View file

@ -0,0 +1,34 @@
#version 330 core
uniform sampler2D gbuffer0_tex;
uniform sampler2D gbuffer1_tex;
uniform sampler2D gbuffer2_tex;
uniform sampler2D gbuffer3_tex;
// normal_encoding.glsl
vec3 decode_normal(vec2 f);
/*
* Read the given surface properties from the G-Buffer.
* See the HDR pipeline definition in $FG_ROOT/Compositor/HDR/hdr.xml for the
* G-buffer layout.
*/
void gbuffer_unpack(in vec2 texcoord,
out vec3 normal, out vec3 base_color, out float metallic,
out float roughness, out float occlusion, out vec3 emissive,
out uint mat_id)
{
vec4 gbuffer0 = texture(gbuffer0_tex, texcoord);
vec4 gbuffer1 = texture(gbuffer1_tex, texcoord);
vec4 gbuffer2 = texture(gbuffer2_tex, texcoord);
vec3 gbuffer3 = texture(gbuffer3_tex, texcoord).rgb;
normal = decode_normal(gbuffer0.rg);
roughness = gbuffer0.b;
mat_id = uint(gbuffer0.a * 3.0);
base_color = gbuffer1.rgb;
metallic = gbuffer1.a;
// gbuffer2.rgb unused
occlusion = gbuffer2.a;
emissive = gbuffer3.rgb;
}

View file

@ -1,23 +0,0 @@
#version 330 core
layout(location = 0) out vec4 outGBuffer0;
layout(location = 1) out vec4 outGBuffer1;
layout(location = 2) out vec4 outGBuffer2;
in vec3 normalVS;
const float CHROME_METALNESS = 1.0;
const float CHROME_ROUGHNESS = 0.1;
vec2 encodeNormal(vec3 n);
void main()
{
outGBuffer0.rg = encodeNormal(normalVS);
outGBuffer0.b = CHROME_ROUGHNESS;
outGBuffer0.a = 1.0;
outGBuffer1.rgb = vec3(1.0);
outGBuffer1.a = CHROME_METALNESS;
outGBuffer2.rgb = vec3(0.0);
outGBuffer2.a = 1.0;
}

View file

@ -1,42 +0,0 @@
#version 330 core
layout(location = 0) out vec4 outGBuffer0;
layout(location = 1) out vec4 outGBuffer1;
layout(location = 2) out vec4 outGBuffer2;
in vec2 texCoord;
in mat3 TBN;
uniform sampler2D color_tex;
uniform sampler2D normal_tex;
uniform int normalmap_enabled;
uniform int normalmap_dds;
uniform float normalmap_tiling;
const float DEFAULT_COMBINED_METALNESS = 0.0;
const float DEFAULT_COMBINED_ROUGHNESS = 0.1;
vec2 encodeNormal(vec3 n);
vec3 decodeSRGB(vec3 screenRGB);
void main()
{
vec3 color = decodeSRGB(texture(color_tex, texCoord).rgb);
vec3 normal = vec3(0.0, 0.0, 1.0);
if (normalmap_enabled > 0) {
normal = texture(normal_tex, texCoord * normalmap_tiling).rgb * 2.0 - 1.0;
// DDS has flipped normals
if (normalmap_dds > 0)
normal = -normal;
}
normal = normalize(TBN * normal);
outGBuffer0.rg = encodeNormal(normal);
outGBuffer0.b = DEFAULT_COMBINED_ROUGHNESS;
outGBuffer0.a = 1.0;
outGBuffer1.rgb = color;
outGBuffer1.a = DEFAULT_COMBINED_METALNESS;
outGBuffer2.rgb = vec3(0.0);
outGBuffer2.a = 1.0;
}

View file

@ -1,30 +0,0 @@
#version 330 core
layout(location = 0) out vec4 outGBuffer0;
layout(location = 1) out vec4 outGBuffer1;
layout(location = 2) out vec4 outGBuffer2;
in vec3 normalVS;
in vec2 texCoord;
uniform sampler2D color_tex;
vec2 encodeNormal(vec3 n);
vec3 decodeSRGB(vec3 screenRGB);
void main()
{
vec4 texel = texture(color_tex, texCoord);
if (texel.a < 0.5)
discard;
vec3 color = decodeSRGB(texel.rgb);
outGBuffer0.rg = encodeNormal(normalVS);
outGBuffer0.b = 0.9;
outGBuffer0.a = 1.0;
outGBuffer1.rgb = color;
outGBuffer1.a = 0.0;
outGBuffer2.rgb = vec3(0.0);
outGBuffer2.a = 1.0;
}

View file

@ -1,107 +0,0 @@
#version 330 core
out vec4 fragColor;
in vec2 texCoord;
in mat3 TBN;
in vec3 ecPos;
uniform sampler2D base_color_tex;
uniform sampler2D normal_tex;
uniform sampler2D orm_tex;
uniform sampler2D emissive_tex;
uniform vec4 base_color_factor;
uniform float metallic_factor;
uniform float roughness_factor;
uniform vec3 emissive_factor;
uniform float alpha_cutoff;
uniform mat4 osg_ViewMatrixInverse;
uniform mat4 osg_ProjectionMatrix;
uniform vec4 fg_Viewport;
uniform vec3 fg_SunDirection;
vec3 decodeSRGB(vec3 screenRGB);
float getShadowing(vec3 p, vec3 n, vec3 l, mat4 viewToClip);
vec3 getF0Reflectance(vec3 baseColor, float metallic);
vec3 evaluateLight(
vec3 baseColor,
float metallic,
float roughness,
vec3 f0,
vec3 intensity,
float visibility,
vec3 n,
vec3 l,
vec3 v,
float NdotL,
float NdotV);
vec3 evaluateIBL(
vec3 baseColor,
float metallic,
float roughness,
vec3 f0,
float visibility,
vec3 nWorldSpace,
float NdotV,
vec3 reflected);
vec3 add_aerial_perspective(vec3 color, vec2 coord, float depth);
vec3 get_sun_radiance(vec3 p);
void main()
{
vec4 baseColorTexel = texture(base_color_tex, texCoord);
vec4 baseColor = vec4(decodeSRGB(baseColorTexel.rgb), baseColorTexel.a)
* base_color_factor;
if (baseColor.a < alpha_cutoff)
discard;
vec3 n = texture(normal_tex, texCoord).rgb * 2.0 - 1.0;
n = normalize(TBN * n);
vec3 orm = texture(orm_tex, texCoord).rgb;
float occlusion = orm.r;
float roughness = orm.g * roughness_factor;
float metallic = orm.b * metallic_factor;
vec3 emissive = texture(emissive_tex, texCoord).rgb * emissive_factor;
vec3 v = normalize(-ecPos);
vec3 l = fg_SunDirection;
float NdotL = dot(n, l);
float NdotV = clamp(abs(dot(n, v)), 0.001, 1.0);
vec3 f0 = getF0Reflectance(baseColor.rgb, metallic);
vec3 pos_world = (osg_ViewMatrixInverse * vec4(ecPos, 1.0)).xyz;
vec3 sun_radiance = get_sun_radiance(pos_world);
float shadowFactor = getShadowing(ecPos, n, l, osg_ProjectionMatrix);
vec3 color = evaluateLight(baseColor.rgb,
metallic,
roughness,
f0,
sun_radiance,
shadowFactor,
n, l, v,
NdotL, NdotV);
vec3 worldNormal = (osg_ViewMatrixInverse * vec4(n, 0.0)).xyz;
vec3 worldReflected = (osg_ViewMatrixInverse * vec4(reflect(-v, n), 0.0)).xyz;
color += evaluateIBL(baseColor.rgb,
metallic,
roughness,
f0,
occlusion,
worldNormal,
NdotV,
worldReflected);
vec2 coord = (gl_FragCoord.xy - fg_Viewport.xy) / fg_Viewport.zw;
color = add_aerial_perspective(color, coord, length(ecPos));
fragColor = vec4(color, baseColor.a);
}

View file

@ -1,44 +0,0 @@
#version 330 core
layout(location = 0) out vec4 outGBuffer0;
layout(location = 1) out vec4 outGBuffer1;
layout(location = 2) out vec4 outGBuffer2;
in vec2 texCoord;
in mat3 TBN;
uniform sampler2D base_color_tex;
uniform sampler2D normal_tex;
uniform sampler2D orm_tex;
uniform sampler2D emissive_tex;
uniform vec4 base_color_factor;
uniform float metallic_factor;
uniform float roughness_factor;
uniform vec3 emissive_factor;
vec2 encodeNormal(vec3 n);
vec3 decodeSRGB(vec3 screenRGB);
void main()
{
vec3 baseColorTexel = texture(base_color_tex, texCoord).rgb; // Ignore alpha
vec3 baseColor = decodeSRGB(baseColorTexel.rgb) * base_color_factor.rgb;
vec3 normal = texture(normal_tex, texCoord).rgb * 2.0 - 1.0;
normal = normalize(TBN * normal);
vec3 orm = texture(orm_tex, texCoord).rgb;
float occlusion = orm.r;
float roughness = orm.g * roughness_factor;
float metallic = orm.b * metallic_factor;
vec3 emissive = texture(emissive_tex, texCoord).rgb * emissive_factor;
outGBuffer0.rg = encodeNormal(normal);
outGBuffer0.b = roughness;
outGBuffer0.a = 1.0;
outGBuffer1.rgb = baseColor;
outGBuffer1.a = metallic;
outGBuffer2.rgb = vec3(0.0);
outGBuffer2.a = occlusion;
}

View file

@ -1,45 +0,0 @@
#version 330 core
layout(location = 0) out vec4 outGBuffer0;
layout(location = 1) out vec4 outGBuffer1;
layout(location = 2) out vec4 outGBuffer2;
in vec3 rawpos;
in vec2 texCoord;
in mat3 TBN;
uniform sampler2D color_tex;
uniform sampler2D normal_tex;
uniform sampler3D noise_tex;
const float NORMAL_MAP_SCALE = 8.0;
vec2 encodeNormal(vec3 n);
vec3 decodeSRGB(vec3 screenRGB);
void main()
{
vec4 texel = texture(color_tex, texCoord);
vec3 color = decodeSRGB(texel.rgb);
vec3 normal_texel = texture(normal_tex, texCoord * NORMAL_MAP_SCALE).rgb;
vec3 normal = normalize(TBN * (normal_texel * 2.0 - 1.0));
vec3 noise_large = texture(noise_tex, rawpos * 0.0045).rgb;
vec3 noise_small = texture(noise_tex, rawpos).rgb;
float mix_factor = noise_large.r * noise_large.g * noise_large.b * 350.0;
mix_factor = smoothstep(0.0, 1.0, mix_factor);
color = mix(color, noise_small, 0.15);
float roughness = mix(0.94, 0.98, mix_factor);
outGBuffer0.rg = encodeNormal(normal);
outGBuffer0.b = roughness;
outGBuffer0.a = 1.0;
outGBuffer1.rgb = vec3(color);
outGBuffer1.a = 0.0;
outGBuffer2.rgb = vec3(0.0);
outGBuffer2.a = 1.0;
}

View file

@ -1,38 +0,0 @@
#version 330 core
layout(location = 0) out vec4 outGBuffer0;
layout(location = 1) out vec4 outGBuffer1;
layout(location = 2) out vec4 outGBuffer2;
in vec3 normalVS;
in vec2 texCoord;
in vec2 orthophoto_texCoord;
uniform sampler2D color_tex;
uniform sampler2D orthophoto_tex;
uniform bool orthophotoAvailable;
vec2 encodeNormal(vec3 n);
vec3 decodeSRGB(vec3 screenRGB);
void main()
{
vec3 texel = texture(color_tex, texCoord).rgb;
if (orthophotoAvailable) {
vec4 sat_texel = texture(orthophoto_tex, orthophoto_texCoord);
if (sat_texel.a > 0.0) {
texel.rgb = sat_texel.rgb;
}
}
vec3 color = decodeSRGB(texel);
outGBuffer0.rg = encodeNormal(normalVS);
outGBuffer0.b = 0.95;
outGBuffer0.a = 1.0;
outGBuffer1.rgb = color;
outGBuffer1.a = 0.0;
outGBuffer2.rgb = vec3(0.0);
outGBuffer2.a = 1.0;
}

View file

@ -1,21 +0,0 @@
#version 330 core
layout(location = 0) in vec4 pos;
layout(location = 1) in vec3 normal;
layout(location = 3) in vec4 multiTexCoord0;
layout(location = 5) in vec4 multiTexCoord2;
out vec3 normalVS;
out vec2 texCoord;
out vec2 orthophoto_texCoord;
uniform mat4 osg_ModelViewProjectionMatrix;
uniform mat3 osg_NormalMatrix;
void main()
{
gl_Position = osg_ModelViewProjectionMatrix * pos;
normalVS = normalize(osg_NormalMatrix * normal);
texCoord = multiTexCoord0.st;
orthophoto_texCoord = multiTexCoord2.st;
}

Some files were not shown because too many files have changed in this diff Show more