Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions code/def_files/data/effects/batched-f.sdr
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
#ifdef GL_ES
precision highp float;
precision highp sampler2DArray;
#endif

#include "gamma.sdr"

layout(location=0) out vec4 fragOut0;

#ifdef VULKAN
layout (location = 0) in vec4 fragTexCoord;
layout (location = 1) in vec4 fragColor;

layout (location = 0) out vec4 fragOut0;

layout (set = 1, binding = 1) uniform sampler2DArray baseMap;

layout (set = 2, binding = 0, std140) uniform genericData {
Expand All @@ -17,8 +21,6 @@ layout (set = 2, binding = 0, std140) uniform genericData {
in vec4 fragTexCoord;
in vec4 fragColor;

out vec4 fragOut0;

uniform sampler2DArray baseMap;

layout (std140) uniform genericData {
Expand Down
4 changes: 4 additions & 0 deletions code/def_files/data/effects/batched-v.sdr
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
#ifdef GL_ES
precision highp float;
#endif

#ifdef VULKAN
layout (location = 0) in vec4 vertPosition;
layout (location = 1) in vec4 vertColor;
Expand Down
9 changes: 7 additions & 2 deletions code/def_files/data/effects/bloom-comp-f.sdr
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
#ifdef GL_ES
precision highp float;
precision highp sampler2D;
#endif

layout(location=0) out vec4 fragOut0;

#ifdef VULKAN
layout(location = 0) in vec2 fragTexCoord;
layout(location = 0) out vec4 fragOut0;
layout(set = 1, binding = 1) uniform sampler2D bloomed;
#else
in vec4 fragTexCoord;
out vec4 fragOut0;

uniform sampler2D bloomed;
#endif

Expand Down
10 changes: 8 additions & 2 deletions code/def_files/data/effects/blur-f.sdr
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
#ifdef GL_ES
precision highp float;
precision highp int;
precision highp sampler2D;
#endif

layout(location = 0) out vec4 fragOut0;

#ifdef VULKAN
layout(location = 0) in vec2 fragTexCoord;
layout(location = 0) out vec4 fragOut0;
layout(set = 1, binding = 1) uniform sampler2D tex;
#else
out vec4 fragOut0;
in vec4 fragTexCoord;
uniform sampler2D tex;
#endif
Expand Down
10 changes: 8 additions & 2 deletions code/def_files/data/effects/brightpass-f.sdr
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
#ifdef GL_ES
precision highp float;
precision highp sampler2D;
#endif

layout(location = 0) out vec4 fragOut0;

#ifdef VULKAN
layout(location = 0) in vec2 fragTexCoord;
layout(location = 0) out vec4 fragOut0;
layout(set = 1, binding = 1) uniform sampler2D tex;
#else
in vec4 fragTexCoord;
out vec4 fragOut0;
uniform sampler2D tex;
#endif

const float Luminance = 0.08;
const float fMiddleGray = 0.2;
const float fWhiteCutoff = 0.4;
Expand Down
9 changes: 7 additions & 2 deletions code/def_files/data/effects/copy-f.sdr
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
#ifdef GL_ES
precision highp sampler2D;
precision highp sampler2DArray;
#endif

layout(location = 0) out vec4 fragOut0;

#ifdef VULKAN
layout(location = 0) in vec2 fragTexCoord;
layout(location = 0) out vec4 fragOut0;
layout(set = 1, binding = 1) uniform sampler2D tex;
#else
in vec4 fragTexCoord;
out vec4 fragOut0;
#ifdef COPY_ARRAY
uniform sampler2DArray tex;
#else
Expand Down
19 changes: 15 additions & 4 deletions code/def_files/data/effects/decal-f.sdr
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
#ifdef GL_ES
precision highp float;
precision highp int;
precision highp sampler2D;
precision highp sampler2DArray;
#endif

// NOTE: The technique and some of this code is based on this tutorial:
// http://martindevans.me/game-development/2015/02/27/Drawing-Stuff-On-Other-Stuff-With-Deferred-Screenspace-Decals/
Expand Down Expand Up @@ -29,9 +35,14 @@ layout (set = 1, binding = 1) uniform sampler2DArray decalTextures;
layout (set = 1, binding = 4) uniform sampler2D gDepthBuffer;
layout (set = 1, binding = 6) uniform sampler2D gNormalBuffer;
#else
out vec4 fragOut0; // Diffuse buffer
out vec4 fragOut1; // Normal buffer
out vec4 fragOut2; // Emissive buffer
layout (location=0) out vec4 fragOut0; // Diffuse buffer
#ifndef GL_ES
layout (location=1) out vec4 fragOut1; // Normal buffer
layout (location=2) out vec4 fragOut2; // Emissive buffer
#else
layout (location=2) out vec4 fragOut1; // Normal buffer -> COLOR_ATTACHMENT2
layout (location=4) out vec4 fragOut2; // Emissive buffer -> COLOR_ATTACHMENT4
#endif

flat in mat4 invModelMatrix;
flat in vec3 decalDirection;
Expand Down Expand Up @@ -124,7 +135,7 @@ vec3 getPixelNormal(vec3 frag_position, vec2 tex_coord, inout float alpha, out v
}

// Make a smooth alpha transition leading up to an edge
alpha = alpha * (1 - smoothstep(angle_fade_start, normal_angle_cutoff, angle));
alpha = alpha * (1.0 - smoothstep(angle_fade_start, normal_angle_cutoff, angle));

return normal;
}
Expand Down
4 changes: 4 additions & 0 deletions code/def_files/data/effects/decal-v.sdr
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
#ifdef GL_ES
precision highp float;
precision highp int;
#endif

#ifdef VULKAN
// Binding 0: box vertex positions
Expand Down
30 changes: 27 additions & 3 deletions code/def_files/data/effects/default-material-f.sdr
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
#ifdef GL_ES
#extension GL_EXT_clip_cull_distance : enable
precision highp float;
precision highp int;
precision highp sampler2DArray;
#endif

#if defined(VULKAN)
//define USE_HW_CLIP_DISTANCE from engine side
#elif !defined(GL_ES) || defined(GL_EXT_clip_cull_distance)
#define USE_HW_CLIP_DISTANCE
#endif

#ifdef VULKAN
layout(set = 2, binding = 0, std140)
#else
Expand All @@ -20,29 +33,40 @@ uniform genericData {
uint clipEnabled;
};

layout(location = 0) out vec4 fragOut0;

#ifdef VULKAN

layout(set = 1, binding = 1) uniform sampler2DArray baseMap;

layout(location = 0) in vec4 fragTexCoord;
layout(location = 1) in vec4 fragColor;

layout(location = 0) out vec4 fragOut0;
#ifndef USE_HW_CLIP_DISTANCE
layout(location = 2) in float vClipDist;
#endif

#else

#ifndef USE_HW_CLIP_DISTANCE
in float vClipDist;
#endif

uniform sampler2DArray baseMap;

in vec4 fragTexCoord;
in vec4 fragColor;
out vec4 fragOut0;

#endif

#include "gamma.sdr"

void main()
{
#ifndef USE_HW_CLIP_DISTANCE
if (clipEnabled != 0u && vClipDist < 0.0) {
discard;
}
#endif
vec4 baseColor = texture(baseMap, vec3(fragTexCoord.xy, float(baseMapIndex)));
if(alphaThreshold > baseColor.a) discard;
baseColor.rgb = (srgb == 1) ? srgb_to_linear(baseColor.rgb) : baseColor.rgb;
Expand Down
32 changes: 26 additions & 6 deletions code/def_files/data/effects/default-material-v.sdr
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
#ifdef GL_ES
#extension GL_EXT_clip_cull_distance : enable
precision highp float;
precision highp int;
#endif

#if defined(VULKAN)
//define USE_HW_CLIP_DISTANCE from engine side
#elif !defined(GL_ES) || defined(GL_EXT_clip_cull_distance)
#define USE_HW_CLIP_DISTANCE
#endif

#ifdef VULKAN
layout(set = 2, binding = 0, std140)
#else
Expand Down Expand Up @@ -38,10 +50,15 @@ layout(location = 2) in vec4 vertTexCoord;

layout(location = 0) out vec4 fragTexCoord;
layout(location = 1) out vec4 fragColor;
#ifndef USE_HW_CLIP_DISTANCE
layout(location = 2) out float vClipDist;
#endif

#else

out float gl_ClipDistance[1];
#ifndef USE_HW_CLIP_DISTANCE
out float vClipDist;
#endif

out vec4 fragTexCoord;
in vec4 vertTexCoord;
Expand All @@ -58,13 +75,16 @@ void main()
gl_Position = projMatrix * modelViewMatrix * vertPosition;

if (clipEnabled != 0u) {
#ifdef USE_HW_CLIP_DISTANCE
gl_ClipDistance[0] = dot(clipEquation, modelMatrix * vertPosition);
#else
vClipDist = dot(clipEquation, modelMatrix * vertPosition);
#endif
} else {
#ifdef VULKAN
// Vulkan has no glEnable(GL_CLIP_DISTANCE0) equivalent — clip distances are
// always evaluated when declared in the shader. Must write a positive value
// when clipping is disabled to prevent undefined-value vertex culling.
#ifdef USE_HW_CLIP_DISTANCE
gl_ClipDistance[0] = 1.0;
#endif
#else
vClipDist = 1.0;
#endif
}
}
17 changes: 11 additions & 6 deletions code/def_files/data/effects/deferred-clear-f.sdr
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
out vec4 fragOut0;
out vec4 fragOut1;
out vec4 fragOut2;
out vec4 fragOut3;
out vec4 fragOut4;
out vec4 fragOut5;
#ifdef GL_ES
precision highp float;
#endif

layout (location=0) out vec4 fragOut0;
layout (location=1) out vec4 fragOut1;
layout (location=2) out vec4 fragOut2;
layout (location=3) out vec4 fragOut3;
layout (location=4) out vec4 fragOut4;
layout (location=5) out vec4 fragOut5;

void main()
{
fragOut0 = vec4(0.0, 0.0, 0.0, 1.0); // color
Expand Down
26 changes: 17 additions & 9 deletions code/def_files/data/effects/deferred-f.sdr
Original file line number Diff line number Diff line change
@@ -1,13 +1,21 @@
//? #version 150
#ifdef GL_ES
precision highp float;
precision highp int;
precision highp sampler2D;
precision highp samplerCube;
precision highp sampler2DArrayShadow;
#endif

#include "lighting.sdr" //! #include "lighting.sdr"
#include "gamma.sdr" //! #include "gamma.sdr"
#include "shadows.sdr" //! #include "shadows.sdr"
#include "z-compress.sdr" //! #include "z-compress.sdr"

#ifdef VULKAN
#ifndef GL_ES
layout(location = 0) out vec4 fragOut0;
#else
out vec4 fragOut0;
layout(location = 5) out vec4 fragOut0; //COLOR_ATTACHMENTn is on location n in ES, here it uses COLOR_ATTACHMENT5
#endif

#ifdef VULKAN
Expand Down Expand Up @@ -141,7 +149,7 @@ void GetLightInfo(vec3 position, in float alpha, in vec3 reflectDir, out vec3 li
dist = length(lightDirOut);
lightDist = dist;
// Energy conservation term
float alpha_adjust = clamp(alpha + (sourceRadius/(2*dist)), 0.0, 1.0);
float alpha_adjust = clamp(alpha + (sourceRadius/(2.0*dist)), 0.0, 1.0);
area_normalisation = alpha/alpha_adjust;
area_normalisation *= area_normalisation;
//end chunk
Expand Down Expand Up @@ -184,7 +192,7 @@ void GetLightInfo(vec3 position, in float alpha, in vec3 reflectDir, out vec3 li
float dist = length(lightDirOut);
lightDist = dist;
// Energy conservation term
float alpha_adjust = min(alpha + (sourceRadius/(2*dist)), 1.0);
float alpha_adjust = min(alpha + (sourceRadius/(2.0*dist)), 1.0);
area_normalisation = alpha/alpha_adjust;
// don't need to square as it's a line rather than a sphere.
//end chunk
Expand Down Expand Up @@ -231,11 +239,11 @@ void ComputeEnvLight(float alpha, float ao, vec3 light_dir, vec3 eyeDir, vec3 no
// so let s = (2/alpha^2 - 2)
// 1/2 log(s + 1) = 1/2 log(2/alpha^2 -1)

const float ENV_REZ = 512; // Ideally this would be #define'd and shader recompiled with envmap rez changes
const float REZ_BIAS = log2(ENV_REZ * sqrt(3));
const float ENV_REZ = 512.0; // Ideally this would be #define'd and shader recompiled with envmap rez changes
const float REZ_BIAS = log2(ENV_REZ * sqrt(3.0));

float alphaSqr = alpha * alpha;
float rough_bias = 0.5 * log2(2/alphaSqr - 1);
float rough_bias = 0.5 * log2(2.0/alphaSqr - 1.0);
float mip_bias = REZ_BIAS - rough_bias;

// Sample light, using mip bias to blur it.
Expand All @@ -253,7 +261,7 @@ void ComputeEnvLight(float alpha, float ao, vec3 light_dir, vec3 eyeDir, vec3 no
// Pseudo-IBL, so use k_IBL
float k = alpha * alpha/ 2.0f;

float NdotL = max(dot(light_dir, normal),0);
float NdotL = max(dot(light_dir, normal),0.0);

float g1vNL = GeometrySchlickGGX(NdotL, k);
vec3 specEnvLighting = specEnvColour.rgb * fresnel * g1vNL;
Expand Down Expand Up @@ -331,6 +339,6 @@ void main()
float NdotL = clamp(dot(normal, lightDir), 0.0, 1.0);
fragmentColor.rgb = computeLighting(specColor.rgb, diffColor, lightDir, normal.xyz, halfVec, eyeDir, roughness, fresnel, NdotL).rgb * diffuseLightColor * attenuation * area_normalisation;
}

fragOut0 = max(fragmentColor, vec4(0.0));
}
4 changes: 4 additions & 0 deletions code/def_files/data/effects/deferred-v.sdr
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
#ifdef GL_ES
precision highp float;
precision highp int;
#endif

#include "lighting.sdr"

Expand Down
Loading
Loading