inclusion guards for shaderlib

main
Dominik Madarász 2024-08-24 19:32:25 +02:00
parent 79dca69ac3
commit 33eecb039b
10 changed files with 77 additions and 33 deletions

View File

@ -1,15 +1,15 @@
#ifndef BRDF_GLSL
#define BRDF_GLSL
#ifdef SHADING_PBR #ifdef SHADING_PBR
uniform vec2 resolution; /// set:640,480 // debug options below use this (USE_MAP_DEBUGGING, USE_AMBIENT_DEBUGGING)
#include "utils.glsl"
#define USE_BRUTEFORCE_IRRADIANCE false // Samples irradiance from tex_skysphere when enabled. #define USE_BRUTEFORCE_IRRADIANCE false // Samples irradiance from tex_skysphere when enabled.
#define USE_WRAPAROUND_SPECULAR true // Makes silhouettes more reflective to avoid black pixels. #define USE_WRAPAROUND_SPECULAR true // Makes silhouettes more reflective to avoid black pixels.
#define USE_SPECULAR_AO_ATTENUATION true // Dampens IBL specular ambient with AO if enabled. #define USE_SPECULAR_AO_ATTENUATION true // Dampens IBL specular ambient with AO if enabled.
#define USE_NORMAL_VARIATION_TO_ROUGHNESS true // Increases roughness if normal map has variation and was minified. #define USE_NORMAL_VARIATION_TO_ROUGHNESS true // Increases roughness if normal map has variation and was minified.
#define USE_MAP_DEBUGGING false // Shows all ColorMaps as horizontal bars
#define USE_AMBIENT_DEBUGGING false // Splits the screen in two and shows image-based specular (left), full shading (middle), diffuse shading (right).
#define BOOST_LIGHTING 2.00f // Multiplies analytic light's color with this constant because otherwise they look really pathetic. #define BOOST_LIGHTING 2.00f // Multiplies analytic light's color with this constant because otherwise they look really pathetic.
#define BOOST_SPECULAR 1.50f #define BOOST_SPECULAR 1.50f
#define BOOST_NOISE 2.50f
struct ColorMap struct ColorMap
{ {
@ -42,32 +42,6 @@ uniform sampler2D tex_brdf_lut;
uniform bool has_tex_skysphere; uniform bool has_tex_skysphere;
uniform bool has_tex_skyenv; uniform bool has_tex_skyenv;
const float PI = 3.1415926536;
// MurMurHash 3 finalizer. Implementation is in public domain.
uint hash( uint h )
{
h ^= h >> 16;
h *= 0x85ebca6bU;
h ^= h >> 13;
h *= 0xc2b2ae35U;
h ^= h >> 16;
return h;
}
// Random function using the idea of StackOverflow user "Spatial" https://stackoverflow.com/a/17479300
// Creates random 23 bits and puts them into the fraction bits of an 32-bit float.
float random( uvec3 h )
{
uint m = hash(h.x ^ hash( h.y ) ^ hash( h.z ));
return uintBitsToFloat( ( m & 0x007FFFFFu ) | 0x3f800000u ) - 1.;
}
float random( vec3 v )
{
return random(floatBitsToUint( v ));
}
vec3 fresnel_schlick( vec3 H, vec3 V, vec3 F0 ) vec3 fresnel_schlick( vec3 H, vec3 V, vec3 F0 )
{ {
float cosTheta = clamp( dot( H, V ), 0., 1. ); float cosTheta = clamp( dot( H, V ), 0., 1. );
@ -229,3 +203,4 @@ vec3 specular_ibl( vec3 V, vec3 N, float roughness, vec3 fresnel )
return specular; return specular;
} }
#endif #endif
#endif

View File

@ -1,3 +1,6 @@
#ifndef LIGHT_GLSL
#define LIGHT_GLSL
#include "brdf.glsl" #include "brdf.glsl"
uniform int u_num_lights; uniform int u_num_lights;
@ -127,3 +130,5 @@ vec3 lighting(material_t m) {
#endif #endif
return lit; return lit;
} }
#endif

View File

@ -1,3 +1,6 @@
#ifndef LIGHTMAP_GLSL
#define LIGHTMAP_GLSL
bool do_lightmap() { bool do_lightmap() {
#ifdef LIGHTMAP_BAKING #ifdef LIGHTMAP_BAKING
vec3 n = normalize(v_normal_ws); vec3 n = normalize(v_normal_ws);
@ -20,3 +23,5 @@ bool do_lightmap() {
return false; return false;
#endif #endif
} }
#endif

View File

@ -1,3 +1,6 @@
#ifndef MODEL_FS_GLSL
#define MODEL_FS_GLSL
uniform mat4 model, view; uniform mat4 model, view;
uniform sampler2D u_texture2d; uniform sampler2D u_texture2d;
uniform vec3 u_coefficients_sh[9]; uniform vec3 u_coefficients_sh[9];
@ -43,3 +46,5 @@ uniform vec3 u_cam_pos;
uniform vec3 u_cam_dir; uniform vec3 u_cam_dir;
uniform float frame_time; uniform float frame_time;
uniform uint frame_count; uniform uint frame_count;
#endif

View File

@ -1,3 +1,6 @@
#ifndef MODEL_VS_GLSL
#define MODEL_VS_GLSL
#ifndef MAX_BONES #ifndef MAX_BONES
#define MAX_BONES 110 #define MAX_BONES 110
#endif #endif
@ -155,3 +158,5 @@ billboard_t setup_billboard(mat4 modelView, mat4 l_model) {
bb.l_model = l_model; bb.l_model = l_model;
return bb; return bb;
} }
#endif

View File

@ -1,3 +1,6 @@
#ifndef RIMLIGHT_GLSL
#define RIMLIGHT_GLSL
vec3 get_rimlight() { vec3 get_rimlight() {
#ifdef RIM #ifdef RIM
vec3 n = normalize(mat3(M) * v_normal); // convert normal to view space vec3 n = normalize(mat3(M) * v_normal); // convert normal to view space
@ -13,3 +16,5 @@ vec3 get_rimlight() {
return vec3(0); return vec3(0);
#endif #endif
} }
#endif

View File

@ -1,3 +1,6 @@
#ifndef SH_LIGHTING_GLSL
#define SH_LIGHTING_GLSL
vec3 sh_lighting(vec3 n) { vec3 sh_lighting(vec3 n) {
vec3 SHLightResult[9]; vec3 SHLightResult[9];
SHLightResult[0] = 0.282095f * u_coefficients_sh[0]; SHLightResult[0] = 0.282095f * u_coefficients_sh[0];
@ -14,3 +17,5 @@ vec3 sh_lighting(vec3 n) {
result += SHLightResult[i]; result += SHLightResult[i];
return result; return result;
} }
#endif

View File

@ -1,3 +1,7 @@
// WIP
#ifndef SHADOWMAP_GLSL
#define SHADOWMAP_GLSL
// uniform mat4 view = mat4(1.0); // uniform mat4 view = mat4(1.0);
uniform vec3 lightPos; /// set:1,1,1 uniform vec3 lightPos; /// set:1,1,1
uniform float doTexture; /// set:1 uniform float doTexture; /// set:1
@ -110,3 +114,5 @@ struct light {
return vec4(clamp(vec3(total_lighting), 0., 1.), 1.0); return vec4(clamp(vec3(total_lighting), 0., 1.), 1.0);
#endif #endif
} }
#endif

View File

@ -1,3 +1,6 @@
#ifndef SURFACE_GLSL
#define SURFACE_GLSL
#include "sh_lighting.glsl" #include "sh_lighting.glsl"
#include "rimlight.glsl" #include "rimlight.glsl"
#include "light.glsl" #include "light.glsl"
@ -199,3 +202,5 @@ surface_t surface() {
return s; return s;
} }
#endif

View File

@ -1,3 +1,30 @@
#ifndef UTILS_GLSL
#define UTILS_GLSL
const float PI = 3.1415926536;
// MurMurHash 3 finalizer. Implementation is in public domain.
uint hash( uint h )
{
h ^= h >> 16;
h *= 0x85ebca6bU;
h ^= h >> 13;
h *= 0xc2b2ae35U;
h ^= h >> 16;
return h;
}
// Random function using the idea of StackOverflow user "Spatial" https://stackoverflow.com/a/17479300
// Creates random 23 bits and puts them into the fraction bits of an 32-bit float.
float random( uvec3 h )
{
uint m = hash(h.x ^ hash( h.y ) ^ hash( h.z ));
return uintBitsToFloat( ( m & 0x007FFFFFu ) | 0x3f800000u ) - 1.;
}
float random( vec3 v )
{
return random(floatBitsToUint( v ));
}
// Classic Perlin 3D Noise // Classic Perlin 3D Noise
// by Stefan Gustavson // by Stefan Gustavson
@ -112,3 +139,4 @@ vec3 hsv2rgb(vec3 c) {
vec3 p = abs(fract(c.xxx + K.xyz) * 6.0 - K.www); vec3 p = abs(fract(c.xxx + K.xyz) * 6.0 - K.www);
return c.z * mix(K.xxx, clamp(p - K.xxx, 0.0, 1.0), c.y); return c.z * mix(K.xxx, clamp(p - K.xxx, 0.0, 1.0), c.y);
} }
#endif