render: rework engine shaders to be loaded from disk

main
Dominik Madarász 2023-09-10 17:10:49 +02:00
parent 358522ea22
commit b8422c6eb9
40 changed files with 94 additions and 2856 deletions

View File

@ -24,7 +24,6 @@ if "%1"=="help" (
echo %0 [bind] ; generate lua bindings echo %0 [bind] ; generate lua bindings
echo %0 [checkmem] ; check untracked allocators in V4K echo %0 [checkmem] ; check untracked allocators in V4K
echo %0 [split^|join] ; engine/v4k* ^>split^> engine/split/* or engine/split/* ^>join^> engine/v4k* echo %0 [split^|join] ; engine/v4k* ^>split^> engine/split/* or engine/split/* ^>join^> engine/v4k*
echo %0 [glsl_split^|glsl_join] ; join/split GLSL shaders
echo %0 [lua] ; execute lua script with v4k echo %0 [lua] ; execute lua script with v4k
echo %0 [amalgamation] ; combine engine/v4k* into a single-header file echo %0 [amalgamation] ; combine engine/v4k* into a single-header file
echo %0 [prep] ; combine split files into a single-header file, ready for use echo %0 [prep] ; combine split files into a single-header file, ready for use
@ -132,7 +131,6 @@ if "%1"=="git" (
call make.bat docs call make.bat docs
call make.bat bind call make.bat bind
call make.bat glsl_join
call make.bat amalgamation call make.bat amalgamation
call make.bat split call make.bat split
@ -167,7 +165,6 @@ if "%1"=="push" (
) )
if "%1"=="prep" ( if "%1"=="prep" (
call make.bat glsl_join
call make.bat join call make.bat join
call make.bat amalgamation call make.bat amalgamation
exit /b exit /b
@ -183,16 +180,6 @@ if "%1"=="join" (
exit /b exit /b
) )
if "%1"=="glsl_split" (
call tools\glsl_split
exit /b
)
if "%1"=="glsl_join" (
call tools\glsl_join
exit /b
)
rem check memory api calls rem check memory api calls
if "%1"=="checkmem" ( if "%1"=="checkmem" (
findstr /RNC:"[^_xv]realloc[(]" engine\v4k.c engine\split\v4k* findstr /RNC:"[^_xv]realloc[(]" engine\v4k.c engine\split\v4k*

View File

@ -13,4 +13,4 @@ vec2 iMouse = vec2(iMousex, iMousey);
vec2 iChannelResolution[2] = vec2[2]( vec2(iChannelRes0x, iChannelRes0y),vec2(iChannelRes1x, iChannelRes1y) ); vec2 iChannelResolution[2] = vec2[2]( vec2(iChannelRes0x, iChannelRes0y),vec2(iChannelRes1x, iChannelRes1y) );
float iGlobalTime = iTime; float iGlobalTime = iTime;
in vec2 texcoord; in vec2 texcoord;
out vec4 fragColor; out vec4 fragColor;

View File

@ -0,0 +1,24 @@
#version 130
#define texture2D texture
uniform float iGlobalTime; // shader playback time (in seconds)
uniform float iGlobalDelta; // ??
uniform float iGlobalFrame; // ??
uniform float iSampleRate; // ??
uniform float iTime; // ??
uniform int iFrame; // ??
uniform float iChannelTime[4]; // channel playback time (in seconds)
uniform vec2 iResolution; // viewport resolution (in pixels)
uniform vec3 iChannelResolution[4]; // channel resolution (in pixels)
uniform vec3 iOffset; // ?? (0,0,0)
uniform vec4 iMouse; // mouse pixel coords. xy: hover, zw: LMB click)
uniform vec4 iDate; // (year, month, day, time in seconds)
uniform sampler2D iChannel0; // input channel 0 /*sampler%s*/
uniform sampler2D iChannel1; // input channel 1
uniform sampler2D iChannel2; // input channel 2
uniform sampler2D iChannel3; // input channel 3
in vec2 texCoord;
out vec4 fragColor;
void mainImage( out vec4 fragColor, in vec2 fragCoord );
void main() {
mainImage(fragColor, texCoord.xy);
}

View File

@ -0,0 +1,10 @@
#version 130
uniform vec2 iResolution; // viewport resolution (in pixels)
out vec2 texCoord;
void main() {
texCoord = vec2( (gl_VertexID << 1) & 2, gl_VertexID & 2 );
gl_Position = vec4( texCoord * 2.0 - 1.0, 0.0, 1.0 );
texCoord = texCoord * iResolution;
}

View File

@ -0,0 +1,11 @@
#version 130
uniform vec2 iResolution; // viewport resolution (in pixels)
out vec2 texCoord;
void main() {
texCoord = vec2( (gl_VertexID << 1) & 2, gl_VertexID & 2 );
gl_Position = vec4( texCoord * 2.0 - 1.0, 0.0, 1.0 );
texCoord = texCoord * iResolution;
texCoord.y = iResolution.y - texCoord.y; // flip Y
}

View File

@ -2545,28 +2545,6 @@ unsigned char *pixels;
int fx_find(const char *name); int fx_find(const char *name);
void* screenshot(int components); void* screenshot(int components);
void* screenshot_async(int components); void* screenshot_async(int components);
extern const char *const fs_0_0_shadowmap_lit;
extern const char *const fs_0_0_shadowmap_unlit;
extern const char *const fs_24_4_sprite;
extern const char *const fs_2_4_preamble;
extern const char *const fs_2_4_texel_inv_gamma;
extern const char *const fs_2_4_texel_ycbr_gamma_saturation;
extern const char *const fs_32_4_model;
extern const char *const fs_32_4_model_basic;
extern const char *const fs_3_4_skybox;
extern const char *const fs_3_4_skybox_rayleigh;
extern const char *const fs_main_shadertoy;
extern const char *const fs_shadow_blur;
extern const char *const fs_shadow_vsm;
extern const char *const vs_0_2_fullscreen_quad_A;
extern const char *const vs_0_2_fullscreen_quad_B;
extern const char *const vs_0_2_fullscreen_quad_B_flipped;
extern const char *const vs_323444143_16_332_model;
extern const char *const vs_324_24_sprite;
extern const char *const vs_332_32;
extern const char *const vs_3_3_skybox;
extern const char *const vs_shadow_blur;
extern const char *const vs_shadow_vsm;
void ddraw_color(unsigned rgb); void ddraw_color(unsigned rgb);
void ddraw_color_push(unsigned rgb); void ddraw_color_push(unsigned rgb);
void ddraw_color_pop(); void ddraw_color_pop();

View File

@ -16814,31 +16814,6 @@ API void* screenshot(int components); // 3 RGB, 4 RGBA, -3 BGR, -4 BGRA
API void* screenshot_async(int components); // 3 RGB, 4 RGBA, -3 BGR, -4 BGRA API void* screenshot_async(int components); // 3 RGB, 4 RGBA, -3 BGR, -4 BGRA
#line 0 #line 0
#line 1 "v4k_shaders.h"
extern const char *const fs_0_0_shadowmap_lit;
extern const char *const fs_0_0_shadowmap_unlit;
extern const char *const fs_24_4_sprite;
extern const char *const fs_2_4_preamble;
extern const char *const fs_2_4_texel_inv_gamma;
extern const char *const fs_2_4_texel_ycbr_gamma_saturation;
extern const char *const fs_32_4_model;
extern const char *const fs_32_4_model_basic;
extern const char *const fs_3_4_skybox;
extern const char *const fs_3_4_skybox_rayleigh;
extern const char *const fs_main_shadertoy;
extern const char *const fs_shadow_blur;
extern const char *const fs_shadow_vsm;
extern const char *const vs_0_2_fullscreen_quad_A;
extern const char *const vs_0_2_fullscreen_quad_B;
extern const char *const vs_0_2_fullscreen_quad_B_flipped;
extern const char *const vs_323444143_16_332_model;
extern const char *const vs_324_24_sprite;
extern const char *const vs_332_32;
extern const char *const vs_3_3_skybox;
extern const char *const vs_shadow_blur;
extern const char *const vs_shadow_vsm;
#line 0
#line 1 "v4k_renderdd.h" #line 1 "v4k_renderdd.h"
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
// debugdraw framework // debugdraw framework
@ -339318,816 +339293,6 @@ void network_rpc_send(unsigned id, const char *cmdline) {
} }
#line 0 #line 0
#line 1 "v4k_shaders.c"
const char *const fs_0_0_shadowmap_lit = "//" FILELINE "\n"
"// uniform mat4 view = mat4(1.0);\n"
"uniform vec3 lightPos = vec3(1.0);\n"
"uniform float doTexture = 1.;\n"
#if VSMCUBE
"uniform samplerCube shadowMap; // VSMCUBE\n"
#else
"uniform sampler2D shadowMap; // !VSMCUBE\n"
#endif
"\n"
"\n"
"struct light {\n"
" vec3 position; // world-space\n"
" vec4 diffuse;\n"
" vec4 specular;\n"
" float constantAttenuation, linearAttenuation, quadraticAttenuation;\n"
" };\n"
" \n"
" light light0 = light(\n"
" lightPos,\n"
" vec4(1,1,1,1), // diffuse\n"
" vec4(1,1,1,1), // specular\n"
" 1.0, 0.0, 0.0 // attenuation (const, linear, quad)\n"
" );\n"
" \n"
" // From http://fabiensanglard.net/shadowmappingVSM/index.php\n"
#if VSMCUBE
" float chebyshevUpperBound(float distance, vec3 dir) {\n"
" distance = distance/20 ;\n"
" vec2 moments = texture(shadowMap, dir).rg;\n"
#else
" float chebyshevUpperBound(float distance, vec4 scPostW) {\n"
" vec2 moments = texture(shadowMap,scPostW.xy).rg;\n"
#endif
" // Surface is fully lit. as the current fragment is before the light occluder\n"
" if (distance <= moments.x)\n"
" return 1.0;\n"
" \n"
" // The fragment is either in shadow or penumbra. We now use chebyshev's upperBound to check\n"
" // How likely this pixel is to be lit (p_max)\n"
" float variance = moments.y - (moments.x*moments.x);\n"
" //variance = max(variance, 0.000002);\n"
" variance = max(variance, 0.00002);\n"
" \n"
" float d = distance - moments.x;\n"
" float p_max = variance / (variance + d*d);\n"
" \n"
" return p_max;\n"
" }\n"
" \n"
" \n"
" vec4 shadowmap(in vec4 vpeye, in vec4 vneye, in vec2 uv, in vec4 sc) {\n"
#ifndef VSMCUBE
" return vec4(1.);\n"
#else
" vec3 fragment = vec3(vpeye);\n"
" vec3 normal = vec3(normalize(vneye));\n"
" vec3 viewDir = normalize(-fragment);\n"
" \n"
" // Lighting\n"
" // Convert to eye-space\n"
" vec3 light = vec3(view * vec4(light0.position, 1.0));\n"
" \n"
#if VSMCUBE
" // Vectors\n"
" vec3 fragmentToLight = light - fragment;\n"
" vec3 fragmentToLightDir = normalize(fragmentToLight);\n"
" \n"
" // Shadows\n"
" vec4 fragmentToLight_world = inverse(view) * vec4(fragmentToLightDir, 0.0);\n"
" float shadowFactor = chebyshevUpperBound(length(fragmentToLight), -fragmentToLight_world.xyz);\n"
#else
" // Shadows\n"
" vec4 scPostW = sc / sc.w;\n"
" scPostW = scPostW * 0.5 + 0.5;\n"
" \n"
" float shadowFactor = 1.0; // Not in shadow\n"
" \n"
" bool outsideShadowMap = sc.w <= 0.0f || (scPostW.x < 0 || scPostW.y < 0) || (scPostW.x >= 1 || scPostW.y >= 1);\n"
" if (!outsideShadowMap) {\n"
" shadowFactor = chebyshevUpperBound(scPostW.z, scPostW);\n"
" }\n"
#endif
" \n"
" vec4 diffColor = vec4(1,1,1,1);\n"
#if VSMCUBE
" if(doTexture != 0) diffColor = vec4(vec3(texture(shadowMap, -fragmentToLight_world.xyz).r), 1.0);\n"
#else
" if(doTexture != 0) diffColor = vec4(vec3(texture(shadowMap, vec2(uv.x, 1.0 - uv.y)).r), 1.0);\n"
#endif
" \n"
#if 1
" vec3 positionToLight = light - fragment;\n"
" vec3 lightDir = normalize(positionToLight);\n"
" \n"
" // Angle between fragment-normal and incoming light\n"
" float cosAngIncidence = dot(lightDir, normal);\n"
" cosAngIncidence = clamp(cosAngIncidence, 0, 1);\n"
" \n"
" float attenuation = 1.0f;\n"
" attenuation = 1.0 / (light0.constantAttenuation + light0.linearAttenuation * length(positionToLight) + light0.quadraticAttenuation * pow(length(positionToLight),2));\n"
" \n"
" vec4 diffuse = diffColor * light0.diffuse * cosAngIncidence * attenuation;\n"
" \n"
" vec4 total_lighting;\n"
" total_lighting += vec4(0.1, 0.1, 0.1, 1.0) * diffColor; // Ambient\n"
" total_lighting += diffuse * shadowFactor; // Diffuse\n"
#else
" vec4 total_lighting = diffColor;\n"
#endif
" return vec4(clamp(vec3(total_lighting), 0., 1.), 1.0);\n"
#endif
" }\n";
const char *const fs_0_0_shadowmap_unlit = "//" FILELINE "\n"
"// uniform mat4 view = mat4(1.0);\n"
"uniform vec3 lightPos = vec3(1.0);\n"
"uniform float doTexture = 0.;\n"
"uniform sampler2D shadowMap;\n"
"\n"
"\n"
"vec4 shadowmap(in vec4 vpeye, in vec4 vneye, in vec2 Texcoord, in vec4 sc) {\n"
" return vec4(1.);\n"
" };\n";
const char *const fs_24_4_sprite = "//" FILELINE "\n"
"uniform sampler2D u_texture;\n"
"\n"
"\n"
"in vec2 vTexCoord;\n"
"in vec4 vColor;\n"
"out vec4 fragColor;\n"
"\n"
"\n"
"// [src] https://www.shadertoy.com/view/MllBWf CC1.0\n"
"vec4 texture_AA(sampler2D tx, vec2 uv) {\n"
" vec2 res = vec2(textureSize(tx, 0));\n"
" uv = uv*res + 0.5;\n"
" // tweak fractionnal value of the texture coordinate\n"
" vec2 fl = floor(uv);\n"
" vec2 fr = fract(uv);\n"
" vec2 aa = fwidth(uv)*0.75;\n"
" fr = smoothstep( vec2(0.5)-aa, vec2(0.5)+aa, fr);\n"
" // return value\n"
" uv = (fl+fr-0.5) / res;\n"
" return texture(tx, uv);\n"
"}\n"
"\n"
"\n"
"// [src] https://www.shadertoy.com/view/MllBWf CC1.0\n"
"vec4 texture_AA2( sampler2D tex, vec2 uv) {\n"
" vec2 res = vec2(textureSize(tex,0));\n"
" uv = uv*res;\n"
" vec2 seam = floor(uv+0.5);\n"
" uv = seam + clamp( (uv-seam)/fwidth(uv), -0.5, 0.5);\n"
" return texture(tex, uv/res);\n"
"}\n"
"\n"
"\n"
"// [src] https://www.shadertoy.com/view/ltBfRD\n"
"vec4 texture_AA3(sampler2D tex, vec2 uv) {\n"
" vec2 res = vec2(textureSize(tex,0));\n"
" float width = 2.0;\n"
" uv = uv * res;\n"
" // ---\n"
" vec2 uv_floor = floor(uv + 0.5);\n"
" vec2 uv_fract = fract(uv + 0.5);\n"
" vec2 uv_aa = fwidth(uv) * width * 0.5;\n"
" uv_fract = smoothstep(\n"
" vec2(0.5) - uv_aa,\n"
" vec2(0.5) + uv_aa,\n"
" uv_fract\n"
" );\n"
" uv = (uv_floor + uv_fract - 0.5) / res;\n"
" return texture(tex, uv);\n"
"}\n"
"\n"
"\n"
"void main() {\n"
" vec4 texColor = texture_AA2(u_texture, vTexCoord);\n"
" if(texColor.a < 0.9) discard;\n"
" fragColor = vColor * texColor;\n"
"}\n";
const char *const fs_2_4_preamble = "//" FILELINE "\n"
"#define texture2D texture\n"
"#define texture2DLod textureLod\n"
"#define FRAGCOLOR fragColor\n"
"#define texcoord uv\n"
"#define TEXCOORD uv\n"
"uniform sampler2D iChannel0;\n"
"uniform sampler2D iChannel1;\n"
"uniform float iWidth, iHeight, iTime, iFrame, iMousex, iMousey;\n"
"uniform float iChannelRes0x, iChannelRes0y;\n"
"uniform float iChannelRes1x, iChannelRes1y;\n"
"vec2 iResolution = vec2(iWidth, iHeight);\n"
"vec2 iMouse = vec2(iMousex, iMousey);\n"
"vec2 iChannelResolution[2] = vec2[2]( vec2(iChannelRes0x, iChannelRes0y),vec2(iChannelRes1x, iChannelRes1y) );\n"
"float iGlobalTime = iTime;\n"
"in vec2 texcoord;\n"
"out vec4 fragColor;\n";
const char *const fs_2_4_texel_inv_gamma = "//" FILELINE "\n"
"uniform sampler2D texture0; /*unit0*/\n"
"uniform float u_inv_gamma;\n"
"\n"
"\n"
"in vec2 uv;\n"
"out vec4 fragcolor;\n"
"\n"
"\n"
"void main() {\n"
" vec4 texel = texture( texture0, uv );\n"
" fragcolor = texel;\n"
" fragcolor.rgb = pow( fragcolor.rgb, vec3( u_inv_gamma ) ); // defaults: 1.0/2.2 gamma\n"
"}\n";
const char *const fs_2_4_texel_ycbr_gamma_saturation = "//" FILELINE "\n"
"uniform sampler2D u_texture_y; /*unit0*/\n"
"uniform sampler2D u_texture_cb; /*unit1*/\n"
"uniform sampler2D u_texture_cr; /*unit2*/\n"
"uniform float u_gamma;\n"
"\n"
"\n"
"in vec2 uv;\n"
"out vec4 fragcolor;\n"
"\n"
"\n"
"void main() {\n"
" float y = texture(u_texture_y, uv).r;\n"
" float cb = texture(u_texture_cb, uv).r;\n"
" float cr = texture(u_texture_cr, uv).r;\n"
" \n"
" const mat4 to_rgb = mat4(\n"
" 1.0000, 1.0000, 1.0000, 0.0000,\n"
" 0.0000, -0.3441, 1.7720, 0.0000,\n"
" 1.4020, -0.7141, 0.0000, 0.0000,\n"
" -0.7010, 0.5291, -0.8860, 1.0000\n"
" );\n"
" vec4 texel = to_rgb * vec4(y, cb, cr, 1.0);\n"
" /* same as:\n"
" vec3 yCbCr = vec3(y,cb-0.5,cr-0.5);\n"
" vec4 texel = vec4( dot( vec3( 1.0, 0.0, 1.402 ), yCbCr ),\n"
" dot( vec3( 1.0 , -0.34414 , -0.71414 ), yCbCr ),\n"
" dot( vec3( 1.0, 1.772, 0.0 ), yCbCr ), 1.0);\n"
" */\n"
" // gamma correction\n"
" texel.rgb = pow(texel.rgb, vec3(1.0 / u_gamma));\n"
" \n"
" // saturation (algorithm from Chapter 16 of OpenGL Shading Language)\n"
" if(false) { float saturation = 2.0; const vec3 W = vec3(0.2125, 0.7154, 0.0721);\n"
" vec3 intensity = vec3(dot(texel.rgb, W));\n"
"texel.rgb = mix(intensity, texel.rgb, saturation); }\n"
"\n"
"\n"
"fragcolor = vec4(texel.rgb, 1.0);\n"
"}\n";
const char *const fs_32_4_model = "//" FILELINE "\n"
"uniform mat4 model, view;\n"
"uniform sampler2D u_texture2d;\n"
"uniform vec3 u_coefficients_sh[9];\n"
"uniform bool u_textured = true;\n"
"uniform bool u_lit = false;\n"
"uniform bool u_matcaps = false;\n"
"uniform vec4 u_diffuse = vec4(1.0,1.0,1.0,1.0);\n"
"\n"
"\n"
#ifdef RIM
"in vec3 v_position;\n"
#endif
"in vec3 v_normal, v_normal_ws;\n"
"in vec2 v_texcoord;\n"
"in vec4 v_color;\n"
"out vec4 fragcolor;\n"
"\n"
"\n"
"{{include-shadowmap}}\n"
"in vec4 vpeye;\n"
"in vec4 vneye;\n"
"in vec4 sc;\n"
"vec4 shadowing() {\n"
"return shadowmap(vpeye, vneye, v_texcoord, sc);\n"
"}\n"
"\n"
"\n"
"void main() {\n"
"vec3 n = /*normalize*/(v_normal);\n"
"\n"
"\n"
"// SH lighting\n"
"vec4 lit = vec4(1.0, 1.0, 1.0, 1.0);\n"
"vec3 SHLightResult[9];\n"
"SHLightResult[0] = 0.282095f * u_coefficients_sh[0];\n"
"SHLightResult[1] = -0.488603f * u_coefficients_sh[1] * n.y;\n"
"SHLightResult[2] = 0.488603f * u_coefficients_sh[2] * n.z;\n"
"SHLightResult[3] = -0.488603f * u_coefficients_sh[3] * n.x;\n"
"SHLightResult[4] = 1.092548f * u_coefficients_sh[4] * n.x * n.y;\n"
"SHLightResult[5] = -1.092548f * u_coefficients_sh[5] * n.y * n.z;\n"
"SHLightResult[6] = 0.315392f * u_coefficients_sh[6] * (3.0f * n.z * n.z - 1.0f);\n"
"SHLightResult[7] = -1.092548f * u_coefficients_sh[7] * n.x * n.z;\n"
"SHLightResult[8] = 0.546274f * u_coefficients_sh[8] * (n.x * n.x - n.y * n.y);\n"
"vec3 result = vec3(0.0);\n"
"for (int i = 0; i < 9; ++i)\n"
"result += SHLightResult[i];\n"
"\n"
"if( (result.x*result.x+result.y*result.y+result.z*result.z) > 0.0 ) lit = vec4(result, 1.0);\n"
"\n"
"\n"
"// base\n"
"vec4 diffuse;\n"
"if(u_matcaps) {\n"
" vec2 muv = vec2(view * vec4(v_normal_ws, 0))*0.5+vec2(0.5,0.5); // normal (model space) to view space\n"
" diffuse = texture(u_texture2d, vec2(muv.x, 1.0-muv.y));\n"
" } else if(u_textured) {\n"
" diffuse = texture(u_texture2d, v_texcoord);\n"
" } else {\n"
" diffuse = u_diffuse; // * v_color;\n"
" }\n"
" \n"
" // lighting mix\n"
" fragcolor = diffuse * lit * shadowing();\n"
" \n"
" // rimlight\n"
#ifdef RIM
" {vec3 n = normalize(mat3(M) * v_normal); // convert normal to view space\n"
" vec3 p = (M * vec4(v_position,1.0)).xyz; // convert position to view space\n"
" vec3 v = normalize(-p); // eye vector\n"
" float rim = 1.0 - max(dot(v, n), 0.0); // rimlight\n"
" rim = smoothstep(1.0-0.01, 1.0, rim); // intensity (0.01)\n"
" fragcolor += vec4(0.0, 0.0, rim, 1.0);} // blue\n"
#endif
" }\n";
const char *const fs_32_4_model_basic = "//" FILELINE "\n"
"uniform sampler2D fsDiffTex;\n"
"uniform sampler2D fsNormalTex;\n"
"uniform sampler2D fsPositionTex;\n"
"uniform mat4 MVP;\n"
"\n"
"\n"
"in vec3 v_normal;\n"
"in vec2 v_texcoord;\n"
"out vec4 fragColor;\n"
"\n"
"\n"
"void main() {\n"
" vec4 diff = texture(fsDiffTex, v_texcoord).rgba;\n"
" vec3 n = normalize(mat3(MVP) * v_normal); // transform normal to eye space\n"
" fragColor = diff;// * vec4(v_normal.xyz, 1);\n"
"}\n";
const char *const fs_3_4_skybox = "//" FILELINE "\n"
"uniform samplerCube u_cubemap;\n"
"\n"
"\n"
"in vec3 v_direction;\n"
"out vec4 fragcolor;\n"
"\n"
"\n"
"void main() {\n"
" fragcolor = vec4(texture(u_cubemap, v_direction).rgb, 1.0);\n"
"}\n";
const char *const fs_3_4_skybox_rayleigh = "//" FILELINE "\n"
"uniform vec3 uSunPos = vec3( 0, 0.1, -1 ); // = [0, Math.cos(theta) * 0.3 + 0.2, -1];\n"
"\n"
"\n"
"in vec3 v_direction;\n"
"out vec4 fragcolor;\n"
"\n"
"\n"
"vec3 atmosphere(vec3 r, vec3 r0, vec3 pSun, float iSun, float rPlanet, float rAtmos, vec3 kRlh, float kMie, float shRlh, float shMie, float g);\n"
"\n"
"\n"
"void main() {\n"
" vec3 color = atmosphere(\n"
" normalize(v_direction), // normalized ray direction\n"
" vec3(0,6372e3,0), // ray origin\n"
" uSunPos, // position of the sun\n"
" 22.0, // intensity of the sun\n"
" 6371e3, // radius of the planet in meters\n"
" 6471e3, // radius of the atmosphere in meters\n"
" vec3(5.5e-6, 13.0e-6, 22.4e-6), // Rayleigh scattering coefficient\n"
" 21e-6, // Mie scattering coefficient\n"
" 8e3, // Rayleigh scale height\n"
" 1.2e3, // Mie scale height\n"
" 0.758 // Mie preferred scattering direction\n"
" );\n"
" \n"
" // Apply exposure.\n"
" color = 1.0 - exp(-1.0 * color);\n"
" \n"
" fragcolor = vec4(color, 1);\n"
"}\n"
"\n"
"\n"
"// [src] https://github.com/wwwtyro/glsl-atmosphere by wwwtyro (Unlicensed)\n"
"// For more information, please refer to <http://unlicense.org>\n"
"\n"
"\n"
"#define PI 3.141592\n"
"#define iSteps 16\n"
"#define jSteps 8\n"
"\n"
"\n"
"vec2 rsi(vec3 r0, vec3 rd, float sr) {\n"
" // ray-sphere intersection that assumes\n"
" // the sphere is centered at the origin.\n"
" // No intersection when result.x > result.y\n"
" float a = dot(rd, rd);\n"
" float b = 2.0 * dot(rd, r0);\n"
" float c = dot(r0, r0) - (sr * sr);\n"
" float d = (b*b) - 4.0*a*c;\n"
" if (d < 0.0) return vec2(1e5,-1e5);\n"
" return vec2(\n"
" (-b - sqrt(d))/(2.0*a),\n"
" (-b + sqrt(d))/(2.0*a)\n"
" );\n"
"}\n"
"\n"
"\n"
"vec3 atmosphere(vec3 r, vec3 r0, vec3 pSun, float iSun, float rPlanet, float rAtmos, vec3 kRlh, float kMie, float shRlh, float shMie, float g) {\n"
" // Normalize the sun and view directions.\n"
" pSun = normalize(pSun);\n"
" r = normalize(r);\n"
" \n"
" // Calculate the step size of the primary ray.\n"
" vec2 p = rsi(r0, r, rAtmos);\n"
" if (p.x > p.y) return vec3(0,0,0);\n"
" p.y = min(p.y, rsi(r0, r, rPlanet).x);\n"
" float iStepSize = (p.y - p.x) / float(iSteps);\n"
" \n"
" // Initialize the primary ray time.\n"
" float iTime = 0.0;\n"
" \n"
" // Initialize accumulators for Rayleigh and Mie scattering.\n"
" vec3 totalRlh = vec3(0,0,0);\n"
" vec3 totalMie = vec3(0,0,0);\n"
" \n"
" // Initialize optical depth accumulators for the primary ray.\n"
" float iOdRlh = 0.0;\n"
" float iOdMie = 0.0;\n"
" \n"
" // Calculate the Rayleigh and Mie phases.\n"
" float mu = dot(r, pSun);\n"
" float mumu = mu * mu;\n"
" float gg = g * g;\n"
" float pRlh = 3.0 / (16.0 * PI) * (1.0 + mumu);\n"
" float pMie = 3.0 / (8.0 * PI) * ((1.0 - gg) * (mumu + 1.0)) / (pow(1.0 + gg - 2.0 * mu * g, 1.5) * (2.0 + gg));\n"
" \n"
" // Sample the primary ray.\n"
" for (int i = 0; i < iSteps; i++) {\n"
" \n"
" // Calculate the primary ray sample position.\n"
" vec3 iPos = r0 + r * (iTime + iStepSize * 0.5);\n"
" \n"
" // Calculate the height of the sample.\n"
" float iHeight = length(iPos) - rPlanet;\n"
" \n"
" // Calculate the optical depth of the Rayleigh and Mie scattering for this step.\n"
" float odStepRlh = exp(-iHeight / shRlh) * iStepSize;\n"
" float odStepMie = exp(-iHeight / shMie) * iStepSize;\n"
" \n"
" // Accumulate optical depth.\n"
" iOdRlh += odStepRlh;\n"
" iOdMie += odStepMie;\n"
" \n"
" // Calculate the step size of the secondary ray.\n"
" float jStepSize = rsi(iPos, pSun, rAtmos).y / float(jSteps);\n"
" \n"
" // Initialize the secondary ray time.\n"
" float jTime = 0.0;\n"
" \n"
" // Initialize optical depth accumulators for the secondary ray.\n"
" float jOdRlh = 0.0;\n"
" float jOdMie = 0.0;\n"
" \n"
" // Sample the secondary ray.\n"
" for (int j = 0; j < jSteps; j++) {\n"
" \n"
" // Calculate the secondary ray sample position.\n"
" vec3 jPos = iPos + pSun * (jTime + jStepSize * 0.5);\n"
" \n"
" // Calculate the height of the sample.\n"
" float jHeight = length(jPos) - rPlanet;\n"
" \n"
" // Accumulate the optical depth.\n"
" jOdRlh += exp(-jHeight / shRlh) * jStepSize;\n"
" jOdMie += exp(-jHeight / shMie) * jStepSize;\n"
" \n"
" // Increment the secondary ray time.\n"
" jTime += jStepSize;\n"
" }\n"
" \n"
" // Calculate attenuation.\n"
" vec3 attn = exp(-(kMie * (iOdMie + jOdMie) + kRlh * (iOdRlh + jOdRlh)));\n"
" \n"
" // Accumulate scattering.\n"
" totalRlh += odStepRlh * attn;\n"
" totalMie += odStepMie * attn;\n"
" \n"
" // Increment the primary ray time.\n"
" iTime += iStepSize;\n"
" \n"
" }\n"
" \n"
" // Calculate and return the final color.\n"
" return iSun * (pRlh * kRlh * totalRlh + pMie * kMie * totalMie);\n"
"}\n";
const char *const fs_main_shadertoy = "//" FILELINE "\n"
"void mainImage( out vec4 fragColor, in vec2 fragCoord );\n"
"void main() {\n"
" mainImage(fragColor, texcoord.xy * iResolution);\n"
"}\n";
const char *const fs_shadow_blur = "//" FILELINE "\n"
"uniform sampler2D textureSource;\n"
"uniform vec2 ScaleU;\n"
"\n"
"in vec2 Texcoord;\n"
"out vec4 outColor;\n"
"\n"
"void main() {\n"
" vec4 color = vec4(0.0);\n"
" color += texture( textureSource, Texcoord.st + vec2( -3.0*ScaleU.x, -3.0*ScaleU.y ) ) * 0.015625;\n"
" color += texture( textureSource, Texcoord.st + vec2( -2.0*ScaleU.x, -2.0*ScaleU.y ) )*0.09375;\n"
" color += texture( textureSource, Texcoord.st + vec2( -1.0*ScaleU.x, -1.0*ScaleU.y ) )*0.234375;\n"
" color += texture( textureSource, Texcoord.st + vec2( 0.0 , 0.0) )*0.3125;\n"
" color += texture( textureSource, Texcoord.st + vec2( 1.0*ScaleU.x, 1.0*ScaleU.y ) )*0.234375;\n"
" color += texture( textureSource, Texcoord.st + vec2( 2.0*ScaleU.x, 2.0*ScaleU.y ) )*0.09375;\n"
" color += texture( textureSource, Texcoord.st + vec2( 3.0*ScaleU.x, -3.0*ScaleU.y ) ) * 0.015625;\n"
" outColor = vec4(color.xyz, 1.0);\n"
"}\n";
const char *const fs_shadow_vsm = "//" FILELINE "\n"
"in vec4 v_position;\n"
"out vec4 outColor;\n"
"\n"
"void main() {\n"
#if VSMCUBE
" float depth = length( vec3(v_position) ) / 20;\n"
#else
" float depth = v_position.z / v_position.w;\n"
" depth = depth * 0.5 + 0.5;\n"
#endif
" \n"
" float moment1 = depth;\n"
" float moment2 = depth * depth;\n"
" \n"
" float dx = dFdx(depth);\n"
" float dy = dFdy(depth);\n"
" moment2 += 0.25*(dx*dx+dy*dy);\n"
" outColor = vec4( moment1, moment2, 0.0, 0.0);\n"
"}\n";
const char *const vs_0_2_fullscreen_quad_A = "//" FILELINE "\n"
"out vec2 texcoord;\n"
"\n"
"\n"
"void main() {\n"
" texcoord = vec2( (gl_VertexID << 1) & 2, gl_VertexID & 2 );\n"
" gl_Position = vec4( texCoord * 2.0 - 1.0, 0.0, 1.0 );\n"
"}\n";
const char *const vs_0_2_fullscreen_quad_B = "//" FILELINE "\n"
"out vec2 uv;\n"
"\n"
"\n"
"void main() {\n"
" float x = float(((uint(gl_VertexID) + 2u) / 3u)%2u);\n"
" float y = float(((uint(gl_VertexID) + 1u) / 3u)%2u);\n"
" gl_Position = vec4(-1.0 + x*2.0, 0.0+(-1.0+y*2.0), 0.0, 1.0); // normal(0+),flipped(0-)\n"
" uv = vec2(x, y); // normal(y),flipped(1.0-y)\n"
"}\n";
const char *const vs_0_2_fullscreen_quad_B_flipped = "//" FILELINE "\n"
"out vec2 uv;\n"
"\n"
"\n"
"void main() {\n"
" float x = float(((uint(gl_VertexID) + 2u) / 3u)%2u);\n"
" float y = float(((uint(gl_VertexID) + 1u) / 3u)%2u);\n"
" gl_Position = vec4(-1.0 + x*2.0, 0.0-(-1.0+y*2.0), 0.0, 1.0); // normal(0+),flipped(0-)\n"
" uv = vec2(x, y); // normal(y),flipped(1.0-y)\n"
"}\n";
const char *const vs_323444143_16_332_model = "//" FILELINE "\n"
#ifndef MAX_BONES
"#define MAX_BONES 110\n"
#endif
"uniform mat3x4 vsBoneMatrix[MAX_BONES];\n"
"uniform bool SKINNED = false;\n"
"// uniform mat4 M; // RIM\n"
"uniform mat4 VP;\n"
"\n"
"\n"
#if 0
"// Fetch blend channels from all attached blend deformers.\n"
"for (size_t di = 0; di < mesh->blend_deformers.count; di++) {\n"
" ufbx_blend_deformer *deformer = mesh->blend_deformers.data[di];\n"
" for (size_t ci = 0; ci < deformer->channels.count; ci++) {\n"
" ufbx_blend_channel *chan = deformer->channels.data[ci];\n"
" if (chan->keyframes.count == 0) continue;\n"
" if (num_blend_shapes < MAX_BLEND_SHAPES) {\n"
" blend_channels[num_blend_shapes] = chan;\n"
" vmesh->blend_channel_indices[num_blend_shapes] = (int32_t)chan->typed_id;\n"
" num_blend_shapes++;\n"
" }\n"
" }\n"
"}\n"
"if (num_blend_shapes > 0) {\n"
" vmesh->blend_shape_image = pack_blend_channels_to_image(mesh, blend_channels, num_blend_shapes);\n"
" vmesh->num_blend_shapes = num_blend_shapes;\n"
"}\n"
"\n"
"\n"
"ubo.f_num_blend_shapes = (float)mesh->num_blend_shapes;\n"
"for (size_t i = 0; i < mesh->num_blend_shapes; i++) {\n"
" ubo.blend_weights[i] = view->scene.blend_channels[mesh->blend_channel_indices[i]].weight;\n"
"}\n"
"\n"
"\n"
"sg_image blend_shapes = mesh->num_blend_shapes > 0 ? mesh->blend_shape_image : view->empty_blend_shape_image;\n"
#endif
"\n"
"\n"
"// for blendshapes\n"
#ifndef MAX_BLENDSHAPES
"#define MAX_BLENDSHAPES 16\n"
#endif
"uniform vec4 blend_weights[MAX_BLENDSHAPES]; // @todo: implement me\n"
"uniform float f_num_blend_shapes; // @todo: implement me\n"
"uniform sampler2DArray blend_shapes; // @todo: implement me\n"
"\n"
"\n"
"in vec3 att_position; // @todo: reorder ass2iqe to emit p3 n3 u2 t3 b3 c4B i4 w4 instead\n"
"in vec2 att_texcoord;\n"
"in vec3 att_normal;\n"
"in vec4 att_tangent; // vec3 + bi sign\n"
"in mat4 att_instanced_matrix; // for instanced rendering\n"
"in vec4 att_indexes; // @fixme: gles might use ivec4 instead?\n"
"in vec4 att_weights; // @todo: downgrade from float to byte\n"
"in float att_vertexindex; // for blendshapes\n"
"in vec4 att_color;\n"
"in vec3 att_bitangent; // @todo: remove? also, ass2iqe might output this\n"
"out vec4 v_color;\n"
"out vec3 v_position;\n"
"out vec3 v_normal, v_normal_ws;\n"
"out vec2 v_texcoord;\n"
"\n"
"\n"
"\n"
"\n"
"// shadow\n"
"uniform mat4 model, view;\n"
"uniform mat4 cameraToShadowProjector;\n"
"out vec4 vneye;\n"
"out vec4 vpeye;\n"
"out vec4 sc;\n"
"void do_shadow() {\n"
" vneye = view * model * vec4(att_normal, 0.0f);\n"
" vpeye = view * model * vec4(att_position, 1.0);\n"
" sc = cameraToShadowProjector * model * vec4(att_position, 1.0f);\n"
"}\n"
"\n"
"\n"
"// blendshapes\n"
"vec3 evaluate_blend_shape(int vertex_index) {\n"
" ivec2 coord = ivec2(vertex_index & (2048 - 1), vertex_index >> 11);\n"
" int num_blend_shapes = int(f_num_blend_shapes);\n"
" vec3 offset = vec3(0.0);\n"
" for (int i = 0; i < num_blend_shapes; i++) {\n"
" vec4 packedw = blend_weights[i >> 2];\n"
" float weight = packedw[i & 3];\n"
" offset += weight * texelFetch(blend_shapes, ivec3(coord, i), 0).xyz;\n"
" }\n"
" return offset;\n"
"}\n"
"\n"
"\n"
"void main() {\n"
" vec3 objPos;\n"
" if(!SKINNED) {\n"
" objPos = att_position;\n"
" v_normal = att_normal;\n"
" } else {\n"
" mat3x4 m = vsBoneMatrix[int(att_indexes.x)] * att_weights.x;\n"
" m += vsBoneMatrix[int(att_indexes.y)] * att_weights.y;\n"
" m += vsBoneMatrix[int(att_indexes.z)] * att_weights.z;\n"
" m += vsBoneMatrix[int(att_indexes.w)] * att_weights.w;\n"
" objPos = vec4(att_position, 1.0) * m;\n"
" \n"
" // blendshapes\n"
" // objPos += evaluate_blend_shape(int(att_vertexindex));\n"
" \n"
" v_normal = vec4(att_normal, 0.0) * m;\n"
" //@todo: tangents\n"
" }\n"
" \n"
" // vec3 tangent = att_tangent.xyz;\n"
" // vec3 bitangent = cross(att_normal, att_tangent.xyz) * att_tangent.w;\n"
" \n"
" v_normal_ws = normalize(vec3(model * vec4(v_normal, 0.))); // normal to world/model space\n"
" v_normal = normalize(v_normal);\n"
" v_position = att_position;\n"
" v_texcoord = att_texcoord;\n"
" v_color = att_color;\n"
" gl_Position = VP * att_instanced_matrix * vec4( objPos, 1.0 );\n"
" do_shadow();\n"
" }\n";
const char *const vs_324_24_sprite = "//" FILELINE "\n"
"uniform mat4 u_mvp;\n"
"\n"
"\n"
"in vec3 att_Position;\n"
"in vec2 att_TexCoord;\n"
"in vec4 att_Color;\n"
"out vec2 vTexCoord;\n"
"out vec4 vColor;\n"
"\n"
"\n"
"void main() {\n"
" vColor = att_Color;\n"
" vTexCoord = att_TexCoord;\n"
" gl_Position = u_mvp * vec4(att_Position, 1.0);\n"
"}\n";
const char *const vs_332_32 = "//" FILELINE "\n"
"uniform mat4 u_mvp;\n"
"\n"
"\n"
"in vec3 att_position;\n"
"in vec3 att_normal;\n"
"in vec2 att_texcoord;\n"
"in vec4 att_color;\n"
"out vec4 v_color;\n"
"out vec3 v_normal;\n"
"out vec3 v_normal_ws;\n"
"out vec2 v_texcoord;\n"
"\n"
"\n"
"// shadow\n"
"uniform mat4 model, view, proj;\n"
"uniform mat4 cameraToShadowProjector; // !VSMCUBE\n"
"out vec4 vneye;\n"
"out vec4 vpeye;\n"
"out vec4 sc; // !VSMCUBE\n"
"void do_shadow() {\n"
" vneye = view * model * vec4(att_normal, 0.0f);\n"
" vpeye = view * model * vec4(att_position, 1.0);\n"
" sc = cameraToShadowProjector * model * vec4(att_position, 1.0f);\n"
"}\n"
"\n"
"\n"
"void main() {\n"
" gl_Position = u_mvp * vec4(att_position, 1.0);\n"
" v_normal = normalize(att_normal);\n"
" v_normal_ws = normalize(vec3(model * vec4(att_normal, 0.))); // normal world/model space\n"
" v_texcoord = att_texcoord;\n"
" v_color = att_color;\n"
" do_shadow();\n"
"}\n";
const char *const vs_3_3_skybox = "//" FILELINE "\n"
"uniform mat4 u_mvp;\n"
"\n"
"\n"
"in vec3 att_position;\n"
"out vec3 v_direction;\n"
"\n"
"\n"
"void main() {\n"
" vec4 position = u_mvp * vec4(att_position, 0.0);\n"
" gl_Position = position.xyww;\n"
" v_direction = att_position;\n"
"}\n";
const char *const vs_shadow_blur = "//" FILELINE "\n"
"in vec3 position;\n"
"in vec2 texcoord;\n"
"out vec2 Texcoord;\n"
"\n"
"void main() {\n"
" gl_Position = vec4(position, 1.0);\n"
" Texcoord = texcoord;\n"
"}\n";
const char *const vs_shadow_vsm = "//" FILELINE "\n"
"uniform mat4 model;\n"
"uniform mat4 cameraToShadowView;\n"
"uniform mat4 cameraToShadowProjector;\n"
"\n"
"in vec3 position;\n"
"out vec4 v_position;\n"
"\n"
"void main() {\n"
" gl_Position = cameraToShadowProjector * model * vec4(position, 1.0);\n"
#if VSMCUBE
" v_position = cameraToShadowView * model * vec4(position, 1.0);\n"
#else
" v_position = gl_Position;\n"
#endif
"}\n";
#line 0
#line 1 "v4k_render.c" #line 1 "v4k_render.c"
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
// opengl // opengl
@ -341163,8 +340328,8 @@ void shadowmatrix_ortho(mat44 shm_proj, float left, float right, float bottom, f
void fullscreen_quad_rgb( texture_t texture, float gamma ) { void fullscreen_quad_rgb( texture_t texture, float gamma ) {
static int program = -1, vao = -1, u_inv_gamma = -1; static int program = -1, vao = -1, u_inv_gamma = -1;
if( program < 0 ) { if( program < 0 ) {
const char* vs = vs_0_2_fullscreen_quad_B_flipped; const char* vs = vfs_read("shaders/vs_0_2_fullscreen_quad_B_flipped.glsl");
const char* fs = fs_2_4_texel_inv_gamma; const char* fs = vfs_read("shaders/fs_2_4_texel_inv_gamma.glsl");
program = shader(vs, fs, "", "fragcolor" ); program = shader(vs, fs, "", "fragcolor" );
u_inv_gamma = glGetUniformLocation(program, "u_inv_gamma"); u_inv_gamma = glGetUniformLocation(program, "u_inv_gamma");
@ -341194,8 +340359,8 @@ void fullscreen_quad_rgb( texture_t texture, float gamma ) {
void fullscreen_quad_ycbcr( texture_t textureYCbCr[3], float gamma ) { void fullscreen_quad_ycbcr( texture_t textureYCbCr[3], float gamma ) {
static int program = -1, vao = -1, u_gamma = -1, uy = -1, ucb = -1, ucr = -1; static int program = -1, vao = -1, u_gamma = -1, uy = -1, ucb = -1, ucr = -1;
if( program < 0 ) { if( program < 0 ) {
const char* vs = vs_0_2_fullscreen_quad_B_flipped; const char* vs = vfs_read("shaders/vs_0_2_fullscreen_quad_B_flipped.glsl");
const char* fs = fs_2_4_texel_ycbr_gamma_saturation; const char* fs = vfs_read("shaders/fs_2_4_texel_ycbr_gamma_saturation.glsl");
program = shader(vs, fs, "", "fragcolor" ); program = shader(vs, fs, "", "fragcolor" );
u_gamma = glGetUniformLocation(program, "u_gamma"); u_gamma = glGetUniformLocation(program, "u_gamma");
@ -341486,7 +340651,7 @@ static void sprite_render_meshes() {
return; return;
if( sprite_program < 0 ) { if( sprite_program < 0 ) {
sprite_program = shader( vs_324_24_sprite, fs_24_4_sprite, sprite_program = shader( vfs_read("shaders/vs_324_24_sprite.glsl"), vfs_read("shaders/fs_24_4_sprite.glsl"),
"att_Position,att_TexCoord,att_Color", "att_Position,att_TexCoord,att_Color",
"fragColor" "fragColor"
); );
@ -342503,8 +341668,8 @@ skybox_t skybox(const char *asset, int flags) {
// sky program // sky program
sky.flags = flags ? flags : !!asset; // either cubemap or rayleigh sky.flags = flags ? flags : !!asset; // either cubemap or rayleigh
sky.program = shader(vs_3_3_skybox, sky.program = shader(vfs_read("shaders/vs_3_3_skybox.glsl"),
sky.flags ? fs_3_4_skybox : fs_3_4_skybox_rayleigh, sky.flags ? vfs_read("fs_3_4_skybox.glsl") : vfs_read("shaders/fs_3_4_skybox_rayleigh.glsl"),
"att_position", "fragcolor"); "att_position", "fragcolor");
// sky cubemap & SH // sky cubemap & SH
@ -343044,14 +342209,14 @@ int postfx_load_from_mem( postfx *fx, const char *name, const char *fs ) {
passfx *p = &fx->pass[ slot & 63 ]; passfx *p = &fx->pass[ slot & 63 ];
p->name = STRDUP(name); p->name = STRDUP(name);
const char *vs = vs_0_2_fullscreen_quad_B; const char *vs = vfs_read("shaders/vs_0_2_fullscreen_quad_B.glsl");
// patch fragment // patch fragment
char *fs2 = (char*)CALLOC(1, 128*1024); char *fs2 = (char*)CALLOC(1, 128*1024);
strcat(fs2, fs_2_4_preamble); strcat(fs2, vfs_read("shaders/fs_2_4_preamble.glsl"));
if( strstr(fs, "mainImage") ) { if( strstr(fs, "mainImage") ) {
strcat(fs2, fs_main_shadertoy ); strcat(fs2, vfs_read("shaders/fs_main_shadertoy.glsl") );
} }
strcat(fs2, fs); strcat(fs2, fs);
@ -343413,52 +342578,8 @@ shadertoy_t shadertoy( const char *shaderfile, unsigned flags ) {
glGenVertexArrays(1, &s.vao); glGenVertexArrays(1, &s.vao);
// Uses gl_VertexID to draw a fullscreen quad without vbo char *fs = stringf("%s%s", vfs_read("header_shadertoy.glsl"), file);
const char *vs = "#version 130\n" s.program = shader(flags ? vfs_read("shaders/vs_shadertoy_flip.glsl") : vfs_read("shaders/vs_shadertoy.glsl"), fs, "", "fragColor");
"uniform vec2 iResolution; // viewport resolution (in pixels)\n"
"out vec2 texCoord;\n"
"void main() {\n"
" texCoord = vec2( (gl_VertexID << 1) & 2, gl_VertexID & 2 );\n"
" gl_Position = vec4( texCoord * 2.0 - 1.0, 0.0, 1.0 );\n"
" texCoord = texCoord * iResolution;\n"
"}\n";
const char *vs_flip = "#version 130\n"
"uniform vec2 iResolution; // viewport resolution (in pixels)\n"
"out vec2 texCoord;\n"
"void main() {\n"
" texCoord = vec2( (gl_VertexID << 1) & 2, gl_VertexID & 2 );\n"
" gl_Position = vec4( texCoord * 2.0 - 1.0, 0.0, 1.0 );\n"
" texCoord = texCoord * iResolution;\n"
" texCoord.y = iResolution.y - texCoord.y; // flip Y\n"
"}\n";
const char *header = "#version 130\n"
"#define texture2D texture\n"
"uniform float iGlobalTime; // shader playback time (in seconds)\n"
"uniform float iGlobalDelta; // ??\n"
"uniform float iGlobalFrame; // ??\n"
"uniform float iSampleRate; // ??\n"
"uniform float iTime; // ??\n"
"uniform int iFrame; // ??\n"
"uniform float iChannelTime[4]; // channel playback time (in seconds)\n"
"uniform vec2 iResolution; // viewport resolution (in pixels)\n"
"uniform vec3 iChannelResolution[4]; // channel resolution (in pixels)\n"
"uniform vec3 iOffset; // ?? (0,0,0)\n"
"uniform vec4 iMouse; // mouse pixel coords. xy: hover, zw: LMB click)\n"
"uniform vec4 iDate; // (year, month, day, time in seconds)\n"
"uniform sampler2D iChannel0; // input channel 0\n" /*sampler%s*/
"uniform sampler2D iChannel1; // input channel 1\n"
"uniform sampler2D iChannel2; // input channel 2\n"
"uniform sampler2D iChannel3; // input channel 3\n"
"in vec2 texCoord;\n"
"out vec4 fragColor;\n"
"void mainImage( out vec4 fragColor, in vec2 fragCoord );\n"
"void main() {\n"
" mainImage(fragColor, texCoord.xy);\n"
"}\n";
char *fs = stringf("%s%s", header, file);
s.program = shader(flags ? vs_flip : vs, fs, "", "fragColor");
FREE(fs); FREE(fs);
if( strstr(file, "noise3.jpg")) if( strstr(file, "noise3.jpg"))
@ -344167,8 +343288,8 @@ model_t model_from_mem(const void *mem, int len, int flags) {
const char *ptr = (const char *)mem; const char *ptr = (const char *)mem;
static int shaderprog = -1; static int shaderprog = -1;
if( shaderprog < 0 ) { if( shaderprog < 0 ) {
const char *symbols[] = { "{{include-shadowmap}}", fs_0_0_shadowmap_lit }; // #define RIM const char *symbols[] = { "{{include-shadowmap}}", vfs_read("shaders/fs_0_0_shadowmap_lit.glsl") }; // #define RIM
shaderprog = shader(strlerp(1,symbols,vs_323444143_16_332_model), strlerp(1,symbols,fs_32_4_model), //fs, shaderprog = shader(strlerp(1,symbols,vfs_read("shaders/vs_323444143_16_332_model.glsl")), strlerp(1,symbols,vfs_read("shaders/fs_32_4_model.glsl")), //fs,
"att_position,att_texcoord,att_normal,att_tangent,att_instanced_matrix,,,,att_indexes,att_weights,att_vertexindex,att_color,att_bitangent","fragColor"); "att_position,att_texcoord,att_normal,att_tangent,att_instanced_matrix,,,,att_indexes,att_weights,att_vertexindex,att_color,att_bitangent","fragColor");
} }
@ -345645,8 +344766,8 @@ scene_t* scene_get_active() {
scene_t* scene_push() { scene_t* scene_push() {
scene_t *s = REALLOC(0, sizeof(scene_t)), clear = {0}; *s = clear; scene_t *s = REALLOC(0, sizeof(scene_t)), clear = {0}; *s = clear;
const char *symbols[] = { "{{include-shadowmap}}", fs_0_0_shadowmap_lit }; const char *symbols[] = { "{{include-shadowmap}}", vfs_read("shaders/fs_0_0_shadowmap_lit.glsl") };
s->program = shader(strlerp(1, symbols, vs_332_32), strlerp(1, symbols, fs_32_4_model), "att_position,att_normal,att_texcoord,att_color", "fragcolor"); s->program = shader(strlerp(1, symbols, vfs_read("shaders/vs_332_32.glsl")), strlerp(1, symbols, vfs_read("shaders/fs_32_4_model.glsl")), "att_position,att_normal,att_texcoord,att_color", "fragcolor");
s->skybox = skybox(NULL, 0); s->skybox = skybox(NULL, 0);
array_push(scenes, s); array_push(scenes, s);
last_scene = s; last_scene = s;

View File

@ -130,8 +130,6 @@
{{FILE:v4k_netsync.c}} {{FILE:v4k_netsync.c}}
{{FILE:v4k_shaders.c}}
{{FILE:v4k_render.c}} {{FILE:v4k_render.c}}
{{FILE:v4k_renderdd.c}} {{FILE:v4k_renderdd.c}}

View File

@ -133,8 +133,6 @@ extern "C" {
{{FILE:v4k_render.h}} {{FILE:v4k_render.h}}
{{FILE:v4k_shaders.h}}
{{FILE:v4k_renderdd.h}} {{FILE:v4k_renderdd.h}}
{{FILE:v4k_scene.h}} {{FILE:v4k_scene.h}}

View File

@ -1032,8 +1032,8 @@ void shadowmatrix_ortho(mat44 shm_proj, float left, float right, float bottom, f
void fullscreen_quad_rgb( texture_t texture, float gamma ) { void fullscreen_quad_rgb( texture_t texture, float gamma ) {
static int program = -1, vao = -1, u_inv_gamma = -1; static int program = -1, vao = -1, u_inv_gamma = -1;
if( program < 0 ) { if( program < 0 ) {
const char* vs = vs_0_2_fullscreen_quad_B_flipped; const char* vs = vfs_read("shaders/vs_0_2_fullscreen_quad_B_flipped.glsl");
const char* fs = fs_2_4_texel_inv_gamma; const char* fs = vfs_read("shaders/fs_2_4_texel_inv_gamma.glsl");
program = shader(vs, fs, "", "fragcolor" ); program = shader(vs, fs, "", "fragcolor" );
u_inv_gamma = glGetUniformLocation(program, "u_inv_gamma"); u_inv_gamma = glGetUniformLocation(program, "u_inv_gamma");
@ -1063,8 +1063,8 @@ void fullscreen_quad_rgb( texture_t texture, float gamma ) {
void fullscreen_quad_ycbcr( texture_t textureYCbCr[3], float gamma ) { void fullscreen_quad_ycbcr( texture_t textureYCbCr[3], float gamma ) {
static int program = -1, vao = -1, u_gamma = -1, uy = -1, ucb = -1, ucr = -1; static int program = -1, vao = -1, u_gamma = -1, uy = -1, ucb = -1, ucr = -1;
if( program < 0 ) { if( program < 0 ) {
const char* vs = vs_0_2_fullscreen_quad_B_flipped; const char* vs = vfs_read("shaders/vs_0_2_fullscreen_quad_B_flipped.glsl");
const char* fs = fs_2_4_texel_ycbr_gamma_saturation; const char* fs = vfs_read("shaders/fs_2_4_texel_ycbr_gamma_saturation.glsl");
program = shader(vs, fs, "", "fragcolor" ); program = shader(vs, fs, "", "fragcolor" );
u_gamma = glGetUniformLocation(program, "u_gamma"); u_gamma = glGetUniformLocation(program, "u_gamma");
@ -1355,7 +1355,7 @@ static void sprite_render_meshes() {
return; return;
if( sprite_program < 0 ) { if( sprite_program < 0 ) {
sprite_program = shader( vs_324_24_sprite, fs_24_4_sprite, sprite_program = shader( vfs_read("shaders/vs_324_24_sprite.glsl"), vfs_read("shaders/fs_24_4_sprite.glsl"),
"att_Position,att_TexCoord,att_Color", "att_Position,att_TexCoord,att_Color",
"fragColor" "fragColor"
); );
@ -2372,8 +2372,8 @@ skybox_t skybox(const char *asset, int flags) {
// sky program // sky program
sky.flags = flags ? flags : !!asset; // either cubemap or rayleigh sky.flags = flags ? flags : !!asset; // either cubemap or rayleigh
sky.program = shader(vs_3_3_skybox, sky.program = shader(vfs_read("shaders/vs_3_3_skybox.glsl"),
sky.flags ? fs_3_4_skybox : fs_3_4_skybox_rayleigh, sky.flags ? vfs_read("fs_3_4_skybox.glsl") : vfs_read("shaders/fs_3_4_skybox_rayleigh.glsl"),
"att_position", "fragcolor"); "att_position", "fragcolor");
// sky cubemap & SH // sky cubemap & SH
@ -2913,14 +2913,14 @@ int postfx_load_from_mem( postfx *fx, const char *name, const char *fs ) {
passfx *p = &fx->pass[ slot & 63 ]; passfx *p = &fx->pass[ slot & 63 ];
p->name = STRDUP(name); p->name = STRDUP(name);
const char *vs = vs_0_2_fullscreen_quad_B; const char *vs = vfs_read("shaders/vs_0_2_fullscreen_quad_B.glsl");
// patch fragment // patch fragment
char *fs2 = (char*)CALLOC(1, 128*1024); char *fs2 = (char*)CALLOC(1, 128*1024);
strcat(fs2, fs_2_4_preamble); strcat(fs2, vfs_read("shaders/fs_2_4_preamble.glsl"));
if( strstr(fs, "mainImage") ) { if( strstr(fs, "mainImage") ) {
strcat(fs2, fs_main_shadertoy ); strcat(fs2, vfs_read("shaders/fs_main_shadertoy.glsl") );
} }
strcat(fs2, fs); strcat(fs2, fs);
@ -3282,52 +3282,8 @@ shadertoy_t shadertoy( const char *shaderfile, unsigned flags ) {
glGenVertexArrays(1, &s.vao); glGenVertexArrays(1, &s.vao);
// Uses gl_VertexID to draw a fullscreen quad without vbo char *fs = stringf("%s%s", vfs_read("header_shadertoy.glsl"), file);
const char *vs = "#version 130\n" s.program = shader(flags ? vfs_read("shaders/vs_shadertoy_flip.glsl") : vfs_read("shaders/vs_shadertoy.glsl"), fs, "", "fragColor");
"uniform vec2 iResolution; // viewport resolution (in pixels)\n"
"out vec2 texCoord;\n"
"void main() {\n"
" texCoord = vec2( (gl_VertexID << 1) & 2, gl_VertexID & 2 );\n"
" gl_Position = vec4( texCoord * 2.0 - 1.0, 0.0, 1.0 );\n"
" texCoord = texCoord * iResolution;\n"
"}\n";
const char *vs_flip = "#version 130\n"
"uniform vec2 iResolution; // viewport resolution (in pixels)\n"
"out vec2 texCoord;\n"
"void main() {\n"
" texCoord = vec2( (gl_VertexID << 1) & 2, gl_VertexID & 2 );\n"
" gl_Position = vec4( texCoord * 2.0 - 1.0, 0.0, 1.0 );\n"
" texCoord = texCoord * iResolution;\n"
" texCoord.y = iResolution.y - texCoord.y; // flip Y\n"
"}\n";
const char *header = "#version 130\n"
"#define texture2D texture\n"
"uniform float iGlobalTime; // shader playback time (in seconds)\n"
"uniform float iGlobalDelta; // ??\n"
"uniform float iGlobalFrame; // ??\n"
"uniform float iSampleRate; // ??\n"
"uniform float iTime; // ??\n"
"uniform int iFrame; // ??\n"
"uniform float iChannelTime[4]; // channel playback time (in seconds)\n"
"uniform vec2 iResolution; // viewport resolution (in pixels)\n"
"uniform vec3 iChannelResolution[4]; // channel resolution (in pixels)\n"
"uniform vec3 iOffset; // ?? (0,0,0)\n"
"uniform vec4 iMouse; // mouse pixel coords. xy: hover, zw: LMB click)\n"
"uniform vec4 iDate; // (year, month, day, time in seconds)\n"
"uniform sampler2D iChannel0; // input channel 0\n" /*sampler%s*/
"uniform sampler2D iChannel1; // input channel 1\n"
"uniform sampler2D iChannel2; // input channel 2\n"
"uniform sampler2D iChannel3; // input channel 3\n"
"in vec2 texCoord;\n"
"out vec4 fragColor;\n"
"void mainImage( out vec4 fragColor, in vec2 fragCoord );\n"
"void main() {\n"
" mainImage(fragColor, texCoord.xy);\n"
"}\n";
char *fs = stringf("%s%s", header, file);
s.program = shader(flags ? vs_flip : vs, fs, "", "fragColor");
FREE(fs); FREE(fs);
if( strstr(file, "noise3.jpg")) if( strstr(file, "noise3.jpg"))
@ -4036,8 +3992,8 @@ model_t model_from_mem(const void *mem, int len, int flags) {
const char *ptr = (const char *)mem; const char *ptr = (const char *)mem;
static int shaderprog = -1; static int shaderprog = -1;
if( shaderprog < 0 ) { if( shaderprog < 0 ) {
const char *symbols[] = { "{{include-shadowmap}}", fs_0_0_shadowmap_lit }; // #define RIM const char *symbols[] = { "{{include-shadowmap}}", vfs_read("shaders/fs_0_0_shadowmap_lit.glsl") }; // #define RIM
shaderprog = shader(strlerp(1,symbols,vs_323444143_16_332_model), strlerp(1,symbols,fs_32_4_model), //fs, shaderprog = shader(strlerp(1,symbols,vfs_read("shaders/vs_323444143_16_332_model.glsl")), strlerp(1,symbols,vfs_read("shaders/fs_32_4_model.glsl")), //fs,
"att_position,att_texcoord,att_normal,att_tangent,att_instanced_matrix,,,,att_indexes,att_weights,att_vertexindex,att_color,att_bitangent","fragColor"); "att_position,att_texcoord,att_normal,att_tangent,att_instanced_matrix,,,,att_indexes,att_weights,att_vertexindex,att_color,att_bitangent","fragColor");
} }

View File

@ -256,8 +256,8 @@ scene_t* scene_get_active() {
scene_t* scene_push() { scene_t* scene_push() {
scene_t *s = REALLOC(0, sizeof(scene_t)), clear = {0}; *s = clear; scene_t *s = REALLOC(0, sizeof(scene_t)), clear = {0}; *s = clear;
const char *symbols[] = { "{{include-shadowmap}}", fs_0_0_shadowmap_lit }; const char *symbols[] = { "{{include-shadowmap}}", vfs_read("shaders/fs_0_0_shadowmap_lit.glsl") };
s->program = shader(strlerp(1, symbols, vs_332_32), strlerp(1, symbols, fs_32_4_model), "att_position,att_normal,att_texcoord,att_color", "fragcolor"); s->program = shader(strlerp(1, symbols, vfs_read("shaders/vs_332_32.glsl")), strlerp(1, symbols, vfs_read("shaders/fs_32_4_model.glsl")), "att_position,att_normal,att_texcoord,att_color", "fragcolor");
s->skybox = skybox(NULL, 0); s->skybox = skybox(NULL, 0);
array_push(scenes, s); array_push(scenes, s);
last_scene = s; last_scene = s;

View File

@ -1,807 +0,0 @@
const char *const fs_0_0_shadowmap_lit = "//" FILELINE "\n"
"// uniform mat4 view = mat4(1.0);\n"
"uniform vec3 lightPos = vec3(1.0);\n"
"uniform float doTexture = 1.;\n"
#if VSMCUBE
"uniform samplerCube shadowMap; // VSMCUBE\n"
#else
"uniform sampler2D shadowMap; // !VSMCUBE\n"
#endif
"\n"
"\n"
"struct light {\n"
" vec3 position; // world-space\n"
" vec4 diffuse;\n"
" vec4 specular;\n"
" float constantAttenuation, linearAttenuation, quadraticAttenuation;\n"
" };\n"
" \n"
" light light0 = light(\n"
" lightPos,\n"
" vec4(1,1,1,1), // diffuse\n"
" vec4(1,1,1,1), // specular\n"
" 1.0, 0.0, 0.0 // attenuation (const, linear, quad)\n"
" );\n"
" \n"
" // From http://fabiensanglard.net/shadowmappingVSM/index.php\n"
#if VSMCUBE
" float chebyshevUpperBound(float distance, vec3 dir) {\n"
" distance = distance/20 ;\n"
" vec2 moments = texture(shadowMap, dir).rg;\n"
#else
" float chebyshevUpperBound(float distance, vec4 scPostW) {\n"
" vec2 moments = texture(shadowMap,scPostW.xy).rg;\n"
#endif
" // Surface is fully lit. as the current fragment is before the light occluder\n"
" if (distance <= moments.x)\n"
" return 1.0;\n"
" \n"
" // The fragment is either in shadow or penumbra. We now use chebyshev's upperBound to check\n"
" // How likely this pixel is to be lit (p_max)\n"
" float variance = moments.y - (moments.x*moments.x);\n"
" //variance = max(variance, 0.000002);\n"
" variance = max(variance, 0.00002);\n"
" \n"
" float d = distance - moments.x;\n"
" float p_max = variance / (variance + d*d);\n"
" \n"
" return p_max;\n"
" }\n"
" \n"
" \n"
" vec4 shadowmap(in vec4 vpeye, in vec4 vneye, in vec2 uv, in vec4 sc) {\n"
#ifndef VSMCUBE
" return vec4(1.);\n"
#else
" vec3 fragment = vec3(vpeye);\n"
" vec3 normal = vec3(normalize(vneye));\n"
" vec3 viewDir = normalize(-fragment);\n"
" \n"
" // Lighting\n"
" // Convert to eye-space\n"
" vec3 light = vec3(view * vec4(light0.position, 1.0));\n"
" \n"
#if VSMCUBE
" // Vectors\n"
" vec3 fragmentToLight = light - fragment;\n"
" vec3 fragmentToLightDir = normalize(fragmentToLight);\n"
" \n"
" // Shadows\n"
" vec4 fragmentToLight_world = inverse(view) * vec4(fragmentToLightDir, 0.0);\n"
" float shadowFactor = chebyshevUpperBound(length(fragmentToLight), -fragmentToLight_world.xyz);\n"
#else
" // Shadows\n"
" vec4 scPostW = sc / sc.w;\n"
" scPostW = scPostW * 0.5 + 0.5;\n"
" \n"
" float shadowFactor = 1.0; // Not in shadow\n"
" \n"
" bool outsideShadowMap = sc.w <= 0.0f || (scPostW.x < 0 || scPostW.y < 0) || (scPostW.x >= 1 || scPostW.y >= 1);\n"
" if (!outsideShadowMap) {\n"
" shadowFactor = chebyshevUpperBound(scPostW.z, scPostW);\n"
" }\n"
#endif
" \n"
" vec4 diffColor = vec4(1,1,1,1);\n"
#if VSMCUBE
" if(doTexture != 0) diffColor = vec4(vec3(texture(shadowMap, -fragmentToLight_world.xyz).r), 1.0);\n"
#else
" if(doTexture != 0) diffColor = vec4(vec3(texture(shadowMap, vec2(uv.x, 1.0 - uv.y)).r), 1.0);\n"
#endif
" \n"
#if 1
" vec3 positionToLight = light - fragment;\n"
" vec3 lightDir = normalize(positionToLight);\n"
" \n"
" // Angle between fragment-normal and incoming light\n"
" float cosAngIncidence = dot(lightDir, normal);\n"
" cosAngIncidence = clamp(cosAngIncidence, 0, 1);\n"
" \n"
" float attenuation = 1.0f;\n"
" attenuation = 1.0 / (light0.constantAttenuation + light0.linearAttenuation * length(positionToLight) + light0.quadraticAttenuation * pow(length(positionToLight),2));\n"
" \n"
" vec4 diffuse = diffColor * light0.diffuse * cosAngIncidence * attenuation;\n"
" \n"
" vec4 total_lighting;\n"
" total_lighting += vec4(0.1, 0.1, 0.1, 1.0) * diffColor; // Ambient\n"
" total_lighting += diffuse * shadowFactor; // Diffuse\n"
#else
" vec4 total_lighting = diffColor;\n"
#endif
" return vec4(clamp(vec3(total_lighting), 0., 1.), 1.0);\n"
#endif
" }\n";
const char *const fs_0_0_shadowmap_unlit = "//" FILELINE "\n"
"// uniform mat4 view = mat4(1.0);\n"
"uniform vec3 lightPos = vec3(1.0);\n"
"uniform float doTexture = 0.;\n"
"uniform sampler2D shadowMap;\n"
"\n"
"\n"
"vec4 shadowmap(in vec4 vpeye, in vec4 vneye, in vec2 Texcoord, in vec4 sc) {\n"
" return vec4(1.);\n"
" };\n";
const char *const fs_24_4_sprite = "//" FILELINE "\n"
"uniform sampler2D u_texture;\n"
"\n"
"\n"
"in vec2 vTexCoord;\n"
"in vec4 vColor;\n"
"out vec4 fragColor;\n"
"\n"
"\n"
"// [src] https://www.shadertoy.com/view/MllBWf CC1.0\n"
"vec4 texture_AA(sampler2D tx, vec2 uv) {\n"
" vec2 res = vec2(textureSize(tx, 0));\n"
" uv = uv*res + 0.5;\n"
" // tweak fractionnal value of the texture coordinate\n"
" vec2 fl = floor(uv);\n"
" vec2 fr = fract(uv);\n"
" vec2 aa = fwidth(uv)*0.75;\n"
" fr = smoothstep( vec2(0.5)-aa, vec2(0.5)+aa, fr);\n"
" // return value\n"
" uv = (fl+fr-0.5) / res;\n"
" return texture(tx, uv);\n"
"}\n"
"\n"
"\n"
"// [src] https://www.shadertoy.com/view/MllBWf CC1.0\n"
"vec4 texture_AA2( sampler2D tex, vec2 uv) {\n"
" vec2 res = vec2(textureSize(tex,0));\n"
" uv = uv*res;\n"
" vec2 seam = floor(uv+0.5);\n"
" uv = seam + clamp( (uv-seam)/fwidth(uv), -0.5, 0.5);\n"
" return texture(tex, uv/res);\n"
"}\n"
"\n"
"\n"
"// [src] https://www.shadertoy.com/view/ltBfRD\n"
"vec4 texture_AA3(sampler2D tex, vec2 uv) {\n"
" vec2 res = vec2(textureSize(tex,0));\n"
" float width = 2.0;\n"
" uv = uv * res;\n"
" // ---\n"
" vec2 uv_floor = floor(uv + 0.5);\n"
" vec2 uv_fract = fract(uv + 0.5);\n"
" vec2 uv_aa = fwidth(uv) * width * 0.5;\n"
" uv_fract = smoothstep(\n"
" vec2(0.5) - uv_aa,\n"
" vec2(0.5) + uv_aa,\n"
" uv_fract\n"
" );\n"
" uv = (uv_floor + uv_fract - 0.5) / res;\n"
" return texture(tex, uv);\n"
"}\n"
"\n"
"\n"
"void main() {\n"
" vec4 texColor = texture_AA2(u_texture, vTexCoord);\n"
" if(texColor.a < 0.9) discard;\n"
" fragColor = vColor * texColor;\n"
"}\n";
const char *const fs_2_4_preamble = "//" FILELINE "\n"
"#define texture2D texture\n"
"#define texture2DLod textureLod\n"
"#define FRAGCOLOR fragColor\n"
"#define texcoord uv\n"
"#define TEXCOORD uv\n"
"uniform sampler2D iChannel0;\n"
"uniform sampler2D iChannel1;\n"
"uniform float iWidth, iHeight, iTime, iFrame, iMousex, iMousey;\n"
"uniform float iChannelRes0x, iChannelRes0y;\n"
"uniform float iChannelRes1x, iChannelRes1y;\n"
"vec2 iResolution = vec2(iWidth, iHeight);\n"
"vec2 iMouse = vec2(iMousex, iMousey);\n"
"vec2 iChannelResolution[2] = vec2[2]( vec2(iChannelRes0x, iChannelRes0y),vec2(iChannelRes1x, iChannelRes1y) );\n"
"float iGlobalTime = iTime;\n"
"in vec2 texcoord;\n"
"out vec4 fragColor;\n";
const char *const fs_2_4_texel_inv_gamma = "//" FILELINE "\n"
"uniform sampler2D texture0; /*unit0*/\n"
"uniform float u_inv_gamma;\n"
"\n"
"\n"
"in vec2 uv;\n"
"out vec4 fragcolor;\n"
"\n"
"\n"
"void main() {\n"
" vec4 texel = texture( texture0, uv );\n"
" fragcolor = texel;\n"
" fragcolor.rgb = pow( fragcolor.rgb, vec3( u_inv_gamma ) ); // defaults: 1.0/2.2 gamma\n"
"}\n";
const char *const fs_2_4_texel_ycbr_gamma_saturation = "//" FILELINE "\n"
"uniform sampler2D u_texture_y; /*unit0*/\n"
"uniform sampler2D u_texture_cb; /*unit1*/\n"
"uniform sampler2D u_texture_cr; /*unit2*/\n"
"uniform float u_gamma;\n"
"\n"
"\n"
"in vec2 uv;\n"
"out vec4 fragcolor;\n"
"\n"
"\n"
"void main() {\n"
" float y = texture(u_texture_y, uv).r;\n"
" float cb = texture(u_texture_cb, uv).r;\n"
" float cr = texture(u_texture_cr, uv).r;\n"
" \n"
" const mat4 to_rgb = mat4(\n"
" 1.0000, 1.0000, 1.0000, 0.0000,\n"
" 0.0000, -0.3441, 1.7720, 0.0000,\n"
" 1.4020, -0.7141, 0.0000, 0.0000,\n"
" -0.7010, 0.5291, -0.8860, 1.0000\n"
" );\n"
" vec4 texel = to_rgb * vec4(y, cb, cr, 1.0);\n"
" /* same as:\n"
" vec3 yCbCr = vec3(y,cb-0.5,cr-0.5);\n"
" vec4 texel = vec4( dot( vec3( 1.0, 0.0, 1.402 ), yCbCr ),\n"
" dot( vec3( 1.0 , -0.34414 , -0.71414 ), yCbCr ),\n"
" dot( vec3( 1.0, 1.772, 0.0 ), yCbCr ), 1.0);\n"
" */\n"
" // gamma correction\n"
" texel.rgb = pow(texel.rgb, vec3(1.0 / u_gamma));\n"
" \n"
" // saturation (algorithm from Chapter 16 of OpenGL Shading Language)\n"
" if(false) { float saturation = 2.0; const vec3 W = vec3(0.2125, 0.7154, 0.0721);\n"
" vec3 intensity = vec3(dot(texel.rgb, W));\n"
"texel.rgb = mix(intensity, texel.rgb, saturation); }\n"
"\n"
"\n"
"fragcolor = vec4(texel.rgb, 1.0);\n"
"}\n";
const char *const fs_32_4_model = "//" FILELINE "\n"
"uniform mat4 model, view;\n"
"uniform sampler2D u_texture2d;\n"
"uniform vec3 u_coefficients_sh[9];\n"
"uniform bool u_textured = true;\n"
"uniform bool u_lit = false;\n"
"uniform bool u_matcaps = false;\n"
"uniform vec4 u_diffuse = vec4(1.0,1.0,1.0,1.0);\n"
"\n"
"\n"
#ifdef RIM
"in vec3 v_position;\n"
#endif
"in vec3 v_normal, v_normal_ws;\n"
"in vec2 v_texcoord;\n"
"in vec4 v_color;\n"
"out vec4 fragcolor;\n"
"\n"
"\n"
"{{include-shadowmap}}\n"
"in vec4 vpeye;\n"
"in vec4 vneye;\n"
"in vec4 sc;\n"
"vec4 shadowing() {\n"
"return shadowmap(vpeye, vneye, v_texcoord, sc);\n"
"}\n"
"\n"
"\n"
"void main() {\n"
"vec3 n = /*normalize*/(v_normal);\n"
"\n"
"\n"
"// SH lighting\n"
"vec4 lit = vec4(1.0, 1.0, 1.0, 1.0);\n"
"vec3 SHLightResult[9];\n"
"SHLightResult[0] = 0.282095f * u_coefficients_sh[0];\n"
"SHLightResult[1] = -0.488603f * u_coefficients_sh[1] * n.y;\n"
"SHLightResult[2] = 0.488603f * u_coefficients_sh[2] * n.z;\n"
"SHLightResult[3] = -0.488603f * u_coefficients_sh[3] * n.x;\n"
"SHLightResult[4] = 1.092548f * u_coefficients_sh[4] * n.x * n.y;\n"
"SHLightResult[5] = -1.092548f * u_coefficients_sh[5] * n.y * n.z;\n"
"SHLightResult[6] = 0.315392f * u_coefficients_sh[6] * (3.0f * n.z * n.z - 1.0f);\n"
"SHLightResult[7] = -1.092548f * u_coefficients_sh[7] * n.x * n.z;\n"
"SHLightResult[8] = 0.546274f * u_coefficients_sh[8] * (n.x * n.x - n.y * n.y);\n"
"vec3 result = vec3(0.0);\n"
"for (int i = 0; i < 9; ++i)\n"
"result += SHLightResult[i];\n"
"\n"
"if( (result.x*result.x+result.y*result.y+result.z*result.z) > 0.0 ) lit = vec4(result, 1.0);\n"
"\n"
"\n"
"// base\n"
"vec4 diffuse;\n"
"if(u_matcaps) {\n"
" vec2 muv = vec2(view * vec4(v_normal_ws, 0))*0.5+vec2(0.5,0.5); // normal (model space) to view space\n"
" diffuse = texture(u_texture2d, vec2(muv.x, 1.0-muv.y));\n"
" } else if(u_textured) {\n"
" diffuse = texture(u_texture2d, v_texcoord);\n"
" } else {\n"
" diffuse = u_diffuse; // * v_color;\n"
" }\n"
" \n"
" // lighting mix\n"
" fragcolor = diffuse * lit * shadowing();\n"
" \n"
" // rimlight\n"
#ifdef RIM
" {vec3 n = normalize(mat3(M) * v_normal); // convert normal to view space\n"
" vec3 p = (M * vec4(v_position,1.0)).xyz; // convert position to view space\n"
" vec3 v = normalize(-p); // eye vector\n"
" float rim = 1.0 - max(dot(v, n), 0.0); // rimlight\n"
" rim = smoothstep(1.0-0.01, 1.0, rim); // intensity (0.01)\n"
" fragcolor += vec4(0.0, 0.0, rim, 1.0);} // blue\n"
#endif
" }\n";
const char *const fs_32_4_model_basic = "//" FILELINE "\n"
"uniform sampler2D fsDiffTex;\n"
"uniform sampler2D fsNormalTex;\n"
"uniform sampler2D fsPositionTex;\n"
"uniform mat4 MVP;\n"
"\n"
"\n"
"in vec3 v_normal;\n"
"in vec2 v_texcoord;\n"
"out vec4 fragColor;\n"
"\n"
"\n"
"void main() {\n"
" vec4 diff = texture(fsDiffTex, v_texcoord).rgba;\n"
" vec3 n = normalize(mat3(MVP) * v_normal); // transform normal to eye space\n"
" fragColor = diff;// * vec4(v_normal.xyz, 1);\n"
"}\n";
const char *const fs_3_4_skybox = "//" FILELINE "\n"
"uniform samplerCube u_cubemap;\n"
"\n"
"\n"
"in vec3 v_direction;\n"
"out vec4 fragcolor;\n"
"\n"
"\n"
"void main() {\n"
" fragcolor = vec4(texture(u_cubemap, v_direction).rgb, 1.0);\n"
"}\n";
const char *const fs_3_4_skybox_rayleigh = "//" FILELINE "\n"
"uniform vec3 uSunPos = vec3( 0, 0.1, -1 ); // = [0, Math.cos(theta) * 0.3 + 0.2, -1];\n"
"\n"
"\n"
"in vec3 v_direction;\n"
"out vec4 fragcolor;\n"
"\n"
"\n"
"vec3 atmosphere(vec3 r, vec3 r0, vec3 pSun, float iSun, float rPlanet, float rAtmos, vec3 kRlh, float kMie, float shRlh, float shMie, float g);\n"
"\n"
"\n"
"void main() {\n"
" vec3 color = atmosphere(\n"
" normalize(v_direction), // normalized ray direction\n"
" vec3(0,6372e3,0), // ray origin\n"
" uSunPos, // position of the sun\n"
" 22.0, // intensity of the sun\n"
" 6371e3, // radius of the planet in meters\n"
" 6471e3, // radius of the atmosphere in meters\n"
" vec3(5.5e-6, 13.0e-6, 22.4e-6), // Rayleigh scattering coefficient\n"
" 21e-6, // Mie scattering coefficient\n"
" 8e3, // Rayleigh scale height\n"
" 1.2e3, // Mie scale height\n"
" 0.758 // Mie preferred scattering direction\n"
" );\n"
" \n"
" // Apply exposure.\n"
" color = 1.0 - exp(-1.0 * color);\n"
" \n"
" fragcolor = vec4(color, 1);\n"
"}\n"
"\n"
"\n"
"// [src] https://github.com/wwwtyro/glsl-atmosphere by wwwtyro (Unlicensed)\n"
"// For more information, please refer to <http://unlicense.org>\n"
"\n"
"\n"
"#define PI 3.141592\n"
"#define iSteps 16\n"
"#define jSteps 8\n"
"\n"
"\n"
"vec2 rsi(vec3 r0, vec3 rd, float sr) {\n"
" // ray-sphere intersection that assumes\n"
" // the sphere is centered at the origin.\n"
" // No intersection when result.x > result.y\n"
" float a = dot(rd, rd);\n"
" float b = 2.0 * dot(rd, r0);\n"
" float c = dot(r0, r0) - (sr * sr);\n"
" float d = (b*b) - 4.0*a*c;\n"
" if (d < 0.0) return vec2(1e5,-1e5);\n"
" return vec2(\n"
" (-b - sqrt(d))/(2.0*a),\n"
" (-b + sqrt(d))/(2.0*a)\n"
" );\n"
"}\n"
"\n"
"\n"
"vec3 atmosphere(vec3 r, vec3 r0, vec3 pSun, float iSun, float rPlanet, float rAtmos, vec3 kRlh, float kMie, float shRlh, float shMie, float g) {\n"
" // Normalize the sun and view directions.\n"
" pSun = normalize(pSun);\n"
" r = normalize(r);\n"
" \n"
" // Calculate the step size of the primary ray.\n"
" vec2 p = rsi(r0, r, rAtmos);\n"
" if (p.x > p.y) return vec3(0,0,0);\n"
" p.y = min(p.y, rsi(r0, r, rPlanet).x);\n"
" float iStepSize = (p.y - p.x) / float(iSteps);\n"
" \n"
" // Initialize the primary ray time.\n"
" float iTime = 0.0;\n"
" \n"
" // Initialize accumulators for Rayleigh and Mie scattering.\n"
" vec3 totalRlh = vec3(0,0,0);\n"
" vec3 totalMie = vec3(0,0,0);\n"
" \n"
" // Initialize optical depth accumulators for the primary ray.\n"
" float iOdRlh = 0.0;\n"
" float iOdMie = 0.0;\n"
" \n"
" // Calculate the Rayleigh and Mie phases.\n"
" float mu = dot(r, pSun);\n"
" float mumu = mu * mu;\n"
" float gg = g * g;\n"
" float pRlh = 3.0 / (16.0 * PI) * (1.0 + mumu);\n"
" float pMie = 3.0 / (8.0 * PI) * ((1.0 - gg) * (mumu + 1.0)) / (pow(1.0 + gg - 2.0 * mu * g, 1.5) * (2.0 + gg));\n"
" \n"
" // Sample the primary ray.\n"
" for (int i = 0; i < iSteps; i++) {\n"
" \n"
" // Calculate the primary ray sample position.\n"
" vec3 iPos = r0 + r * (iTime + iStepSize * 0.5);\n"
" \n"
" // Calculate the height of the sample.\n"
" float iHeight = length(iPos) - rPlanet;\n"
" \n"
" // Calculate the optical depth of the Rayleigh and Mie scattering for this step.\n"
" float odStepRlh = exp(-iHeight / shRlh) * iStepSize;\n"
" float odStepMie = exp(-iHeight / shMie) * iStepSize;\n"
" \n"
" // Accumulate optical depth.\n"
" iOdRlh += odStepRlh;\n"
" iOdMie += odStepMie;\n"
" \n"
" // Calculate the step size of the secondary ray.\n"
" float jStepSize = rsi(iPos, pSun, rAtmos).y / float(jSteps);\n"
" \n"
" // Initialize the secondary ray time.\n"
" float jTime = 0.0;\n"
" \n"
" // Initialize optical depth accumulators for the secondary ray.\n"
" float jOdRlh = 0.0;\n"
" float jOdMie = 0.0;\n"
" \n"
" // Sample the secondary ray.\n"
" for (int j = 0; j < jSteps; j++) {\n"
" \n"
" // Calculate the secondary ray sample position.\n"
" vec3 jPos = iPos + pSun * (jTime + jStepSize * 0.5);\n"
" \n"
" // Calculate the height of the sample.\n"
" float jHeight = length(jPos) - rPlanet;\n"
" \n"
" // Accumulate the optical depth.\n"
" jOdRlh += exp(-jHeight / shRlh) * jStepSize;\n"
" jOdMie += exp(-jHeight / shMie) * jStepSize;\n"
" \n"
" // Increment the secondary ray time.\n"
" jTime += jStepSize;\n"
" }\n"
" \n"
" // Calculate attenuation.\n"
" vec3 attn = exp(-(kMie * (iOdMie + jOdMie) + kRlh * (iOdRlh + jOdRlh)));\n"
" \n"
" // Accumulate scattering.\n"
" totalRlh += odStepRlh * attn;\n"
" totalMie += odStepMie * attn;\n"
" \n"
" // Increment the primary ray time.\n"
" iTime += iStepSize;\n"
" \n"
" }\n"
" \n"
" // Calculate and return the final color.\n"
" return iSun * (pRlh * kRlh * totalRlh + pMie * kMie * totalMie);\n"
"}\n";
const char *const fs_main_shadertoy = "//" FILELINE "\n"
"void mainImage( out vec4 fragColor, in vec2 fragCoord );\n"
"void main() {\n"
" mainImage(fragColor, texcoord.xy * iResolution);\n"
"}\n";
const char *const fs_shadow_blur = "//" FILELINE "\n"
"uniform sampler2D textureSource;\n"
"uniform vec2 ScaleU;\n"
"\n"
"in vec2 Texcoord;\n"
"out vec4 outColor;\n"
"\n"
"void main() {\n"
" vec4 color = vec4(0.0);\n"
" color += texture( textureSource, Texcoord.st + vec2( -3.0*ScaleU.x, -3.0*ScaleU.y ) ) * 0.015625;\n"
" color += texture( textureSource, Texcoord.st + vec2( -2.0*ScaleU.x, -2.0*ScaleU.y ) )*0.09375;\n"
" color += texture( textureSource, Texcoord.st + vec2( -1.0*ScaleU.x, -1.0*ScaleU.y ) )*0.234375;\n"
" color += texture( textureSource, Texcoord.st + vec2( 0.0 , 0.0) )*0.3125;\n"
" color += texture( textureSource, Texcoord.st + vec2( 1.0*ScaleU.x, 1.0*ScaleU.y ) )*0.234375;\n"
" color += texture( textureSource, Texcoord.st + vec2( 2.0*ScaleU.x, 2.0*ScaleU.y ) )*0.09375;\n"
" color += texture( textureSource, Texcoord.st + vec2( 3.0*ScaleU.x, -3.0*ScaleU.y ) ) * 0.015625;\n"
" outColor = vec4(color.xyz, 1.0);\n"
"}\n";
const char *const fs_shadow_vsm = "//" FILELINE "\n"
"in vec4 v_position;\n"
"out vec4 outColor;\n"
"\n"
"void main() {\n"
#if VSMCUBE
" float depth = length( vec3(v_position) ) / 20;\n"
#else
" float depth = v_position.z / v_position.w;\n"
" depth = depth * 0.5 + 0.5;\n"
#endif
" \n"
" float moment1 = depth;\n"
" float moment2 = depth * depth;\n"
" \n"
" float dx = dFdx(depth);\n"
" float dy = dFdy(depth);\n"
" moment2 += 0.25*(dx*dx+dy*dy);\n"
" outColor = vec4( moment1, moment2, 0.0, 0.0);\n"
"}\n";
const char *const vs_0_2_fullscreen_quad_A = "//" FILELINE "\n"
"out vec2 texcoord;\n"
"\n"
"\n"
"void main() {\n"
" texcoord = vec2( (gl_VertexID << 1) & 2, gl_VertexID & 2 );\n"
" gl_Position = vec4( texCoord * 2.0 - 1.0, 0.0, 1.0 );\n"
"}\n";
const char *const vs_0_2_fullscreen_quad_B = "//" FILELINE "\n"
"out vec2 uv;\n"
"\n"
"\n"
"void main() {\n"
" float x = float(((uint(gl_VertexID) + 2u) / 3u)%2u);\n"
" float y = float(((uint(gl_VertexID) + 1u) / 3u)%2u);\n"
" gl_Position = vec4(-1.0 + x*2.0, 0.0+(-1.0+y*2.0), 0.0, 1.0); // normal(0+),flipped(0-)\n"
" uv = vec2(x, y); // normal(y),flipped(1.0-y)\n"
"}\n";
const char *const vs_0_2_fullscreen_quad_B_flipped = "//" FILELINE "\n"
"out vec2 uv;\n"
"\n"
"\n"
"void main() {\n"
" float x = float(((uint(gl_VertexID) + 2u) / 3u)%2u);\n"
" float y = float(((uint(gl_VertexID) + 1u) / 3u)%2u);\n"
" gl_Position = vec4(-1.0 + x*2.0, 0.0-(-1.0+y*2.0), 0.0, 1.0); // normal(0+),flipped(0-)\n"
" uv = vec2(x, y); // normal(y),flipped(1.0-y)\n"
"}\n";
const char *const vs_323444143_16_332_model = "//" FILELINE "\n"
#ifndef MAX_BONES
"#define MAX_BONES 110\n"
#endif
"uniform mat3x4 vsBoneMatrix[MAX_BONES];\n"
"uniform bool SKINNED = false;\n"
"// uniform mat4 M; // RIM\n"
"uniform mat4 VP;\n"
"\n"
"\n"
#if 0
"// Fetch blend channels from all attached blend deformers.\n"
"for (size_t di = 0; di < mesh->blend_deformers.count; di++) {\n"
" ufbx_blend_deformer *deformer = mesh->blend_deformers.data[di];\n"
" for (size_t ci = 0; ci < deformer->channels.count; ci++) {\n"
" ufbx_blend_channel *chan = deformer->channels.data[ci];\n"
" if (chan->keyframes.count == 0) continue;\n"
" if (num_blend_shapes < MAX_BLEND_SHAPES) {\n"
" blend_channels[num_blend_shapes] = chan;\n"
" vmesh->blend_channel_indices[num_blend_shapes] = (int32_t)chan->typed_id;\n"
" num_blend_shapes++;\n"
" }\n"
" }\n"
"}\n"
"if (num_blend_shapes > 0) {\n"
" vmesh->blend_shape_image = pack_blend_channels_to_image(mesh, blend_channels, num_blend_shapes);\n"
" vmesh->num_blend_shapes = num_blend_shapes;\n"
"}\n"
"\n"
"\n"
"ubo.f_num_blend_shapes = (float)mesh->num_blend_shapes;\n"
"for (size_t i = 0; i < mesh->num_blend_shapes; i++) {\n"
" ubo.blend_weights[i] = view->scene.blend_channels[mesh->blend_channel_indices[i]].weight;\n"
"}\n"
"\n"
"\n"
"sg_image blend_shapes = mesh->num_blend_shapes > 0 ? mesh->blend_shape_image : view->empty_blend_shape_image;\n"
#endif
"\n"
"\n"
"// for blendshapes\n"
#ifndef MAX_BLENDSHAPES
"#define MAX_BLENDSHAPES 16\n"
#endif
"uniform vec4 blend_weights[MAX_BLENDSHAPES]; // @todo: implement me\n"
"uniform float f_num_blend_shapes; // @todo: implement me\n"
"uniform sampler2DArray blend_shapes; // @todo: implement me\n"
"\n"
"\n"
"in vec3 att_position; // @todo: reorder ass2iqe to emit p3 n3 u2 t3 b3 c4B i4 w4 instead\n"
"in vec2 att_texcoord;\n"
"in vec3 att_normal;\n"
"in vec4 att_tangent; // vec3 + bi sign\n"
"in mat4 att_instanced_matrix; // for instanced rendering\n"
"in vec4 att_indexes; // @fixme: gles might use ivec4 instead?\n"
"in vec4 att_weights; // @todo: downgrade from float to byte\n"
"in float att_vertexindex; // for blendshapes\n"
"in vec4 att_color;\n"
"in vec3 att_bitangent; // @todo: remove? also, ass2iqe might output this\n"
"out vec4 v_color;\n"
"out vec3 v_position;\n"
"out vec3 v_normal, v_normal_ws;\n"
"out vec2 v_texcoord;\n"
"\n"
"\n"
"\n"
"\n"
"// shadow\n"
"uniform mat4 model, view;\n"
"uniform mat4 cameraToShadowProjector;\n"
"out vec4 vneye;\n"
"out vec4 vpeye;\n"
"out vec4 sc;\n"
"void do_shadow() {\n"
" vneye = view * model * vec4(att_normal, 0.0f);\n"
" vpeye = view * model * vec4(att_position, 1.0);\n"
" sc = cameraToShadowProjector * model * vec4(att_position, 1.0f);\n"
"}\n"
"\n"
"\n"
"// blendshapes\n"
"vec3 evaluate_blend_shape(int vertex_index) {\n"
" ivec2 coord = ivec2(vertex_index & (2048 - 1), vertex_index >> 11);\n"
" int num_blend_shapes = int(f_num_blend_shapes);\n"
" vec3 offset = vec3(0.0);\n"
" for (int i = 0; i < num_blend_shapes; i++) {\n"
" vec4 packedw = blend_weights[i >> 2];\n"
" float weight = packedw[i & 3];\n"
" offset += weight * texelFetch(blend_shapes, ivec3(coord, i), 0).xyz;\n"
" }\n"
" return offset;\n"
"}\n"
"\n"
"\n"
"void main() {\n"
" vec3 objPos;\n"
" if(!SKINNED) {\n"
" objPos = att_position;\n"
" v_normal = att_normal;\n"
" } else {\n"
" mat3x4 m = vsBoneMatrix[int(att_indexes.x)] * att_weights.x;\n"
" m += vsBoneMatrix[int(att_indexes.y)] * att_weights.y;\n"
" m += vsBoneMatrix[int(att_indexes.z)] * att_weights.z;\n"
" m += vsBoneMatrix[int(att_indexes.w)] * att_weights.w;\n"
" objPos = vec4(att_position, 1.0) * m;\n"
" \n"
" // blendshapes\n"
" // objPos += evaluate_blend_shape(int(att_vertexindex));\n"
" \n"
" v_normal = vec4(att_normal, 0.0) * m;\n"
" //@todo: tangents\n"
" }\n"
" \n"
" // vec3 tangent = att_tangent.xyz;\n"
" // vec3 bitangent = cross(att_normal, att_tangent.xyz) * att_tangent.w;\n"
" \n"
" v_normal_ws = normalize(vec3(model * vec4(v_normal, 0.))); // normal to world/model space\n"
" v_normal = normalize(v_normal);\n"
" v_position = att_position;\n"
" v_texcoord = att_texcoord;\n"
" v_color = att_color;\n"
" gl_Position = VP * att_instanced_matrix * vec4( objPos, 1.0 );\n"
" do_shadow();\n"
" }\n";
const char *const vs_324_24_sprite = "//" FILELINE "\n"
"uniform mat4 u_mvp;\n"
"\n"
"\n"
"in vec3 att_Position;\n"
"in vec2 att_TexCoord;\n"
"in vec4 att_Color;\n"
"out vec2 vTexCoord;\n"
"out vec4 vColor;\n"
"\n"
"\n"
"void main() {\n"
" vColor = att_Color;\n"
" vTexCoord = att_TexCoord;\n"
" gl_Position = u_mvp * vec4(att_Position, 1.0);\n"
"}\n";
const char *const vs_332_32 = "//" FILELINE "\n"
"uniform mat4 u_mvp;\n"
"\n"
"\n"
"in vec3 att_position;\n"
"in vec3 att_normal;\n"
"in vec2 att_texcoord;\n"
"in vec4 att_color;\n"
"out vec4 v_color;\n"
"out vec3 v_normal;\n"
"out vec3 v_normal_ws;\n"
"out vec2 v_texcoord;\n"
"\n"
"\n"
"// shadow\n"
"uniform mat4 model, view, proj;\n"
"uniform mat4 cameraToShadowProjector; // !VSMCUBE\n"
"out vec4 vneye;\n"
"out vec4 vpeye;\n"
"out vec4 sc; // !VSMCUBE\n"
"void do_shadow() {\n"
" vneye = view * model * vec4(att_normal, 0.0f);\n"
" vpeye = view * model * vec4(att_position, 1.0);\n"
" sc = cameraToShadowProjector * model * vec4(att_position, 1.0f);\n"
"}\n"
"\n"
"\n"
"void main() {\n"
" gl_Position = u_mvp * vec4(att_position, 1.0);\n"
" v_normal = normalize(att_normal);\n"
" v_normal_ws = normalize(vec3(model * vec4(att_normal, 0.))); // normal world/model space\n"
" v_texcoord = att_texcoord;\n"
" v_color = att_color;\n"
" do_shadow();\n"
"}\n";
const char *const vs_3_3_skybox = "//" FILELINE "\n"
"uniform mat4 u_mvp;\n"
"\n"
"\n"
"in vec3 att_position;\n"
"out vec3 v_direction;\n"
"\n"
"\n"
"void main() {\n"
" vec4 position = u_mvp * vec4(att_position, 0.0);\n"
" gl_Position = position.xyww;\n"
" v_direction = att_position;\n"
"}\n";
const char *const vs_shadow_blur = "//" FILELINE "\n"
"in vec3 position;\n"
"in vec2 texcoord;\n"
"out vec2 Texcoord;\n"
"\n"
"void main() {\n"
" gl_Position = vec4(position, 1.0);\n"
" Texcoord = texcoord;\n"
"}\n";
const char *const vs_shadow_vsm = "//" FILELINE "\n"
"uniform mat4 model;\n"
"uniform mat4 cameraToShadowView;\n"
"uniform mat4 cameraToShadowProjector;\n"
"\n"
"in vec3 position;\n"
"out vec4 v_position;\n"
"\n"
"void main() {\n"
" gl_Position = cameraToShadowProjector * model * vec4(position, 1.0);\n"
#if VSMCUBE
" v_position = cameraToShadowView * model * vec4(position, 1.0);\n"
#else
" v_position = gl_Position;\n"
#endif
"}\n";

View File

@ -1,22 +0,0 @@
extern const char *const fs_0_0_shadowmap_lit;
extern const char *const fs_0_0_shadowmap_unlit;
extern const char *const fs_24_4_sprite;
extern const char *const fs_2_4_preamble;
extern const char *const fs_2_4_texel_inv_gamma;
extern const char *const fs_2_4_texel_ycbr_gamma_saturation;
extern const char *const fs_32_4_model;
extern const char *const fs_32_4_model_basic;
extern const char *const fs_3_4_skybox;
extern const char *const fs_3_4_skybox_rayleigh;
extern const char *const fs_main_shadertoy;
extern const char *const fs_shadow_blur;
extern const char *const fs_shadow_vsm;
extern const char *const vs_0_2_fullscreen_quad_A;
extern const char *const vs_0_2_fullscreen_quad_B;
extern const char *const vs_0_2_fullscreen_quad_B_flipped;
extern const char *const vs_323444143_16_332_model;
extern const char *const vs_324_24_sprite;
extern const char *const vs_332_32;
extern const char *const vs_3_3_skybox;
extern const char *const vs_shadow_blur;
extern const char *const vs_shadow_vsm;

View File

@ -10209,816 +10209,6 @@ void network_rpc_send(unsigned id, const char *cmdline) {
} }
#line 0 #line 0
#line 1 "v4k_shaders.c"
const char *const fs_0_0_shadowmap_lit = "//" FILELINE "\n"
"// uniform mat4 view = mat4(1.0);\n"
"uniform vec3 lightPos = vec3(1.0);\n"
"uniform float doTexture = 1.;\n"
#if VSMCUBE
"uniform samplerCube shadowMap; // VSMCUBE\n"
#else
"uniform sampler2D shadowMap; // !VSMCUBE\n"
#endif
"\n"
"\n"
"struct light {\n"
" vec3 position; // world-space\n"
" vec4 diffuse;\n"
" vec4 specular;\n"
" float constantAttenuation, linearAttenuation, quadraticAttenuation;\n"
" };\n"
" \n"
" light light0 = light(\n"
" lightPos,\n"
" vec4(1,1,1,1), // diffuse\n"
" vec4(1,1,1,1), // specular\n"
" 1.0, 0.0, 0.0 // attenuation (const, linear, quad)\n"
" );\n"
" \n"
" // From http://fabiensanglard.net/shadowmappingVSM/index.php\n"
#if VSMCUBE
" float chebyshevUpperBound(float distance, vec3 dir) {\n"
" distance = distance/20 ;\n"
" vec2 moments = texture(shadowMap, dir).rg;\n"
#else
" float chebyshevUpperBound(float distance, vec4 scPostW) {\n"
" vec2 moments = texture(shadowMap,scPostW.xy).rg;\n"
#endif
" // Surface is fully lit. as the current fragment is before the light occluder\n"
" if (distance <= moments.x)\n"
" return 1.0;\n"
" \n"
" // The fragment is either in shadow or penumbra. We now use chebyshev's upperBound to check\n"
" // How likely this pixel is to be lit (p_max)\n"
" float variance = moments.y - (moments.x*moments.x);\n"
" //variance = max(variance, 0.000002);\n"
" variance = max(variance, 0.00002);\n"
" \n"
" float d = distance - moments.x;\n"
" float p_max = variance / (variance + d*d);\n"
" \n"
" return p_max;\n"
" }\n"
" \n"
" \n"
" vec4 shadowmap(in vec4 vpeye, in vec4 vneye, in vec2 uv, in vec4 sc) {\n"
#ifndef VSMCUBE
" return vec4(1.);\n"
#else
" vec3 fragment = vec3(vpeye);\n"
" vec3 normal = vec3(normalize(vneye));\n"
" vec3 viewDir = normalize(-fragment);\n"
" \n"
" // Lighting\n"
" // Convert to eye-space\n"
" vec3 light = vec3(view * vec4(light0.position, 1.0));\n"
" \n"
#if VSMCUBE
" // Vectors\n"
" vec3 fragmentToLight = light - fragment;\n"
" vec3 fragmentToLightDir = normalize(fragmentToLight);\n"
" \n"
" // Shadows\n"
" vec4 fragmentToLight_world = inverse(view) * vec4(fragmentToLightDir, 0.0);\n"
" float shadowFactor = chebyshevUpperBound(length(fragmentToLight), -fragmentToLight_world.xyz);\n"
#else
" // Shadows\n"
" vec4 scPostW = sc / sc.w;\n"
" scPostW = scPostW * 0.5 + 0.5;\n"
" \n"
" float shadowFactor = 1.0; // Not in shadow\n"
" \n"
" bool outsideShadowMap = sc.w <= 0.0f || (scPostW.x < 0 || scPostW.y < 0) || (scPostW.x >= 1 || scPostW.y >= 1);\n"
" if (!outsideShadowMap) {\n"
" shadowFactor = chebyshevUpperBound(scPostW.z, scPostW);\n"
" }\n"
#endif
" \n"
" vec4 diffColor = vec4(1,1,1,1);\n"
#if VSMCUBE
" if(doTexture != 0) diffColor = vec4(vec3(texture(shadowMap, -fragmentToLight_world.xyz).r), 1.0);\n"
#else
" if(doTexture != 0) diffColor = vec4(vec3(texture(shadowMap, vec2(uv.x, 1.0 - uv.y)).r), 1.0);\n"
#endif
" \n"
#if 1
" vec3 positionToLight = light - fragment;\n"
" vec3 lightDir = normalize(positionToLight);\n"
" \n"
" // Angle between fragment-normal and incoming light\n"
" float cosAngIncidence = dot(lightDir, normal);\n"
" cosAngIncidence = clamp(cosAngIncidence, 0, 1);\n"
" \n"
" float attenuation = 1.0f;\n"
" attenuation = 1.0 / (light0.constantAttenuation + light0.linearAttenuation * length(positionToLight) + light0.quadraticAttenuation * pow(length(positionToLight),2));\n"
" \n"
" vec4 diffuse = diffColor * light0.diffuse * cosAngIncidence * attenuation;\n"
" \n"
" vec4 total_lighting;\n"
" total_lighting += vec4(0.1, 0.1, 0.1, 1.0) * diffColor; // Ambient\n"
" total_lighting += diffuse * shadowFactor; // Diffuse\n"
#else
" vec4 total_lighting = diffColor;\n"
#endif
" return vec4(clamp(vec3(total_lighting), 0., 1.), 1.0);\n"
#endif
" }\n";
const char *const fs_0_0_shadowmap_unlit = "//" FILELINE "\n"
"// uniform mat4 view = mat4(1.0);\n"
"uniform vec3 lightPos = vec3(1.0);\n"
"uniform float doTexture = 0.;\n"
"uniform sampler2D shadowMap;\n"
"\n"
"\n"
"vec4 shadowmap(in vec4 vpeye, in vec4 vneye, in vec2 Texcoord, in vec4 sc) {\n"
" return vec4(1.);\n"
" };\n";
const char *const fs_24_4_sprite = "//" FILELINE "\n"
"uniform sampler2D u_texture;\n"
"\n"
"\n"
"in vec2 vTexCoord;\n"
"in vec4 vColor;\n"
"out vec4 fragColor;\n"
"\n"
"\n"
"// [src] https://www.shadertoy.com/view/MllBWf CC1.0\n"
"vec4 texture_AA(sampler2D tx, vec2 uv) {\n"
" vec2 res = vec2(textureSize(tx, 0));\n"
" uv = uv*res + 0.5;\n"
" // tweak fractionnal value of the texture coordinate\n"
" vec2 fl = floor(uv);\n"
" vec2 fr = fract(uv);\n"
" vec2 aa = fwidth(uv)*0.75;\n"
" fr = smoothstep( vec2(0.5)-aa, vec2(0.5)+aa, fr);\n"
" // return value\n"
" uv = (fl+fr-0.5) / res;\n"
" return texture(tx, uv);\n"
"}\n"
"\n"
"\n"
"// [src] https://www.shadertoy.com/view/MllBWf CC1.0\n"
"vec4 texture_AA2( sampler2D tex, vec2 uv) {\n"
" vec2 res = vec2(textureSize(tex,0));\n"
" uv = uv*res;\n"
" vec2 seam = floor(uv+0.5);\n"
" uv = seam + clamp( (uv-seam)/fwidth(uv), -0.5, 0.5);\n"
" return texture(tex, uv/res);\n"
"}\n"
"\n"
"\n"
"// [src] https://www.shadertoy.com/view/ltBfRD\n"
"vec4 texture_AA3(sampler2D tex, vec2 uv) {\n"
" vec2 res = vec2(textureSize(tex,0));\n"
" float width = 2.0;\n"
" uv = uv * res;\n"
" // ---\n"
" vec2 uv_floor = floor(uv + 0.5);\n"
" vec2 uv_fract = fract(uv + 0.5);\n"
" vec2 uv_aa = fwidth(uv) * width * 0.5;\n"
" uv_fract = smoothstep(\n"
" vec2(0.5) - uv_aa,\n"
" vec2(0.5) + uv_aa,\n"
" uv_fract\n"
" );\n"
" uv = (uv_floor + uv_fract - 0.5) / res;\n"
" return texture(tex, uv);\n"
"}\n"
"\n"
"\n"
"void main() {\n"
" vec4 texColor = texture_AA2(u_texture, vTexCoord);\n"
" if(texColor.a < 0.9) discard;\n"
" fragColor = vColor * texColor;\n"
"}\n";
const char *const fs_2_4_preamble = "//" FILELINE "\n"
"#define texture2D texture\n"
"#define texture2DLod textureLod\n"
"#define FRAGCOLOR fragColor\n"
"#define texcoord uv\n"
"#define TEXCOORD uv\n"
"uniform sampler2D iChannel0;\n"
"uniform sampler2D iChannel1;\n"
"uniform float iWidth, iHeight, iTime, iFrame, iMousex, iMousey;\n"
"uniform float iChannelRes0x, iChannelRes0y;\n"
"uniform float iChannelRes1x, iChannelRes1y;\n"
"vec2 iResolution = vec2(iWidth, iHeight);\n"
"vec2 iMouse = vec2(iMousex, iMousey);\n"
"vec2 iChannelResolution[2] = vec2[2]( vec2(iChannelRes0x, iChannelRes0y),vec2(iChannelRes1x, iChannelRes1y) );\n"
"float iGlobalTime = iTime;\n"
"in vec2 texcoord;\n"
"out vec4 fragColor;\n";
const char *const fs_2_4_texel_inv_gamma = "//" FILELINE "\n"
"uniform sampler2D texture0; /*unit0*/\n"
"uniform float u_inv_gamma;\n"
"\n"
"\n"
"in vec2 uv;\n"
"out vec4 fragcolor;\n"
"\n"
"\n"
"void main() {\n"
" vec4 texel = texture( texture0, uv );\n"
" fragcolor = texel;\n"
" fragcolor.rgb = pow( fragcolor.rgb, vec3( u_inv_gamma ) ); // defaults: 1.0/2.2 gamma\n"
"}\n";
const char *const fs_2_4_texel_ycbr_gamma_saturation = "//" FILELINE "\n"
"uniform sampler2D u_texture_y; /*unit0*/\n"
"uniform sampler2D u_texture_cb; /*unit1*/\n"
"uniform sampler2D u_texture_cr; /*unit2*/\n"
"uniform float u_gamma;\n"
"\n"
"\n"
"in vec2 uv;\n"
"out vec4 fragcolor;\n"
"\n"
"\n"
"void main() {\n"
" float y = texture(u_texture_y, uv).r;\n"
" float cb = texture(u_texture_cb, uv).r;\n"
" float cr = texture(u_texture_cr, uv).r;\n"
" \n"
" const mat4 to_rgb = mat4(\n"
" 1.0000, 1.0000, 1.0000, 0.0000,\n"
" 0.0000, -0.3441, 1.7720, 0.0000,\n"
" 1.4020, -0.7141, 0.0000, 0.0000,\n"
" -0.7010, 0.5291, -0.8860, 1.0000\n"
" );\n"
" vec4 texel = to_rgb * vec4(y, cb, cr, 1.0);\n"
" /* same as:\n"
" vec3 yCbCr = vec3(y,cb-0.5,cr-0.5);\n"
" vec4 texel = vec4( dot( vec3( 1.0, 0.0, 1.402 ), yCbCr ),\n"
" dot( vec3( 1.0 , -0.34414 , -0.71414 ), yCbCr ),\n"
" dot( vec3( 1.0, 1.772, 0.0 ), yCbCr ), 1.0);\n"
" */\n"
" // gamma correction\n"
" texel.rgb = pow(texel.rgb, vec3(1.0 / u_gamma));\n"
" \n"
" // saturation (algorithm from Chapter 16 of OpenGL Shading Language)\n"
" if(false) { float saturation = 2.0; const vec3 W = vec3(0.2125, 0.7154, 0.0721);\n"
" vec3 intensity = vec3(dot(texel.rgb, W));\n"
"texel.rgb = mix(intensity, texel.rgb, saturation); }\n"
"\n"
"\n"
"fragcolor = vec4(texel.rgb, 1.0);\n"
"}\n";
const char *const fs_32_4_model = "//" FILELINE "\n"
"uniform mat4 model, view;\n"
"uniform sampler2D u_texture2d;\n"
"uniform vec3 u_coefficients_sh[9];\n"
"uniform bool u_textured = true;\n"
"uniform bool u_lit = false;\n"
"uniform bool u_matcaps = false;\n"
"uniform vec4 u_diffuse = vec4(1.0,1.0,1.0,1.0);\n"
"\n"
"\n"
#ifdef RIM
"in vec3 v_position;\n"
#endif
"in vec3 v_normal, v_normal_ws;\n"
"in vec2 v_texcoord;\n"
"in vec4 v_color;\n"
"out vec4 fragcolor;\n"
"\n"
"\n"
"{{include-shadowmap}}\n"
"in vec4 vpeye;\n"
"in vec4 vneye;\n"
"in vec4 sc;\n"
"vec4 shadowing() {\n"
"return shadowmap(vpeye, vneye, v_texcoord, sc);\n"
"}\n"
"\n"
"\n"
"void main() {\n"
"vec3 n = /*normalize*/(v_normal);\n"
"\n"
"\n"
"// SH lighting\n"
"vec4 lit = vec4(1.0, 1.0, 1.0, 1.0);\n"
"vec3 SHLightResult[9];\n"
"SHLightResult[0] = 0.282095f * u_coefficients_sh[0];\n"
"SHLightResult[1] = -0.488603f * u_coefficients_sh[1] * n.y;\n"
"SHLightResult[2] = 0.488603f * u_coefficients_sh[2] * n.z;\n"
"SHLightResult[3] = -0.488603f * u_coefficients_sh[3] * n.x;\n"
"SHLightResult[4] = 1.092548f * u_coefficients_sh[4] * n.x * n.y;\n"
"SHLightResult[5] = -1.092548f * u_coefficients_sh[5] * n.y * n.z;\n"
"SHLightResult[6] = 0.315392f * u_coefficients_sh[6] * (3.0f * n.z * n.z - 1.0f);\n"
"SHLightResult[7] = -1.092548f * u_coefficients_sh[7] * n.x * n.z;\n"
"SHLightResult[8] = 0.546274f * u_coefficients_sh[8] * (n.x * n.x - n.y * n.y);\n"
"vec3 result = vec3(0.0);\n"
"for (int i = 0; i < 9; ++i)\n"
"result += SHLightResult[i];\n"
"\n"
"if( (result.x*result.x+result.y*result.y+result.z*result.z) > 0.0 ) lit = vec4(result, 1.0);\n"
"\n"
"\n"
"// base\n"
"vec4 diffuse;\n"
"if(u_matcaps) {\n"
" vec2 muv = vec2(view * vec4(v_normal_ws, 0))*0.5+vec2(0.5,0.5); // normal (model space) to view space\n"
" diffuse = texture(u_texture2d, vec2(muv.x, 1.0-muv.y));\n"
" } else if(u_textured) {\n"
" diffuse = texture(u_texture2d, v_texcoord);\n"
" } else {\n"
" diffuse = u_diffuse; // * v_color;\n"
" }\n"
" \n"
" // lighting mix\n"
" fragcolor = diffuse * lit * shadowing();\n"
" \n"
" // rimlight\n"
#ifdef RIM
" {vec3 n = normalize(mat3(M) * v_normal); // convert normal to view space\n"
" vec3 p = (M * vec4(v_position,1.0)).xyz; // convert position to view space\n"
" vec3 v = normalize(-p); // eye vector\n"
" float rim = 1.0 - max(dot(v, n), 0.0); // rimlight\n"
" rim = smoothstep(1.0-0.01, 1.0, rim); // intensity (0.01)\n"
" fragcolor += vec4(0.0, 0.0, rim, 1.0);} // blue\n"
#endif
" }\n";
const char *const fs_32_4_model_basic = "//" FILELINE "\n"
"uniform sampler2D fsDiffTex;\n"
"uniform sampler2D fsNormalTex;\n"
"uniform sampler2D fsPositionTex;\n"
"uniform mat4 MVP;\n"
"\n"
"\n"
"in vec3 v_normal;\n"
"in vec2 v_texcoord;\n"
"out vec4 fragColor;\n"
"\n"
"\n"
"void main() {\n"
" vec4 diff = texture(fsDiffTex, v_texcoord).rgba;\n"
" vec3 n = normalize(mat3(MVP) * v_normal); // transform normal to eye space\n"
" fragColor = diff;// * vec4(v_normal.xyz, 1);\n"
"}\n";
const char *const fs_3_4_skybox = "//" FILELINE "\n"
"uniform samplerCube u_cubemap;\n"
"\n"
"\n"
"in vec3 v_direction;\n"
"out vec4 fragcolor;\n"
"\n"
"\n"
"void main() {\n"
" fragcolor = vec4(texture(u_cubemap, v_direction).rgb, 1.0);\n"
"}\n";
const char *const fs_3_4_skybox_rayleigh = "//" FILELINE "\n"
"uniform vec3 uSunPos = vec3( 0, 0.1, -1 ); // = [0, Math.cos(theta) * 0.3 + 0.2, -1];\n"
"\n"
"\n"
"in vec3 v_direction;\n"
"out vec4 fragcolor;\n"
"\n"
"\n"
"vec3 atmosphere(vec3 r, vec3 r0, vec3 pSun, float iSun, float rPlanet, float rAtmos, vec3 kRlh, float kMie, float shRlh, float shMie, float g);\n"
"\n"
"\n"
"void main() {\n"
" vec3 color = atmosphere(\n"
" normalize(v_direction), // normalized ray direction\n"
" vec3(0,6372e3,0), // ray origin\n"
" uSunPos, // position of the sun\n"
" 22.0, // intensity of the sun\n"
" 6371e3, // radius of the planet in meters\n"
" 6471e3, // radius of the atmosphere in meters\n"
" vec3(5.5e-6, 13.0e-6, 22.4e-6), // Rayleigh scattering coefficient\n"
" 21e-6, // Mie scattering coefficient\n"
" 8e3, // Rayleigh scale height\n"
" 1.2e3, // Mie scale height\n"
" 0.758 // Mie preferred scattering direction\n"
" );\n"
" \n"
" // Apply exposure.\n"
" color = 1.0 - exp(-1.0 * color);\n"
" \n"
" fragcolor = vec4(color, 1);\n"
"}\n"
"\n"
"\n"
"// [src] https://github.com/wwwtyro/glsl-atmosphere by wwwtyro (Unlicensed)\n"
"// For more information, please refer to <http://unlicense.org>\n"
"\n"
"\n"
"#define PI 3.141592\n"
"#define iSteps 16\n"
"#define jSteps 8\n"
"\n"
"\n"
"vec2 rsi(vec3 r0, vec3 rd, float sr) {\n"
" // ray-sphere intersection that assumes\n"
" // the sphere is centered at the origin.\n"
" // No intersection when result.x > result.y\n"
" float a = dot(rd, rd);\n"
" float b = 2.0 * dot(rd, r0);\n"
" float c = dot(r0, r0) - (sr * sr);\n"
" float d = (b*b) - 4.0*a*c;\n"
" if (d < 0.0) return vec2(1e5,-1e5);\n"
" return vec2(\n"
" (-b - sqrt(d))/(2.0*a),\n"
" (-b + sqrt(d))/(2.0*a)\n"
" );\n"
"}\n"
"\n"
"\n"
"vec3 atmosphere(vec3 r, vec3 r0, vec3 pSun, float iSun, float rPlanet, float rAtmos, vec3 kRlh, float kMie, float shRlh, float shMie, float g) {\n"
" // Normalize the sun and view directions.\n"
" pSun = normalize(pSun);\n"
" r = normalize(r);\n"
" \n"
" // Calculate the step size of the primary ray.\n"
" vec2 p = rsi(r0, r, rAtmos);\n"
" if (p.x > p.y) return vec3(0,0,0);\n"
" p.y = min(p.y, rsi(r0, r, rPlanet).x);\n"
" float iStepSize = (p.y - p.x) / float(iSteps);\n"
" \n"
" // Initialize the primary ray time.\n"
" float iTime = 0.0;\n"
" \n"
" // Initialize accumulators for Rayleigh and Mie scattering.\n"
" vec3 totalRlh = vec3(0,0,0);\n"
" vec3 totalMie = vec3(0,0,0);\n"
" \n"
" // Initialize optical depth accumulators for the primary ray.\n"
" float iOdRlh = 0.0;\n"
" float iOdMie = 0.0;\n"
" \n"
" // Calculate the Rayleigh and Mie phases.\n"
" float mu = dot(r, pSun);\n"
" float mumu = mu * mu;\n"
" float gg = g * g;\n"
" float pRlh = 3.0 / (16.0 * PI) * (1.0 + mumu);\n"
" float pMie = 3.0 / (8.0 * PI) * ((1.0 - gg) * (mumu + 1.0)) / (pow(1.0 + gg - 2.0 * mu * g, 1.5) * (2.0 + gg));\n"
" \n"
" // Sample the primary ray.\n"
" for (int i = 0; i < iSteps; i++) {\n"
" \n"
" // Calculate the primary ray sample position.\n"
" vec3 iPos = r0 + r * (iTime + iStepSize * 0.5);\n"
" \n"
" // Calculate the height of the sample.\n"
" float iHeight = length(iPos) - rPlanet;\n"
" \n"
" // Calculate the optical depth of the Rayleigh and Mie scattering for this step.\n"
" float odStepRlh = exp(-iHeight / shRlh) * iStepSize;\n"
" float odStepMie = exp(-iHeight / shMie) * iStepSize;\n"
" \n"
" // Accumulate optical depth.\n"
" iOdRlh += odStepRlh;\n"
" iOdMie += odStepMie;\n"
" \n"
" // Calculate the step size of the secondary ray.\n"
" float jStepSize = rsi(iPos, pSun, rAtmos).y / float(jSteps);\n"
" \n"
" // Initialize the secondary ray time.\n"
" float jTime = 0.0;\n"
" \n"
" // Initialize optical depth accumulators for the secondary ray.\n"
" float jOdRlh = 0.0;\n"
" float jOdMie = 0.0;\n"
" \n"
" // Sample the secondary ray.\n"
" for (int j = 0; j < jSteps; j++) {\n"
" \n"
" // Calculate the secondary ray sample position.\n"
" vec3 jPos = iPos + pSun * (jTime + jStepSize * 0.5);\n"
" \n"
" // Calculate the height of the sample.\n"
" float jHeight = length(jPos) - rPlanet;\n"
" \n"
" // Accumulate the optical depth.\n"
" jOdRlh += exp(-jHeight / shRlh) * jStepSize;\n"
" jOdMie += exp(-jHeight / shMie) * jStepSize;\n"
" \n"
" // Increment the secondary ray time.\n"
" jTime += jStepSize;\n"
" }\n"
" \n"
" // Calculate attenuation.\n"
" vec3 attn = exp(-(kMie * (iOdMie + jOdMie) + kRlh * (iOdRlh + jOdRlh)));\n"
" \n"
" // Accumulate scattering.\n"
" totalRlh += odStepRlh * attn;\n"
" totalMie += odStepMie * attn;\n"
" \n"
" // Increment the primary ray time.\n"
" iTime += iStepSize;\n"
" \n"
" }\n"
" \n"
" // Calculate and return the final color.\n"
" return iSun * (pRlh * kRlh * totalRlh + pMie * kMie * totalMie);\n"
"}\n";
const char *const fs_main_shadertoy = "//" FILELINE "\n"
"void mainImage( out vec4 fragColor, in vec2 fragCoord );\n"
"void main() {\n"
" mainImage(fragColor, texcoord.xy * iResolution);\n"
"}\n";
const char *const fs_shadow_blur = "//" FILELINE "\n"
"uniform sampler2D textureSource;\n"
"uniform vec2 ScaleU;\n"
"\n"
"in vec2 Texcoord;\n"
"out vec4 outColor;\n"
"\n"
"void main() {\n"
" vec4 color = vec4(0.0);\n"
" color += texture( textureSource, Texcoord.st + vec2( -3.0*ScaleU.x, -3.0*ScaleU.y ) ) * 0.015625;\n"
" color += texture( textureSource, Texcoord.st + vec2( -2.0*ScaleU.x, -2.0*ScaleU.y ) )*0.09375;\n"
" color += texture( textureSource, Texcoord.st + vec2( -1.0*ScaleU.x, -1.0*ScaleU.y ) )*0.234375;\n"
" color += texture( textureSource, Texcoord.st + vec2( 0.0 , 0.0) )*0.3125;\n"
" color += texture( textureSource, Texcoord.st + vec2( 1.0*ScaleU.x, 1.0*ScaleU.y ) )*0.234375;\n"
" color += texture( textureSource, Texcoord.st + vec2( 2.0*ScaleU.x, 2.0*ScaleU.y ) )*0.09375;\n"
" color += texture( textureSource, Texcoord.st + vec2( 3.0*ScaleU.x, -3.0*ScaleU.y ) ) * 0.015625;\n"
" outColor = vec4(color.xyz, 1.0);\n"
"}\n";
const char *const fs_shadow_vsm = "//" FILELINE "\n"
"in vec4 v_position;\n"
"out vec4 outColor;\n"
"\n"
"void main() {\n"
#if VSMCUBE
" float depth = length( vec3(v_position) ) / 20;\n"
#else
" float depth = v_position.z / v_position.w;\n"
" depth = depth * 0.5 + 0.5;\n"
#endif
" \n"
" float moment1 = depth;\n"
" float moment2 = depth * depth;\n"
" \n"
" float dx = dFdx(depth);\n"
" float dy = dFdy(depth);\n"
" moment2 += 0.25*(dx*dx+dy*dy);\n"
" outColor = vec4( moment1, moment2, 0.0, 0.0);\n"
"}\n";
const char *const vs_0_2_fullscreen_quad_A = "//" FILELINE "\n"
"out vec2 texcoord;\n"
"\n"
"\n"
"void main() {\n"
" texcoord = vec2( (gl_VertexID << 1) & 2, gl_VertexID & 2 );\n"
" gl_Position = vec4( texCoord * 2.0 - 1.0, 0.0, 1.0 );\n"
"}\n";
const char *const vs_0_2_fullscreen_quad_B = "//" FILELINE "\n"
"out vec2 uv;\n"
"\n"
"\n"
"void main() {\n"
" float x = float(((uint(gl_VertexID) + 2u) / 3u)%2u);\n"
" float y = float(((uint(gl_VertexID) + 1u) / 3u)%2u);\n"
" gl_Position = vec4(-1.0 + x*2.0, 0.0+(-1.0+y*2.0), 0.0, 1.0); // normal(0+),flipped(0-)\n"
" uv = vec2(x, y); // normal(y),flipped(1.0-y)\n"
"}\n";
const char *const vs_0_2_fullscreen_quad_B_flipped = "//" FILELINE "\n"
"out vec2 uv;\n"
"\n"
"\n"
"void main() {\n"
" float x = float(((uint(gl_VertexID) + 2u) / 3u)%2u);\n"
" float y = float(((uint(gl_VertexID) + 1u) / 3u)%2u);\n"
" gl_Position = vec4(-1.0 + x*2.0, 0.0-(-1.0+y*2.0), 0.0, 1.0); // normal(0+),flipped(0-)\n"
" uv = vec2(x, y); // normal(y),flipped(1.0-y)\n"
"}\n";
const char *const vs_323444143_16_332_model = "//" FILELINE "\n"
#ifndef MAX_BONES
"#define MAX_BONES 110\n"
#endif
"uniform mat3x4 vsBoneMatrix[MAX_BONES];\n"
"uniform bool SKINNED = false;\n"
"// uniform mat4 M; // RIM\n"
"uniform mat4 VP;\n"
"\n"
"\n"
#if 0
"// Fetch blend channels from all attached blend deformers.\n"
"for (size_t di = 0; di < mesh->blend_deformers.count; di++) {\n"
" ufbx_blend_deformer *deformer = mesh->blend_deformers.data[di];\n"
" for (size_t ci = 0; ci < deformer->channels.count; ci++) {\n"
" ufbx_blend_channel *chan = deformer->channels.data[ci];\n"
" if (chan->keyframes.count == 0) continue;\n"
" if (num_blend_shapes < MAX_BLEND_SHAPES) {\n"
" blend_channels[num_blend_shapes] = chan;\n"
" vmesh->blend_channel_indices[num_blend_shapes] = (int32_t)chan->typed_id;\n"
" num_blend_shapes++;\n"
" }\n"
" }\n"
"}\n"
"if (num_blend_shapes > 0) {\n"
" vmesh->blend_shape_image = pack_blend_channels_to_image(mesh, blend_channels, num_blend_shapes);\n"
" vmesh->num_blend_shapes = num_blend_shapes;\n"
"}\n"
"\n"
"\n"
"ubo.f_num_blend_shapes = (float)mesh->num_blend_shapes;\n"
"for (size_t i = 0; i < mesh->num_blend_shapes; i++) {\n"
" ubo.blend_weights[i] = view->scene.blend_channels[mesh->blend_channel_indices[i]].weight;\n"
"}\n"
"\n"
"\n"
"sg_image blend_shapes = mesh->num_blend_shapes > 0 ? mesh->blend_shape_image : view->empty_blend_shape_image;\n"
#endif
"\n"
"\n"
"// for blendshapes\n"
#ifndef MAX_BLENDSHAPES
"#define MAX_BLENDSHAPES 16\n"
#endif
"uniform vec4 blend_weights[MAX_BLENDSHAPES]; // @todo: implement me\n"
"uniform float f_num_blend_shapes; // @todo: implement me\n"
"uniform sampler2DArray blend_shapes; // @todo: implement me\n"
"\n"
"\n"
"in vec3 att_position; // @todo: reorder ass2iqe to emit p3 n3 u2 t3 b3 c4B i4 w4 instead\n"
"in vec2 att_texcoord;\n"
"in vec3 att_normal;\n"
"in vec4 att_tangent; // vec3 + bi sign\n"
"in mat4 att_instanced_matrix; // for instanced rendering\n"
"in vec4 att_indexes; // @fixme: gles might use ivec4 instead?\n"
"in vec4 att_weights; // @todo: downgrade from float to byte\n"
"in float att_vertexindex; // for blendshapes\n"
"in vec4 att_color;\n"
"in vec3 att_bitangent; // @todo: remove? also, ass2iqe might output this\n"
"out vec4 v_color;\n"
"out vec3 v_position;\n"
"out vec3 v_normal, v_normal_ws;\n"
"out vec2 v_texcoord;\n"
"\n"
"\n"
"\n"
"\n"
"// shadow\n"
"uniform mat4 model, view;\n"
"uniform mat4 cameraToShadowProjector;\n"
"out vec4 vneye;\n"
"out vec4 vpeye;\n"
"out vec4 sc;\n"
"void do_shadow() {\n"
" vneye = view * model * vec4(att_normal, 0.0f);\n"
" vpeye = view * model * vec4(att_position, 1.0);\n"
" sc = cameraToShadowProjector * model * vec4(att_position, 1.0f);\n"
"}\n"
"\n"
"\n"
"// blendshapes\n"
"vec3 evaluate_blend_shape(int vertex_index) {\n"
" ivec2 coord = ivec2(vertex_index & (2048 - 1), vertex_index >> 11);\n"
" int num_blend_shapes = int(f_num_blend_shapes);\n"
" vec3 offset = vec3(0.0);\n"
" for (int i = 0; i < num_blend_shapes; i++) {\n"
" vec4 packedw = blend_weights[i >> 2];\n"
" float weight = packedw[i & 3];\n"
" offset += weight * texelFetch(blend_shapes, ivec3(coord, i), 0).xyz;\n"
" }\n"
" return offset;\n"
"}\n"
"\n"
"\n"
"void main() {\n"
" vec3 objPos;\n"
" if(!SKINNED) {\n"
" objPos = att_position;\n"
" v_normal = att_normal;\n"
" } else {\n"
" mat3x4 m = vsBoneMatrix[int(att_indexes.x)] * att_weights.x;\n"
" m += vsBoneMatrix[int(att_indexes.y)] * att_weights.y;\n"
" m += vsBoneMatrix[int(att_indexes.z)] * att_weights.z;\n"
" m += vsBoneMatrix[int(att_indexes.w)] * att_weights.w;\n"
" objPos = vec4(att_position, 1.0) * m;\n"
" \n"
" // blendshapes\n"
" // objPos += evaluate_blend_shape(int(att_vertexindex));\n"
" \n"
" v_normal = vec4(att_normal, 0.0) * m;\n"
" //@todo: tangents\n"
" }\n"
" \n"
" // vec3 tangent = att_tangent.xyz;\n"
" // vec3 bitangent = cross(att_normal, att_tangent.xyz) * att_tangent.w;\n"
" \n"
" v_normal_ws = normalize(vec3(model * vec4(v_normal, 0.))); // normal to world/model space\n"
" v_normal = normalize(v_normal);\n"
" v_position = att_position;\n"
" v_texcoord = att_texcoord;\n"
" v_color = att_color;\n"
" gl_Position = VP * att_instanced_matrix * vec4( objPos, 1.0 );\n"
" do_shadow();\n"
" }\n";
const char *const vs_324_24_sprite = "//" FILELINE "\n"
"uniform mat4 u_mvp;\n"
"\n"
"\n"
"in vec3 att_Position;\n"
"in vec2 att_TexCoord;\n"
"in vec4 att_Color;\n"
"out vec2 vTexCoord;\n"
"out vec4 vColor;\n"
"\n"
"\n"
"void main() {\n"
" vColor = att_Color;\n"
" vTexCoord = att_TexCoord;\n"
" gl_Position = u_mvp * vec4(att_Position, 1.0);\n"
"}\n";
const char *const vs_332_32 = "//" FILELINE "\n"
"uniform mat4 u_mvp;\n"
"\n"
"\n"
"in vec3 att_position;\n"
"in vec3 att_normal;\n"
"in vec2 att_texcoord;\n"
"in vec4 att_color;\n"
"out vec4 v_color;\n"
"out vec3 v_normal;\n"
"out vec3 v_normal_ws;\n"
"out vec2 v_texcoord;\n"
"\n"
"\n"
"// shadow\n"
"uniform mat4 model, view, proj;\n"
"uniform mat4 cameraToShadowProjector; // !VSMCUBE\n"
"out vec4 vneye;\n"
"out vec4 vpeye;\n"
"out vec4 sc; // !VSMCUBE\n"
"void do_shadow() {\n"
" vneye = view * model * vec4(att_normal, 0.0f);\n"
" vpeye = view * model * vec4(att_position, 1.0);\n"
" sc = cameraToShadowProjector * model * vec4(att_position, 1.0f);\n"
"}\n"
"\n"
"\n"
"void main() {\n"
" gl_Position = u_mvp * vec4(att_position, 1.0);\n"
" v_normal = normalize(att_normal);\n"
" v_normal_ws = normalize(vec3(model * vec4(att_normal, 0.))); // normal world/model space\n"
" v_texcoord = att_texcoord;\n"
" v_color = att_color;\n"
" do_shadow();\n"
"}\n";
const char *const vs_3_3_skybox = "//" FILELINE "\n"
"uniform mat4 u_mvp;\n"
"\n"
"\n"
"in vec3 att_position;\n"
"out vec3 v_direction;\n"
"\n"
"\n"
"void main() {\n"
" vec4 position = u_mvp * vec4(att_position, 0.0);\n"
" gl_Position = position.xyww;\n"
" v_direction = att_position;\n"
"}\n";
const char *const vs_shadow_blur = "//" FILELINE "\n"
"in vec3 position;\n"
"in vec2 texcoord;\n"
"out vec2 Texcoord;\n"
"\n"
"void main() {\n"
" gl_Position = vec4(position, 1.0);\n"
" Texcoord = texcoord;\n"
"}\n";
const char *const vs_shadow_vsm = "//" FILELINE "\n"
"uniform mat4 model;\n"
"uniform mat4 cameraToShadowView;\n"
"uniform mat4 cameraToShadowProjector;\n"
"\n"
"in vec3 position;\n"
"out vec4 v_position;\n"
"\n"
"void main() {\n"
" gl_Position = cameraToShadowProjector * model * vec4(position, 1.0);\n"
#if VSMCUBE
" v_position = cameraToShadowView * model * vec4(position, 1.0);\n"
#else
" v_position = gl_Position;\n"
#endif
"}\n";
#line 0
#line 1 "v4k_render.c" #line 1 "v4k_render.c"
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
// opengl // opengl
@ -12054,8 +11244,8 @@ void shadowmatrix_ortho(mat44 shm_proj, float left, float right, float bottom, f
void fullscreen_quad_rgb( texture_t texture, float gamma ) { void fullscreen_quad_rgb( texture_t texture, float gamma ) {
static int program = -1, vao = -1, u_inv_gamma = -1; static int program = -1, vao = -1, u_inv_gamma = -1;
if( program < 0 ) { if( program < 0 ) {
const char* vs = vs_0_2_fullscreen_quad_B_flipped; const char* vs = vfs_read("shaders/vs_0_2_fullscreen_quad_B_flipped.glsl");
const char* fs = fs_2_4_texel_inv_gamma; const char* fs = vfs_read("shaders/fs_2_4_texel_inv_gamma.glsl");
program = shader(vs, fs, "", "fragcolor" ); program = shader(vs, fs, "", "fragcolor" );
u_inv_gamma = glGetUniformLocation(program, "u_inv_gamma"); u_inv_gamma = glGetUniformLocation(program, "u_inv_gamma");
@ -12085,8 +11275,8 @@ void fullscreen_quad_rgb( texture_t texture, float gamma ) {
void fullscreen_quad_ycbcr( texture_t textureYCbCr[3], float gamma ) { void fullscreen_quad_ycbcr( texture_t textureYCbCr[3], float gamma ) {
static int program = -1, vao = -1, u_gamma = -1, uy = -1, ucb = -1, ucr = -1; static int program = -1, vao = -1, u_gamma = -1, uy = -1, ucb = -1, ucr = -1;
if( program < 0 ) { if( program < 0 ) {
const char* vs = vs_0_2_fullscreen_quad_B_flipped; const char* vs = vfs_read("shaders/vs_0_2_fullscreen_quad_B_flipped.glsl");
const char* fs = fs_2_4_texel_ycbr_gamma_saturation; const char* fs = vfs_read("shaders/fs_2_4_texel_ycbr_gamma_saturation.glsl");
program = shader(vs, fs, "", "fragcolor" ); program = shader(vs, fs, "", "fragcolor" );
u_gamma = glGetUniformLocation(program, "u_gamma"); u_gamma = glGetUniformLocation(program, "u_gamma");
@ -12377,7 +11567,7 @@ static void sprite_render_meshes() {
return; return;
if( sprite_program < 0 ) { if( sprite_program < 0 ) {
sprite_program = shader( vs_324_24_sprite, fs_24_4_sprite, sprite_program = shader( vfs_read("shaders/vs_324_24_sprite.glsl"), vfs_read("shaders/fs_24_4_sprite.glsl"),
"att_Position,att_TexCoord,att_Color", "att_Position,att_TexCoord,att_Color",
"fragColor" "fragColor"
); );
@ -13394,8 +12584,8 @@ skybox_t skybox(const char *asset, int flags) {
// sky program // sky program
sky.flags = flags ? flags : !!asset; // either cubemap or rayleigh sky.flags = flags ? flags : !!asset; // either cubemap or rayleigh
sky.program = shader(vs_3_3_skybox, sky.program = shader(vfs_read("shaders/vs_3_3_skybox.glsl"),
sky.flags ? fs_3_4_skybox : fs_3_4_skybox_rayleigh, sky.flags ? vfs_read("fs_3_4_skybox.glsl") : vfs_read("shaders/fs_3_4_skybox_rayleigh.glsl"),
"att_position", "fragcolor"); "att_position", "fragcolor");
// sky cubemap & SH // sky cubemap & SH
@ -13935,14 +13125,14 @@ int postfx_load_from_mem( postfx *fx, const char *name, const char *fs ) {
passfx *p = &fx->pass[ slot & 63 ]; passfx *p = &fx->pass[ slot & 63 ];
p->name = STRDUP(name); p->name = STRDUP(name);
const char *vs = vs_0_2_fullscreen_quad_B; const char *vs = vfs_read("shaders/vs_0_2_fullscreen_quad_B.glsl");
// patch fragment // patch fragment
char *fs2 = (char*)CALLOC(1, 128*1024); char *fs2 = (char*)CALLOC(1, 128*1024);
strcat(fs2, fs_2_4_preamble); strcat(fs2, vfs_read("shaders/fs_2_4_preamble.glsl"));
if( strstr(fs, "mainImage") ) { if( strstr(fs, "mainImage") ) {
strcat(fs2, fs_main_shadertoy ); strcat(fs2, vfs_read("shaders/fs_main_shadertoy.glsl") );
} }
strcat(fs2, fs); strcat(fs2, fs);
@ -14304,52 +13494,8 @@ shadertoy_t shadertoy( const char *shaderfile, unsigned flags ) {
glGenVertexArrays(1, &s.vao); glGenVertexArrays(1, &s.vao);
// Uses gl_VertexID to draw a fullscreen quad without vbo char *fs = stringf("%s%s", vfs_read("header_shadertoy.glsl"), file);
const char *vs = "#version 130\n" s.program = shader(flags ? vfs_read("shaders/vs_shadertoy_flip.glsl") : vfs_read("shaders/vs_shadertoy.glsl"), fs, "", "fragColor");
"uniform vec2 iResolution; // viewport resolution (in pixels)\n"
"out vec2 texCoord;\n"
"void main() {\n"
" texCoord = vec2( (gl_VertexID << 1) & 2, gl_VertexID & 2 );\n"
" gl_Position = vec4( texCoord * 2.0 - 1.0, 0.0, 1.0 );\n"
" texCoord = texCoord * iResolution;\n"
"}\n";
const char *vs_flip = "#version 130\n"
"uniform vec2 iResolution; // viewport resolution (in pixels)\n"
"out vec2 texCoord;\n"
"void main() {\n"
" texCoord = vec2( (gl_VertexID << 1) & 2, gl_VertexID & 2 );\n"
" gl_Position = vec4( texCoord * 2.0 - 1.0, 0.0, 1.0 );\n"
" texCoord = texCoord * iResolution;\n"
" texCoord.y = iResolution.y - texCoord.y; // flip Y\n"
"}\n";
const char *header = "#version 130\n"
"#define texture2D texture\n"
"uniform float iGlobalTime; // shader playback time (in seconds)\n"
"uniform float iGlobalDelta; // ??\n"
"uniform float iGlobalFrame; // ??\n"
"uniform float iSampleRate; // ??\n"
"uniform float iTime; // ??\n"
"uniform int iFrame; // ??\n"
"uniform float iChannelTime[4]; // channel playback time (in seconds)\n"
"uniform vec2 iResolution; // viewport resolution (in pixels)\n"
"uniform vec3 iChannelResolution[4]; // channel resolution (in pixels)\n"
"uniform vec3 iOffset; // ?? (0,0,0)\n"
"uniform vec4 iMouse; // mouse pixel coords. xy: hover, zw: LMB click)\n"
"uniform vec4 iDate; // (year, month, day, time in seconds)\n"
"uniform sampler2D iChannel0; // input channel 0\n" /*sampler%s*/
"uniform sampler2D iChannel1; // input channel 1\n"
"uniform sampler2D iChannel2; // input channel 2\n"
"uniform sampler2D iChannel3; // input channel 3\n"
"in vec2 texCoord;\n"
"out vec4 fragColor;\n"
"void mainImage( out vec4 fragColor, in vec2 fragCoord );\n"
"void main() {\n"
" mainImage(fragColor, texCoord.xy);\n"
"}\n";
char *fs = stringf("%s%s", header, file);
s.program = shader(flags ? vs_flip : vs, fs, "", "fragColor");
FREE(fs); FREE(fs);
if( strstr(file, "noise3.jpg")) if( strstr(file, "noise3.jpg"))
@ -15058,8 +14204,8 @@ model_t model_from_mem(const void *mem, int len, int flags) {
const char *ptr = (const char *)mem; const char *ptr = (const char *)mem;
static int shaderprog = -1; static int shaderprog = -1;
if( shaderprog < 0 ) { if( shaderprog < 0 ) {
const char *symbols[] = { "{{include-shadowmap}}", fs_0_0_shadowmap_lit }; // #define RIM const char *symbols[] = { "{{include-shadowmap}}", vfs_read("shaders/fs_0_0_shadowmap_lit.glsl") }; // #define RIM
shaderprog = shader(strlerp(1,symbols,vs_323444143_16_332_model), strlerp(1,symbols,fs_32_4_model), //fs, shaderprog = shader(strlerp(1,symbols,vfs_read("shaders/vs_323444143_16_332_model.glsl")), strlerp(1,symbols,vfs_read("shaders/fs_32_4_model.glsl")), //fs,
"att_position,att_texcoord,att_normal,att_tangent,att_instanced_matrix,,,,att_indexes,att_weights,att_vertexindex,att_color,att_bitangent","fragColor"); "att_position,att_texcoord,att_normal,att_tangent,att_instanced_matrix,,,,att_indexes,att_weights,att_vertexindex,att_color,att_bitangent","fragColor");
} }
@ -16536,8 +15682,8 @@ scene_t* scene_get_active() {
scene_t* scene_push() { scene_t* scene_push() {
scene_t *s = REALLOC(0, sizeof(scene_t)), clear = {0}; *s = clear; scene_t *s = REALLOC(0, sizeof(scene_t)), clear = {0}; *s = clear;
const char *symbols[] = { "{{include-shadowmap}}", fs_0_0_shadowmap_lit }; const char *symbols[] = { "{{include-shadowmap}}", vfs_read("shaders/fs_0_0_shadowmap_lit.glsl") };
s->program = shader(strlerp(1, symbols, vs_332_32), strlerp(1, symbols, fs_32_4_model), "att_position,att_normal,att_texcoord,att_color", "fragcolor"); s->program = shader(strlerp(1, symbols, vfs_read("shaders/vs_332_32.glsl")), strlerp(1, symbols, vfs_read("shaders/fs_32_4_model.glsl")), "att_position,att_normal,att_texcoord,att_color", "fragcolor");
s->skybox = skybox(NULL, 0); s->skybox = skybox(NULL, 0);
array_push(scenes, s); array_push(scenes, s);
last_scene = s; last_scene = s;

View File

@ -2897,31 +2897,6 @@ API void* screenshot(int components); // 3 RGB, 4 RGBA, -3 BGR, -4 BGRA
API void* screenshot_async(int components); // 3 RGB, 4 RGBA, -3 BGR, -4 BGRA API void* screenshot_async(int components); // 3 RGB, 4 RGBA, -3 BGR, -4 BGRA
#line 0 #line 0
#line 1 "v4k_shaders.h"
extern const char *const fs_0_0_shadowmap_lit;
extern const char *const fs_0_0_shadowmap_unlit;
extern const char *const fs_24_4_sprite;
extern const char *const fs_2_4_preamble;
extern const char *const fs_2_4_texel_inv_gamma;
extern const char *const fs_2_4_texel_ycbr_gamma_saturation;
extern const char *const fs_32_4_model;
extern const char *const fs_32_4_model_basic;
extern const char *const fs_3_4_skybox;
extern const char *const fs_3_4_skybox_rayleigh;
extern const char *const fs_main_shadertoy;
extern const char *const fs_shadow_blur;
extern const char *const fs_shadow_vsm;
extern const char *const vs_0_2_fullscreen_quad_A;
extern const char *const vs_0_2_fullscreen_quad_B;
extern const char *const vs_0_2_fullscreen_quad_B_flipped;
extern const char *const vs_323444143_16_332_model;
extern const char *const vs_324_24_sprite;
extern const char *const vs_332_32;
extern const char *const vs_3_3_skybox;
extern const char *const vs_shadow_blur;
extern const char *const vs_shadow_vsm;
#line 0
#line 1 "v4k_renderdd.h" #line 1 "v4k_renderdd.h"
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
// debugdraw framework // debugdraw framework

View File

@ -1,4 +0,0 @@
#!/bin/bash 2>nul
python tools/glsl_join.py --output ./engine/split/v4k_shaders.c
python tools/glsl_join.py --output ./engine/split/v4k_shaders.h --header

View File

@ -1,61 +0,0 @@
import argparse
import os
def glsl_to_c(output_filename: str):
glsl_directory = "engine/shaders/"
all_shaders = []
for filename in os.listdir(glsl_directory):
if filename.endswith(".glsl"):
with open(os.path.join(glsl_directory, filename), 'r') as f:
shader_code = f.read()
shader_code_escaped = ""
lines = shader_code.split('\n')
for idx, line in enumerate(lines):
if any(keyword in line for keyword in ["#if", "#ifdef", "#else", "#endif"]):
shader_code_escaped += line
else:
shader_code_escaped += f'"{line}\\n"'
# Append semicolon if it's the last line
if idx == len(lines) - 1:
shader_code_escaped += ";"
shader_code_escaped += "\n"
variable_name = os.path.splitext(filename)[0] # Remove the .glsl extension
c_shader_code = f'const char *const {variable_name} = \"//\" FILELINE \"\\n\"\n{shader_code_escaped}'
all_shaders.append(c_shader_code)
# Write all shaders to the C file
with open(output_filename, 'w') as f:
f.write('\n'.join(all_shaders)+'\n')
def glsl_to_h(output_filename: str):
glsl_directory = "engine/shaders/"
all_shaders = []
for filename in os.listdir(glsl_directory):
if filename.endswith(".glsl"):
with open(os.path.join(glsl_directory, filename), 'r') as f:
variable_name = os.path.splitext(filename)[0] # Remove the .glsl extension
h_shader_code = f'extern const char *const {variable_name};'
all_shaders.append(h_shader_code)
# Write all shaders to the C file
with open(output_filename, 'w') as f:
f.write('\n'.join(all_shaders)+'\n')
def main():
parser = argparse.ArgumentParser()
parser.add_argument("--output", required=True, help="Output filename for the C file")
parser.add_argument("--header", required=False, help="Is header file output requested", action=argparse.BooleanOptionalAction)
args = parser.parse_args()
if args.header is True:
glsl_to_h(args.output)
else:
glsl_to_c(args.output)
if __name__ == "__main__":
main()

View File

@ -1,3 +0,0 @@
#!/bin/bash 2>nul
python tools/glsl_split.py --input ./engine/split/v4k_shaders.c

View File

@ -1,69 +0,0 @@
import argparse
import os
import re
def reindent_code(shader_code: str) -> str:
indented_code = []
indentation_level = 0
tab_size = 4 # You can change this to set the desired tab size
for line in shader_code.split('\n'):
line = line.strip()
if line.endswith('}'):
indentation_level -= 1
indented_code.append(' ' * (tab_size * indentation_level) + line)
if line.endswith('{'):
indentation_level += 1
return '\n'.join(indented_code)
def c_to_glsl(input_filename: str):
# Ensure the output directory exists
if not os.path.exists("engine/shaders"):
os.makedirs("engine/shaders")
# Read the C code from the file
with open(input_filename, 'r') as f:
lines = f.readlines()
capturing = False
shader_code = ""
output_filename = None
for line in lines:
if not capturing:
match = re.search(r'const char \*const ([a-zA-Z0-9_]+) =', line)
if match:
output_filename = f"engine/shaders/{match.group(1)}.glsl"
capturing = True
continue # skip the current line since it's just the declaration
if capturing:
if line.strip().endswith('";'):
shader_code += line.rstrip('";\n')
# Process the captured shader code
shader_code = shader_code.replace(r'"\n"', '\n').replace(r'\n', '').replace(r'"', '')
# Save to a .glsl file
with open(output_filename, 'w') as f:
shader_code = shader_code.strip()
f.write(reindent_code(shader_code.strip()))
# Reset for the next shader code
capturing = False
shader_code = ""
output_filename = None
else:
shader_code += line
def main():
parser = argparse.ArgumentParser()
parser.add_argument("--input", required=True)
args = parser.parse_args()
c_to_glsl(args.input)
if __name__ == "__main__":
main()