17
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-10-31 16:59:06 +01:00

feat(vulkan): vulkan 1.4 core with the user interface and the launcher, shaders split into ogl46/vk14 with SPIR-V binaries loaded first

This commit is contained in:
2026-10-24 05:47:11 +02:00
parent 68fa5dc2da
commit bd589f272d
235 changed files with 9397 additions and 3975 deletions

43
shaders/README.md Normal file
View File

@@ -0,0 +1,43 @@
# Shaders
| Directory | What is in it |
|---|---|
| `ogl46/` | GLSL sources of the OpenGL 4.6 renderer |
| `ogl46bin/` | SPIR-V binaries of `ogl46/` (optional, made by `compile_spirv.py`) |
| `vk14/` | GLSL sources of the Vulkan 1.4 renderer |
| `vk14bin/` | SPIR-V binaries of `vk14/` (optional, made by `compile_spirv.py`) |
The renderers load the binary of a shader first, when there is one and it was compiled from the sources that are there now
(`manifest.txt` of the directory of the binaries lists the sources of each binary with their hashes). Otherwise the source is
compiled: by the OpenGL driver for `ogl46/`, by glslang inside the simulator for `vk14/` (with a cache of the results in the
directory of the user). `gfx.shaders.binaries no` in `eu07.ini` makes them always use the sources. The sources are needed
even with the binaries: the directives of the materials (`#pragma texture`, `#pragma param`) are read from them.
## Compiling to SPIR-V
python shaders/compile_spirv.py
compiles every shader of `ogl46/` (with the variant `MODEL_DRAWS` of the vertex and fragment shaders) and of `vk14/` with
`glslc` (Vulkan SDK, `VULKAN_SDK`, or `--glslc <path>`). A single file compiles the same way by hand:
glslc --target-env=opengl4.5 ogl46/mat_default.frag -o ogl46bin/mat_default.frag.spv
glslc --target-env=opengl4.5 -DMODEL_DRAWS=1 ogl46/vertex.vert -o ogl46bin/vertex.vert.MODEL_DRAWS.spv
glslc --target-env=vulkan1.4 vk14/imgui.frag -o vk14bin/imgui.frag.spv
A binary made by hand isn't in the manifest, so it is taken without being compared with its source. After a change of a
source, compile the binaries again (or delete them): a binary older than its source is not used, and the log says so.
## Writing shaders
* Every stage file starts with `#version 460 core` and `#define STAGE_VERTEX 1` (`STAGE_FRAGMENT`, `STAGE_GEOMETRY`,
`STAGE_COMPUTE`); files included by others (`.glsl`) don't.
* Includes: `#include "file.glsl"`, relative to the directory of the file.
* Every input and output between the stages has an explicit `layout(location = N)`, every sampler, image and block an explicit
binding, every loose uniform an explicit location: SPIR-V has no names to link by. The locations of the inputs and outputs
of `ogl46/` are one table for all the shaders (a name has the same location everywhere), see `ogl46/common.glsl`.
* The settings of the game (`SHADOWMAP_ENABLED`, `ENVMAP_ENABLED`, `MOTIONBLUR_ENABLED`, `POSTFX_ENABLED`,
`EXTRAEFFECTS_ENABLED`, `OUTPUT_GAMMA`) are `const bool` (specialization constants in the binaries, `ogl46/settings.glsl`):
use them in `if`, not in `#if`.
* The constants of the game (bindings, sizes) are written in `ogl46/common.glsl` and `vk14/common.glsl` for the binaries; the
game puts its own values before the sources and checks at the start that the files have the same ones (the shader
validator in `ci_shadervalidator` checks them too).

View File

@@ -1,10 +0,0 @@
in vec2 f_coord;
#texture (tex1, 0, sRGB_A)
uniform sampler2D tex1;
void main()
{
if (texture(tex1, f_coord).a < 0.5f)
discard;
}

View File

@@ -1,25 +0,0 @@
in vec2 f_coord;
#texture (tex1, 0, sRGB_A)
uniform sampler2D tex1;
#include <common>
#include <tonemapping.glsl>
layout(location = 0) out vec4 out_color;
#if MOTIONBLUR_ENABLED
layout(location = 1) out vec4 out_motion;
#endif
void main()
{
vec4 tex_color = texture(tex1, f_coord);
#if POSTFX_ENABLED
out_color = tex_color * param[0];
#else
out_color = tonemap(tex_color * param[0]);
#endif
#if MOTIONBLUR_ENABLED
out_motion = vec4(0.0f);
#endif
}

View File

@@ -1,26 +0,0 @@
in vec3 f_color;
in vec4 f_pos;
#include <common>
#include <apply_fog.glsl>
#include <tonemapping.glsl>
layout(location = 0) out vec4 out_color;
#if MOTIONBLUR_ENABLED
layout(location = 1) out vec4 out_motion;
#endif
#include <sky_shoulder.glsl>
void main()
{
vec3 col = sky_shoulder(pow(max(f_color.rgb, vec3(0.0)), vec3(2.2)));
#if POSTFX_ENABLED
out_color = vec4(apply_fog(col), 1.0f);
#else
out_color = tonemap(vec4(apply_fog(col), 1.0f));
#endif
#if MOTIONBLUR_ENABLED
out_motion = vec4(0.0f);
#endif
}

130
shaders/compile_spirv.py Normal file
View File

@@ -0,0 +1,130 @@
#!/usr/bin/env python3
# compiles the shaders of shaders/ogl46 and shaders/vk14 to SPIR-V with glslc, into shaders/ogl46bin and shaders/vk14bin,
# which the renderers load before they compile the sources (gfx.shaders.binaries). each directory of binaries gets
# manifest.txt: the source files each binary was compiled from, with their hashes, so the game doesn't take a binary older
# than its sources.
#
# python shaders/compile_spirv.py [--glslc <path>] [--only ogl46|vk14] [<shaders directory>]
#
# glslc comes with the Vulkan SDK (VULKAN_SDK is looked at) or with the shaderc package. the shaders of opengl are compiled
# for --target-env=opengl4.5 (SPIR-V 1.0, which opengl 4.6 takes), with the variant of the multi draws (MODEL_DRAWS) of the
# vertex and fragment shaders; those of vulkan for --target-env=vulkan1.4. a single file can be compiled by hand the same way:
# glslc --target-env=opengl4.5 shaders/ogl46/mat_default.frag -o shaders/ogl46bin/mat_default.frag.spv
# glslc --target-env=opengl4.5 -DMODEL_DRAWS=1 shaders/ogl46/vertex.vert -o shaders/ogl46bin/vertex.vert.MODEL_DRAWS.spv
# glslc --target-env=vulkan1.4 shaders/vk14/imgui.frag -o shaders/vk14bin/imgui.frag.spv
# (a binary compiled by hand isn't in the manifest, so the game takes it without comparing it with its sources)
import argparse
import os
import re
import shutil
import subprocess
import sys
STAGES = ('.vert', '.frag', '.geom', '.comp')
TREES = {
# source directory, binary directory, target environment, variants of the vertex and fragment shaders
'ogl46': ('ogl46', 'ogl46bin', 'opengl4.5', ['MODEL_DRAWS']),
'vk14': ('vk14', 'vk14bin', 'vulkan1.4', []),
}
INCLUDE = re.compile(r'^[ \t]*#include[ \t]*[<"]([^>"]+)[>"]', re.M)
def file_hash(path):
# fnv-1a 64 of the text with the line ends made \n, the same as gfx::shader_file_hash()
with open(path, 'rb') as f:
data = f.read().replace(b'\r\n', b'\n')
h = 14695981039346656037
for b in data:
h ^= b
h = (h * 1099511628211) & 0xFFFFFFFFFFFFFFFF
return '%016x' % h
def dependencies(directory, name, found=None):
# the file and the files it includes, the same way as gfx::preprocess_shader()
if found is None:
found = []
if name in found:
return found
found.append(name)
with open(os.path.join(directory, name), 'r', encoding='utf-8', errors='replace') as f:
text = f.read()
for include in INCLUDE.findall(text):
if include == 'common':
include = 'common.glsl'
dependencies(directory, include, found)
return found
def find_glslc(explicit):
if explicit:
return explicit
sdk = os.environ.get('VULKAN_SDK')
if sdk:
for sub in ('Bin', 'bin'):
for exe in ('glslc.exe', 'glslc'):
path = os.path.join(sdk, sub, exe)
if os.path.isfile(path):
return path
return shutil.which('glslc')
def main():
parser = argparse.ArgumentParser(description='compiles the shaders of MaSzyna to SPIR-V with glslc')
parser.add_argument('shaders', nargs='?', default=os.path.dirname(os.path.abspath(__file__)), help='the shaders directory (the one of this script by default)')
parser.add_argument('--glslc', help='path of glslc')
parser.add_argument('--only', choices=sorted(TREES), help='only the shaders of one renderer')
args = parser.parse_args()
glslc = find_glslc(args.glslc)
if not glslc:
print('glslc not found: install the Vulkan SDK (VULKAN_SDK) or shaderc, or give --glslc', file=sys.stderr)
return 1
failed = []
count = 0
for key, (sourcedir, binarydir, env, variants) in TREES.items():
if args.only and args.only != key:
continue
sources = os.path.join(args.shaders, sourcedir)
binaries = os.path.join(args.shaders, binarydir)
if not os.path.isdir(sources):
continue
os.makedirs(binaries, exist_ok=True)
manifest = ['# made by compile_spirv.py: binary, source file it was compiled from, fnv-1a 64 of the source (line ends as \\n)']
names = sorted(n for n in os.listdir(sources) if os.path.splitext(n)[1] in STAGES)
for name in names:
jobs = [('', [])]
if os.path.splitext(name)[1] in ('.vert', '.frag'):
jobs += [(v, ['-D%s=1' % v]) for v in variants]
try:
deps = dependencies(sources, name)
except OSError as e:
failed.append('%s/%s (%s)' % (sourcedir, name, e))
continue
for variant, defines in jobs:
binary = name + ('.' + variant if variant else '') + '.spv'
command = [glslc, '--target-env=' + env] + defines + [os.path.join(sources, name), '-o', os.path.join(binaries, binary)]
result = subprocess.run(command, capture_output=True, text=True)
if result.returncode != 0:
failed.append('%s/%s' % (binarydir, binary))
sys.stderr.write(result.stderr)
continue
if result.stderr.strip():
sys.stderr.write(result.stderr)
count += 1
for dep in deps:
manifest.append('%s %s %s' % (binary, dep, file_hash(os.path.join(sources, dep))))
with open(os.path.join(binaries, 'manifest.txt'), 'w', newline='\n') as f:
f.write('\n'.join(manifest) + '\n')
print('%d binaries compiled' % count)
if failed:
print('failed: ' + ' '.join(failed), file=sys.stderr)
return 1
return 0
if __name__ == '__main__':
sys.exit(main())

View File

@@ -1,11 +0,0 @@
in vec2 f_coords;
#texture (tex1, 0, sRGB)
uniform sampler2D tex1;
layout(location = 0) out vec4 out_color;
void main()
{
out_color = texture(tex1, f_coords);
}

View File

@@ -1,65 +0,0 @@
#if ENVMAP_ENABLED
uniform samplerCube envmap;
// the same map prefiltered with the GGX lobe (envmap_prefilter.comp), used when env_ggx is 1
uniform samplerCube envmap_ggx;
#endif
vec3 envmap_color( vec3 normal )
{
#if ENVMAP_ENABLED
vec3 refvec = reflect(f_pos.xyz, normal); // view space
refvec = vec3(inv_view * vec4(refvec, 0.0)); // world space
vec3 envcolor = texture(envmap, refvec).rgb;
// Sanitize. The env cubemap can briefly contain NaN/Inf after a
// reflection-pass regeneration (m_empty_cubemap was bound during the
// face render and on NVIDIA can sample as undefined). Without this
// guard, a single bad texel propagates through env_reflection in
// apply_lights() and produces one-frame black flashes on glossy
// (esp. specgloss) surfaces.
if (any(isnan(envcolor)) || any(isinf(envcolor))) envcolor = vec3(0.0);
envcolor = max(envcolor, vec3(0.0));
#else
vec3 envcolor = vec3(0.5);
#endif
return envcolor;
}
// Roughness-aware env map lookup — uses mip levels for blurry reflections.
// lod 0.0 = mirror sharp, lod ~8.0 = fully diffuse blur.
vec3 envmap_color_lod(vec3 fragnormal, float lod)
{
#if ENVMAP_ENABLED
vec3 refvec = reflect(f_pos.xyz, fragnormal); // view space — matches envmap_color exactly
refvec = vec3(inv_view * vec4(refvec, 0.0)); // world space — was missing
vec3 envcolor = textureLod(envmap, refvec, lod).rgb;
// See envmap_color() above — same NaN/Inf sanitize, also needed here
// because mipmap generation propagates a single NaN texel across the
// whole mip chain.
if (any(isnan(envcolor)) || any(isinf(envcolor))) envcolor = vec3(0.0);
return max(envcolor, vec3(0.0));
#else
return vec3(0.5); // was vec3(0.0), match the non-LOD fallback
#endif
}
// reflection of the surroundings in a surface of the given perceptual roughness (0 mirror, 1 matte)
vec3 envmap_color_rough(vec3 fragnormal, float roughness)
{
// the plain map, its mipmaps (box filtered) standing for the roughness
const float MAX_REFLECTION_LOD = 8.0;
vec3 boxcolor = envmap_color_lod(fragnormal, roughness * MAX_REFLECTION_LOD);
#if ENVMAP_ENABLED
if (env_ggx == 0U || roughness <= ENVMAP_GGX_ROUGHNESS_MIN)
return boxcolor;
vec3 refvec = reflect(f_pos.xyz, fragnormal);
refvec = vec3(inv_view * vec4(refvec, 0.0));
float level = (roughness - ENVMAP_GGX_ROUGHNESS_MIN) / (1.0 - ENVMAP_GGX_ROUGHNESS_MIN) * float(ENVMAP_GGX_LEVELS - 1U);
vec3 ggxcolor = textureLod(envmap_ggx, refvec, level).rgb;
if (any(isnan(ggxcolor)) || any(isinf(ggxcolor))) ggxcolor = vec3(0.0);
ggxcolor = max(ggxcolor, vec3(0.0));
// the prefiltered map takes over over the first tenth of the roughness above its lowest level
return mix(boxcolor, ggxcolor, clamp((roughness - ENVMAP_GGX_ROUGHNESS_MIN) * 10.0, 0.0, 1.0));
#else
return boxcolor;
#endif
}

View File

@@ -1,14 +0,0 @@
in vec2 f_coords;
layout(location = 0) out vec4 out_color;
#texture (tex1, 0, sRGB_A)
uniform sampler2D tex1;
void main()
{
vec2 texcoord = f_coords;
vec4 color = texture(tex1, texcoord);
out_color = color;
}

View File

@@ -1 +0,0 @@
#include <mat_colored.frag>

View File

@@ -1 +0,0 @@
#include <mat_default.frag>

View File

@@ -1 +0,0 @@
#include <mat_reflmap.frag>

View File

@@ -1,142 +0,0 @@
in vec3 f_normal;
in vec2 f_coord;
in vec4 f_pos;
in mat3 f_tbn; //tangent matrix nietransponowany; mnożyć przez f_tbn dla TangentLightPos; TangentViewPos; TangentFragPos;
in vec4 f_clip_pos;
in vec4 f_clip_future_pos;
in vec3 TangentFragPos;
#include <common>
layout(location = 0) out vec4 out_color;
#if MOTIONBLUR_ENABLED
layout(location = 1) out vec4 out_motion;
#endif
#param (color, 0, 0, 4, diffuse)
#param (diffuse, 1, 0, 1, diffuse)
#param (specular, 1, 1, 1, specular)
#param (reflection, 1, 2, 1, one)
#param (glossiness, 1, 3, 1, glossiness)
#param (detail_scale, 2, 0, 1, one)
#param (detail_height_scale, 2, 1, 1, one)
#param (height_scale, 2, 2, 1, zero)
#param (height_offset, 2, 3, 1, zero)
#texture (diffuse, 0, sRGB_A)
uniform sampler2D diffuse;
#texture (normalmap, 1, RGBA)
uniform sampler2D normalmap;
#texture (detailnormalmap, 2, RGBA)
uniform sampler2D detailnormalmap;
#define PARALLAX
// param[2].w is the height offset, not the weathering
#define NO_WEATHERING
#include <light_common.glsl>
#include <apply_fog.glsl>
#include <tonemapping.glsl>
vec2 ParallaxMapping(vec2 f_coord, vec3 viewDir);
void main()
{
//parallax mapping
vec3 viewDir = normalize(-TangentFragPos); //tangent view pos - tangent frag pos
vec2 f_coord_p = ParallaxMapping(f_coord, viewDir);
vec4 normal_map = texture(normalmap, f_coord_p);
vec4 detailnormal_map = texture(detailnormalmap, f_coord_p * param[2].x);
vec4 tex_color = texture(diffuse, f_coord_p);
bool alphatestfail = ( opacity >= 0.0 ? (tex_color.a < opacity) : (tex_color.a >= -opacity) );
if(alphatestfail)
discard;
// if (tex_color.a < opacity)
// discard;
vec3 fragcolor = ambient;
vec3 normal;
vec3 normaldetail;
normaldetail.xy = detailnormal_map.rg* 2.0 - 1.0;
normaldetail.z = sqrt(1.0 - clamp((dot(normaldetail.xy, normaldetail.xy)), 0.0, 1.0));
normaldetail.xyz = normaldetail.xyz * param[2].y;
normal.xy = normal_map.rg* 2.0 - 1.0;
normal.z = sqrt(1.0 - clamp((dot(normal.xy, normal.xy)), 0.0, 1.0));
vec3 fragnormal = normalize(f_tbn * normalize(vec3(normal.xy + normaldetail.xy, normal.z)));
float reflectivity = param[1].z * normal_map.a;
float specularity = (tex_color.r + tex_color.g + tex_color.b) * 0.5;
legacy_gloss();
fragcolor = apply_lights(fragcolor, fragnormal, tex_color.rgb, reflectivity, specularity, shadow_tone);
vec4 color = vec4(apply_fog(fragcolor), tex_color.a * alpha_mult);
#if POSTFX_ENABLED
out_color = color;
#else
out_color = tonemap(color);
#endif
#if MOTIONBLUR_ENABLED
{
vec2 a = (f_clip_future_pos.xy / f_clip_future_pos.w) * 0.5 + 0.5;;
vec2 b = (f_clip_pos.xy / f_clip_pos.w) * 0.5 + 0.5;;
out_motion = vec4(a - b, 0.0f, 0.0f);
}
#endif
}
vec2 ParallaxMapping(vec2 f_coord, vec3 viewDir)
{
float pos_len = length(f_pos.xyz);
// gradients of the coordinates taken here: inside the loop the fragments of a quad don't go the same way
vec2 dcoorddx = dFdx(f_coord);
vec2 dcoorddy = dFdy(f_coord);
if (pos_len > 100.0) {
return f_coord;
}
// the shift fades out before the distance it stops at, so it doesn't switch off at once there
float fade = 1.0 - smoothstep(80.0, 100.0, pos_len);
#if EXTRAEFFECTS_ENABLED
const float minLayers = 8.0;
const float maxLayers = 32.0;
float LayersWeight = pos_len / 20.0;
vec2 currentTexCoords = f_coord;
float currentDepthMapValue = textureGrad(normalmap, currentTexCoords, dcoorddx, dcoorddy).b;
LayersWeight = min(abs(dot(vec3(0.0, 0.0, 1.0), viewDir)),LayersWeight);
float numLayers = mix(maxLayers, minLayers, clamp(LayersWeight, 0.0, 1.0)); // number of depth layers
float layerDepth = 1.0 / numLayers; // calculate the size of each layer
float currentLayerDepth = 0.0; // depth of current layer
vec2 P = viewDir.xy * param[2].z * fade; // the amount to shift the texture coordinates per layer (from vector P)
vec2 deltaTexCoords = P / numLayers;
while(currentLayerDepth < currentDepthMapValue)
{
currentTexCoords -= deltaTexCoords; // shift texture coordinates along direction of P
currentDepthMapValue = textureGrad(normalmap, currentTexCoords, dcoorddx, dcoorddy).b; // get depthmap value at current texture coordinates
currentLayerDepth += layerDepth; // get depth of next layer
}
vec2 prevTexCoords = currentTexCoords + deltaTexCoords; // get texture coordinates before collision (reverse operations)
float afterDepth = currentDepthMapValue - currentLayerDepth; // get depth after and before collision for linear interpolation
float beforeDepth = textureGrad(normalmap, prevTexCoords, dcoorddx, dcoorddy).b - currentLayerDepth + layerDepth;
float weight = afterDepth / (afterDepth - beforeDepth); // interpolation of texture coordinates
vec2 finalTexCoords = prevTexCoords * weight + currentTexCoords * (1.0 - weight);
return finalTexCoords;
#else
float height = texture(normalmap, f_coord).b;
vec2 p = viewDir.xy / viewDir.z * (height * (param[2].z - param[2].w) * 0.2) * fade;
return f_coord - p;
#endif
}

View File

@@ -1,148 +0,0 @@
in vec3 f_normal;
in vec2 f_coord;
in vec4 f_pos;
in mat3 f_tbn; //tangent matrix nietransponowany; mnożyć przez f_tbn dla TangentLightPos; TangentViewPos; TangentFragPos;
in vec4 f_clip_pos;
in vec4 f_clip_future_pos;
in vec3 TangentFragPos;
#include <common>
layout(location = 0) out vec4 out_color;
#if MOTIONBLUR_ENABLED
layout(location = 1) out vec4 out_motion;
#endif
#param (color, 0, 0, 4, diffuse)
#param (diffuse, 1, 0, 1, diffuse)
#param (specular, 1, 1, 1, specular)
#param (reflection, 1, 2, 1, one)
#param (glossiness, 1, 3, 1, glossiness)
#param (detail_scale, 2, 0, 1, one)
#param (detail_height_scale, 2, 1, 1, one)
#param (height_scale, 2, 2, 1, zero)
#param (height_offset, 2, 3, 1, zero)
#texture (diffuse, 0, sRGB_A)
uniform sampler2D diffuse;
#texture (normalmap, 1, RGBA)
uniform sampler2D normalmap;
#texture (specgloss, 2, RGBA)
uniform sampler2D specgloss;
#texture (detailnormalmap, 3, RGBA)
uniform sampler2D detailnormalmap;
#define PARALLAX
// param[2].w is the height offset, not the weathering
#define NO_WEATHERING
#include <light_common.glsl>
#include <apply_fog.glsl>
#include <tonemapping.glsl>
vec2 ParallaxMapping(vec2 f_coord, vec3 viewDir);
void main()
{
//parallax mapping
vec3 viewDir = normalize(vec3(0.0f, 0.0f, 0.0f) - TangentFragPos); //tangent view pos - tangent frag pos
vec2 f_coord_p = ParallaxMapping(f_coord, viewDir);
vec4 normal_map = texture(normalmap, f_coord_p);
vec4 detailnormal_map = texture(detailnormalmap, f_coord_p * param[2].x);
vec4 tex_color = texture(diffuse, f_coord_p);
vec4 specgloss_map = texture(specgloss, f_coord_p);
bool alphatestfail = ( opacity >= 0.0 ? (tex_color.a < opacity) : (tex_color.a >= -opacity) );
if(alphatestfail)
discard;
vec3 fragcolor = ambient;
vec3 normal;
vec3 normaldetail;
normaldetail.xy = detailnormal_map.rg* 2.0 - 1.0;
normaldetail.z = sqrt(1.0 - clamp((dot(normaldetail.xy, normaldetail.xy)), 0.0, 1.0));
normaldetail.xyz = normaldetail.xyz * param[2].y;
normal.xy = normal_map.rg* 2.0 - 1.0;
normal.z = sqrt(1.0 - clamp((dot(normal.xy, normal.xy)), 0.0, 1.0));
vec3 fragnormal = normalize(f_tbn * normalize(vec3(normal.xy + normaldetail.xy, normal.z)));
float reflectivity = param[1].z * normal_map.a;
float specularity = specgloss_map.r;
glossiness = specgloss_map.g * abs(param[1].w);
metalic = specgloss_map.b;
fragcolor = apply_lights(fragcolor, fragnormal, tex_color.rgb, reflectivity, specularity, shadow_tone);
vec4 color = vec4(apply_fog(fragcolor), tex_color.a * alpha_mult);
#if POSTFX_ENABLED
out_color = color;
#else
out_color = tonemap(color);
#endif
#if MOTIONBLUR_ENABLED
{
vec2 a = (f_clip_future_pos.xy / f_clip_future_pos.w) * 0.5 + 0.5;;
vec2 b = (f_clip_pos.xy / f_clip_pos.w) * 0.5 + 0.5;;
out_motion = vec4(a - b, 0.0f, 0.0f);
}
#endif
}
vec2 ParallaxMapping(vec2 f_coord, vec3 viewDir)
{
float pos_len = length(f_pos.xyz);
// gradients of the coordinates taken here: inside the loop the fragments of a quad don't go the same way
vec2 dcoorddx = dFdx(f_coord);
vec2 dcoorddy = dFdy(f_coord);
if (pos_len > 100.0) {
return f_coord;
}
// the shift fades out before the distance it stops at, so it doesn't switch off at once there
float fade = 1.0 - smoothstep(80.0, 100.0, pos_len);
#if EXTRAEFFECTS_ENABLED
const float minLayers = 8.0;
const float maxLayers = 32.0;
float LayersWeight = pos_len / 20.0;
vec2 currentTexCoords = f_coord;
float currentDepthMapValue = textureGrad(normalmap, currentTexCoords, dcoorddx, dcoorddy).b;
LayersWeight = min(abs(dot(vec3(0.0, 0.0, 1.0), viewDir)),LayersWeight);
float numLayers = mix(maxLayers, minLayers, clamp(LayersWeight, 0.0, 1.0)); // number of depth layers
float layerDepth = 1.0 / numLayers; // calculate the size of each layer
float currentLayerDepth = 0.0; // depth of current layer
vec2 P = viewDir.xy * param[2].z * fade; // the amount to shift the texture coordinates per layer (from vector P)
vec2 deltaTexCoords = P / numLayers;
while(currentLayerDepth < currentDepthMapValue)
{
currentTexCoords -= deltaTexCoords; // shift texture coordinates along direction of P
currentDepthMapValue = textureGrad(normalmap, currentTexCoords, dcoorddx, dcoorddy).b; // get depthmap value at current texture coordinates
currentLayerDepth += layerDepth; // get depth of next layer
}
vec2 prevTexCoords = currentTexCoords + deltaTexCoords; // get texture coordinates before collision (reverse operations)
float afterDepth = currentDepthMapValue - currentLayerDepth; // get depth after and before collision for linear interpolation
float beforeDepth = textureGrad(normalmap, prevTexCoords, dcoorddx, dcoorddy).b - currentLayerDepth + layerDepth;
float weight = afterDepth / (afterDepth - beforeDepth); // interpolation of texture coordinates
vec2 finalTexCoords = prevTexCoords * weight + currentTexCoords * (1.0 - weight);
return finalTexCoords;
#else
float height = texture(normalmap, f_coord).b;
vec2 p = viewDir.xy / viewDir.z * (height * (param[2].z - param[2].w) * 0.2) * fade;
return f_coord - p;
#endif
}

View File

@@ -1,20 +0,0 @@
#include <common>
#include <tonemapping.glsl>
layout(location = 0) out vec4 out_color;
#if MOTIONBLUR_ENABLED
layout(location = 1) out vec4 out_motion;
#endif
void main()
{
vec4 color = vec4(1.0, 0.0, 1.0, 1.0);
#if POSTFX_ENABLED
out_color = color;
#else
out_color = tonemap(color);
#endif
#if MOTIONBLUR_ENABLED
out_motion = vec4(0.0f);
#endif
}

View File

@@ -1,127 +0,0 @@
in vec3 f_normal;
in vec2 f_coord;
in vec4 f_pos;
in mat3 f_tbn; //tangent matrix nietransponowany; mnożyć przez f_tbn dla TangentLightPos; TangentViewPos; TangentFragPos;
in vec4 f_clip_pos;
in vec4 f_clip_future_pos;
in vec3 TangentFragPos;
#include <common>
layout(location = 0) out vec4 out_color;
#if MOTIONBLUR_ENABLED
layout(location = 1) out vec4 out_motion;
#endif
#param (color, 0, 0, 4, diffuse)
#param (diffuse, 1, 0, 1, diffuse)
#param (specular, 1, 1, 1, specular)
#param (reflection, 1, 2, 1, one)
#param (glossiness, 1, 3, 1, glossiness)
#param (height_scale, 2, 1, 1, zero)
#param (height_offset, 2, 2, 1, zero)
#texture (diffuse, 0, sRGB_A)
uniform sampler2D diffuse;
#texture (normalmap, 1, RGBA)
uniform sampler2D normalmap;
#define PARALLAX
#include <light_common.glsl>
#include <apply_fog.glsl>
#include <tonemapping.glsl>
vec2 ParallaxMapping(vec2 f_coord, vec3 viewDir);
void main()
{
//parallax mapping
vec3 viewDir = normalize(vec3(0.0f, 0.0f, 0.0f) - TangentFragPos); //tangent view pos - tangent frag pos
vec2 f_coord_p = ParallaxMapping(f_coord, viewDir);
vec4 tex_color = texture(diffuse, f_coord_p);
bool alphatestfail = ( opacity >= 0.0 ? (tex_color.a < opacity) : (tex_color.a >= -opacity) );
if(alphatestfail)
discard;
// if (tex_color.a < opacity)
// discard;
vec3 fragcolor = ambient;
vec3 normal;
normal.xy = (texture(normalmap, f_coord_p).rg * 2.0 - 1.0);
normal.z = sqrt(1.0 - clamp((dot(normal.xy, normal.xy)), 0.0, 1.0));
vec3 fragnormal = normalize(f_tbn * normalize(normal.xyz));
float reflectivity = param[1].z * texture(normalmap, f_coord_p).a;
float specularity = (tex_color.r + tex_color.g + tex_color.b) * 0.5;
legacy_gloss();
fragcolor = apply_lights(fragcolor, fragnormal, tex_color.rgb, reflectivity, specularity, shadow_tone);
vec4 color = vec4(apply_fog(fragcolor), tex_color.a * alpha_mult);
#if POSTFX_ENABLED
out_color = color;
#else
out_color = tonemap(color);
#endif
#if MOTIONBLUR_ENABLED
{
vec2 a = (f_clip_future_pos.xy / f_clip_future_pos.w) * 0.5 + 0.5;;
vec2 b = (f_clip_pos.xy / f_clip_pos.w) * 0.5 + 0.5;;
out_motion = vec4(a - b, 0.0f, 0.0f);
}
#endif
}
vec2 ParallaxMapping(vec2 f_coord, vec3 viewDir)
{
float pos_len = length(f_pos.xyz);
// gradients of the coordinates taken here: inside the loop the fragments of a quad don't go the same way
vec2 dcoorddx = dFdx(f_coord);
vec2 dcoorddy = dFdy(f_coord);
if (pos_len > 100.0) {
return f_coord;
}
// the shift fades out before the distance it stops at, so it doesn't switch off at once there
float fade = 1.0 - smoothstep(80.0, 100.0, pos_len);
#if EXTRAEFFECTS_ENABLED
const float minLayers = 8.0;
const float maxLayers = 32.0;
float LayersWeight = pos_len / 20.0;
vec2 currentTexCoords = f_coord;
float currentDepthMapValue = textureGrad(normalmap, currentTexCoords, dcoorddx, dcoorddy).b;
LayersWeight = min(abs(dot(vec3(0.0, 0.0, 1.0), viewDir)),LayersWeight);
float numLayers = mix(maxLayers, minLayers, clamp(LayersWeight, 0.0, 1.0)); // number of depth layers
float layerDepth = 1.0 / numLayers; // calculate the size of each layer
float currentLayerDepth = 0.0; // depth of current layer
vec2 P = viewDir.xy * param[2].y * fade; // the amount to shift the texture coordinates per layer (from vector P)
vec2 deltaTexCoords = P / numLayers;
while(currentLayerDepth < currentDepthMapValue)
{
currentTexCoords -= deltaTexCoords; // shift texture coordinates along direction of P
currentDepthMapValue = textureGrad(normalmap, currentTexCoords, dcoorddx, dcoorddy).b; // get depthmap value at current texture coordinates
currentLayerDepth += layerDepth; // get depth of next layer
}
vec2 prevTexCoords = currentTexCoords + deltaTexCoords; // get texture coordinates before collision (reverse operations)
float afterDepth = currentDepthMapValue - currentLayerDepth; // get depth after and before collision for linear interpolation
float beforeDepth = textureGrad(normalmap, prevTexCoords, dcoorddx, dcoorddy).b - currentLayerDepth + layerDepth;
float weight = afterDepth / (afterDepth - beforeDepth); // interpolation of texture coordinates
vec2 finalTexCoords = prevTexCoords * weight + currentTexCoords * (1.0 - weight);
return finalTexCoords;
#else
float height = texture(normalmap, f_coord).b;
vec2 p = viewDir.xy / viewDir.z * (height * (param[2].y - param[2].z) * 0.2) * fade;
return f_coord - p;
#endif
}

View File

@@ -1,132 +0,0 @@
in vec3 f_normal;
in vec2 f_coord;
in vec4 f_pos;
in mat3 f_tbn; //tangent matrix nietransponowany; mnożyć przez f_tbn dla TangentLightPos; TangentViewPos; TangentFragPos;
in vec4 f_clip_pos;
in vec4 f_clip_future_pos;
in vec3 TangentFragPos;
#include <common>
layout(location = 0) out vec4 out_color;
#if MOTIONBLUR_ENABLED
layout(location = 1) out vec4 out_motion;
#endif
#param (color, 0, 0, 4, diffuse)
#param (diffuse, 1, 0, 1, diffuse)
#param (specular, 1, 1, 1, specular)
#param (reflection, 1, 2, 1, one)
#param (glossiness, 1, 3, 1, glossiness)
#param (height_scale, 2, 1, 1, zero)
#param (height_offset, 2, 2, 1, zero)
#texture (diffuse, 0, sRGB_A)
uniform sampler2D diffuse;
#texture (normalmap, 1, RGBA)
uniform sampler2D normalmap;
#texture (specgloss, 2, RGBA)
uniform sampler2D specgloss;
#define PARALLAX
#include <light_common.glsl>
#include <apply_fog.glsl>
#include <tonemapping.glsl>
vec2 ParallaxMapping(vec2 f_coord, vec3 viewDir);
void main()
{
//parallax mapping
vec3 viewDir = normalize(vec3(0.0f, 0.0f, 0.0f) - TangentFragPos); //tangent view pos - tangent frag pos
vec2 f_coord_p = ParallaxMapping(f_coord, viewDir);
vec4 tex_color = texture(diffuse, f_coord_p);
bool alphatestfail = ( opacity >= 0.0 ? (tex_color.a < opacity) : (tex_color.a >= -opacity) );
if(alphatestfail)
discard;
// if (tex_color.a < opacity)
// discard;
vec3 fragcolor = ambient;
vec3 normal;
normal.xy = (texture(normalmap, f_coord_p).rg * 2.0 - 1.0);
normal.z = sqrt(1.0 - clamp((dot(normal.xy, normal.xy)), 0.0, 1.0));
vec3 fragnormal = normalize(f_tbn * normalize(normal.xyz));
float reflectivity = param[1].z * texture(normalmap, f_coord_p).a;
float specularity = texture(specgloss, f_coord_p).r;
glossiness = texture(specgloss, f_coord_p).g * abs(param[1].w);
metalic = texture(specgloss, f_coord_p).b;
fragcolor = apply_lights(fragcolor, fragnormal, tex_color.rgb, reflectivity, specularity, shadow_tone);
vec4 color = vec4(apply_fog(fragcolor), tex_color.a * alpha_mult);
#if POSTFX_ENABLED
out_color = color;
#else
out_color = tonemap(color);
#endif
#if MOTIONBLUR_ENABLED
{
vec2 a = (f_clip_future_pos.xy / f_clip_future_pos.w) * 0.5 + 0.5;;
vec2 b = (f_clip_pos.xy / f_clip_pos.w) * 0.5 + 0.5;;
out_motion = vec4(a - b, 0.0f, 0.0f);
}
#endif
}
vec2 ParallaxMapping(vec2 f_coord, vec3 viewDir)
{
float pos_len = length(f_pos.xyz);
// gradients of the coordinates taken here: inside the loop the fragments of a quad don't go the same way
vec2 dcoorddx = dFdx(f_coord);
vec2 dcoorddy = dFdy(f_coord);
if (pos_len > 100.0) {
return f_coord;
}
// the shift fades out before the distance it stops at, so it doesn't switch off at once there
float fade = 1.0 - smoothstep(80.0, 100.0, pos_len);
#if EXTRAEFFECTS_ENABLED
const float minLayers = 8.0;
const float maxLayers = 32.0;
float LayersWeight = pos_len / 20.0;
vec2 currentTexCoords = f_coord;
float currentDepthMapValue = textureGrad(normalmap, currentTexCoords, dcoorddx, dcoorddy).b;
LayersWeight = min(abs(dot(vec3(0.0, 0.0, 1.0), viewDir)),LayersWeight);
float numLayers = mix(maxLayers, minLayers, clamp(LayersWeight, 0.0, 1.0)); // number of depth layers
float layerDepth = 1.0 / numLayers; // calculate the size of each layer
float currentLayerDepth = 0.0; // depth of current layer
vec2 P = viewDir.xy * param[2].y * fade; // the amount to shift the texture coordinates per layer (from vector P)
vec2 deltaTexCoords = P / numLayers;
while(currentLayerDepth < currentDepthMapValue)
{
currentTexCoords -= deltaTexCoords; // shift texture coordinates along direction of P
currentDepthMapValue = textureGrad(normalmap, currentTexCoords, dcoorddx, dcoorddy).b; // get depthmap value at current texture coordinates
currentLayerDepth += layerDepth; // get depth of next layer
}
vec2 prevTexCoords = currentTexCoords + deltaTexCoords; // get texture coordinates before collision (reverse operations)
float afterDepth = currentDepthMapValue - currentLayerDepth; // get depth after and before collision for linear interpolation
float beforeDepth = textureGrad(normalmap, prevTexCoords, dcoorddx, dcoorddy).b - currentLayerDepth + layerDepth;
float weight = afterDepth / (afterDepth - beforeDepth); // interpolation of texture coordinates
vec2 finalTexCoords = prevTexCoords * weight + currentTexCoords * (1.0 - weight);
return finalTexCoords;
#else
float height = texture(normalmap, f_coord).b;
vec2 p = viewDir.xy / viewDir.z * (height * (param[2].y - param[2].z) * 0.2) * fade;
return f_coord - p;
#endif
}

View File

@@ -1,10 +0,0 @@
// the rails and the ballast of a track faded into those of the tracks joined at its ends, see trackblend.glsl
#texture (diffuse, 0, sRGB_A)
uniform sampler2D diffuse;
#texture (diffuse1, 1, sRGB_A)
uniform sampler2D diffuse1;
#texture (diffuse2, 2, sRGB_A)
uniform sampler2D diffuse2;
#texture (diffuse3, 3, sRGB_A)
uniform sampler2D diffuse3;
#include <trackblend.glsl>

View File

@@ -1,19 +0,0 @@
// the rails and the ballast of a track of a normal mapped material faded into those of the tracks joined at its ends, see trackblend.glsl
#define TRACKBLEND_NORMALMAP 1
#texture (diffuse, 0, sRGB_A)
uniform sampler2D diffuse;
#texture (diffuse1, 1, sRGB_A)
uniform sampler2D diffuse1;
#texture (diffuse2, 2, sRGB_A)
uniform sampler2D diffuse2;
#texture (diffuse3, 3, sRGB_A)
uniform sampler2D diffuse3;
#texture (normalmap, 4, RGBA)
uniform sampler2D normalmap;
#texture (normalmap1, 5, RGBA)
uniform sampler2D normalmap1;
#texture (normalmap2, 6, RGBA)
uniform sampler2D normalmap2;
#texture (normalmap3, 7, RGBA)
uniform sampler2D normalmap3;
#include <trackblend.glsl>

View File

@@ -1,22 +0,0 @@
// the rails and the ballast of a track of a parallax material faded into those of the tracks joined at its ends, see trackblend.glsl
#define TRACKBLEND_NORMALMAP 1
#define TRACKBLEND_PARALLAX 1
#param (height_scale, 2, 1, 1, zero)
#param (height_offset, 2, 2, 1, zero)
#texture (diffuse, 0, sRGB_A)
uniform sampler2D diffuse;
#texture (diffuse1, 1, sRGB_A)
uniform sampler2D diffuse1;
#texture (diffuse2, 2, sRGB_A)
uniform sampler2D diffuse2;
#texture (diffuse3, 3, sRGB_A)
uniform sampler2D diffuse3;
#texture (normalmap, 4, RGBA)
uniform sampler2D normalmap;
#texture (normalmap1, 5, RGBA)
uniform sampler2D normalmap1;
#texture (normalmap2, 6, RGBA)
uniform sampler2D normalmap2;
#texture (normalmap3, 7, RGBA)
uniform sampler2D normalmap3;
#include <trackblend.glsl>

View File

@@ -1,18 +0,0 @@
// the rails and the ballast of a track of a material with normal and specgloss maps faded into those of the tracks joined at its ends, see trackblend.glsl
#define TRACKBLEND_NORMALMAP 1
#define TRACKBLEND_SPECGLOSS 1
#texture (diffuse, 0, sRGB_A)
uniform sampler2D diffuse;
#texture (diffuse1, 1, sRGB_A)
uniform sampler2D diffuse1;
#texture (diffuse2, 2, sRGB_A)
uniform sampler2D diffuse2;
#texture (normalmap, 3, RGBA)
uniform sampler2D normalmap;
#texture (normalmap1, 4, RGBA)
uniform sampler2D normalmap1;
#texture (normalmap2, 5, RGBA)
uniform sampler2D normalmap2;
#texture (specgloss, 6, RGBA)
uniform sampler2D specgloss;
#include <trackblend.glsl>

View File

@@ -0,0 +1,12 @@
#version 460 core
#define STAGE_FRAGMENT 1
layout(location = 2) in vec2 f_coord;
#pragma texture(tex1, 0, sRGB_A)
layout(binding = 0) uniform sampler2D tex1;
void main()
{
if (texture(tex1, f_coord).a < 0.5f)
discard;
}

View File

@@ -1,6 +1,6 @@
// fog between the camera and a fragment, see fog_volume.glsl and weather_common.glsl. a draw with a fog_density of 0 is not
// fogged; one with another density than the regular one (the glare of lamps) gets the optical depth scaled by the ratio
#include <fog_volume.glsl>
#include "fog_volume.glsl"
// rgb: light the fog adds, a: what it lets through
vec4 fog_at_fragment()

View File

@@ -1,10 +1,12 @@
#version 460 core
#define STAGE_COMPUTE 1
// what the cpu needs from the atmosphere, worked out from the sky-view table in one work group: the light arriving at the
// observer from every direction as spherical harmonics (the ground below the horizon lit by the sun and the sky), the
// transmittance towards the sun, and the average light of the sky above the horizon and over the whole sky.
// run after the sky-view table; the result is read back by the cpu a few frames later
#include <common>
#include <atmosphere_common.glsl>
#include "common.glsl"
#include "atmosphere_common.glsl"
layout(binding = ATMOSPHERE_TRANSMITTANCE_UNIT) uniform sampler2D atmo_transmittance_lut;
layout(binding = ATMOSPHERE_SKYVIEW_UNIT) uniform sampler2D atmo_skyview_lut;

View File

@@ -1,12 +1,14 @@
#version 460 core
#define STAGE_COMPUTE 1
// light scattered more than once, for the multiple scattering table (Hillaire 2020, section 5.5): for a point at a height
// lit by the sun at an angle, the second order scattering from 64 directions around it, summed as a geometric series of
// all the orders. one work group per texel, one invocation per direction. run after the transmittance table
#include <common>
#include <atmosphere_common.glsl>
#include "common.glsl"
#include "atmosphere_common.glsl"
layout(binding = ATMOSPHERE_TRANSMITTANCE_UNIT) uniform sampler2D atmo_transmittance_lut;
#include <atmosphere_integrate.glsl>
#include "atmosphere_integrate.glsl"
layout(local_size_x = 64) in;

View File

@@ -1,14 +1,16 @@
#version 460 core
#define STAGE_COMPUTE 1
// light of the sky seen by the observer in every direction, for the sky-view table (atmosphere_common.glsl), which the
// sky, the ambient light and the fog colour are read from. one invocation per texel. run every frame the sky is drawn with
// the atmosphere, after the transmittance and multiple scattering tables
#include <common>
#include <atmosphere_common.glsl>
#include "common.glsl"
#include "atmosphere_common.glsl"
layout(binding = ATMOSPHERE_TRANSMITTANCE_UNIT) uniform sampler2D atmo_transmittance_lut;
layout(binding = ATMOSPHERE_MULTISCATTERING_UNIT) uniform sampler2D atmo_multiscattering_lut;
#define ATMO_MULTISCATTERING_LUT
#include <atmosphere_integrate.glsl>
#include "atmosphere_integrate.glsl"
layout(local_size_x = 8, local_size_y = 8) in;

View File

@@ -1,8 +1,10 @@
#version 460 core
#define STAGE_COMPUTE 1
// transmittance from a point in the atmosphere to its top, for the transmittance table (atmosphere_common.glsl).
// one invocation per texel. run when the parameters of the atmosphere change
#include <common>
#include <atmosphere_common.glsl>
#include "common.glsl"
#include "atmosphere_common.glsl"
layout(local_size_x = 8, local_size_y = 8) in;

View File

@@ -0,0 +1,29 @@
#version 460 core
#define STAGE_FRAGMENT 1
layout(location = 2) in vec2 f_coord;
#pragma texture(tex1, 0, sRGB_A)
layout(binding = 0) uniform sampler2D tex1;
#include "common.glsl"
#include "tonemapping.glsl"
layout(location = 0) out vec4 out_color;
layout(location = 1) out vec4 out_motion;
void main()
{
vec4 tex_color = texture(tex1, f_coord);
if (POSTFX_ENABLED)
{
out_color = tex_color * param[0];
}
else
{
out_color = tonemap(tex_color * param[0]);
}
if (MOTIONBLUR_ENABLED)
{
out_motion = vec4(0.0f);
}
}

View File

@@ -1,17 +1,19 @@
#version 460 core
#define STAGE_FRAGMENT 1
// the sun, the moon and the textured sprite of the easter egg, drawn over the sky on a quad around the direction of the body
// (celestial.vert). param[0]: colour (rgb) and alpha, param[1]: position in view space and half the size of the quad,
// param[2].xy: corner (sprite) or centre (moon) of the picture in the texture, param[2].z: its size (sprite) or the radius of
// the disc in it (moon), in texture units, param[2].w: kind of body, 0: textured sprite, 1: sun, 2: moon.
// the colour goes out premultiplied, the alpha is how much of the sky behind the body it hides (blending ONE, ONE_MINUS_SRC_ALPHA)
in vec2 f_coord;
in vec2 f_local;
layout(location = 2) in vec2 f_coord;
layout(location = 15) in vec2 f_local;
#texture (tex1, 0, sRGB_A)
uniform sampler2D tex1;
#pragma texture(tex1, 0, sRGB_A)
layout(binding = 0) uniform sampler2D tex1;
#include <common>
#include <tonemapping.glsl>
#include "common.glsl"
#include "tonemapping.glsl"
// shape and light of the sun and the moon, set by opengl46_renderer::Render(world_environment *):
// [0].xy: direction to the zenith on the quad, [0].z: height over width of the disc (flattened by the refraction near the
@@ -22,9 +24,7 @@ uniform sampler2D tex1;
layout(location = 0) uniform vec4 body[3];
layout(location = 0) out vec4 out_color;
#if MOTIONBLUR_ENABLED
layout(location = 1) out vec4 out_motion;
#endif
void main()
{
@@ -72,12 +72,16 @@ void main()
color = vec4(albedo * param[0].rgb * ((lit + body[1].w) * coverage), coverage * param[0].a);
}
}
#if POSTFX_ENABLED
out_color = color;
#else
out_color = vec4(tonemap(vec4(color.rgb, 1.0)).rgb, color.a);
#endif
#if MOTIONBLUR_ENABLED
out_motion = vec4(0.0f);
#endif
if (POSTFX_ENABLED)
{
out_color = color;
}
else
{
out_color = vec4(tonemap(vec4(color.rgb, 1.0)).rgb, color.a);
}
if (MOTIONBLUR_ENABLED)
{
out_motion = vec4(0.0f);
}
}

View File

@@ -1,3 +1,5 @@
#version 460 core
#define STAGE_VERTEX 1
const vec2 vert[4] = vec2[]
(
vec2(-1.0, 1.0),
@@ -6,11 +8,11 @@ const vec2 vert[4] = vec2[]
vec2( 1.0, -1.0)
);
out vec2 f_coord;
layout(location = 2) out vec2 f_coord;
// the corner of the quad, -1...1 across it
out vec2 f_local;
layout(location = 15) out vec2 f_local;
#include <common>
#include "common.glsl"
void main()
{

View File

@@ -2,7 +2,7 @@
// the shape noise (3d, clouds_noise.comp) gives the lumps of a cloud, the detail noise (3d) eats into their edges, the coverage
// noise (2d) spreads the clouds of a layer over the sky so they take up its coverage. positions are world offsets from the
// camera, in metres, y up; the earth curves away from the camera, so far clouds sink below the horizon
#include <weather_common.glsl>
#include "weather_common.glsl"
layout(binding = CLOUD_SHAPE_TEX) uniform sampler3D cloud_shape_noise;
layout(binding = CLOUD_DETAIL_TEX) uniform sampler3D cloud_detail_noise;

View File

@@ -1,11 +1,13 @@
#version 460 core
#define STAGE_COMPUTE 1
// clouds of the weather ray marched through their layers (clouds_common.glsl), into an image the sky pass lays over the sky
// (sky_weather.frag). mode 0: the view of the main camera at a part of the resolution, smoothed over frames by
// clouds_temporal.comp; mode 1: a panorama around the camera (azimuth across, elevation up), a band of rows per frame, for the
// environment map and the other views. rgb: the light of the clouds with the fog in front of them, a: what they let through
// of the sky behind; the depth image gets the distance of the clouds, for the reprojection
#include <common>
#include <clouds_common.glsl>
#include "common.glsl"
#include "clouds_common.glsl"
layout(local_size_x = WEATHER_GROUP_SIZE, local_size_y = WEATHER_GROUP_SIZE, local_size_z = 1) in;

View File

@@ -1,10 +1,12 @@
#version 460 core
#define STAGE_COMPUTE 1
// the tiling noises the clouds and the fog are made of, made once at the start (opengl46_weather::init).
// kind 0, the shape (3d): r perlin-worley (perlin fbm with the worley cells carved in), g b a worley fbm of rising frequency;
// kind 1, the detail (3d): r g b worley fbm of rising frequency;
// kind 2, the coverage (2d): r g b three perlin fbm, spread evenly over 0-1 so a threshold of 1 - c leaves a share c above it
#include <common>
#include <random.glsl>
#include "common.glsl"
#include "random.glsl"
layout(local_size_x = WEATHER_GROUP_SIZE, local_size_y = WEATHER_GROUP_SIZE, local_size_z = 1) in;

View File

@@ -1,9 +1,11 @@
#version 460 core
#define STAGE_COMPUTE 1
// the shadow the clouds cast on the ground: for points of the ground reference around the camera, what the clouds let through
// towards the key light. the shading (light_common.glsl) and the fog (fog_inject.comp) look it up along the ray of the sun,
// see cloud_shadow() in weather_common.glsl
#include <common>
#include <clouds_common.glsl>
#include "common.glsl"
#include "clouds_common.glsl"
layout(local_size_x = WEATHER_GROUP_SIZE, local_size_y = WEATHER_GROUP_SIZE, local_size_z = 1) in;

View File

@@ -1,9 +1,11 @@
#version 460 core
#define STAGE_COMPUTE 1
// the clouds of the main view smoothed over frames: the image of this frame (clouds_march.comp, ray started at another
// distance every frame) blended into the one of the previous frames, found where the clouds were by the distance of the
// clouds, the rotation and the move of the camera. the history is held to the range of the neighbourhood of this frame,
// so moving clouds and a turning camera don't leave trails
#include <common>
#include "common.glsl"
layout(local_size_x = WEATHER_GROUP_SIZE, local_size_y = WEATHER_GROUP_SIZE, local_size_z = 1) in;

View File

@@ -1,7 +1,9 @@
#version 460 core
#define STAGE_COMPUTE 1
// bounding boxes of the light clusters in view space, see gl/cluster_grid.h
// one invocation per cluster, run when the projection or the depth range of the pass changes
#include <common>
#include "common.glsl"
layout(local_size_x = CLUSTER_BUILD_GROUP_SIZE) in;

View File

@@ -1,9 +1,11 @@
#version 460 core
#define STAGE_COMPUTE 1
// assigns the lights to the light clusters, see gl/cluster_grid.h
// one invocation per cluster: tests every light of light_ssbo (the sun, slot 0, is handled apart from the clusters)
// against the bounding box of the cluster in view space, and writes the indices of the lights which reach it.
// run every frame after the lights were updated, for the grid of the pass about to be drawn
#include <common>
#include "common.glsl"
layout(local_size_x = CLUSTER_CULL_GROUP_SIZE) in;

View File

@@ -1,13 +1,15 @@
#version 460 core
#define STAGE_FRAGMENT 1
// debug view of the light clusters: tints every pixel of the scene with the colour of the number of lights which
// were assigned to its cluster (see gl/cluster_grid.h), pixels of clusters without lights stay as they are.
// drawn over the resolved image
in vec2 f_coords;
layout(location = 14) in vec2 f_coords;
#include <common>
#include "common.glsl"
#texture (depth_tex, 0, R)
uniform sampler2D depth_tex;
#pragma texture(depth_tex, 0, R)
layout(binding = 0) uniform sampler2D depth_tex;
layout(location = 0) out vec4 out_color;

30
shaders/ogl46/color.frag Normal file
View File

@@ -0,0 +1,30 @@
#version 460 core
#define STAGE_FRAGMENT 1
layout(location = 13) in vec3 f_color;
layout(location = 3) in vec4 f_pos;
#include "common.glsl"
#include "apply_fog.glsl"
#include "tonemapping.glsl"
layout(location = 0) out vec4 out_color;
layout(location = 1) out vec4 out_motion;
#include "sky_shoulder.glsl"
void main()
{
vec3 col = sky_shoulder(pow(max(f_color.rgb, vec3(0.0)), vec3(2.2)));
if (POSTFX_ENABLED)
{
out_color = vec4(apply_fog(col), 1.0f);
}
else
{
out_color = tonemap(vec4(apply_fog(col), 1.0f));
}
if (MOTIONBLUR_ENABLED)
{
out_motion = vec4(0.0f);
}
}

322
shaders/ogl46/common.glsl Normal file
View File

@@ -0,0 +1,322 @@
// what the shaders of the opengl 4.6 renderer share: the settings, the constants of the game, the lights, the clusters, the
// blocks of the scene and of the model being drawn. the constants below are the values of the game (gl/ubo.h and others):
// compiled from the source, the game puts its own values before the source (gl::glsl_common) and they are taken instead;
// the SPIR-V binaries (shaders/ogl46bin) are compiled with the values written here, so they have to stay the same as in the
// game, which checks them when it starts (and doesn't load the binaries when they differ).
//
// the locations of the inputs and outputs between the stages, the same for a name in every shader (SPIR-V links the stages by
// the locations, not by the names): 0 f_normal, 1 f_normal_raw, 2 f_coord, 3 f_pos, 4 f_clip_pos, 5 f_clip_future_pos,
// 6 TangentFragPos, 7 UserData, 8-10 f_tbn, 11 f_model_draw, 12 f_albedo, 13 f_color, 14 f_coords, 15 f_local, 16 f_soft,
// 17 f_streak, 18 g_coord, 19 g_coords, 20 g_pos
#ifndef COMMON_GLSL
#define COMMON_GLSL
#if !defined(STAGE_VERTEX) && !defined(STAGE_FRAGMENT) && !defined(STAGE_GEOMETRY) && !defined(STAGE_COMPUTE)
#error "the stage of the shader isn't defined: #define STAGE_VERTEX 1 (STAGE_FRAGMENT, STAGE_GEOMETRY, STAGE_COMPUTE) before the include of common.glsl"
#endif
#include "settings.glsl"
#ifndef MASZYNA_CONSTANTS
#define MASZYNA_CONSTANTS 1
#define MAX_LIGHTS 1024U
#define MAX_CASCADES 3U
#define MAX_PARAMS 3U
#define SHADOW_TEX 8
#define ENV_TEX 9
#define HEADLIGHT_TEX 10
#define ENV_GGX_TEX 11
#define SCENE_UBO_BINDING 0
#define MODEL_UBO_BINDING 1
#define INSTANCE_SSBO_BINDING 8
#define INSTANCE_RECORD_SSBO_BINDING 9
#define INSTANCE_JOB_SSBO_BINDING 10
#define INSTANCE_GROUP_SSBO_BINDING 11
#define INSTANCE_LOD_SSBO_BINDING 12
#define INSTANCE_COUNTER_SSBO_BINDING 13
#define INSTANCE_OUTPUT_SSBO_BINDING 14
#define INSTANCE_COMMAND_SSBO_BINDING 15
#define MODEL_DRAW_SSBO_BINDING 10
#define INSTANCE_CULL_GROUP_SIZE 64
#define INSTANCE_OFFSETS_GROUP_SIZE 1024
#define INSTANCE_COMMAND_GROUP_SIZE 64
#define HIZ_GROUP_SIZE 8
#define SHADOW_FIT_GROUP_SIZE 16
#define SHADOW_FIT_SSBO_BINDING 9
#define PARTICLE_GROUP_SIZE 64
#define PARTICLE_SSBO_BINDING 9
#define PARTICLE_SOURCE_SSBO_BINDING 10
#define PARTICLE_OWNER_SSBO_BINDING 11
#define PARTICLE_OUTPUT_SSBO_BINDING 12
#define PARTICLE_COMMAND_SSBO_BINDING 13
#define INSTANCE_COUNTER_HEADER 8
#define INSTANCE_JOB_SLEEPERS 1U
#define LIGHT_SSBO_BINDING 0
#define CLUSTER_GRID_X 16
#define CLUSTER_GRID_Y 9
#define CLUSTER_GRID_Z 24
#define CLUSTER_COUNT 3456
#define MAX_LIGHTS_PER_CLUSTER 64
#define CLUSTER_BUILD_GROUP_SIZE 64
#define CLUSTER_CULL_GROUP_SIZE 64
#define CLUSTER_UBO_BINDING 2
#define CLUSTER_AABB_SSBO_BINDING 1
#define CLUSTER_RANGE_SSBO_BINDING 2
#define CLUSTER_INDEX_SSBO_BINDING 3
#define CLUSTER_COUNTER_SSBO_BINDING 4
#define ENVMAP_GGX_LEVELS 7
#define ENVMAP_GGX_ROUGHNESS_MIN 0.200000
#define ENVMAP_GGX_GROUP_SIZE 8
#define SKY_SSBO_BINDING 5
#define EXPOSURE_SSBO_BINDING 6
#define EXPOSURE_HISTOGRAM_BINS 256
#define EXPOSURE_HISTOGRAM_GROUP_SIZE 16
#define ATMOSPHERE_UBO_BINDING 4
#define ATMOSPHERE_RESULT_SSBO_BINDING 7
#define ATMOSPHERE_TRANSMITTANCE_WIDTH 256
#define ATMOSPHERE_TRANSMITTANCE_HEIGHT 64
#define ATMOSPHERE_MULTISCATTERING_SIZE 32
#define ATMOSPHERE_SKYVIEW_WIDTH 192
#define ATMOSPHERE_SKYVIEW_HEIGHT 108
#define ATMOSPHERE_AMBIENT_GROUP_SIZE 256
#define ATMOSPHERE_TRANSMITTANCE_UNIT 0
#define ATMOSPHERE_MULTISCATTERING_UNIT 1
#define ATMOSPHERE_SKYVIEW_UNIT 2
#define SKY_VIEW_TEX 12
#define LOCAL_SHADOW_TEX 13
#define LOCAL_SHADOW_LAMPS_TEX 14
#define HEADLIGHT_SHADOW_TEX 15
#define MAX_HEADLIGHT_SHADOWS 4U
#define FOG_VOLUME_TEX 16
#define CLOUD_SHADOW_TEX 17
#define CLOUD_TEX 18
#define CLOUD_SHAPE_TEX 19
#define CLOUD_DETAIL_TEX 20
#define CLOUD_COVERAGE_TEX 21
#define CLOUD_HISTORY_TEX 22
#define SCENE_DEPTH_TEX 23
#define WEATHER_UBO_BINDING 5
#define WEATHER_SCRATCH_SSBO_BINDING 9
#define MAX_CLOUD_LAYERS 4
#define FOG_HORIZON_SAMPLES 32
#define WEATHER_GROUP_SIZE 8
#define FOG_VOLUME_BIAS 10.000000
#endif
const uint LIGHT_SPOT = 0U;
const uint LIGHT_POINT = 1U;
const uint LIGHT_DIR = 2U;
const uint LIGHT_HEADLIGHTS = 3U;
struct light_s
{
vec3 pos;
uint type;
vec3 dir;
float in_cutoff;
vec3 color;
float out_cutoff;
float linear;
float quadratic;
float intensity;
float ambient;
mat4 headlight_projection;
vec4 headlight_weights;
};
// storage blocks are guaranteed only in fragment and compute shaders (GL 4.6 minimum for the other stages is 0)
#if defined(STAGE_FRAGMENT) || defined(STAGE_COMPUTE)
layout(std430, binding = LIGHT_SSBO_BINDING) readonly buffer light_ssbo
{
vec3 ambient;
// lights stored in lights[], what the cluster culling goes through
uint lights_total;
vec3 fog_color;
// lights the shading loop goes through when the lights are not clustered
uint lights_count;
// 1 if the shading takes the lights from the list of the cluster of a fragment, see cluster_ubo
uint lights_clustered;
// scale of the directional part of the sky ambient light, see sky_ssbo
float sky_ambient_factor;
// 1 if rough reflections come from the prefiltered environment map
uint env_ggx;
light_s lights[];
};
// directional part of the sky ambient light: real spherical harmonics (bands 1 and 2, band 0 is ambient) of the light
// a surface facing a world space direction gets, in units of ambient. see gl::sky_data
layout(std430, binding = SKY_SSBO_BINDING) readonly buffer sky_ssbo
{
vec4 sky_ambient_sh[9];
};
#endif
// light clusters, see gl/cluster_grid.h
struct cluster_aabb_s
{
vec4 lower;
vec4 upper;
};
struct cluster_range_s
{
uint offset;
uint count;
};
#if defined(STAGE_FRAGMENT) || defined(STAGE_COMPUTE)
// parameters of the grid for the pass being drawn
layout(std140, binding = CLUSTER_UBO_BINDING) uniform cluster_ubo
{
mat4 cluster_projection;
float cluster_znear;
float cluster_zfar;
float cluster_slice_scale;
float cluster_slice_bias;
vec2 cluster_viewport_size;
uint cluster_valid;
};
// the compute passes fill the cluster buffers, shading only reads them
#ifdef STAGE_COMPUTE
#define CLUSTER_SSBO_ACCESS
layout(std430, binding = CLUSTER_AABB_SSBO_BINDING) buffer cluster_aabb_ssbo
{
cluster_aabb_s cluster_aabbs[];
};
layout(std430, binding = CLUSTER_COUNTER_SSBO_BINDING) buffer cluster_counter_ssbo
{
uint cluster_index_count;
uint cluster_overflow_count;
};
#else
#define CLUSTER_SSBO_ACCESS readonly
#endif
layout(std430, binding = CLUSTER_RANGE_SSBO_BINDING) CLUSTER_SSBO_ACCESS buffer cluster_range_ssbo
{
cluster_range_s cluster_ranges[];
};
layout(std430, binding = CLUSTER_INDEX_SSBO_BINDING) CLUSTER_SSBO_ACCESS buffer cluster_index_ssbo
{
uint cluster_light_indices[];
};
#endif
#ifdef MODEL_DRAWS
// programs of the multi draws of the instances drawn from the gpu culling: the model block of every draw comes from a
// storage buffer, picked by the number of the draw in the multi draw. the fragment stage gets the number from the vertex
// stage (which writes f_model_draw), and the names of the uniform block below stand for the fields of the draw
struct model_draw_s
{
mat4 modelview;
mat3 modelviewnormal;
vec4 param[MAX_PARAMS];
mat4 future;
float opacity;
float emission;
float fog_density;
float alpha_mult;
float shadow_tone;
};
layout(std430, binding = MODEL_DRAW_SSBO_BINDING) readonly buffer model_draw_ssbo
{
model_draw_s model_draws[];
};
#if defined(STAGE_VERTEX)
layout(location = 11) flat out uint f_model_draw;
#define MODEL_DRAW gl_DrawID
#elif defined(STAGE_FRAGMENT)
layout(location = 11) flat in uint f_model_draw;
#define MODEL_DRAW f_model_draw
#else
#define MODEL_DRAW 0
#endif
#define modelview model_draws[MODEL_DRAW].modelview
#define modelviewnormal model_draws[MODEL_DRAW].modelviewnormal
#define param model_draws[MODEL_DRAW].param
#define future model_draws[MODEL_DRAW].future
#define opacity model_draws[MODEL_DRAW].opacity
#define emission model_draws[MODEL_DRAW].emission
#define fog_density model_draws[MODEL_DRAW].fog_density
#define alpha_mult model_draws[MODEL_DRAW].alpha_mult
#define shadow_tone model_draws[MODEL_DRAW].shadow_tone
#else
layout(std140, binding = MODEL_UBO_BINDING) uniform model_ubo
{
mat4 modelview;
mat3 modelviewnormal;
vec4 param[MAX_PARAMS];
mat4 future;
float opacity;
float emission;
float fog_density;
float alpha_mult;
float shadow_tone;
};
#endif
layout(std140, binding = SCENE_UBO_BINDING) uniform scene_ubo
{
mat4 projection;
mat4 inv_view;
mat4 lightview[MAX_CASCADES];
vec3 cascade_end;
float time;
vec4 rain_params;
vec4 wiper_pos;
vec4 wiper_timer_out;
vec4 wiper_timer_return;
// shadow maps of the headlights, see gl::scene_ubs
mat4 headlight_shadow[MAX_HEADLIGHT_SHADOWS];
vec4 headlight_shadow_params[MAX_HEADLIGHT_SHADOWS];
// contact shadows, see gl::scene_ubs
vec4 contact_shadow_params;
vec4 contact_shadow_lamps;
// cascades of the sun shadows fitted to the depth of the view, see gl::scene_ubs
vec4 shadow_fit;
};
#ifdef STAGE_VERTEX
// Per-instance modelview matrices for GPU-instanced draws, element 0 is identity.
// Draws which aren't instanced have gl_BaseInstance == 0 and gl_InstanceID == 0,
// so effective_modelview() reduces to model_ubo.modelview. For instanced draws
// the C++ side uploads camera-space root transforms of the instances and draws
// them from base instance onwards, with model_ubo.modelview set to the submodel-local
// chain (computed from identity, NOT from the camera/instance), so the product
// gives the correct final transform per instance per submodel.
layout(std430, binding = INSTANCE_SSBO_BINDING) readonly buffer instance_ssbo
{
mat4 instance_modelview[];
};
mat4 effective_modelview() {
return instance_modelview[gl_BaseInstance + gl_InstanceID] * modelview;
}
mat3 effective_modelviewnormal() {
// instance_modelview can include per-instance scale (uniform or per-axis),
// so its upper-3x3 is NOT its own inverse-transpose in the non-uniform
// case. Compute the correct normal matrix via transpose(inverse(...)).
// For pure rotation+translation this still produces the rotation matrix
// (one extra mat3 inverse per vertex — modern GPUs handle it cheaply).
mat3 instance_mv3 = mat3(instance_modelview[gl_BaseInstance + gl_InstanceID]);
mat3 instance_normal = transpose(inverse(instance_mv3));
return instance_normal * modelviewnormal;
}
#endif
#endif

View File

@@ -1,108 +1,108 @@
vec3 rgb2yuv(vec3 val)
{
return
clamp(
vec3(
(0.257 * val.r) + (0.504 * val.g) + (0.098 * val.b) + 0.0625,
-(0.148 * val.r) - (0.291 * val.g) + (0.439 * val.b) + 0.5,
(0.439 * val.r) - (0.368 * val.g) - (0.071 * val.b) + 0.5 ),
0.0, 1.0);
}
vec3 yuv2rgb(vec3 val)
{
val -= vec3(0.0625, 0.5, 0.5);
return
clamp(
vec3(
(1.164 * val.r) + (1.596 * val.b),
(1.164 * val.r) - (0.391 * val.g) - (0.813 * val.b),
(1.164 * val.r) + (2.018 * val.g) ),
0.0, 1.0);
}
vec3 rgb2hsl( vec3 col )
{
float red = col.r;
float green = col.g;
float blue = col.b;
float minc = min( col.r, min( col.g, col.b ));
float maxc = max( col.r, max( col.g, col.b ));
float delta = maxc - minc;
float lum = (minc + maxc) * 0.5;
float sat = 0.0;
float hue = 0.0;
if (lum > 0.0 && lum < 1.0) {
float mul = (lum < 0.5) ? (lum) : (1.0-lum);
sat = delta / (mul * 2.0);
}
vec3 masks = vec3(
(maxc == red && maxc != green) ? 1.0 : 0.0,
(maxc == green && maxc != blue) ? 1.0 : 0.0,
(maxc == blue && maxc != red) ? 1.0 : 0.0
);
vec3 adds = vec3(
((green - blue ) / delta),
2.0 + ((blue - red ) / delta),
4.0 + ((red - green) / delta)
);
float deltaGtz = (delta > 0.0) ? 1.0 : 0.0;
hue += dot( adds, masks );
hue *= deltaGtz;
hue /= 6.0;
if (hue < 0.0)
hue += 1.0;
return vec3( hue, sat, lum );
}
vec3 hsl2rgb( vec3 col )
{
const float onethird = 1.0 / 3.0;
const float twothird = 2.0 / 3.0;
const float rcpsixth = 6.0;
float hue = col.x;
float sat = col.y;
float lum = col.z;
vec3 xt = vec3(
rcpsixth * (hue - twothird),
0.0,
rcpsixth * (1.0 - hue)
);
if (hue < twothird) {
xt.r = 0.0;
xt.g = rcpsixth * (twothird - hue);
xt.b = rcpsixth * (hue - onethird);
}
if (hue < onethird) {
xt.r = rcpsixth * (onethird - hue);
xt.g = rcpsixth * hue;
xt.b = 0.0;
}
xt = min( xt, 1.0 );
float sat2 = 2.0 * sat;
float satinv = 1.0 - sat;
float luminv = 1.0 - lum;
float lum2m1 = (2.0 * lum) - 1.0;
vec3 ct = (sat2 * xt) + satinv;
vec3 rgb;
if (lum >= 0.5) { rgb = (luminv * ct) + lum2m1; }
else { rgb = lum * ct; }
return rgb;
}
vec3 rgb2yuv(vec3 val)
{
return
clamp(
vec3(
(0.257 * val.r) + (0.504 * val.g) + (0.098 * val.b) + 0.0625,
-(0.148 * val.r) - (0.291 * val.g) + (0.439 * val.b) + 0.5,
(0.439 * val.r) - (0.368 * val.g) - (0.071 * val.b) + 0.5 ),
0.0, 1.0);
}
vec3 yuv2rgb(vec3 val)
{
val -= vec3(0.0625, 0.5, 0.5);
return
clamp(
vec3(
(1.164 * val.r) + (1.596 * val.b),
(1.164 * val.r) - (0.391 * val.g) - (0.813 * val.b),
(1.164 * val.r) + (2.018 * val.g) ),
0.0, 1.0);
}
vec3 rgb2hsl( vec3 col )
{
float red = col.r;
float green = col.g;
float blue = col.b;
float minc = min( col.r, min( col.g, col.b ));
float maxc = max( col.r, max( col.g, col.b ));
float delta = maxc - minc;
float lum = (minc + maxc) * 0.5;
float sat = 0.0;
float hue = 0.0;
if (lum > 0.0 && lum < 1.0) {
float mul = (lum < 0.5) ? (lum) : (1.0-lum);
sat = delta / (mul * 2.0);
}
vec3 masks = vec3(
(maxc == red && maxc != green) ? 1.0 : 0.0,
(maxc == green && maxc != blue) ? 1.0 : 0.0,
(maxc == blue && maxc != red) ? 1.0 : 0.0
);
vec3 adds = vec3(
((green - blue ) / delta),
2.0 + ((blue - red ) / delta),
4.0 + ((red - green) / delta)
);
float deltaGtz = (delta > 0.0) ? 1.0 : 0.0;
hue += dot( adds, masks );
hue *= deltaGtz;
hue /= 6.0;
if (hue < 0.0)
hue += 1.0;
return vec3( hue, sat, lum );
}
vec3 hsl2rgb( vec3 col )
{
const float onethird = 1.0 / 3.0;
const float twothird = 2.0 / 3.0;
const float rcpsixth = 6.0;
float hue = col.x;
float sat = col.y;
float lum = col.z;
vec3 xt = vec3(
rcpsixth * (hue - twothird),
0.0,
rcpsixth * (1.0 - hue)
);
if (hue < twothird) {
xt.r = 0.0;
xt.g = rcpsixth * (twothird - hue);
xt.b = rcpsixth * (hue - onethird);
}
if (hue < onethird) {
xt.r = rcpsixth * (onethird - hue);
xt.g = rcpsixth * hue;
xt.b = 0.0;
}
xt = min( xt, 1.0 );
float sat2 = 2.0 * sat;
float satinv = 1.0 - sat;
float luminv = 1.0 - lum;
float lum2m1 = (2.0 * lum) - 1.0;
vec3 ct = (sat2 * xt) + satinv;
vec3 rgb;
if (lum >= 0.5) { rgb = (luminv * ct) + lum2m1; }
else { rgb = lum * ct; }
return rgb;
}

13
shaders/ogl46/copy.frag Normal file
View File

@@ -0,0 +1,13 @@
#version 460 core
#define STAGE_FRAGMENT 1
layout(location = 14) in vec2 f_coords;
#pragma texture(tex1, 0, sRGB)
layout(binding = 0) uniform sampler2D tex1;
layout(location = 0) out vec4 out_color;
void main()
{
out_color = texture(tex1, f_coords);
}

View File

@@ -1,6 +1,8 @@
#version 460 core
#define STAGE_FRAGMENT 1
// depth prepass of materials which never discard a fragment (no alpha test)
in vec2 f_coord;
layout(location = 2) in vec2 f_coord;
void main()
{

View File

@@ -1,3 +1,5 @@
#version 460 core
#define STAGE_VERTEX 1
// depth prepass of the instances drawn from the gpu culling (opengl46_renderer::Render_Instances_Indirect()).
// the position is worked out the way vertex.vert of the materials does it, and declared invariant in both, so the colour
// pass which follows gets the same depth for the same surface
@@ -5,11 +7,11 @@
layout(location = 0) in vec3 v_vert;
layout(location = 2) in vec2 v_coord;
#include <common>
#include "common.glsl"
invariant gl_Position;
out vec2 f_coord;
layout(location = 2) out vec2 f_coord;
void main()
{

View File

@@ -1,13 +1,15 @@
#version 460 core
#define STAGE_FRAGMENT 1
// depth prepass of materials whose colour shader tests the alpha of the diffuse texture against the opacity of the
// material (mat_default.frag and the like). the test here is stricter by one step of 8-bit alpha: a fragment which writes
// depth here is never discarded by the colour pass, which would leave a hole with nothing drawn behind it
in vec2 f_coord;
layout(location = 2) in vec2 f_coord;
#include <common>
#include "common.glsl"
#texture (diffuse, 0, sRGB_A)
uniform sampler2D diffuse;
#pragma texture(diffuse, 0, sRGB_A)
layout(binding = 0) uniform sampler2D diffuse;
void main()
{

View File

@@ -5,17 +5,22 @@
#ifndef DITHER_GLSL
#define DITHER_GLSL
#include "settings.glsl"
vec3 dither_output(vec3 color)
{
float noise = (fract(52.9829189 * fract(dot(gl_FragCoord.xy, vec2(0.06711056, 0.00583715)))) - 0.5) / 255.0;
#if OUTPUT_GAMMA
return max(color + noise, vec3(0.0));
#else
vec3 linear = max(color, vec3(0.0));
vec3 encoded = mix(linear * 12.92, 1.055 * pow(linear, vec3(1.0 / 2.4)) - 0.055, step(vec3(0.0031308), linear));
encoded = max(encoded + noise, vec3(0.0));
return mix(encoded / 12.92, pow((encoded + 0.055) / 1.055, vec3(2.4)), step(vec3(0.04045), encoded));
#endif
if (OUTPUT_GAMMA)
{
return max(color + noise, vec3(0.0));
}
else
{
vec3 linear = max(color, vec3(0.0));
vec3 encoded = mix(linear * 12.92, 1.055 * pow(linear, vec3(1.0 / 2.4)) - 0.055, step(vec3(0.0031308), linear));
encoded = max(encoded + noise, vec3(0.0));
return mix(encoded / 12.92, pow((encoded + 0.055) / 1.055, vec3(2.4)), step(vec3(0.04045), encoded));
}
}
#endif

View File

@@ -1,15 +1,17 @@
#version 460 core
#define STAGE_COMPUTE 1
// prefilters the environment map with the GGX lobe for rough reflections (split sum approximation, Karis 2013), one level
// of the prefiltered map per dispatch. filtered importance sampling (Krivanek, Colbert 2008): each sample reads the mipmap
// of the source whose texels are about as large as the solid angle the sample stands for, so a few dozen samples give a
// smooth result. run when an update of the environment map is complete
#include <common>
#include "common.glsl"
layout(local_size_x = ENVMAP_GGX_GROUP_SIZE, local_size_y = ENVMAP_GGX_GROUP_SIZE) in;
layout(binding = 0, rgba16f) writeonly uniform imageCube prefilter_target;
// the plain map with its box filtered mipmaps, on the unit gl::program binds envmap to
uniform samplerCube envmap;
layout(binding = ENV_TEX) uniform samplerCube envmap;
// perceptual roughness of the level being written
layout(location = 0) uniform float roughness;

View File

@@ -0,0 +1,73 @@
layout(binding = ENV_TEX) uniform samplerCube envmap;
// the same map prefiltered with the GGX lobe (envmap_prefilter.comp), used when env_ggx is 1
layout(binding = ENV_GGX_TEX) uniform samplerCube envmap_ggx;
vec3 envmap_color( vec3 normal )
{
vec3 envcolor;
if (ENVMAP_ENABLED)
{
vec3 refvec = reflect(f_pos.xyz, normal); // view space
refvec = vec3(inv_view * vec4(refvec, 0.0)); // world space
envcolor = texture(envmap, refvec).rgb;
// Sanitize. The env cubemap can briefly contain NaN/Inf after a
// reflection-pass regeneration (m_empty_cubemap was bound during the
// face render and on NVIDIA can sample as undefined). Without this
// guard, a single bad texel propagates through env_reflection in
// apply_lights() and produces one-frame black flashes on glossy
// (esp. specgloss) surfaces.
if (any(isnan(envcolor)) || any(isinf(envcolor))) envcolor = vec3(0.0);
envcolor = max(envcolor, vec3(0.0));
}
else
{
envcolor = vec3(0.5);
}
return envcolor;
}
// Roughness-aware env map lookup — uses mip levels for blurry reflections.
// lod 0.0 = mirror sharp, lod ~8.0 = fully diffuse blur.
vec3 envmap_color_lod(vec3 fragnormal, float lod)
{
if (ENVMAP_ENABLED)
{
vec3 refvec = reflect(f_pos.xyz, fragnormal); // view space — matches envmap_color exactly
refvec = vec3(inv_view * vec4(refvec, 0.0)); // world space — was missing
vec3 envcolor = textureLod(envmap, refvec, lod).rgb;
// See envmap_color() above — same NaN/Inf sanitize, also needed here
// because mipmap generation propagates a single NaN texel across the
// whole mip chain.
if (any(isnan(envcolor)) || any(isinf(envcolor))) envcolor = vec3(0.0);
return max(envcolor, vec3(0.0));
}
else
{
return vec3(0.5); // was vec3(0.0), match the non-LOD fallback
}
}
// reflection of the surroundings in a surface of the given perceptual roughness (0 mirror, 1 matte)
vec3 envmap_color_rough(vec3 fragnormal, float roughness)
{
// the plain map, its mipmaps (box filtered) standing for the roughness
const float MAX_REFLECTION_LOD = 8.0;
vec3 boxcolor = envmap_color_lod(fragnormal, roughness * MAX_REFLECTION_LOD);
if (ENVMAP_ENABLED)
{
if (env_ggx == 0U || roughness <= ENVMAP_GGX_ROUGHNESS_MIN)
return boxcolor;
vec3 refvec = reflect(f_pos.xyz, fragnormal);
refvec = vec3(inv_view * vec4(refvec, 0.0));
float level = (roughness - ENVMAP_GGX_ROUGHNESS_MIN) / (1.0 - ENVMAP_GGX_ROUGHNESS_MIN) * float(ENVMAP_GGX_LEVELS - 1U);
vec3 ggxcolor = textureLod(envmap_ggx, refvec, level).rgb;
if (any(isnan(ggxcolor)) || any(isinf(ggxcolor))) ggxcolor = vec3(0.0);
ggxcolor = max(ggxcolor, vec3(0.0));
// the prefiltered map takes over over the first tenth of the roughness above its lowest level
return mix(boxcolor, ggxcolor, clamp((roughness - ENVMAP_GGX_ROUGHNESS_MIN) * 10.0, 0.0, 1.0));
}
else
{
return boxcolor;
}
}

View File

@@ -1,9 +1,11 @@
#version 460 core
#define STAGE_COMPUTE 1
// exposure from the luminance histogram (exposure_histogram.comp): the average log2 luminance of the pixels between the
// low and high percentile (the darkest and brightest parts of the image do not move the exposure), adapted over time to,
// faster towards the brighter. the exposure brings the adapted luminance to the key, within the limits. one work group,
// one invocation per bin; the histogram is cleared for the next frame
#include <common>
#include "common.glsl"
layout(local_size_x = EXPOSURE_HISTOGRAM_BINS) in;

View File

@@ -1,7 +1,9 @@
#version 460 core
#define STAGE_COMPUTE 1
// luminance histogram of the image for the automatic exposure: every second pixel in both directions, binned by the log2
// of its luminance. bin 0 takes the black pixels, which the average leaves out. exposure_average.comp reads and clears it
#include <common>
#include "common.glsl"
layout(local_size_x = EXPOSURE_HISTOGRAM_GROUP_SIZE, local_size_y = EXPOSURE_HISTOGRAM_GROUP_SIZE) in;

View File

@@ -1,9 +1,11 @@
#version 460 core
#define STAGE_COMPUTE 1
// colours of the fog towards the horizon by the angle from the azimuth of the sun, from the sky-view table of the atmosphere,
// written into the weather buffer (weather_common.glsl: fog_horizon). the far fog then has the colour of the sky behind it.
// the atmosphere blends into the old sky as opengl46_sky does it, by its share, white balance and brightness
#include <common>
#include <atmosphere_common.glsl>
#include "common.glsl"
#include "atmosphere_common.glsl"
layout(local_size_x = FOG_HORIZON_SAMPLES) in;

View File

@@ -1,3 +1,5 @@
#version 460 core
#define STAGE_COMPUTE 1
// the fog volume of the main view, first pass: in every cell of a grid laid over the view (slices spaced exponentially in the
// depth), how dense the fog is and how much light it scatters towards the camera. the density: the haze, the patches of the
// ground fog, the low clouds; the light: the colour the fog has towards the horizon (weather_common.glsl), less what the
@@ -8,18 +10,16 @@
// from doesn't depend on the point (the clusters of the middle of the cell)
// rgb: light scattered towards the camera per metre, a: extinction per metre
#include <common>
#include <clouds_common.glsl>
#include "common.glsl"
#include "clouds_common.glsl"
layout(local_size_x = WEATHER_GROUP_SIZE, local_size_y = WEATHER_GROUP_SIZE, local_size_z = 1) in;
layout(rgba16f, binding = 0) uniform writeonly image3D fog_scattering;
layout(binding = CLOUD_HISTORY_TEX) uniform sampler3D fog_history;
#if SHADOWMAP_ENABLED
uniform sampler2DArrayShadow shadowmap;
#endif
uniform sampler2D headlightmap;
layout(binding = SHADOW_TEX) uniform sampler2DArrayShadow shadowmap;
layout(binding = HEADLIGHT_TEX) uniform sampler2D headlightmap;
layout(binding = HEADLIGHT_SHADOW_TEX) uniform sampler2DArrayShadow headlight_shadowmap;
layout(location = 0) uniform ivec3 grid;
@@ -81,31 +81,34 @@ float henyey_greenstein(float cosangle, float g)
// share of the sunlight the shadow map holds back at a point of the view space, one comparison
float sun_shadow(vec3 position)
{
#if SHADOWMAP_ENABLED
float span_distance = dot(position, position);
uint cascade;
for (cascade = 0U; cascade < MAX_CASCADES; cascade++)
if (span_distance <= cascade_end[cascade])
break;
for (; cascade < MAX_CASCADES; cascade++)
if (SHADOWMAP_ENABLED)
{
vec4 lightpos = lightview[cascade] * vec4(position, 1.0);
vec3 coords = lightpos.xyz / lightpos.w;
if (all(greaterThanEqual(coords.xy, vec2(0.0))) && all(lessThanEqual(coords.xy, vec2(1.0))))
float span_distance = dot(position, position);
uint cascade;
for (cascade = 0U; cascade < MAX_CASCADES; cascade++)
if (span_distance <= cascade_end[cascade])
break;
for (; cascade < MAX_CASCADES; cascade++)
{
if (coords.z < 0.0)
vec4 lightpos = lightview[cascade] * vec4(position, 1.0);
vec3 coords = lightpos.xyz / lightpos.w;
if (all(greaterThanEqual(coords.xy, vec2(0.0))) && all(lessThanEqual(coords.xy, vec2(1.0))))
{
if (coords.z < 0.0)
return 0.0;
return texture(shadowmap, vec4(coords.xy, float(cascade), coords.z + 0.0001 * float(cascade + 1U)));
}
// outside the map: lit, unless the cascades are fitted to the depth of the view (gfx.shadow.sdsm), whose maps cover
// only the area of the surfaces seen; then the first further cascade whose map holds the point
if (shadow_fit.x <= 0.0)
return 0.0;
return texture(shadowmap, vec4(coords.xy, float(cascade), coords.z + 0.0001 * float(cascade + 1U)));
}
// outside the map: lit, unless the cascades are fitted to the depth of the view (gfx.shadow.sdsm), whose maps cover
// only the area of the surfaces seen; then the first further cascade whose map holds the point
if (shadow_fit.x <= 0.0)
return 0.0;
return 0.0;
}
else
{
return 0.0;
}
return 0.0;
#else
return 0.0;
#endif
}
// light of a lamp or of the beam of headlights at a point of the view space, before the phase

View File

@@ -1,3 +1,5 @@
#version 460 core
#define STAGE_COMPUTE 1
// the fog volume of the main view, second pass: the light and extinction of the cells (fog_inject.comp) added up along the rays
// of the view, front to back, into what the fog adds and lets through from the camera to the far side of every slice
// (apply_fog.glsl). the light of a cell is integrated over its length as Hillaire (2015) does it, so it doesn't grow with
@@ -6,8 +8,8 @@
// the blending over frames differs from cell to cell, which the filter evens out. the history keeps the cells unfiltered.
// past the last slice one more: the fog all the way through the volume without the low clouds it holds, for the sky
#include <common>
#include <weather_common.glsl>
#include "common.glsl"
#include "weather_common.glsl"
layout(local_size_x = WEATHER_GROUP_SIZE, local_size_y = WEATHER_GROUP_SIZE, local_size_z = 1) in;

View File

@@ -5,7 +5,7 @@
#ifndef FOG_VOLUME_GLSL
#define FOG_VOLUME_GLSL
#include <weather_common.glsl>
#include "weather_common.glsl"
layout(binding = FOG_VOLUME_TEX) uniform sampler3D fog_volume;

View File

@@ -1,16 +1,16 @@
in vec4 f_pos;
in vec4 f_clip_pos;
in vec4 f_clip_future_pos;
#version 460 core
#define STAGE_FRAGMENT 1
layout(location = 3) in vec4 f_pos;
layout(location = 4) in vec4 f_clip_pos;
layout(location = 5) in vec4 f_clip_future_pos;
#include <common>
#include "common.glsl"
layout(location = 0) out vec4 out_color;
#if MOTIONBLUR_ENABLED
layout(location = 1) out vec4 out_motion;
#endif
#include <tonemapping.glsl>
#include <apply_fog.glsl>
#include "tonemapping.glsl"
#include "apply_fog.glsl"
void main()
{
@@ -23,12 +23,11 @@ void main()
vec4 color = vec4(apply_fog(pow(param[0].rgb, vec3(2.2)) * emission), mix(param[0].a, 0.0f, dist * 2.0f));
// vec4 color = vec4(add_fog(param[0].rgb * emission * (1.0 - get_fog_amount()), 1.0), mix(param[0].a, 0.0f, dist * 2.0f));
out_color = FBOUT(color);
#if MOTIONBLUR_ENABLED
if (MOTIONBLUR_ENABLED)
{
vec2 a = (f_clip_future_pos.xy / f_clip_future_pos.w) * 0.5 + 0.5;;
vec2 b = (f_clip_pos.xy / f_clip_pos.w) * 0.5 + 0.5;;
out_motion = vec4(a - b, 0.0f, 0.0f);
}
#endif
}

View File

@@ -1,12 +1,14 @@
#version 460 core
#define STAGE_VERTEX 1
layout(location = 0) in vec3 v_vert;
layout(location = 1) in vec3 v_normal;
layout(location = 2) in vec2 v_coord;
#include <common>
#include "common.glsl"
out vec4 f_pos;
out vec4 f_clip_pos;
out vec4 f_clip_future_pos;
layout(location = 3) out vec4 f_pos;
layout(location = 4) out vec4 f_clip_pos;
layout(location = 5) out vec4 f_clip_future_pos;
void main()
{

View File

@@ -1,21 +1,21 @@
#version 460 core
#define STAGE_FRAGMENT 1
// grass of the heightmap terrain (opengl46_grass, grass.vert): the blades lit like the rest of the scene
in vec3 f_normal;
in vec4 f_pos;
in vec3 f_albedo;
in vec4 f_clip_pos;
in vec4 f_clip_future_pos;
layout(location = 0) in vec3 f_normal;
layout(location = 3) in vec4 f_pos;
layout(location = 12) in vec3 f_albedo;
layout(location = 4) in vec4 f_clip_pos;
layout(location = 5) in vec4 f_clip_future_pos;
#include <common>
#include "common.glsl"
layout(location = 0) out vec4 out_color;
#if MOTIONBLUR_ENABLED
layout(location = 1) out vec4 out_motion;
#endif
#include <light_common.glsl>
#include <apply_fog.glsl>
#include <tonemapping.glsl>
#include "light_common.glsl"
#include "apply_fog.glsl"
#include "tonemapping.glsl"
void main()
{
@@ -25,17 +25,19 @@ void main()
vec3 fragcolor = apply_lights(ambient, fragnormal, f_albedo, 0.0, 0.2, shadow_tone);
vec4 color = vec4(apply_fog(fragcolor), 1.0);
#if POSTFX_ENABLED
out_color = color;
#else
out_color = tonemap(color);
#endif
#if MOTIONBLUR_ENABLED
if (POSTFX_ENABLED)
{
out_color = color;
}
else
{
out_color = tonemap(color);
}
if (MOTIONBLUR_ENABLED)
{
vec2 a = (f_clip_future_pos.xy / f_clip_future_pos.w) * 0.5 + 0.5;
vec2 b = (f_clip_pos.xy / f_clip_pos.w) * 0.5 + 0.5;
out_motion = vec4(a - b, 0.0f, 0.0f);
}
#endif
}

View File

@@ -1,3 +1,5 @@
#version 460 core
#define STAGE_VERTEX 1
// grass of the heightmap terrain (opengl46_grass): a blade made of the numbers of its vertex and its instance.
//
// the instances of a draw stand in a tile of a chunk. a blade takes its place in the tile from a sequence which spreads
@@ -7,43 +9,43 @@
// collapsed into a point outside the view. the vertices go up the blade in pairs, the last one is its tip.
// the chunk is drawn relative to its corner: x, z in metres from the corner, y the height as it is
#include <common>
#include "common.glsl"
// x, z: corner of the tile in the chunk, metres; y: side of the tile; w: blades of the tile where its densest kind is painted fully
uniform vec4 grass_tile;
layout(location = 0) uniform vec4 grass_tile;
// x: the share of the densest kind at the densest place of the tile (the blades of the tile are counted for it); y: segments
// of a blade; z, w: number of the tile in the world
uniform vec4 grass_part;
layout(location = 1) uniform vec4 grass_part;
// x: side of the chunk, metres; y: cells of its grid along a side; z: grass samples along a side less one
uniform vec4 grass_chunk;
layout(location = 2) uniform vec4 grass_chunk;
// the camera relative to the corner of the chunk (y as it is)
uniform vec4 grass_camera;
layout(location = 3) uniform vec4 grass_camera;
// x: distance the grass starts to thin out at, for speed; y: distance the fading starts at (gfx.grass.distance); z: where the
// grass ends (gfx.grass.fadedistance)
uniform vec4 grass_lod;
layout(location = 4) uniform vec4 grass_lod;
// x, y: direction of the wind (x, z of the world); z: its strength, 0..1; w: time, seconds
uniform vec4 grass_wind;
layout(location = 5) uniform vec4 grass_wind;
// the kinds of the chunk: colour at the root and at the tip (linear rgb), and height, its variation, width, lean
uniform vec4 grass_base[4];
uniform vec4 grass_tip[4];
uniform vec4 grass_shape[4];
layout(location = 6) uniform vec4 grass_base[4];
layout(location = 10) uniform vec4 grass_tip[4];
layout(location = 14) uniform vec4 grass_shape[4];
// share of the blades of each kind against the densest one of the chunk
uniform vec4 grass_share;
layout(location = 18) uniform vec4 grass_share;
// the colour of each kind dried out (linear rgb), and how much it follows the seasons
uniform vec4 grass_dry[4];
layout(location = 19) uniform vec4 grass_dry[4];
// the time of the year: x: how dry the grass is, y: how fresh (spring), z: how grown (share of the height)
uniform vec4 grass_season;
layout(location = 23) uniform vec4 grass_season;
layout(binding = 0) uniform sampler2D grass_heights; // heights of the grid points, R32F
layout(binding = 1) uniform sampler2D grass_density; // densities of the kinds, RGBA8
layout(binding = 2) uniform sampler2D grass_holes; // holes cut in the ground, R8
out vec3 f_normal;
out vec4 f_pos;
out vec3 f_albedo;
out vec4 f_clip_pos;
out vec4 f_clip_future_pos;
out vec4 UserData;
layout(location = 0) out vec3 f_normal;
layout(location = 3) out vec4 f_pos;
layout(location = 12) out vec3 f_albedo;
layout(location = 4) out vec4 f_clip_pos;
layout(location = 5) out vec4 f_clip_future_pos;
layout(location = 7) out vec4 UserData;
uint hash(uint x)
{

View File

@@ -1,3 +1,5 @@
#version 460 core
#define STAGE_COMPUTE 1
// smooths the ambient occlusion of gtao_main.comp: the average of the 4x4 pixels around each one, which takes out the
// repeating 4x4 pattern of the slices, with the pixels at a clearly different distance left out so the occlusion does
// not leak across the edges of objects. one invocation per pixel of the half size target

View File

@@ -1,3 +1,5 @@
#version 460 core
#define STAGE_COMPUTE 1
// ground truth ambient occlusion (Jimenez et al. 2016, "Practical realtime strategies for accurate indirect occlusion";
// integration as in Intel XeGTAO) at half the resolution of the image. for every pixel, a few slices through the
// hemisphere around the view direction; in each the horizons on both sides are searched in the depth buffer and the

View File

@@ -1,15 +1,16 @@
#include <common>
#version 460 core
#define STAGE_FRAGMENT 1
#include "common.glsl"
layout(location = 0) out vec4 out_color;
#if MOTIONBLUR_ENABLED
layout(location = 1) out vec4 out_motion;
#endif
void main()
{
out_color = vec4(vec3(0.0f), 1.0f);
#if MOTIONBLUR_ENABLED
out_motion = vec4(0.0f);
#endif
if (MOTIONBLUR_ENABLED)
{
out_motion = vec4(0.0f);
}
gl_FragDepth = 1.0f;
}

View File

@@ -1,3 +1,5 @@
#version 460 core
#define STAGE_VERTEX 1
layout(location = 0) in vec3 v_vert;
void main()

View File

@@ -1,10 +1,12 @@
#version 460 core
#define STAGE_COMPUTE 1
// one level of the depth pyramid of the occlusion test of the instances (opengl46_hiz): each texel holds the farthest
// depth of the texels of the level below it which it covers. the depth is reversed (1 near, 0 far), so the farthest is
// the smallest. the first level is made from the resolved depth of the scene, the others from the level below.
// a level halves the one below, rounding down; when that one has an odd size, the last row and column of the new level
// take its last row and column as well, so that nothing is left out
#include <common>
#include "common.glsl"
layout(local_size_x = HIZ_GROUP_SIZE, local_size_y = HIZ_GROUP_SIZE) in;

View File

@@ -1,3 +1,5 @@
#version 460 core
#define STAGE_COMPUTE 1
// culls the model instances of the buckets queued in a render pass and assigns them their lod bands, with the tests
// opengl46_renderer::Render_Instanced() makes on the cpu. one invocation per record of a queued bucket. the sleepers of the
// tracks queued come as buckets too, with the tests of opengl46_renderer::Render_Sleepers().
@@ -12,7 +14,7 @@
// pyramid is hidden behind the second one as well (it only holds nearer depth), so each instance is drawn at most once,
// and everything left out is hidden behind something drawn
#include <common>
#include "common.glsl"
layout(local_size_x = INSTANCE_CULL_GROUP_SIZE) in;

View File

@@ -1,3 +1,5 @@
#version 460 core
#define STAGE_COMPUTE 1
// fills in the instances of the indirect draw commands of the entries, after instance_cull.comp wrote the modelview
// matrices of the instances drawn. one invocation per command. the commands are kept three times over: the first copy
// draws the instances of stage 1, the second all of them, the third those of stage 2 (two phases), each from its first
@@ -5,7 +7,7 @@
// cursor of its entry, the base instance the first slot of the entry. stage 1 (after stage 2): the other two copies take
// the command of the first one, the second with the instances of both stages, the third with the ones past the first copy
#include <common>
#include "common.glsl"
layout(local_size_x = INSTANCE_COMMAND_GROUP_SIZE) in;

View File

@@ -1,9 +1,11 @@
#version 460 core
#define STAGE_COMPUTE 1
// turns the counts of instances of the entries, written by stage 0 of instance_cull.comp, into the first slots of the
// entries in the output (cursors, which stages 1 and 2 advance as they write, and the same first slots kept for
// instance_cull_commands.comp), and puts the total in the header.
// a single work group: each invocation sums a run of the entries, then the sums are scanned in shared memory
#include <common>
#include "common.glsl"
layout(local_size_x = INSTANCE_OFFSETS_GROUP_SIZE) in;

File diff suppressed because it is too large Load Diff

View File

@@ -1,4 +1,6 @@
#include <common>
#version 460 core
#define STAGE_FRAGMENT 1
#include "common.glsl"
layout(location = 0) out vec4 out_color;

View File

@@ -1,9 +1,11 @@
#version 460 core
#define STAGE_VERTEX 1
layout(location = 0) in vec3 v_vert;
layout(location = 2) in vec2 v_coords;
out vec2 g_coords;
layout(location = 19) out vec2 g_coords;
#include <common>
#include "common.glsl"
void main()
{

View File

@@ -0,0 +1,16 @@
#version 460 core
#define STAGE_FRAGMENT 1
layout(location = 14) in vec2 f_coords;
layout(location = 0) out vec4 out_color;
#pragma texture(tex1, 0, sRGB_A)
layout(binding = 0) uniform sampler2D tex1;
void main()
{
vec2 texcoord = f_coords;
vec4 color = texture(tex1, texcoord);
out_color = color;
}

View File

@@ -1,10 +1,12 @@
#version 460 core
#define STAGE_GEOMETRY 1
layout (points) in;
layout (triangle_strip, max_vertices = 4) out;
in vec2 g_coords[];
out vec2 f_coords;
layout(location = 19) in vec2 g_coords[];
layout(location = 14) out vec2 f_coords;
#include <common>
#include "common.glsl"
void main() {
vec4 position = gl_in[0].gl_Position;

View File

@@ -1,24 +1,24 @@
in vec3 f_normal;
in vec2 f_coord;
in vec4 f_pos;
#version 460 core
#define STAGE_FRAGMENT 1
layout(location = 0) in vec3 f_normal;
layout(location = 2) in vec2 f_coord;
layout(location = 3) in vec4 f_pos;
in vec4 f_clip_pos;
in vec4 f_clip_future_pos;
layout(location = 4) in vec4 f_clip_pos;
layout(location = 5) in vec4 f_clip_future_pos;
#include <common>
#include "common.glsl"
#param (diffuse, 1, 0, 1, diffuse)
#pragma param(diffuse, 1, 0, 1, diffuse)
#texture (diffuse, 0, sRGB_A)
uniform sampler2D diffuse;
#pragma texture(diffuse, 0, sRGB_A)
layout(binding = 0) uniform sampler2D diffuse;
layout(location = 0) out vec4 out_color;
#if MOTIONBLUR_ENABLED
layout(location = 1) out vec4 out_motion;
#endif
#include <apply_fog.glsl>
#include <tonemapping.glsl>
#include "apply_fog.glsl"
#include "tonemapping.glsl"
vec3 apply_lights_clouds(vec3 fragcolor, vec3 fragnormal, vec3 texturecolor)
{
@@ -49,13 +49,17 @@ void main()
fragcolor = apply_lights_clouds(fragcolor, fragnormal, tex_color.rgb);
vec4 color = vec4(apply_fog(fragcolor), tex_color.a);
#if POSTFX_ENABLED
out_color = color;
#else
out_color = tonemap(color);
#endif
if (POSTFX_ENABLED)
{
out_color = color;
}
else
{
out_color = tonemap(color);
}
#if MOTIONBLUR_ENABLED
out_motion = vec4(0.0f);
#endif
if (MOTIONBLUR_ENABLED)
{
out_motion = vec4(0.0f);
}
}

View File

@@ -0,0 +1,3 @@
#version 460 core
#define STAGE_FRAGMENT 1
#include "mat_colored.glsl"

View File

@@ -1,26 +1,24 @@
in vec3 f_normal;
in vec2 f_coord;
in vec4 f_pos;
layout(location = 0) in vec3 f_normal;
layout(location = 2) in vec2 f_coord;
layout(location = 3) in vec4 f_pos;
in vec4 f_clip_pos;
in vec4 f_clip_future_pos;
layout(location = 4) in vec4 f_clip_pos;
layout(location = 5) in vec4 f_clip_future_pos;
#include <common>
#include "common.glsl"
#param (color, 0, 0, 4, diffuse)
#param (diffuse, 1, 0, 1, diffuse)
#param (specular, 1, 1, 1, specular)
#param (reflection, 1, 2, 1, zero)
#param (glossiness, 1, 3, 1, glossiness)
#pragma param(color, 0, 0, 4, diffuse)
#pragma param(diffuse, 1, 0, 1, diffuse)
#pragma param(specular, 1, 1, 1, specular)
#pragma param(reflection, 1, 2, 1, zero)
#pragma param(glossiness, 1, 3, 1, glossiness)
layout(location = 0) out vec4 out_color;
#if MOTIONBLUR_ENABLED
layout(location = 1) out vec4 out_motion;
#endif
#include <light_common.glsl>
#include <apply_fog.glsl>
#include <tonemapping.glsl>
#include "light_common.glsl"
#include "apply_fog.glsl"
#include "tonemapping.glsl"
void main()
{
@@ -39,17 +37,19 @@ void main()
fragcolor = apply_lights(fragcolor, fragnormal, tex_color.rgb, reflectivity, specularity, shadow_tone);
vec4 color = vec4(apply_fog(fragcolor), tex_color.a * alpha_mult);
#if POSTFX_ENABLED
out_color = color;
#else
out_color = tonemap(color);
#endif
#if MOTIONBLUR_ENABLED
if (POSTFX_ENABLED)
{
out_color = color;
}
else
{
out_color = tonemap(color);
}
if (MOTIONBLUR_ENABLED)
{
vec2 a = (f_clip_future_pos.xy / f_clip_future_pos.w) * 0.5 + 0.5;;
vec2 b = (f_clip_pos.xy / f_clip_pos.w) * 0.5 + 0.5;;
out_motion = vec4(a - b, 0.0f, 0.0f);
}
#endif
}

View File

@@ -0,0 +1,3 @@
#version 460 core
#define STAGE_FRAGMENT 1
#include "mat_default.glsl"

View File

@@ -1,29 +1,27 @@
in vec3 f_normal;
in vec2 f_coord;
in vec4 f_pos;
layout(location = 0) in vec3 f_normal;
layout(location = 2) in vec2 f_coord;
layout(location = 3) in vec4 f_pos;
in vec4 f_clip_pos;
in vec4 f_clip_future_pos;
layout(location = 4) in vec4 f_clip_pos;
layout(location = 5) in vec4 f_clip_future_pos;
#include <common>
#include "common.glsl"
#param (color, 0, 0, 4, diffuse)
#param (diffuse, 1, 0, 1, diffuse)
#param (specular, 1, 1, 1, specular)
#param (reflection, 1, 2, 1, zero)
#param (glossiness, 1, 3, 1, glossiness)
#pragma param(color, 0, 0, 4, diffuse)
#pragma param(diffuse, 1, 0, 1, diffuse)
#pragma param(specular, 1, 1, 1, specular)
#pragma param(reflection, 1, 2, 1, zero)
#pragma param(glossiness, 1, 3, 1, glossiness)
#texture (diffuse, 0, sRGB_A)
uniform sampler2D diffuse;
#pragma texture(diffuse, 0, sRGB_A)
layout(binding = 0) uniform sampler2D diffuse;
layout(location = 0) out vec4 out_color;
#if MOTIONBLUR_ENABLED
layout(location = 1) out vec4 out_motion;
#endif
#include <light_common.glsl>
#include <apply_fog.glsl>
#include <tonemapping.glsl>
#include "light_common.glsl"
#include "apply_fog.glsl"
#include "tonemapping.glsl"
void main()
{
@@ -47,18 +45,20 @@ void main()
else if( distance <= cascade_end.y ) { color.g += 0.25; }
else if( distance <= cascade_end.z ) { color.b += 0.25; }
*/
#if POSTFX_ENABLED
out_color = color;
#else
out_color = tonemap(color);
#endif
if (POSTFX_ENABLED)
{
out_color = color;
}
else
{
out_color = tonemap(color);
}
#if MOTIONBLUR_ENABLED
if (MOTIONBLUR_ENABLED)
{
vec2 a = (f_clip_future_pos.xy / f_clip_future_pos.w) * 0.5 + 0.5;;
vec2 b = (f_clip_pos.xy / f_clip_pos.w) * 0.5 + 0.5;;
out_motion = vec4(a - b, 0.0f, tex_color.a * alpha_mult);
}
#endif
}

View File

@@ -0,0 +1,3 @@
#version 460 core
#define STAGE_FRAGMENT 1
#include "mat_colored.glsl"

View File

@@ -0,0 +1,3 @@
#version 460 core
#define STAGE_FRAGMENT 1
#include "mat_default.glsl"

View File

@@ -0,0 +1,3 @@
#version 460 core
#define STAGE_FRAGMENT 1
#include "mat_reflmap.glsl"

View File

@@ -1,35 +1,35 @@
in vec3 f_normal;
in vec2 f_coord;
in vec4 f_pos;
in mat3 f_tbn;
#version 460 core
#define STAGE_FRAGMENT 1
layout(location = 0) in vec3 f_normal;
layout(location = 2) in vec2 f_coord;
layout(location = 3) in vec4 f_pos;
layout(location = 8) in mat3 f_tbn;
in vec4 f_clip_pos;
in vec4 f_clip_future_pos;
layout(location = 4) in vec4 f_clip_pos;
layout(location = 5) in vec4 f_clip_future_pos;
#include <common>
#include "common.glsl"
#param (color, 0, 0, 4, diffuse)
#param (diffuse, 1, 0, 1, diffuse)
#param (specular, 1, 1, 1, specular)
#param (reflection, 1, 2, 1, zero)
#param (glossiness, 1, 3, 1, glossiness)
#param (detail_scale, 2, 0, 1, one)
#pragma param(color, 0, 0, 4, diffuse)
#pragma param(diffuse, 1, 0, 1, diffuse)
#pragma param(specular, 1, 1, 1, specular)
#pragma param(reflection, 1, 2, 1, zero)
#pragma param(glossiness, 1, 3, 1, glossiness)
#pragma param(detail_scale, 2, 0, 1, one)
#texture (diffuse, 0, sRGB_A)
uniform sampler2D diffuse;
#pragma texture(diffuse, 0, sRGB_A)
layout(binding = 0) uniform sampler2D diffuse;
layout(location = 0) out vec4 out_color;
#if MOTIONBLUR_ENABLED
layout(location = 1) out vec4 out_motion;
#endif
#texture (detailnormalmap, 1, RGBA)
uniform sampler2D detailnormalmap;
#pragma texture(detailnormalmap, 1, RGBA)
layout(binding = 1) uniform sampler2D detailnormalmap;
#define NORMALMAP
#include <light_common.glsl>
#include <apply_fog.glsl>
#include <tonemapping.glsl>
#include "light_common.glsl"
#include "apply_fog.glsl"
#include "tonemapping.glsl"
void main()
{
@@ -53,18 +53,20 @@ void main()
fragcolor = apply_lights(fragcolor, fragnormal, tex_color.rgb, reflectivity, specularity, shadow_tone);
vec4 color = vec4(apply_fog(fragcolor), tex_color.a * alpha_mult);
#if POSTFX_ENABLED
out_color = color;
#else
out_color = tonemap(color);
#endif
if (POSTFX_ENABLED)
{
out_color = color;
}
else
{
out_color = tonemap(color);
}
#if MOTIONBLUR_ENABLED
if (MOTIONBLUR_ENABLED)
{
vec2 a = (f_clip_future_pos.xy / f_clip_future_pos.w) * 0.5 + 0.5;;
vec2 b = (f_clip_pos.xy / f_clip_pos.w) * 0.5 + 0.5;;
out_motion = vec4(a - b, 0.0f, tex_color.a * alpha_mult);
}
#endif
}

View File

@@ -1,32 +1,32 @@
in vec3 f_normal;
in vec2 f_coord;
in vec4 f_pos;
#version 460 core
#define STAGE_FRAGMENT 1
layout(location = 0) in vec3 f_normal;
layout(location = 2) in vec2 f_coord;
layout(location = 3) in vec4 f_pos;
in vec4 f_clip_pos;
in vec4 f_clip_future_pos;
layout(location = 4) in vec4 f_clip_pos;
layout(location = 5) in vec4 f_clip_future_pos;
#include <common>
#include "common.glsl"
#param (color, 0, 0, 4, diffuse)
#param (diffuse, 1, 0, 1, diffuse)
#param (specular, 1, 1, 1, specular)
#param (reflection, 1, 2, 1, zero)
#param (glossiness, 1, 3, 1, glossiness)
#pragma param(color, 0, 0, 4, diffuse)
#pragma param(diffuse, 1, 0, 1, diffuse)
#pragma param(specular, 1, 1, 1, specular)
#pragma param(reflection, 1, 2, 1, zero)
#pragma param(glossiness, 1, 3, 1, glossiness)
#texture (diffuse, 0, sRGB_A)
uniform sampler2D diffuse;
#pragma texture(diffuse, 0, sRGB_A)
layout(binding = 0) uniform sampler2D diffuse;
#texture (specgloss, 1, RGBA)
uniform sampler2D specgloss;
#pragma texture(specgloss, 1, RGBA)
layout(binding = 1) uniform sampler2D specgloss;
layout(location = 0) out vec4 out_color;
#if MOTIONBLUR_ENABLED
layout(location = 1) out vec4 out_motion;
#endif
#include <light_common.glsl>
#include <apply_fog.glsl>
#include <tonemapping.glsl>
#include "light_common.glsl"
#include "apply_fog.glsl"
#include "tonemapping.glsl"
void main()
{
@@ -53,18 +53,20 @@ void main()
else if( distance <= cascade_end.y ) { color.g += 0.25; }
else if( distance <= cascade_end.z ) { color.b += 0.25; }
*/
#if POSTFX_ENABLED
out_color = color;
#else
out_color = tonemap(color);
#endif
if (POSTFX_ENABLED)
{
out_color = color;
}
else
{
out_color = tonemap(color);
}
#if MOTIONBLUR_ENABLED
if (MOTIONBLUR_ENABLED)
{
vec2 a = (f_clip_future_pos.xy / f_clip_future_pos.w) * 0.5 + 0.5;;
vec2 b = (f_clip_pos.xy / f_clip_pos.w) * 0.5 + 0.5;;
out_motion = vec4(a - b, 0.0f, tex_color.a * alpha_mult);
}
#endif
}

View File

@@ -1,82 +1,84 @@
in vec3 f_normal;
in vec2 f_coord;
in vec4 f_pos;
in mat3 f_tbn;
in vec4 f_clip_pos;
in vec4 f_clip_future_pos;
#include <common>
layout(location = 0) out vec4 out_color;
#if MOTIONBLUR_ENABLED
layout(location = 1) out vec4 out_motion;
#endif
#param (color, 0, 0, 4, diffuse)
#param (diffuse, 1, 0, 1, diffuse)
#param (specular, 1, 1, 1, specular)
#param (reflection, 1, 2, 1, one)
#param (glossiness, 1, 3, 1, glossiness)
#param (detail_scale, 2, 0, 1, one)
#param (detail_height_scale, 2, 1, 1, one)
#texture (diffuse, 0, sRGB_A)
uniform sampler2D diffuse;
#texture (normalmap, 1, RGBA)
uniform sampler2D normalmap;
#texture (detailnormalmap, 2, RGBA)
uniform sampler2D detailnormalmap;
#define NORMALMAP
#include <light_common.glsl>
#include <apply_fog.glsl>
#include <tonemapping.glsl>
void main()
{
vec4 tex_color = texture(diffuse, f_coord);
bool alphatestfail = ( opacity >= 0.0 ? (tex_color.a < opacity) : (tex_color.a >= -opacity) );
if(alphatestfail)
discard;
vec3 fragcolor = ambient;
vec4 normal_map = texture(normalmap, f_coord);
vec4 detailnormal_map = texture(detailnormalmap, f_coord * param[2].x);
vec3 normal;
vec3 normaldetail;
normaldetail.xy = detailnormal_map.rg* 2.0 - 1.0;
normaldetail.z = sqrt(1.0 - clamp((dot(normaldetail.xy, normaldetail.xy)), 0.0, 1.0));
normaldetail.xyz = normaldetail.xyz * param[2].y;
normal.xy = normal_map.rg* 2.0 - 1.0;
normal.z = sqrt(1.0 - clamp((dot(normal.xy, normal.xy)), 0.0, 1.0));
vec3 fragnormal = normalize(f_tbn * normalize(vec3(normal.xy + normaldetail.xy, normal.z)));
float reflblend = (normal_map.a + detailnormal_map.a);
float reflectivity = reflblend > 1.0 ? param[1].z * 1.0 : param[1].z * reflblend;
float specularity = (tex_color.r + tex_color.g + tex_color.b) * 0.5;
legacy_gloss();
fragcolor = apply_lights(fragcolor, fragnormal, tex_color.rgb, reflectivity, specularity, shadow_tone);
vec4 color = vec4(apply_fog(fragcolor), tex_color.a * alpha_mult);
#if POSTFX_ENABLED
out_color = color;
#else
out_color = tonemap(color);
#endif
#if MOTIONBLUR_ENABLED
{
vec2 a = (f_clip_future_pos.xy / f_clip_future_pos.w) * 0.5 + 0.5;;
vec2 b = (f_clip_pos.xy / f_clip_pos.w) * 0.5 + 0.5;;
out_motion = vec4(a - b, 0.0f, 0.0f);
}
#endif
}
#version 460 core
#define STAGE_FRAGMENT 1
layout(location = 0) in vec3 f_normal;
layout(location = 2) in vec2 f_coord;
layout(location = 3) in vec4 f_pos;
layout(location = 8) in mat3 f_tbn;
layout(location = 4) in vec4 f_clip_pos;
layout(location = 5) in vec4 f_clip_future_pos;
#include "common.glsl"
layout(location = 0) out vec4 out_color;
layout(location = 1) out vec4 out_motion;
#pragma param(color, 0, 0, 4, diffuse)
#pragma param(diffuse, 1, 0, 1, diffuse)
#pragma param(specular, 1, 1, 1, specular)
#pragma param(reflection, 1, 2, 1, one)
#pragma param(glossiness, 1, 3, 1, glossiness)
#pragma param(detail_scale, 2, 0, 1, one)
#pragma param(detail_height_scale, 2, 1, 1, one)
#pragma texture(diffuse, 0, sRGB_A)
layout(binding = 0) uniform sampler2D diffuse;
#pragma texture(normalmap, 1, RGBA)
layout(binding = 1) uniform sampler2D normalmap;
#pragma texture(detailnormalmap, 2, RGBA)
layout(binding = 2) uniform sampler2D detailnormalmap;
#define NORMALMAP
#include "light_common.glsl"
#include "apply_fog.glsl"
#include "tonemapping.glsl"
void main()
{
vec4 tex_color = texture(diffuse, f_coord);
bool alphatestfail = ( opacity >= 0.0 ? (tex_color.a < opacity) : (tex_color.a >= -opacity) );
if(alphatestfail)
discard;
vec3 fragcolor = ambient;
vec4 normal_map = texture(normalmap, f_coord);
vec4 detailnormal_map = texture(detailnormalmap, f_coord * param[2].x);
vec3 normal;
vec3 normaldetail;
normaldetail.xy = detailnormal_map.rg* 2.0 - 1.0;
normaldetail.z = sqrt(1.0 - clamp((dot(normaldetail.xy, normaldetail.xy)), 0.0, 1.0));
normaldetail.xyz = normaldetail.xyz * param[2].y;
normal.xy = normal_map.rg* 2.0 - 1.0;
normal.z = sqrt(1.0 - clamp((dot(normal.xy, normal.xy)), 0.0, 1.0));
vec3 fragnormal = normalize(f_tbn * normalize(vec3(normal.xy + normaldetail.xy, normal.z)));
float reflblend = (normal_map.a + detailnormal_map.a);
float reflectivity = reflblend > 1.0 ? param[1].z * 1.0 : param[1].z * reflblend;
float specularity = (tex_color.r + tex_color.g + tex_color.b) * 0.5;
legacy_gloss();
fragcolor = apply_lights(fragcolor, fragnormal, tex_color.rgb, reflectivity, specularity, shadow_tone);
vec4 color = vec4(apply_fog(fragcolor), tex_color.a * alpha_mult);
if (POSTFX_ENABLED)
{
out_color = color;
}
else
{
out_color = tonemap(color);
}
if (MOTIONBLUR_ENABLED)
{
vec2 a = (f_clip_future_pos.xy / f_clip_future_pos.w) * 0.5 + 0.5;;
vec2 b = (f_clip_pos.xy / f_clip_pos.w) * 0.5 + 0.5;;
out_motion = vec4(a - b, 0.0f, 0.0f);
}
}

View File

@@ -1,89 +1,91 @@
in vec3 f_normal;
in vec2 f_coord;
in vec4 f_pos;
in mat3 f_tbn;
in vec4 f_clip_pos;
in vec4 f_clip_future_pos;
#include <common>
layout(location = 0) out vec4 out_color;
#if MOTIONBLUR_ENABLED
layout(location = 1) out vec4 out_motion;
#endif
#param (color, 0, 0, 4, diffuse)
#param (diffuse, 1, 0, 1, diffuse)
#param (specular, 1, 1, 1, specular)
#param (reflection, 1, 2, 1, one)
#param (glossiness, 1, 3, 1, glossiness)
#param (detail_scale, 2, 0, 1, one)
#param (detail_height_scale, 2, 1, 1, one)
#texture (diffuse, 0, sRGB_A)
uniform sampler2D diffuse;
#texture (normalmap, 1, RGBA)
uniform sampler2D normalmap;
#texture (detailnormalmap, 2, RGBA)
uniform sampler2D detailnormalmap;
#texture (specgloss, 3, RGBA)
uniform sampler2D specgloss;
#define NORMALMAP
#include <light_common.glsl>
#include <apply_fog.glsl>
#include <tonemapping.glsl>
void main()
{
vec4 tex_color = texture(diffuse, f_coord);
bool alphatestfail = ( opacity >= 0.0 ? (tex_color.a < opacity) : (tex_color.a >= -opacity) );
if(alphatestfail)
discard;
// if (tex_color.a < opacity)
// discard;
vec3 fragcolor = ambient;
vec4 normal_map = texture(normalmap, f_coord);
vec4 detailnormal_map = texture(detailnormalmap, f_coord * param[2].x);
vec4 specgloss_map = texture(specgloss, f_coord);
vec3 normal;
vec3 normaldetail;
normaldetail.xy = detailnormal_map.rg* 2.0 - 1.0;
normaldetail.z = sqrt(1.0 - clamp((dot(normaldetail.xy, normaldetail.xy)), 0.0, 1.0));
normaldetail.xyz = normaldetail.xyz * param[2].y;
normal.xy = normal_map.rg* 2.0 - 1.0;
normal.z = sqrt(1.0 - clamp((dot(normal.xy, normal.xy)), 0.0, 1.0));
vec3 fragnormal = normalize(f_tbn * normalize(vec3(normal.xy + normaldetail.xy, normal.z)));
float reflblend = (normal_map.a + detailnormal_map.a);
float reflectivity = reflblend > 1.0 ? param[1].z * 1.0 : param[1].z * reflblend;
float specularity = specgloss_map.r;
glossiness = specgloss_map.g * abs(param[1].w);
metalic = specgloss_map.b;
fragcolor = apply_lights(fragcolor, fragnormal, tex_color.rgb, reflectivity, specularity, shadow_tone);
vec4 color = vec4(apply_fog(fragcolor), tex_color.a * alpha_mult);
#if POSTFX_ENABLED
out_color = color;
#else
out_color = tonemap(color);
#endif
#if MOTIONBLUR_ENABLED
{
vec2 a = (f_clip_future_pos.xy / f_clip_future_pos.w) * 0.5 + 0.5;;
vec2 b = (f_clip_pos.xy / f_clip_pos.w) * 0.5 + 0.5;;
out_motion = vec4(a - b, 0.0f, 0.0f);
}
#endif
}
#version 460 core
#define STAGE_FRAGMENT 1
layout(location = 0) in vec3 f_normal;
layout(location = 2) in vec2 f_coord;
layout(location = 3) in vec4 f_pos;
layout(location = 8) in mat3 f_tbn;
layout(location = 4) in vec4 f_clip_pos;
layout(location = 5) in vec4 f_clip_future_pos;
#include "common.glsl"
layout(location = 0) out vec4 out_color;
layout(location = 1) out vec4 out_motion;
#pragma param(color, 0, 0, 4, diffuse)
#pragma param(diffuse, 1, 0, 1, diffuse)
#pragma param(specular, 1, 1, 1, specular)
#pragma param(reflection, 1, 2, 1, one)
#pragma param(glossiness, 1, 3, 1, glossiness)
#pragma param(detail_scale, 2, 0, 1, one)
#pragma param(detail_height_scale, 2, 1, 1, one)
#pragma texture(diffuse, 0, sRGB_A)
layout(binding = 0) uniform sampler2D diffuse;
#pragma texture(normalmap, 1, RGBA)
layout(binding = 1) uniform sampler2D normalmap;
#pragma texture(detailnormalmap, 2, RGBA)
layout(binding = 2) uniform sampler2D detailnormalmap;
#pragma texture(specgloss, 3, RGBA)
layout(binding = 3) uniform sampler2D specgloss;
#define NORMALMAP
#include "light_common.glsl"
#include "apply_fog.glsl"
#include "tonemapping.glsl"
void main()
{
vec4 tex_color = texture(diffuse, f_coord);
bool alphatestfail = ( opacity >= 0.0 ? (tex_color.a < opacity) : (tex_color.a >= -opacity) );
if(alphatestfail)
discard;
// if (tex_color.a < opacity)
// discard;
vec3 fragcolor = ambient;
vec4 normal_map = texture(normalmap, f_coord);
vec4 detailnormal_map = texture(detailnormalmap, f_coord * param[2].x);
vec4 specgloss_map = texture(specgloss, f_coord);
vec3 normal;
vec3 normaldetail;
normaldetail.xy = detailnormal_map.rg* 2.0 - 1.0;
normaldetail.z = sqrt(1.0 - clamp((dot(normaldetail.xy, normaldetail.xy)), 0.0, 1.0));
normaldetail.xyz = normaldetail.xyz * param[2].y;
normal.xy = normal_map.rg* 2.0 - 1.0;
normal.z = sqrt(1.0 - clamp((dot(normal.xy, normal.xy)), 0.0, 1.0));
vec3 fragnormal = normalize(f_tbn * normalize(vec3(normal.xy + normaldetail.xy, normal.z)));
float reflblend = (normal_map.a + detailnormal_map.a);
float reflectivity = reflblend > 1.0 ? param[1].z * 1.0 : param[1].z * reflblend;
float specularity = specgloss_map.r;
glossiness = specgloss_map.g * abs(param[1].w);
metalic = specgloss_map.b;
fragcolor = apply_lights(fragcolor, fragnormal, tex_color.rgb, reflectivity, specularity, shadow_tone);
vec4 color = vec4(apply_fog(fragcolor), tex_color.a * alpha_mult);
if (POSTFX_ENABLED)
{
out_color = color;
}
else
{
out_color = tonemap(color);
}
if (MOTIONBLUR_ENABLED)
{
vec2 a = (f_clip_future_pos.xy / f_clip_future_pos.w) * 0.5 + 0.5;;
vec2 b = (f_clip_pos.xy / f_clip_pos.w) * 0.5 + 0.5;;
out_motion = vec4(a - b, 0.0f, 0.0f);
}
}

View File

@@ -0,0 +1,147 @@
#version 460 core
#define STAGE_FRAGMENT 1
layout(location = 0) in vec3 f_normal;
layout(location = 2) in vec2 f_coord;
layout(location = 3) in vec4 f_pos;
layout(location = 8) in mat3 f_tbn; //tangent matrix nietransponowany; mnożyć przez f_tbn dla TangentLightPos; TangentViewPos; TangentFragPos;
layout(location = 4) in vec4 f_clip_pos;
layout(location = 5) in vec4 f_clip_future_pos;
layout(location = 6) in vec3 TangentFragPos;
#include "common.glsl"
layout(location = 0) out vec4 out_color;
layout(location = 1) out vec4 out_motion;
#pragma param(color, 0, 0, 4, diffuse)
#pragma param(diffuse, 1, 0, 1, diffuse)
#pragma param(specular, 1, 1, 1, specular)
#pragma param(reflection, 1, 2, 1, one)
#pragma param(glossiness, 1, 3, 1, glossiness)
#pragma param(detail_scale, 2, 0, 1, one)
#pragma param(detail_height_scale, 2, 1, 1, one)
#pragma param(height_scale, 2, 2, 1, zero)
#pragma param(height_offset, 2, 3, 1, zero)
#pragma texture(diffuse, 0, sRGB_A)
layout(binding = 0) uniform sampler2D diffuse;
#pragma texture(normalmap, 1, RGBA)
layout(binding = 1) uniform sampler2D normalmap;
#pragma texture(detailnormalmap, 2, RGBA)
layout(binding = 2) uniform sampler2D detailnormalmap;
#define PARALLAX
// param[2].w is the height offset, not the weathering
#define NO_WEATHERING
#include "light_common.glsl"
#include "apply_fog.glsl"
#include "tonemapping.glsl"
vec2 ParallaxMapping(vec2 f_coord, vec3 viewDir);
void main()
{
//parallax mapping
vec3 viewDir = normalize(-TangentFragPos); //tangent view pos - tangent frag pos
vec2 f_coord_p = ParallaxMapping(f_coord, viewDir);
vec4 normal_map = texture(normalmap, f_coord_p);
vec4 detailnormal_map = texture(detailnormalmap, f_coord_p * param[2].x);
vec4 tex_color = texture(diffuse, f_coord_p);
bool alphatestfail = ( opacity >= 0.0 ? (tex_color.a < opacity) : (tex_color.a >= -opacity) );
if(alphatestfail)
discard;
// if (tex_color.a < opacity)
// discard;
vec3 fragcolor = ambient;
vec3 normal;
vec3 normaldetail;
normaldetail.xy = detailnormal_map.rg* 2.0 - 1.0;
normaldetail.z = sqrt(1.0 - clamp((dot(normaldetail.xy, normaldetail.xy)), 0.0, 1.0));
normaldetail.xyz = normaldetail.xyz * param[2].y;
normal.xy = normal_map.rg* 2.0 - 1.0;
normal.z = sqrt(1.0 - clamp((dot(normal.xy, normal.xy)), 0.0, 1.0));
vec3 fragnormal = normalize(f_tbn * normalize(vec3(normal.xy + normaldetail.xy, normal.z)));
float reflectivity = param[1].z * normal_map.a;
float specularity = (tex_color.r + tex_color.g + tex_color.b) * 0.5;
legacy_gloss();
fragcolor = apply_lights(fragcolor, fragnormal, tex_color.rgb, reflectivity, specularity, shadow_tone);
vec4 color = vec4(apply_fog(fragcolor), tex_color.a * alpha_mult);
if (POSTFX_ENABLED)
{
out_color = color;
}
else
{
out_color = tonemap(color);
}
if (MOTIONBLUR_ENABLED)
{
vec2 a = (f_clip_future_pos.xy / f_clip_future_pos.w) * 0.5 + 0.5;;
vec2 b = (f_clip_pos.xy / f_clip_pos.w) * 0.5 + 0.5;;
out_motion = vec4(a - b, 0.0f, 0.0f);
}
}
vec2 ParallaxMapping(vec2 f_coord, vec3 viewDir)
{
float pos_len = length(f_pos.xyz);
// gradients of the coordinates taken here: inside the loop the fragments of a quad don't go the same way
vec2 dcoorddx = dFdx(f_coord);
vec2 dcoorddy = dFdy(f_coord);
if (pos_len > 100.0) {
return f_coord;
}
// the shift fades out before the distance it stops at, so it doesn't switch off at once there
float fade = 1.0 - smoothstep(80.0, 100.0, pos_len);
if (EXTRAEFFECTS_ENABLED)
{
const float minLayers = 8.0;
const float maxLayers = 32.0;
float LayersWeight = pos_len / 20.0;
vec2 currentTexCoords = f_coord;
float currentDepthMapValue = textureGrad(normalmap, currentTexCoords, dcoorddx, dcoorddy).b;
LayersWeight = min(abs(dot(vec3(0.0, 0.0, 1.0), viewDir)),LayersWeight);
float numLayers = mix(maxLayers, minLayers, clamp(LayersWeight, 0.0, 1.0)); // number of depth layers
float layerDepth = 1.0 / numLayers; // calculate the size of each layer
float currentLayerDepth = 0.0; // depth of current layer
vec2 P = viewDir.xy * param[2].z * fade; // the amount to shift the texture coordinates per layer (from vector P)
vec2 deltaTexCoords = P / numLayers;
while(currentLayerDepth < currentDepthMapValue)
{
currentTexCoords -= deltaTexCoords; // shift texture coordinates along direction of P
currentDepthMapValue = textureGrad(normalmap, currentTexCoords, dcoorddx, dcoorddy).b; // get depthmap value at current texture coordinates
currentLayerDepth += layerDepth; // get depth of next layer
}
vec2 prevTexCoords = currentTexCoords + deltaTexCoords; // get texture coordinates before collision (reverse operations)
float afterDepth = currentDepthMapValue - currentLayerDepth; // get depth after and before collision for linear interpolation
float beforeDepth = textureGrad(normalmap, prevTexCoords, dcoorddx, dcoorddy).b - currentLayerDepth + layerDepth;
float weight = afterDepth / (afterDepth - beforeDepth); // interpolation of texture coordinates
vec2 finalTexCoords = prevTexCoords * weight + currentTexCoords * (1.0 - weight);
return finalTexCoords;
}
else
{
float height = texture(normalmap, f_coord).b;
vec2 p = viewDir.xy / viewDir.z * (height * (param[2].z - param[2].w) * 0.2) * fade;
return f_coord - p;
}
}

View File

@@ -0,0 +1,153 @@
#version 460 core
#define STAGE_FRAGMENT 1
layout(location = 0) in vec3 f_normal;
layout(location = 2) in vec2 f_coord;
layout(location = 3) in vec4 f_pos;
layout(location = 8) in mat3 f_tbn; //tangent matrix nietransponowany; mnożyć przez f_tbn dla TangentLightPos; TangentViewPos; TangentFragPos;
layout(location = 4) in vec4 f_clip_pos;
layout(location = 5) in vec4 f_clip_future_pos;
layout(location = 6) in vec3 TangentFragPos;
#include "common.glsl"
layout(location = 0) out vec4 out_color;
layout(location = 1) out vec4 out_motion;
#pragma param(color, 0, 0, 4, diffuse)
#pragma param(diffuse, 1, 0, 1, diffuse)
#pragma param(specular, 1, 1, 1, specular)
#pragma param(reflection, 1, 2, 1, one)
#pragma param(glossiness, 1, 3, 1, glossiness)
#pragma param(detail_scale, 2, 0, 1, one)
#pragma param(detail_height_scale, 2, 1, 1, one)
#pragma param(height_scale, 2, 2, 1, zero)
#pragma param(height_offset, 2, 3, 1, zero)
#pragma texture(diffuse, 0, sRGB_A)
layout(binding = 0) uniform sampler2D diffuse;
#pragma texture(normalmap, 1, RGBA)
layout(binding = 1) uniform sampler2D normalmap;
#pragma texture(specgloss, 2, RGBA)
layout(binding = 2) uniform sampler2D specgloss;
#pragma texture(detailnormalmap, 3, RGBA)
layout(binding = 3) uniform sampler2D detailnormalmap;
#define PARALLAX
// param[2].w is the height offset, not the weathering
#define NO_WEATHERING
#include "light_common.glsl"
#include "apply_fog.glsl"
#include "tonemapping.glsl"
vec2 ParallaxMapping(vec2 f_coord, vec3 viewDir);
void main()
{
//parallax mapping
vec3 viewDir = normalize(vec3(0.0f, 0.0f, 0.0f) - TangentFragPos); //tangent view pos - tangent frag pos
vec2 f_coord_p = ParallaxMapping(f_coord, viewDir);
vec4 normal_map = texture(normalmap, f_coord_p);
vec4 detailnormal_map = texture(detailnormalmap, f_coord_p * param[2].x);
vec4 tex_color = texture(diffuse, f_coord_p);
vec4 specgloss_map = texture(specgloss, f_coord_p);
bool alphatestfail = ( opacity >= 0.0 ? (tex_color.a < opacity) : (tex_color.a >= -opacity) );
if(alphatestfail)
discard;
vec3 fragcolor = ambient;
vec3 normal;
vec3 normaldetail;
normaldetail.xy = detailnormal_map.rg* 2.0 - 1.0;
normaldetail.z = sqrt(1.0 - clamp((dot(normaldetail.xy, normaldetail.xy)), 0.0, 1.0));
normaldetail.xyz = normaldetail.xyz * param[2].y;
normal.xy = normal_map.rg* 2.0 - 1.0;
normal.z = sqrt(1.0 - clamp((dot(normal.xy, normal.xy)), 0.0, 1.0));
vec3 fragnormal = normalize(f_tbn * normalize(vec3(normal.xy + normaldetail.xy, normal.z)));
float reflectivity = param[1].z * normal_map.a;
float specularity = specgloss_map.r;
glossiness = specgloss_map.g * abs(param[1].w);
metalic = specgloss_map.b;
fragcolor = apply_lights(fragcolor, fragnormal, tex_color.rgb, reflectivity, specularity, shadow_tone);
vec4 color = vec4(apply_fog(fragcolor), tex_color.a * alpha_mult);
if (POSTFX_ENABLED)
{
out_color = color;
}
else
{
out_color = tonemap(color);
}
if (MOTIONBLUR_ENABLED)
{
vec2 a = (f_clip_future_pos.xy / f_clip_future_pos.w) * 0.5 + 0.5;;
vec2 b = (f_clip_pos.xy / f_clip_pos.w) * 0.5 + 0.5;;
out_motion = vec4(a - b, 0.0f, 0.0f);
}
}
vec2 ParallaxMapping(vec2 f_coord, vec3 viewDir)
{
float pos_len = length(f_pos.xyz);
// gradients of the coordinates taken here: inside the loop the fragments of a quad don't go the same way
vec2 dcoorddx = dFdx(f_coord);
vec2 dcoorddy = dFdy(f_coord);
if (pos_len > 100.0) {
return f_coord;
}
// the shift fades out before the distance it stops at, so it doesn't switch off at once there
float fade = 1.0 - smoothstep(80.0, 100.0, pos_len);
if (EXTRAEFFECTS_ENABLED)
{
const float minLayers = 8.0;
const float maxLayers = 32.0;
float LayersWeight = pos_len / 20.0;
vec2 currentTexCoords = f_coord;
float currentDepthMapValue = textureGrad(normalmap, currentTexCoords, dcoorddx, dcoorddy).b;
LayersWeight = min(abs(dot(vec3(0.0, 0.0, 1.0), viewDir)),LayersWeight);
float numLayers = mix(maxLayers, minLayers, clamp(LayersWeight, 0.0, 1.0)); // number of depth layers
float layerDepth = 1.0 / numLayers; // calculate the size of each layer
float currentLayerDepth = 0.0; // depth of current layer
vec2 P = viewDir.xy * param[2].z * fade; // the amount to shift the texture coordinates per layer (from vector P)
vec2 deltaTexCoords = P / numLayers;
while(currentLayerDepth < currentDepthMapValue)
{
currentTexCoords -= deltaTexCoords; // shift texture coordinates along direction of P
currentDepthMapValue = textureGrad(normalmap, currentTexCoords, dcoorddx, dcoorddy).b; // get depthmap value at current texture coordinates
currentLayerDepth += layerDepth; // get depth of next layer
}
vec2 prevTexCoords = currentTexCoords + deltaTexCoords; // get texture coordinates before collision (reverse operations)
float afterDepth = currentDepthMapValue - currentLayerDepth; // get depth after and before collision for linear interpolation
float beforeDepth = textureGrad(normalmap, prevTexCoords, dcoorddx, dcoorddy).b - currentLayerDepth + layerDepth;
float weight = afterDepth / (afterDepth - beforeDepth); // interpolation of texture coordinates
vec2 finalTexCoords = prevTexCoords * weight + currentTexCoords * (1.0 - weight);
return finalTexCoords;
}
else
{
float height = texture(normalmap, f_coord).b;
vec2 p = viewDir.xy / viewDir.z * (height * (param[2].z - param[2].w) * 0.2) * fade;
return f_coord - p;
}
}

View File

@@ -0,0 +1,24 @@
#version 460 core
#define STAGE_FRAGMENT 1
#include "common.glsl"
#include "tonemapping.glsl"
layout(location = 0) out vec4 out_color;
layout(location = 1) out vec4 out_motion;
void main()
{
vec4 color = vec4(1.0, 0.0, 1.0, 1.0);
if (POSTFX_ENABLED)
{
out_color = color;
}
else
{
out_color = tonemap(color);
}
if (MOTIONBLUR_ENABLED)
{
out_motion = vec4(0.0f);
}
}

View File

@@ -1,34 +1,34 @@
in vec3 f_normal;
in vec2 f_coord;
in vec4 f_pos;
in mat3 f_tbn;
#version 460 core
#define STAGE_FRAGMENT 1
layout(location = 0) in vec3 f_normal;
layout(location = 2) in vec2 f_coord;
layout(location = 3) in vec4 f_pos;
layout(location = 8) in mat3 f_tbn;
in vec4 f_clip_pos;
in vec4 f_clip_future_pos;
layout(location = 4) in vec4 f_clip_pos;
layout(location = 5) in vec4 f_clip_future_pos;
#include <common>
#include "common.glsl"
layout(location = 0) out vec4 out_color;
#if MOTIONBLUR_ENABLED
layout(location = 1) out vec4 out_motion;
#endif
#param (color, 0, 0, 4, diffuse)
#param (diffuse, 1, 0, 1, diffuse)
#param (specular, 1, 1, 1, specular)
#param (reflection, 1, 2, 1, one)
#param (glossiness, 1, 3, 1, glossiness)
#pragma param(color, 0, 0, 4, diffuse)
#pragma param(diffuse, 1, 0, 1, diffuse)
#pragma param(specular, 1, 1, 1, specular)
#pragma param(reflection, 1, 2, 1, one)
#pragma param(glossiness, 1, 3, 1, glossiness)
#texture (diffuse, 0, sRGB_A)
uniform sampler2D diffuse;
#pragma texture(diffuse, 0, sRGB_A)
layout(binding = 0) uniform sampler2D diffuse;
#texture (normalmap, 1, RGBA)
uniform sampler2D normalmap;
#pragma texture(normalmap, 1, RGBA)
layout(binding = 1) uniform sampler2D normalmap;
#define NORMALMAP
#include <light_common.glsl>
#include <apply_fog.glsl>
#include <tonemapping.glsl>
#include "light_common.glsl"
#include "apply_fog.glsl"
#include "tonemapping.glsl"
void main()
{
@@ -53,17 +53,19 @@ void main()
fragcolor = apply_lights(fragcolor, fragnormal, tex_color.rgb, reflectivity, specularity, shadow_tone);
vec4 color = vec4(apply_fog(fragcolor), tex_color.a * alpha_mult);
#if POSTFX_ENABLED
out_color = color;
#else
out_color = tonemap(color);
#endif
#if MOTIONBLUR_ENABLED
if (POSTFX_ENABLED)
{
out_color = color;
}
else
{
out_color = tonemap(color);
}
if (MOTIONBLUR_ENABLED)
{
vec2 a = (f_clip_future_pos.xy / f_clip_future_pos.w) * 0.5 + 0.5;;
vec2 b = (f_clip_pos.xy / f_clip_pos.w) * 0.5 + 0.5;;
out_motion = vec4(a - b, 0.0f, 0.0f);
}
#endif
}

View File

@@ -1,38 +1,38 @@
in vec3 f_normal;
in vec2 f_coord;
in vec4 f_pos;
in mat3 f_tbn;
#version 460 core
#define STAGE_FRAGMENT 1
layout(location = 0) in vec3 f_normal;
layout(location = 2) in vec2 f_coord;
layout(location = 3) in vec4 f_pos;
layout(location = 8) in mat3 f_tbn;
in vec4 f_clip_pos;
in vec4 f_clip_future_pos;
layout(location = 4) in vec4 f_clip_pos;
layout(location = 5) in vec4 f_clip_future_pos;
#include <common>
#include "common.glsl"
layout(location = 0) out vec4 out_color;
#if MOTIONBLUR_ENABLED
layout(location = 1) out vec4 out_motion;
#endif
#param (color, 0, 0, 4, diffuse)
#param (diffuse, 1, 0, 1, diffuse)
#param (specular, 1, 1, 1, specular)
#param (reflection, 1, 2, 1, one)
#param (glossiness, 1, 3, 1, glossiness)
#pragma param(color, 0, 0, 4, diffuse)
#pragma param(diffuse, 1, 0, 1, diffuse)
#pragma param(specular, 1, 1, 1, specular)
#pragma param(reflection, 1, 2, 1, one)
#pragma param(glossiness, 1, 3, 1, glossiness)
#texture (diffuse, 0, sRGB_A)
uniform sampler2D diffuse;
#pragma texture(diffuse, 0, sRGB_A)
layout(binding = 0) uniform sampler2D diffuse;
#texture (normalmap, 1, RGBA)
uniform sampler2D normalmap;
#pragma texture(normalmap, 1, RGBA)
layout(binding = 1) uniform sampler2D normalmap;
#texture (specgloss, 2, RGBA)
uniform sampler2D specgloss;
#pragma texture(specgloss, 2, RGBA)
layout(binding = 2) uniform sampler2D specgloss;
#define NORMALMAP
#include <light_common.glsl>
#include <apply_fog.glsl>
#include <tonemapping.glsl>
#include "light_common.glsl"
#include "apply_fog.glsl"
#include "tonemapping.glsl"
void main()
{
@@ -58,17 +58,19 @@ void main()
fragcolor = apply_lights(fragcolor, fragnormal, tex_color.rgb, reflectivity, specularity, shadow_tone);
vec4 color = vec4(apply_fog(fragcolor), tex_color.a * alpha_mult);
#if POSTFX_ENABLED
out_color = color;
#else
out_color = tonemap(color);
#endif
#if MOTIONBLUR_ENABLED
if (POSTFX_ENABLED)
{
out_color = color;
}
else
{
out_color = tonemap(color);
}
if (MOTIONBLUR_ENABLED)
{
vec2 a = (f_clip_future_pos.xy / f_clip_future_pos.w) * 0.5 + 0.5;;
vec2 b = (f_clip_pos.xy / f_clip_pos.w) * 0.5 + 0.5;;
out_motion = vec4(a - b, 0.0f, 0.0f);
}
#endif
}

View File

@@ -0,0 +1,132 @@
#version 460 core
#define STAGE_FRAGMENT 1
layout(location = 0) in vec3 f_normal;
layout(location = 2) in vec2 f_coord;
layout(location = 3) in vec4 f_pos;
layout(location = 8) in mat3 f_tbn; //tangent matrix nietransponowany; mnożyć przez f_tbn dla TangentLightPos; TangentViewPos; TangentFragPos;
layout(location = 4) in vec4 f_clip_pos;
layout(location = 5) in vec4 f_clip_future_pos;
layout(location = 6) in vec3 TangentFragPos;
#include "common.glsl"
layout(location = 0) out vec4 out_color;
layout(location = 1) out vec4 out_motion;
#pragma param(color, 0, 0, 4, diffuse)
#pragma param(diffuse, 1, 0, 1, diffuse)
#pragma param(specular, 1, 1, 1, specular)
#pragma param(reflection, 1, 2, 1, one)
#pragma param(glossiness, 1, 3, 1, glossiness)
#pragma param(height_scale, 2, 1, 1, zero)
#pragma param(height_offset, 2, 2, 1, zero)
#pragma texture(diffuse, 0, sRGB_A)
layout(binding = 0) uniform sampler2D diffuse;
#pragma texture(normalmap, 1, RGBA)
layout(binding = 1) uniform sampler2D normalmap;
#define PARALLAX
#include "light_common.glsl"
#include "apply_fog.glsl"
#include "tonemapping.glsl"
vec2 ParallaxMapping(vec2 f_coord, vec3 viewDir);
void main()
{
//parallax mapping
vec3 viewDir = normalize(vec3(0.0f, 0.0f, 0.0f) - TangentFragPos); //tangent view pos - tangent frag pos
vec2 f_coord_p = ParallaxMapping(f_coord, viewDir);
vec4 tex_color = texture(diffuse, f_coord_p);
bool alphatestfail = ( opacity >= 0.0 ? (tex_color.a < opacity) : (tex_color.a >= -opacity) );
if(alphatestfail)
discard;
// if (tex_color.a < opacity)
// discard;
vec3 fragcolor = ambient;
vec3 normal;
normal.xy = (texture(normalmap, f_coord_p).rg * 2.0 - 1.0);
normal.z = sqrt(1.0 - clamp((dot(normal.xy, normal.xy)), 0.0, 1.0));
vec3 fragnormal = normalize(f_tbn * normalize(normal.xyz));
float reflectivity = param[1].z * texture(normalmap, f_coord_p).a;
float specularity = (tex_color.r + tex_color.g + tex_color.b) * 0.5;
legacy_gloss();
fragcolor = apply_lights(fragcolor, fragnormal, tex_color.rgb, reflectivity, specularity, shadow_tone);
vec4 color = vec4(apply_fog(fragcolor), tex_color.a * alpha_mult);
if (POSTFX_ENABLED)
{
out_color = color;
}
else
{
out_color = tonemap(color);
}
if (MOTIONBLUR_ENABLED)
{
vec2 a = (f_clip_future_pos.xy / f_clip_future_pos.w) * 0.5 + 0.5;;
vec2 b = (f_clip_pos.xy / f_clip_pos.w) * 0.5 + 0.5;;
out_motion = vec4(a - b, 0.0f, 0.0f);
}
}
vec2 ParallaxMapping(vec2 f_coord, vec3 viewDir)
{
float pos_len = length(f_pos.xyz);
// gradients of the coordinates taken here: inside the loop the fragments of a quad don't go the same way
vec2 dcoorddx = dFdx(f_coord);
vec2 dcoorddy = dFdy(f_coord);
if (pos_len > 100.0) {
return f_coord;
}
// the shift fades out before the distance it stops at, so it doesn't switch off at once there
float fade = 1.0 - smoothstep(80.0, 100.0, pos_len);
if (EXTRAEFFECTS_ENABLED)
{
const float minLayers = 8.0;
const float maxLayers = 32.0;
float LayersWeight = pos_len / 20.0;
vec2 currentTexCoords = f_coord;
float currentDepthMapValue = textureGrad(normalmap, currentTexCoords, dcoorddx, dcoorddy).b;
LayersWeight = min(abs(dot(vec3(0.0, 0.0, 1.0), viewDir)),LayersWeight);
float numLayers = mix(maxLayers, minLayers, clamp(LayersWeight, 0.0, 1.0)); // number of depth layers
float layerDepth = 1.0 / numLayers; // calculate the size of each layer
float currentLayerDepth = 0.0; // depth of current layer
vec2 P = viewDir.xy * param[2].y * fade; // the amount to shift the texture coordinates per layer (from vector P)
vec2 deltaTexCoords = P / numLayers;
while(currentLayerDepth < currentDepthMapValue)
{
currentTexCoords -= deltaTexCoords; // shift texture coordinates along direction of P
currentDepthMapValue = textureGrad(normalmap, currentTexCoords, dcoorddx, dcoorddy).b; // get depthmap value at current texture coordinates
currentLayerDepth += layerDepth; // get depth of next layer
}
vec2 prevTexCoords = currentTexCoords + deltaTexCoords; // get texture coordinates before collision (reverse operations)
float afterDepth = currentDepthMapValue - currentLayerDepth; // get depth after and before collision for linear interpolation
float beforeDepth = textureGrad(normalmap, prevTexCoords, dcoorddx, dcoorddy).b - currentLayerDepth + layerDepth;
float weight = afterDepth / (afterDepth - beforeDepth); // interpolation of texture coordinates
vec2 finalTexCoords = prevTexCoords * weight + currentTexCoords * (1.0 - weight);
return finalTexCoords;
}
else
{
float height = texture(normalmap, f_coord).b;
vec2 p = viewDir.xy / viewDir.z * (height * (param[2].y - param[2].z) * 0.2) * fade;
return f_coord - p;
}
}

View File

@@ -0,0 +1,137 @@
#version 460 core
#define STAGE_FRAGMENT 1
layout(location = 0) in vec3 f_normal;
layout(location = 2) in vec2 f_coord;
layout(location = 3) in vec4 f_pos;
layout(location = 8) in mat3 f_tbn; //tangent matrix nietransponowany; mnożyć przez f_tbn dla TangentLightPos; TangentViewPos; TangentFragPos;
layout(location = 4) in vec4 f_clip_pos;
layout(location = 5) in vec4 f_clip_future_pos;
layout(location = 6) in vec3 TangentFragPos;
#include "common.glsl"
layout(location = 0) out vec4 out_color;
layout(location = 1) out vec4 out_motion;
#pragma param(color, 0, 0, 4, diffuse)
#pragma param(diffuse, 1, 0, 1, diffuse)
#pragma param(specular, 1, 1, 1, specular)
#pragma param(reflection, 1, 2, 1, one)
#pragma param(glossiness, 1, 3, 1, glossiness)
#pragma param(height_scale, 2, 1, 1, zero)
#pragma param(height_offset, 2, 2, 1, zero)
#pragma texture(diffuse, 0, sRGB_A)
layout(binding = 0) uniform sampler2D diffuse;
#pragma texture(normalmap, 1, RGBA)
layout(binding = 1) uniform sampler2D normalmap;
#pragma texture(specgloss, 2, RGBA)
layout(binding = 2) uniform sampler2D specgloss;
#define PARALLAX
#include "light_common.glsl"
#include "apply_fog.glsl"
#include "tonemapping.glsl"
vec2 ParallaxMapping(vec2 f_coord, vec3 viewDir);
void main()
{
//parallax mapping
vec3 viewDir = normalize(vec3(0.0f, 0.0f, 0.0f) - TangentFragPos); //tangent view pos - tangent frag pos
vec2 f_coord_p = ParallaxMapping(f_coord, viewDir);
vec4 tex_color = texture(diffuse, f_coord_p);
bool alphatestfail = ( opacity >= 0.0 ? (tex_color.a < opacity) : (tex_color.a >= -opacity) );
if(alphatestfail)
discard;
// if (tex_color.a < opacity)
// discard;
vec3 fragcolor = ambient;
vec3 normal;
normal.xy = (texture(normalmap, f_coord_p).rg * 2.0 - 1.0);
normal.z = sqrt(1.0 - clamp((dot(normal.xy, normal.xy)), 0.0, 1.0));
vec3 fragnormal = normalize(f_tbn * normalize(normal.xyz));
float reflectivity = param[1].z * texture(normalmap, f_coord_p).a;
float specularity = texture(specgloss, f_coord_p).r;
glossiness = texture(specgloss, f_coord_p).g * abs(param[1].w);
metalic = texture(specgloss, f_coord_p).b;
fragcolor = apply_lights(fragcolor, fragnormal, tex_color.rgb, reflectivity, specularity, shadow_tone);
vec4 color = vec4(apply_fog(fragcolor), tex_color.a * alpha_mult);
if (POSTFX_ENABLED)
{
out_color = color;
}
else
{
out_color = tonemap(color);
}
if (MOTIONBLUR_ENABLED)
{
vec2 a = (f_clip_future_pos.xy / f_clip_future_pos.w) * 0.5 + 0.5;;
vec2 b = (f_clip_pos.xy / f_clip_pos.w) * 0.5 + 0.5;;
out_motion = vec4(a - b, 0.0f, 0.0f);
}
}
vec2 ParallaxMapping(vec2 f_coord, vec3 viewDir)
{
float pos_len = length(f_pos.xyz);
// gradients of the coordinates taken here: inside the loop the fragments of a quad don't go the same way
vec2 dcoorddx = dFdx(f_coord);
vec2 dcoorddy = dFdy(f_coord);
if (pos_len > 100.0) {
return f_coord;
}
// the shift fades out before the distance it stops at, so it doesn't switch off at once there
float fade = 1.0 - smoothstep(80.0, 100.0, pos_len);
if (EXTRAEFFECTS_ENABLED)
{
const float minLayers = 8.0;
const float maxLayers = 32.0;
float LayersWeight = pos_len / 20.0;
vec2 currentTexCoords = f_coord;
float currentDepthMapValue = textureGrad(normalmap, currentTexCoords, dcoorddx, dcoorddy).b;
LayersWeight = min(abs(dot(vec3(0.0, 0.0, 1.0), viewDir)),LayersWeight);
float numLayers = mix(maxLayers, minLayers, clamp(LayersWeight, 0.0, 1.0)); // number of depth layers
float layerDepth = 1.0 / numLayers; // calculate the size of each layer
float currentLayerDepth = 0.0; // depth of current layer
vec2 P = viewDir.xy * param[2].y * fade; // the amount to shift the texture coordinates per layer (from vector P)
vec2 deltaTexCoords = P / numLayers;
while(currentLayerDepth < currentDepthMapValue)
{
currentTexCoords -= deltaTexCoords; // shift texture coordinates along direction of P
currentDepthMapValue = textureGrad(normalmap, currentTexCoords, dcoorddx, dcoorddy).b; // get depthmap value at current texture coordinates
currentLayerDepth += layerDepth; // get depth of next layer
}
vec2 prevTexCoords = currentTexCoords + deltaTexCoords; // get texture coordinates before collision (reverse operations)
float afterDepth = currentDepthMapValue - currentLayerDepth; // get depth after and before collision for linear interpolation
float beforeDepth = textureGrad(normalmap, prevTexCoords, dcoorddx, dcoorddy).b - currentLayerDepth + layerDepth;
float weight = afterDepth / (afterDepth - beforeDepth); // interpolation of texture coordinates
vec2 finalTexCoords = prevTexCoords * weight + currentTexCoords * (1.0 - weight);
return finalTexCoords;
}
else
{
float height = texture(normalmap, f_coord).b;
vec2 p = viewDir.xy / viewDir.z * (height * (param[2].y - param[2].z) * 0.2) * fade;
return f_coord - p;
}
}

View File

@@ -1,39 +1,39 @@
#version 460 core
#define STAGE_FRAGMENT 1
// Windshield rain effects
// by @lcddisplay; wiper movement @MichauSto
in vec3 f_normal;
in vec2 f_coord;
in vec4 f_pos;
#include <common>
layout(location = 0) in vec3 f_normal;
layout(location = 2) in vec2 f_coord;
layout(location = 3) in vec4 f_pos;
#include "common.glsl"
layout(location = 0) out vec4 out_color;
#if MOTIONBLUR_ENABLED
layout(location = 1) out vec4 out_motion;
#endif
#texture(diffuse, 0, sRGB_A)
#texture(raindropsatlas, 1, sRGB_A)
#texture(wipermask, 2, sRGB_A)
#param (color, 0, 0, 4, diffuse)
#param (diffuse, 1, 0, 1, diffuse)
#param (specular, 1, 1, 1, specular)
#param (reflection, 1, 2, 1, zero)
#param (glossiness, 1, 3, 1, glossiness)
#param (raindrop_grid_size, 2, 0, 1, one)
#pragma texture(diffuse, 0, sRGB_A)
#pragma texture(raindropsatlas, 1, sRGB_A)
#pragma texture(wipermask, 2, sRGB_A)
#pragma param(color, 0, 0, 4, diffuse)
#pragma param(diffuse, 1, 0, 1, diffuse)
#pragma param(specular, 1, 1, 1, specular)
#pragma param(reflection, 1, 2, 1, zero)
#pragma param(glossiness, 1, 3, 1, glossiness)
#pragma param(raindrop_grid_size, 2, 0, 1, one)
#include <light_common.glsl>
#include <apply_fog.glsl>
#include <tonemapping.glsl>
#include <random.glsl>
#include "light_common.glsl"
#include "apply_fog.glsl"
#include "tonemapping.glsl"
#include "random.glsl"
uniform sampler2D diffuse;
uniform sampler2D raindropsatlas;
uniform sampler2D wipermask;
layout(binding = 0) uniform sampler2D diffuse;
layout(binding = 1) uniform sampler2D raindropsatlas;
layout(binding = 2) uniform sampler2D wipermask;
uniform float specular_intensity = 1.0;
uniform float wobble_strength = 0.002;
uniform float wobble_speed = 30.0;
const float specular_intensity = 1.0;
const float wobble_strength = 0.002;
const float wobble_speed = 30.0;
vec4 getDropTex(float choice, vec2 uv) {
vec2 offset;
@@ -167,9 +167,10 @@ void main() {
out_color.a = mix(out_color.a, 1., color.a);
}
#if MOTIONBLUR_ENABLED
out_motion = vec4(0.0);
#endif
if (MOTIONBLUR_ENABLED)
{
out_motion = vec4(0.0);
}
}
float GetMixFactor(in vec2 co, out float side) {

View File

@@ -0,0 +1,3 @@
#version 460 core
#define STAGE_FRAGMENT 1
#include "mat_reflmap.glsl"

View File

@@ -1,32 +1,30 @@
in vec3 f_normal;
in vec2 f_coord;
in vec4 f_pos;
layout(location = 0) in vec3 f_normal;
layout(location = 2) in vec2 f_coord;
layout(location = 3) in vec4 f_pos;
in vec4 f_clip_pos;
in vec4 f_clip_future_pos;
layout(location = 4) in vec4 f_clip_pos;
layout(location = 5) in vec4 f_clip_future_pos;
#include <common>
#include "common.glsl"
layout(location = 0) out vec4 out_color;
#if MOTIONBLUR_ENABLED
layout(location = 1) out vec4 out_motion;
#endif
#param (color, 0, 0, 4, diffuse)
#param (diffuse, 1, 0, 1, diffuse)
#param (specular, 1, 1, 1, specular)
#param (reflection, 1, 2, 1, one)
#param (glossiness, 1, 3, 1, glossiness)
#pragma param(color, 0, 0, 4, diffuse)
#pragma param(diffuse, 1, 0, 1, diffuse)
#pragma param(specular, 1, 1, 1, specular)
#pragma param(reflection, 1, 2, 1, one)
#pragma param(glossiness, 1, 3, 1, glossiness)
#texture (diffuse, 0, sRGB_A)
uniform sampler2D diffuse;
#pragma texture(diffuse, 0, sRGB_A)
layout(binding = 0) uniform sampler2D diffuse;
#texture (reflmap, 1, RGBA)
uniform sampler2D reflmap;
#pragma texture(reflmap, 1, RGBA)
layout(binding = 1) uniform sampler2D reflmap;
#include <light_common.glsl>
#include <apply_fog.glsl>
#include <tonemapping.glsl>
#include "light_common.glsl"
#include "apply_fog.glsl"
#include "tonemapping.glsl"
void main()
{
@@ -51,17 +49,19 @@ void main()
vec4 color = vec4(apply_fog(fragcolor), tex_color.a * alpha_mult);
#if POSTFX_ENABLED
out_color = color;
#else
out_color = tonemap(color);
#endif
#if MOTIONBLUR_ENABLED
if (POSTFX_ENABLED)
{
out_color = color;
}
else
{
out_color = tonemap(color);
}
if (MOTIONBLUR_ENABLED)
{
vec2 a = (f_clip_future_pos.xy / f_clip_future_pos.w) * 0.5 + 0.5;;
vec2 b = (f_clip_pos.xy / f_clip_pos.w) * 0.5 + 0.5;;
out_motion = vec4(a - b, 0.0f, 0.0f);
}
#endif
}

View File

@@ -1,36 +1,36 @@
in vec3 f_normal;
in vec2 f_coord;
in vec4 f_pos;
#version 460 core
#define STAGE_FRAGMENT 1
layout(location = 0) in vec3 f_normal;
layout(location = 2) in vec2 f_coord;
layout(location = 3) in vec4 f_pos;
in vec4 f_clip_pos;
in vec4 f_clip_future_pos;
layout(location = 4) in vec4 f_clip_pos;
layout(location = 5) in vec4 f_clip_future_pos;
#include <common>
#include "common.glsl"
layout(location = 0) out vec4 out_color;
#if MOTIONBLUR_ENABLED
layout(location = 1) out vec4 out_motion;
#endif
#param (color, 0, 0, 4, diffuse)
#param (diffuse, 1, 0, 1, diffuse)
#param (specular, 1, 1, 1, specular)
#param (reflection, 1, 2, 1, one)
#param (glossiness, 1, 3, 1, glossiness)
#pragma param(color, 0, 0, 4, diffuse)
#pragma param(diffuse, 1, 0, 1, diffuse)
#pragma param(specular, 1, 1, 1, specular)
#pragma param(reflection, 1, 2, 1, one)
#pragma param(glossiness, 1, 3, 1, glossiness)
#texture (diffuse, 0, sRGB_A)
uniform sampler2D diffuse;
#pragma texture(diffuse, 0, sRGB_A)
layout(binding = 0) uniform sampler2D diffuse;
#texture (reflmap, 1, RGBA)
uniform sampler2D reflmap;
#pragma texture(reflmap, 1, RGBA)
layout(binding = 1) uniform sampler2D reflmap;
#texture (specgloss, 2, RGBA)
uniform sampler2D specgloss;
#pragma texture(specgloss, 2, RGBA)
layout(binding = 2) uniform sampler2D specgloss;
#include <light_common.glsl>
#include <apply_fog.glsl>
#include <tonemapping.glsl>
#include "light_common.glsl"
#include "apply_fog.glsl"
#include "tonemapping.glsl"
void main()
{
@@ -56,17 +56,19 @@ void main()
vec4 color = vec4(apply_fog(fragcolor), tex_color.a * alpha_mult);
#if POSTFX_ENABLED
out_color = color;
#else
out_color = tonemap(color);
#endif
#if MOTIONBLUR_ENABLED
if (POSTFX_ENABLED)
{
out_color = color;
}
else
{
out_color = tonemap(color);
}
if (MOTIONBLUR_ENABLED)
{
vec2 a = (f_clip_future_pos.xy / f_clip_future_pos.w) * 0.5 + 0.5;;
vec2 b = (f_clip_pos.xy / f_clip_pos.w) * 0.5 + 0.5;;
out_motion = vec4(a - b, 0.0f, 0.0f);
}
#endif
}

View File

@@ -1,34 +1,34 @@
in vec3 f_normal;
in vec2 f_coord;
in vec4 f_pos;
in mat3 f_tbn;
#version 460 core
#define STAGE_FRAGMENT 1
layout(location = 0) in vec3 f_normal;
layout(location = 2) in vec2 f_coord;
layout(location = 3) in vec4 f_pos;
layout(location = 8) in mat3 f_tbn;
in vec4 f_clip_pos;
in vec4 f_clip_future_pos;
layout(location = 4) in vec4 f_clip_pos;
layout(location = 5) in vec4 f_clip_future_pos;
#include <common>
#include "common.glsl"
layout(location = 0) out vec4 out_color;
#if MOTIONBLUR_ENABLED
layout(location = 1) out vec4 out_motion;
#endif
#param (color, 0, 0, 4, diffuse)
#param (diffuse, 1, 0, 1, diffuse)
#param (specular, 1, 1, 1, specular)
#param (reflection, 1, 2, 1, zero)
#param (glossiness, 1, 3, 1, glossiness)
#pragma param(color, 0, 0, 4, diffuse)
#pragma param(diffuse, 1, 0, 1, diffuse)
#pragma param(specular, 1, 1, 1, specular)
#pragma param(reflection, 1, 2, 1, zero)
#pragma param(glossiness, 1, 3, 1, glossiness)
#texture (diffuse, 0, sRGB_A)
uniform sampler2D diffuse;
#pragma texture(diffuse, 0, sRGB_A)
layout(binding = 0) uniform sampler2D diffuse;
#texture (normalmap, 1, RGBA)
uniform sampler2D normalmap;
#pragma texture(normalmap, 1, RGBA)
layout(binding = 1) uniform sampler2D normalmap;
#define NORMALMAP
#include <light_common.glsl>
#include <apply_fog.glsl>
#include <tonemapping.glsl>
#include "light_common.glsl"
#include "apply_fog.glsl"
#include "tonemapping.glsl"
void main()
{
@@ -52,17 +52,19 @@ void main()
fragcolor = apply_lights(fragcolor, fragnormal, tex_color.rgb, reflectivity, specularity, 1.0);
vec4 color = vec4(apply_fog(fragcolor), tex_color.a * alpha_mult);
#if POSTFX_ENABLED
out_color = color;
#else
out_color = tonemap(color);
#endif
#if MOTIONBLUR_ENABLED
if (POSTFX_ENABLED)
{
out_color = color;
}
else
{
out_color = tonemap(color);
}
if (MOTIONBLUR_ENABLED)
{
vec2 a = (f_clip_future_pos.xy / f_clip_future_pos.w) * 0.5 + 0.5;;
vec2 b = (f_clip_pos.xy / f_clip_pos.w) * 0.5 + 0.5;;
out_motion = vec4(a - b, 0.0f, 0.0f);
}
#endif
}

View File

@@ -1,38 +1,38 @@
in vec3 f_normal;
in vec2 f_coord;
in vec4 f_pos;
in mat3 f_tbn;
#version 460 core
#define STAGE_FRAGMENT 1
layout(location = 0) in vec3 f_normal;
layout(location = 2) in vec2 f_coord;
layout(location = 3) in vec4 f_pos;
layout(location = 8) in mat3 f_tbn;
in vec4 f_clip_pos;
in vec4 f_clip_future_pos;
layout(location = 4) in vec4 f_clip_pos;
layout(location = 5) in vec4 f_clip_future_pos;
#include <common>
#include "common.glsl"
layout(location = 0) out vec4 out_color;
#if MOTIONBLUR_ENABLED
layout(location = 1) out vec4 out_motion;
#endif
#param (color, 0, 0, 4, diffuse)
#param (diffuse, 1, 0, 1, diffuse)
#param (specular, 1, 1, 1, specular)
#param (reflection, 1, 2, 1, zero)
#param (glossiness, 1, 3, 1, glossiness)
#pragma param(color, 0, 0, 4, diffuse)
#pragma param(diffuse, 1, 0, 1, diffuse)
#pragma param(specular, 1, 1, 1, specular)
#pragma param(reflection, 1, 2, 1, zero)
#pragma param(glossiness, 1, 3, 1, glossiness)
#texture (diffuse, 0, sRGB_A)
uniform sampler2D diffuse;
#pragma texture(diffuse, 0, sRGB_A)
layout(binding = 0) uniform sampler2D diffuse;
#texture (normalmap, 1, RGBA)
uniform sampler2D normalmap;
#pragma texture(normalmap, 1, RGBA)
layout(binding = 1) uniform sampler2D normalmap;
#texture (specgloss, 2, RGBA)
uniform sampler2D specgloss;
#pragma texture(specgloss, 2, RGBA)
layout(binding = 2) uniform sampler2D specgloss;
#define NORMALMAP
#include <light_common.glsl>
#include <apply_fog.glsl>
#include <tonemapping.glsl>
#include "light_common.glsl"
#include "apply_fog.glsl"
#include "tonemapping.glsl"
void main()
{
@@ -57,17 +57,19 @@ void main()
fragcolor = apply_lights(fragcolor, fragnormal, tex_color.rgb, reflectivity, specularity, 1.0);
vec4 color = vec4(apply_fog(fragcolor), tex_color.a * alpha_mult);
#if POSTFX_ENABLED
out_color = color;
#else
out_color = tonemap(color);
#endif
#if MOTIONBLUR_ENABLED
if (POSTFX_ENABLED)
{
out_color = color;
}
else
{
out_color = tonemap(color);
}
if (MOTIONBLUR_ENABLED)
{
vec2 a = (f_clip_future_pos.xy / f_clip_future_pos.w) * 0.5 + 0.5;;
vec2 b = (f_clip_pos.xy / f_clip_pos.w) * 0.5 + 0.5;;
out_motion = vec4(a - b, 0.0f, 0.0f);
}
#endif
}

View File

@@ -1,12 +1,12 @@
#include <common>
#include <tonemapping.glsl>
#version 460 core
#define STAGE_FRAGMENT 1
#include "common.glsl"
#include "tonemapping.glsl"
flat in vec3 f_normal_raw;
layout(location = 1) flat in vec3 f_normal_raw;
layout(location = 0) out vec4 out_color;
#if MOTIONBLUR_ENABLED
layout(location = 1) out vec4 out_motion;
#endif
void main()
{
@@ -18,12 +18,16 @@ void main()
// color data space is shared with normals, ugh
vec4 color = vec4(pow(f_normal_raw.rgb, vec3(2.2)), 1.0f);
#if POSTFX_ENABLED
out_color = color;
#else
out_color = tonemap(color);
#endif
#if MOTIONBLUR_ENABLED
out_motion = vec4(0.0f);
#endif
if (POSTFX_ENABLED)
{
out_color = color;
}
else
{
out_color = tonemap(color);
}
if (MOTIONBLUR_ENABLED)
{
out_motion = vec4(0.0f);
}
}

View File

@@ -1,68 +1,70 @@
in vec3 f_normal;
in vec2 f_coord;
in vec4 f_pos;
in mat3 f_tbn;
in vec4 f_clip_pos;
in vec4 f_clip_future_pos;
#include <common>
layout(location = 0) out vec4 out_color;
#if MOTIONBLUR_ENABLED
layout(location = 1) out vec4 out_motion;
#endif
#param (color, 0, 0, 4, diffuse)
#param (diffuse, 1, 0, 1, diffuse)
#param (specular, 1, 1, 1, specular)
#param (reflection, 1, 2, 1, zero)
#param (glossiness, 1, 3, 1, glossiness)
#texture (diffuse, 0, sRGB_A)
uniform sampler2D diffuse;
#texture (normalmap, 1, RGBA)
uniform sampler2D normalmap;
#define NORMALMAP
#include <light_common.glsl>
#include <apply_fog.glsl>
#include <tonemapping.glsl>
void main()
{
vec4 tex_color = texture(diffuse, f_coord);
bool alphatestfail = ( opacity >= 0.0 ? (tex_color.a < opacity) : (tex_color.a >= -opacity) );
if(alphatestfail)
discard;
// if (tex_color.a < opacity)
// discard;
vec3 fragcolor = ambient;
vec3 normal;
normal.xy = (texture(normalmap, f_coord).rg * 2.0 - 1.0);
normal.z = sqrt(1.0 - clamp((dot(normal.xy, normal.xy)), 0.0, 1.0));
vec3 fragnormal = normalize(f_tbn * normalize(normal.xyz));
float reflectivity = param[1].z * texture(normalmap, f_coord).a;
float specularity = (tex_color.r + tex_color.g + tex_color.b) * 0.5;
legacy_gloss();
fragcolor = apply_lights_sunless(fragcolor, fragnormal, tex_color.rgb, reflectivity, specularity, shadow_tone);
vec4 color = vec4(apply_fog(fragcolor), tex_color.a * alpha_mult);
#if POSTFX_ENABLED
out_color = color;
#else
out_color = tonemap(color);
#endif
#if MOTIONBLUR_ENABLED
{
vec2 a = (f_clip_future_pos.xy / f_clip_future_pos.w) * 0.5 + 0.5;;
vec2 b = (f_clip_pos.xy / f_clip_pos.w) * 0.5 + 0.5;;
out_motion = vec4(a - b, 0.0f, 0.0f);
}
#endif
}
#version 460 core
#define STAGE_FRAGMENT 1
layout(location = 0) in vec3 f_normal;
layout(location = 2) in vec2 f_coord;
layout(location = 3) in vec4 f_pos;
layout(location = 8) in mat3 f_tbn;
layout(location = 4) in vec4 f_clip_pos;
layout(location = 5) in vec4 f_clip_future_pos;
#include "common.glsl"
layout(location = 0) out vec4 out_color;
layout(location = 1) out vec4 out_motion;
#pragma param(color, 0, 0, 4, diffuse)
#pragma param(diffuse, 1, 0, 1, diffuse)
#pragma param(specular, 1, 1, 1, specular)
#pragma param(reflection, 1, 2, 1, zero)
#pragma param(glossiness, 1, 3, 1, glossiness)
#pragma texture(diffuse, 0, sRGB_A)
layout(binding = 0) uniform sampler2D diffuse;
#pragma texture(normalmap, 1, RGBA)
layout(binding = 1) uniform sampler2D normalmap;
#define NORMALMAP
#include "light_common.glsl"
#include "apply_fog.glsl"
#include "tonemapping.glsl"
void main()
{
vec4 tex_color = texture(diffuse, f_coord);
bool alphatestfail = ( opacity >= 0.0 ? (tex_color.a < opacity) : (tex_color.a >= -opacity) );
if(alphatestfail)
discard;
// if (tex_color.a < opacity)
// discard;
vec3 fragcolor = ambient;
vec3 normal;
normal.xy = (texture(normalmap, f_coord).rg * 2.0 - 1.0);
normal.z = sqrt(1.0 - clamp((dot(normal.xy, normal.xy)), 0.0, 1.0));
vec3 fragnormal = normalize(f_tbn * normalize(normal.xyz));
float reflectivity = param[1].z * texture(normalmap, f_coord).a;
float specularity = (tex_color.r + tex_color.g + tex_color.b) * 0.5;
legacy_gloss();
fragcolor = apply_lights_sunless(fragcolor, fragnormal, tex_color.rgb, reflectivity, specularity, shadow_tone);
vec4 color = vec4(apply_fog(fragcolor), tex_color.a * alpha_mult);
if (POSTFX_ENABLED)
{
out_color = color;
}
else
{
out_color = tonemap(color);
}
if (MOTIONBLUR_ENABLED)
{
vec2 a = (f_clip_future_pos.xy / f_clip_future_pos.w) * 0.5 + 0.5;;
vec2 b = (f_clip_pos.xy / f_clip_pos.w) * 0.5 + 0.5;;
out_motion = vec4(a - b, 0.0f, 0.0f);
}
}

View File

@@ -1,73 +1,75 @@
in vec3 f_normal;
in vec2 f_coord;
in vec4 f_pos;
in mat3 f_tbn;
in vec4 f_clip_pos;
in vec4 f_clip_future_pos;
#include <common>
layout(location = 0) out vec4 out_color;
#if MOTIONBLUR_ENABLED
layout(location = 1) out vec4 out_motion;
#endif
#param (color, 0, 0, 4, diffuse)
#param (diffuse, 1, 0, 1, diffuse)
#param (specular, 1, 1, 1, specular)
#param (reflection, 1, 2, 1, zero)
#param (glossiness, 1, 3, 1, glossiness)
#texture (diffuse, 0, sRGB_A)
uniform sampler2D diffuse;
#texture (normalmap, 1, RGBA)
uniform sampler2D normalmap;
#texture (specgloss, 2, RGBA)
uniform sampler2D specgloss;
#define NORMALMAP
#include <light_common.glsl>
#include <apply_fog.glsl>
#include <tonemapping.glsl>
void main()
{
vec4 tex_color = texture(diffuse, f_coord);
bool alphatestfail = ( opacity >= 0.0 ? (tex_color.a < opacity) : (tex_color.a >= -opacity) );
if(alphatestfail)
discard;
// if (tex_color.a < opacity)
// discard;
vec3 fragcolor = ambient;
vec3 normal;
normal.xy = (texture(normalmap, f_coord).rg * 2.0 - 1.0);
normal.z = sqrt(1.0 - clamp((dot(normal.xy, normal.xy)), 0.0, 1.0));
vec3 fragnormal = normalize(f_tbn * normalize(normal.xyz));
float reflectivity = param[1].z * texture(normalmap, f_coord).a;
float specularity = texture(specgloss, f_coord).r;
glossiness = texture(specgloss, f_coord).g * abs(param[1].w);
metalic = texture(specgloss, f_coord).b;
fragcolor = apply_lights_sunless(fragcolor, fragnormal, tex_color.rgb, reflectivity, specularity, shadow_tone);
vec4 color = vec4(apply_fog(fragcolor), tex_color.a * alpha_mult);
#if POSTFX_ENABLED
out_color = color;
#else
out_color = tonemap(color);
#endif
#if MOTIONBLUR_ENABLED
{
vec2 a = (f_clip_future_pos.xy / f_clip_future_pos.w) * 0.5 + 0.5;;
vec2 b = (f_clip_pos.xy / f_clip_pos.w) * 0.5 + 0.5;;
out_motion = vec4(a - b, 0.0f, 0.0f);
}
#endif
}
#version 460 core
#define STAGE_FRAGMENT 1
layout(location = 0) in vec3 f_normal;
layout(location = 2) in vec2 f_coord;
layout(location = 3) in vec4 f_pos;
layout(location = 8) in mat3 f_tbn;
layout(location = 4) in vec4 f_clip_pos;
layout(location = 5) in vec4 f_clip_future_pos;
#include "common.glsl"
layout(location = 0) out vec4 out_color;
layout(location = 1) out vec4 out_motion;
#pragma param(color, 0, 0, 4, diffuse)
#pragma param(diffuse, 1, 0, 1, diffuse)
#pragma param(specular, 1, 1, 1, specular)
#pragma param(reflection, 1, 2, 1, zero)
#pragma param(glossiness, 1, 3, 1, glossiness)
#pragma texture(diffuse, 0, sRGB_A)
layout(binding = 0) uniform sampler2D diffuse;
#pragma texture(normalmap, 1, RGBA)
layout(binding = 1) uniform sampler2D normalmap;
#pragma texture(specgloss, 2, RGBA)
layout(binding = 2) uniform sampler2D specgloss;
#define NORMALMAP
#include "light_common.glsl"
#include "apply_fog.glsl"
#include "tonemapping.glsl"
void main()
{
vec4 tex_color = texture(diffuse, f_coord);
bool alphatestfail = ( opacity >= 0.0 ? (tex_color.a < opacity) : (tex_color.a >= -opacity) );
if(alphatestfail)
discard;
// if (tex_color.a < opacity)
// discard;
vec3 fragcolor = ambient;
vec3 normal;
normal.xy = (texture(normalmap, f_coord).rg * 2.0 - 1.0);
normal.z = sqrt(1.0 - clamp((dot(normal.xy, normal.xy)), 0.0, 1.0));
vec3 fragnormal = normalize(f_tbn * normalize(normal.xyz));
float reflectivity = param[1].z * texture(normalmap, f_coord).a;
float specularity = texture(specgloss, f_coord).r;
glossiness = texture(specgloss, f_coord).g * abs(param[1].w);
metalic = texture(specgloss, f_coord).b;
fragcolor = apply_lights_sunless(fragcolor, fragnormal, tex_color.rgb, reflectivity, specularity, shadow_tone);
vec4 color = vec4(apply_fog(fragcolor), tex_color.a * alpha_mult);
if (POSTFX_ENABLED)
{
out_color = color;
}
else
{
out_color = tonemap(color);
}
if (MOTIONBLUR_ENABLED)
{
vec2 a = (f_clip_future_pos.xy / f_clip_future_pos.w) * 0.5 + 0.5;;
vec2 b = (f_clip_pos.xy / f_clip_pos.w) * 0.5 + 0.5;;
out_motion = vec4(a - b, 0.0f, 0.0f);
}
}

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