keep comments

main
Dominik Madarász 2023-08-11 00:46:04 +02:00
parent a706369557
commit 82a2db5301
17 changed files with 543 additions and 495 deletions

View File

@ -339063,28 +339063,33 @@ void network_rpc_send(unsigned id, const char *cmdline) {
#line 1 "v4k_shaders.c"
static const char *const fs_0_0_shadowmap_lit = "//" FILELINE "\n"
"// #version 140 // inverse() requires v140\n"
"// FILELINE\n"
"\n"
"\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;\n"
"uniform samplerCube shadowMap; // VSMCUBE\n"
#else
"uniform sampler2D shadowMap;\n"
"uniform sampler2D shadowMap; // !VSMCUBE\n"
#endif
"\n"
"struct light {\n"
" vec3 position;\n"
" vec3 position; // world-space\n"
" vec4 diffuse;\n"
" vec4 specular;\n"
" float constantAttenuation, linearAttenuation, quadraticAttenuation;\n"
" };\n"
" light light0 = light(\n"
" lightPos,\n"
" vec4(1,1,1,1),\n"
" vec4(1,1,1,1),\n"
" 1.0, 0.0, 0.0\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"
" \n"
" // From http://fabiensanglard.net/shadowmappingVSM/index.php\n"
#if VSMCUBE
" float chebyshevUpperBound(float distance, vec3 dir) {\n"
" distance = distance/20 ;\n"
@ -339093,14 +339098,14 @@ static const char *const fs_0_0_shadowmap_lit = "//" FILELINE "\n"
" float chebyshevUpperBound(float distance, vec4 scPostW) {\n"
" vec2 moments = texture(shadowMap,scPostW.xy).rg;\n"
#endif
" \n"
" // Surface is fully lit. as the current fragment is before the light occluder\n"
" if (distance <= moments.x)\n"
" return 1.0;\n"
" \n"
" \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"
" \n"
" //variance = max(variance, 0.000002);\n"
" variance = max(variance, 0.00002);\n"
" \n"
" float d = distance - moments.x;\n"
@ -339118,24 +339123,24 @@ static const char *const fs_0_0_shadowmap_lit = "//" FILELINE "\n"
" vec3 normal = vec3(normalize(vneye));\n"
" vec3 viewDir = normalize(-fragment);\n"
" \n"
" \n"
" \n"
" // Lighting\n"
" // Convert to eye-space\n"
" vec3 light = vec3(view * vec4(light0.position, 1.0));\n"
" \n"
#if VSMCUBE
" \n"
" // Vectors\n"
" vec3 fragmentToLight = light - fragment;\n"
" vec3 fragmentToLightDir = normalize(fragmentToLight);\n"
" \n"
" \n"
" // Shadows\n"
" vec4 fragmentToLight_world = inverse(view) * vec4(fragmentToLightDir, 0.0);\n"
" float shadowFactor = chebyshevUpperBound(length(fragmentToLight), -fragmentToLight_world.xyz);\n"
#else
" \n"
" // Shadows\n"
" vec4 scPostW = sc / sc.w;\n"
" scPostW = scPostW * 0.5 + 0.5;\n"
" \n"
" float shadowFactor = 1.0;\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"
@ -339154,7 +339159,7 @@ static const char *const fs_0_0_shadowmap_lit = "//" FILELINE "\n"
" vec3 positionToLight = light - fragment;\n"
" vec3 lightDir = normalize(positionToLight);\n"
" \n"
" \n"
" // Angle between fragment-normal and incoming light\n"
" float cosAngIncidence = dot(lightDir, normal);\n"
" cosAngIncidence = clamp(cosAngIncidence, 0, 1);\n"
" \n"
@ -339164,8 +339169,8 @@ static const char *const fs_0_0_shadowmap_lit = "//" FILELINE "\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;\n"
" total_lighting += diffuse * shadowFactor;\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
@ -339174,6 +339179,7 @@ static const char *const fs_0_0_shadowmap_lit = "//" FILELINE "\n"
" }\n";
static 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"
@ -339189,21 +339195,21 @@ static const char *const fs_24_4_sprite = "//" FILELINE "\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"
" \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"
" \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"
@ -339212,12 +339218,12 @@ static const char *const fs_24_4_sprite = "//" FILELINE "\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"
" // ---\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"
@ -339255,7 +339261,7 @@ static const char *const fs_2_4_preamble = "//" FILELINE "\n"
"out vec4 fragColor;\n";
static const char *const fs_2_4_texel_inv_gamma = "//" FILELINE "\n"
"uniform sampler2D texture0;\n"
"uniform sampler2D texture0; /*unit0*/\n"
"uniform float u_inv_gamma;\n"
"\n"
"in vec2 uv;\n"
@ -339264,13 +339270,13 @@ static const char *const fs_2_4_texel_inv_gamma = "//" FILELINE "\n"
"void main() {\n"
" vec4 texel = texture( texture0, uv );\n"
" fragcolor = texel;\n"
" fragcolor.rgb = pow( fragcolor.rgb, vec3( u_inv_gamma ) );\n"
" fragcolor.rgb = pow( fragcolor.rgb, vec3( u_inv_gamma ) ); // defaults: 1.0/2.2 gamma\n"
"}\n";
static const char *const fs_2_4_texel_ycbr_gamma_saturation = "//" FILELINE "\n"
"uniform sampler2D u_texture_y;\n"
"uniform sampler2D u_texture_cb;\n"
"uniform sampler2D u_texture_cr;\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"
"in vec2 uv;\n"
@ -339288,11 +339294,16 @@ static const char *const fs_2_4_texel_ycbr_gamma_saturation = "//" FILELINE "\n"
" -0.7010, 0.5291, -0.8860, 1.0000\n"
" );\n"
" vec4 texel = to_rgb * vec4(y, cb, cr, 1.0);\n"
" \n"
" \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"
" \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"
@ -339326,9 +339337,9 @@ static const char *const fs_32_4_model = "//" FILELINE "\n"
"}\n"
"\n"
"void main() {\n"
"vec3 n = (v_normal);\n"
"\n"
"vec3 n = /*normalize*/(v_normal);\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"
@ -339347,31 +339358,31 @@ static const char *const fs_32_4_model = "//" FILELINE "\n"
"\n"
"\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);\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;\n"
" diffuse = u_diffuse; // * v_color;\n"
" }\n"
" \n"
" \n"
" // lighting mix\n"
" fragcolor = diffuse * lit * shadowing();\n"
" \n"
" \n"
" // rimlight\n"
#ifdef RIM
" {vec3 n = normalize(mat3(M) * v_normal);\n"
" vec3 p = (M * vec4(v_position,1.0)).xyz;\n"
" vec3 v = normalize(-p);\n"
" float rim = 1.0 - max(dot(v, n), 0.0);\n"
" rim = smoothstep(1.0-0.01, 1.0, rim);\n"
" fragcolor += vec4(0.0, 0.0, rim, 1.0);}\n"
#endif
" \n"
"}\n";
" {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"
" }\n";
static const char *const fs_32_4_model_basic = "//" FILELINE "\n"
"uniform sampler2D fsDiffTex;\n"
@ -339385,8 +339396,8 @@ static const char *const fs_32_4_model_basic = "//" FILELINE "\n"
"\n"
"void main() {\n"
" vec4 diff = texture(fsDiffTex, v_texcoord).rgba;\n"
" vec3 n = normalize(mat3(MVP) * v_normal);\n"
" fragColor = diff;\n"
" vec3 n = normalize(mat3(MVP) * v_normal); // transform normal to eye space\n"
" fragColor = diff;// * vec4(v_normal.xyz, 1);\n"
"}\n";
static const char *const fs_3_4_skybox = "//" FILELINE "\n"
@ -339400,7 +339411,7 @@ static const char *const fs_3_4_skybox = "//" FILELINE "\n"
"}\n";
static const char *const fs_3_4_skybox_rayleigh = "//" FILELINE "\n"
"uniform vec3 uSunPos = vec3( 0, 0.1, -1 );\n"
"uniform vec3 uSunPos = vec3( 0, 0.1, -1 ); // = [0, Math.cos(theta) * 0.3 + 0.2, -1];\n"
"\n"
"in vec3 v_direction;\n"
"out vec4 fragcolor;\n"
@ -339409,36 +339420,36 @@ static const char *const fs_3_4_skybox_rayleigh = "//" FILELINE "\n"
"\n"
"void main() {\n"
" vec3 color = atmosphere(\n"
" normalize(v_direction),\n"
" vec3(0,6372e3,0),\n"
" uSunPos,\n"
" 22.0,\n"
" 6371e3,\n"
" 6471e3,\n"
" vec3(5.5e-6, 13.0e-6, 22.4e-6),\n"
" 21e-6,\n"
" 8e3,\n"
" 1.2e3,\n"
" 0.758\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"
" \n"
" // Apply exposure.\n"
" color = 1.0 - exp(-1.0 * color);\n"
" \n"
" fragcolor = vec4(color, 1);\n"
"}\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"
"#define PI 3.141592\n"
"#define iSteps 16\n"
"#define jSteps 8\n"
"\n"
"vec2 rsi(vec3 r0, vec3 rd, float sr) {\n"
" \n"
" \n"
" \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"
@ -339451,91 +339462,91 @@ static const char *const fs_3_4_skybox_rayleigh = "//" FILELINE "\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"
" // Normalize the sun and view directions.\n"
" pSun = normalize(pSun);\n"
" r = normalize(r);\n"
" \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"
" \n"
" // Initialize the primary ray time.\n"
" float iTime = 0.0;\n"
" \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"
" \n"
" // Initialize optical depth accumulators for the primary ray.\n"
" float iOdRlh = 0.0;\n"
" float iOdMie = 0.0;\n"
" \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"
" \n"
" // Sample the primary ray.\n"
" for (int i = 0; i < iSteps; i++) {\n"
" \n"
" \n"
" // Calculate the primary ray sample position.\n"
" vec3 iPos = r0 + r * (iTime + iStepSize * 0.5);\n"
" \n"
" \n"
" // Calculate the height of the sample.\n"
" float iHeight = length(iPos) - rPlanet;\n"
" \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"
" \n"
" // Accumulate optical depth.\n"
" iOdRlh += odStepRlh;\n"
" iOdMie += odStepMie;\n"
" \n"
" \n"
" // Calculate the step size of the secondary ray.\n"
" float jStepSize = rsi(iPos, pSun, rAtmos).y / float(jSteps);\n"
" \n"
" \n"
" // Initialize the secondary ray time.\n"
" float jTime = 0.0;\n"
" \n"
" \n"
" // Initialize optical depth accumulators for the secondary ray.\n"
" float jOdRlh = 0.0;\n"
" float jOdMie = 0.0;\n"
" \n"
" \n"
" // Sample the secondary ray.\n"
" for (int j = 0; j < jSteps; j++) {\n"
" \n"
" \n"
" // Calculate the secondary ray sample position.\n"
" vec3 jPos = iPos + pSun * (jTime + jStepSize * 0.5);\n"
" \n"
" \n"
" // Calculate the height of the sample.\n"
" float jHeight = length(jPos) - rPlanet;\n"
" \n"
" \n"
" // Accumulate the optical depth.\n"
" jOdRlh += exp(-jHeight / shRlh) * jStepSize;\n"
" jOdMie += exp(-jHeight / shMie) * jStepSize;\n"
" \n"
" \n"
" // Increment the secondary ray time.\n"
" jTime += jStepSize;\n"
" }\n"
" \n"
" \n"
" // Calculate attenuation.\n"
" vec3 attn = exp(-(kMie * (iOdMie + jOdMie) + kRlh * (iOdRlh + jOdRlh)));\n"
" \n"
" \n"
" // Accumulate scattering.\n"
" totalRlh += odStepRlh * attn;\n"
" totalMie += odStepMie * attn;\n"
" \n"
" \n"
" // Increment the primary ray time.\n"
" iTime += iStepSize;\n"
" \n"
" }\n"
" \n"
" \n"
" // Calculate and return the final color.\n"
" return iSun * (pRlh * kRlh * totalRlh + pMie * kMie * totalMie);\n"
"}\n";
@ -339559,8 +339570,8 @@ static const char *const vs_0_2_fullscreen_quad_B = "//" FILELINE "\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);\n"
" uv = vec2(x, y);\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";
static const char *const vs_0_2_fullscreen_quad_B_flipped = "//" FILELINE "\n"
@ -339569,8 +339580,8 @@ static const char *const vs_0_2_fullscreen_quad_B_flipped = "//" FILELINE "\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);\n"
" uv = vec2(x, y);\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";
static const char *const vs_323444143_16_332_model = "//" FILELINE "\n"
@ -339579,11 +339590,11 @@ static const char *const vs_323444143_16_332_model = "//" FILELINE "\n"
#endif
"uniform mat3x4 vsBoneMatrix[MAX_BONES];\n"
"uniform bool SKINNED = false;\n"
"\n"
"// uniform mat4 M; // RIM\n"
"uniform mat4 VP;\n"
"\n"
#if 0
"\n"
"// 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"
@ -339609,31 +339620,31 @@ static const char *const vs_323444143_16_332_model = "//" FILELINE "\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];\n"
"uniform float f_num_blend_shapes;\n"
"uniform sampler2DArray blend_shapes;\n"
"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"
"in vec3 att_position;\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;\n"
"in mat4 att_instanced_matrix;\n"
"in vec4 att_indexes;\n"
"in vec4 att_weights;\n"
"in float att_vertexindex;\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;\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"
"// shadow\n"
"uniform mat4 model, view;\n"
"uniform mat4 cameraToShadowProjector;\n"
"out vec4 vneye;\n"
@ -339645,7 +339656,7 @@ static const char *const vs_323444143_16_332_model = "//" FILELINE "\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"
@ -339670,17 +339681,17 @@ static const char *const vs_323444143_16_332_model = "//" FILELINE "\n"
" m += vsBoneMatrix[int(att_indexes.w)] * att_weights.w;\n"
" objPos = vec4(att_position, 1.0) * m;\n"
" \n"
" \n"
" \n"
" // blendshapes\n"
" // objPos += evaluate_blend_shape(int(att_vertexindex));\n"
" \n"
" v_normal = vec4(att_normal, 0.0) * m;\n"
" \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"
" \n"
" \n"
" v_normal_ws = normalize(vec3(model * vec4(v_normal, 0.)));\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"
@ -339705,6 +339716,7 @@ static const char *const vs_324_24_sprite = "//" FILELINE "\n"
"}\n";
static const char *const vs_332_32 = "//" FILELINE "\n"
"//uniform mat4 u_model, u_view, u_proj;\n"
"uniform mat4 u_mvp;\n"
"\n"
"in vec3 att_position;\n"
@ -339716,12 +339728,12 @@ static const char *const vs_332_32 = "//" FILELINE "\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;\n"
"uniform mat4 cameraToShadowProjector; // !VSMCUBE\n"
"out vec4 vneye;\n"
"out vec4 vpeye;\n"
"out vec4 sc;\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"
@ -339729,10 +339741,10 @@ static const char *const vs_332_32 = "//" FILELINE "\n"
"}\n"
"\n"
"void main() {\n"
" \n"
" // gl_Position = proj * view * model * vec4(att_position, 1.0);\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.)));\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"

View File

@ -1,25 +1,30 @@
// #version 140 // inverse() requires v140
// FILELINE
// uniform mat4 view = mat4(1.0);
uniform vec3 lightPos = vec3(1.0);
uniform float doTexture = 1.;
#if VSMCUBE
uniform samplerCube shadowMap;
uniform samplerCube shadowMap; // VSMCUBE
#else
uniform sampler2D shadowMap;
uniform sampler2D shadowMap; // !VSMCUBE
#endif
struct light {
vec3 position;
vec3 position; // world-space
vec4 diffuse;
vec4 specular;
float constantAttenuation, linearAttenuation, quadraticAttenuation;
};
light light0 = light(
lightPos,
vec4(1,1,1,1),
vec4(1,1,1,1),
1.0, 0.0, 0.0
vec4(1,1,1,1), // diffuse
vec4(1,1,1,1), // specular
1.0, 0.0, 0.0 // attenuation (const, linear, quad)
);
// From http://fabiensanglard.net/shadowmappingVSM/index.php
#if VSMCUBE
float chebyshevUpperBound(float distance, vec3 dir) {
distance = distance/20 ;
@ -28,14 +33,14 @@ struct light {
float chebyshevUpperBound(float distance, vec4 scPostW) {
vec2 moments = texture(shadowMap,scPostW.xy).rg;
#endif
// Surface is fully lit. as the current fragment is before the light occluder
if (distance <= moments.x)
return 1.0;
// The fragment is either in shadow or penumbra. We now use chebyshev's upperBound to check
// How likely this pixel is to be lit (p_max)
float variance = moments.y - (moments.x*moments.x);
//variance = max(variance, 0.000002);
variance = max(variance, 0.00002);
float d = distance - moments.x;
@ -53,24 +58,24 @@ struct light {
vec3 normal = vec3(normalize(vneye));
vec3 viewDir = normalize(-fragment);
// Lighting
// Convert to eye-space
vec3 light = vec3(view * vec4(light0.position, 1.0));
#if VSMCUBE
// Vectors
vec3 fragmentToLight = light - fragment;
vec3 fragmentToLightDir = normalize(fragmentToLight);
// Shadows
vec4 fragmentToLight_world = inverse(view) * vec4(fragmentToLightDir, 0.0);
float shadowFactor = chebyshevUpperBound(length(fragmentToLight), -fragmentToLight_world.xyz);
#else
// Shadows
vec4 scPostW = sc / sc.w;
scPostW = scPostW * 0.5 + 0.5;
float shadowFactor = 1.0;
float shadowFactor = 1.0; // Not in shadow
bool outsideShadowMap = sc.w <= 0.0f || (scPostW.x < 0 || scPostW.y < 0) || (scPostW.x >= 1 || scPostW.y >= 1);
if (!outsideShadowMap) {
@ -89,7 +94,7 @@ struct light {
vec3 positionToLight = light - fragment;
vec3 lightDir = normalize(positionToLight);
// Angle between fragment-normal and incoming light
float cosAngIncidence = dot(lightDir, normal);
cosAngIncidence = clamp(cosAngIncidence, 0, 1);
@ -99,8 +104,8 @@ struct light {
vec4 diffuse = diffColor * light0.diffuse * cosAngIncidence * attenuation;
vec4 total_lighting;
total_lighting += vec4(0.1, 0.1, 0.1, 1.0) * diffColor;
total_lighting += diffuse * shadowFactor;
total_lighting += vec4(0.1, 0.1, 0.1, 1.0) * diffColor; // Ambient
total_lighting += diffuse * shadowFactor; // Diffuse
#else
vec4 total_lighting = diffColor;
#endif

View File

@ -1,3 +1,4 @@
// uniform mat4 view = mat4(1.0);
uniform vec3 lightPos = vec3(1.0);
uniform float doTexture = 0.;
uniform sampler2D shadowMap;

View File

@ -4,21 +4,21 @@ in vec2 vTexCoord;
in vec4 vColor;
out vec4 fragColor;
// [src] https://www.shadertoy.com/view/MllBWf CC1.0
vec4 texture_AA(sampler2D tx, vec2 uv) {
vec2 res = vec2(textureSize(tx, 0));
uv = uv*res + 0.5;
// tweak fractionnal value of the texture coordinate
vec2 fl = floor(uv);
vec2 fr = fract(uv);
vec2 aa = fwidth(uv)*0.75;
fr = smoothstep( vec2(0.5)-aa, vec2(0.5)+aa, fr);
// return value
uv = (fl+fr-0.5) / res;
return texture(tx, uv);
}
// [src] https://www.shadertoy.com/view/MllBWf CC1.0
vec4 texture_AA2( sampler2D tex, vec2 uv) {
vec2 res = vec2(textureSize(tex,0));
uv = uv*res;
@ -27,12 +27,12 @@ vec4 texture_AA2( sampler2D tex, vec2 uv) {
return texture(tex, uv/res);
}
// [src] https://www.shadertoy.com/view/ltBfRD
vec4 texture_AA3(sampler2D tex, vec2 uv) {
vec2 res = vec2(textureSize(tex,0));
float width = 2.0;
uv = uv * res;
// ---
vec2 uv_floor = floor(uv + 0.5);
vec2 uv_fract = fract(uv + 0.5);
vec2 uv_aa = fwidth(uv) * width * 0.5;

View File

@ -1,4 +1,4 @@
uniform sampler2D texture0;
uniform sampler2D texture0; /*unit0*/
uniform float u_inv_gamma;
in vec2 uv;
@ -7,5 +7,5 @@ out vec4 fragcolor;
void main() {
vec4 texel = texture( texture0, uv );
fragcolor = texel;
fragcolor.rgb = pow( fragcolor.rgb, vec3( u_inv_gamma ) );
fragcolor.rgb = pow( fragcolor.rgb, vec3( u_inv_gamma ) ); // defaults: 1.0/2.2 gamma
}

View File

@ -1,6 +1,6 @@
uniform sampler2D u_texture_y;
uniform sampler2D u_texture_cb;
uniform sampler2D u_texture_cr;
uniform sampler2D u_texture_y; /*unit0*/
uniform sampler2D u_texture_cb; /*unit1*/
uniform sampler2D u_texture_cr; /*unit2*/
uniform float u_gamma;
in vec2 uv;
@ -18,11 +18,16 @@ void main() {
-0.7010, 0.5291, -0.8860, 1.0000
);
vec4 texel = to_rgb * vec4(y, cb, cr, 1.0);
/* same as:
vec3 yCbCr = vec3(y,cb-0.5,cr-0.5);
vec4 texel = vec4( dot( vec3( 1.0, 0.0, 1.402 ), yCbCr ),
dot( vec3( 1.0 , -0.34414 , -0.71414 ), yCbCr ),
dot( vec3( 1.0, 1.772, 0.0 ), yCbCr ), 1.0);
*/
// gamma correction
texel.rgb = pow(texel.rgb, vec3(1.0 / u_gamma));
// saturation (algorithm from Chapter 16 of OpenGL Shading Language)
if(false) { float saturation = 2.0; const vec3 W = vec3(0.2125, 0.7154, 0.0721);
vec3 intensity = vec3(dot(texel.rgb, W));
texel.rgb = mix(intensity, texel.rgb, saturation); }

View File

@ -23,9 +23,9 @@ return shadowmap(vpeye, vneye, v_texcoord, sc);
}
void main() {
vec3 n = (v_normal);
vec3 n = /*normalize*/(v_normal);
// SH lighting
vec4 lit = vec4(1.0, 1.0, 1.0, 1.0);
vec3 SHLightResult[9];
SHLightResult[0] = 0.282095f * u_coefficients_sh[0];
@ -44,28 +44,28 @@ if( (result.x*result.x+result.y*result.y+result.z*result.z) > 0.0 ) lit = vec4(r
// base
vec4 diffuse;
if(u_matcaps) {
vec2 muv = vec2(view * vec4(v_normal_ws, 0))*0.5+vec2(0.5,0.5);
vec2 muv = vec2(view * vec4(v_normal_ws, 0))*0.5+vec2(0.5,0.5); // normal (model space) to view space
diffuse = texture(u_texture2d, vec2(muv.x, 1.0-muv.y));
} else if(u_textured) {
diffuse = texture(u_texture2d, v_texcoord);
} else {
diffuse = u_diffuse;
diffuse = u_diffuse; // * v_color;
}
// lighting mix
fragcolor = diffuse * lit * shadowing();
// rimlight
#ifdef RIM
{vec3 n = normalize(mat3(M) * v_normal);
vec3 p = (M * vec4(v_position,1.0)).xyz;
vec3 v = normalize(-p);
float rim = 1.0 - max(dot(v, n), 0.0);
rim = smoothstep(1.0-0.01, 1.0, rim);
fragcolor += vec4(0.0, 0.0, rim, 1.0);}
#endif
}
{vec3 n = normalize(mat3(M) * v_normal); // convert normal to view space
vec3 p = (M * vec4(v_position,1.0)).xyz; // convert position to view space
vec3 v = normalize(-p); // eye vector
float rim = 1.0 - max(dot(v, n), 0.0); // rimlight
rim = smoothstep(1.0-0.01, 1.0, rim); // intensity (0.01)
fragcolor += vec4(0.0, 0.0, rim, 1.0);} // blue
#endif
}

View File

@ -9,6 +9,6 @@ out vec4 fragColor;
void main() {
vec4 diff = texture(fsDiffTex, v_texcoord).rgba;
vec3 n = normalize(mat3(MVP) * v_normal);
fragColor = diff;
vec3 n = normalize(mat3(MVP) * v_normal); // transform normal to eye space
fragColor = diff;// * vec4(v_normal.xyz, 1);
}

View File

@ -1,4 +1,4 @@
uniform vec3 uSunPos = vec3( 0, 0.1, -1 );
uniform vec3 uSunPos = vec3( 0, 0.1, -1 ); // = [0, Math.cos(theta) * 0.3 + 0.2, -1];
in vec3 v_direction;
out vec4 fragcolor;
@ -7,36 +7,36 @@ vec3 atmosphere(vec3 r, vec3 r0, vec3 pSun, float iSun, float rPlanet, float rAt
void main() {
vec3 color = atmosphere(
normalize(v_direction),
vec3(0,6372e3,0),
uSunPos,
22.0,
6371e3,
6471e3,
vec3(5.5e-6, 13.0e-6, 22.4e-6),
21e-6,
8e3,
1.2e3,
0.758
normalize(v_direction), // normalized ray direction
vec3(0,6372e3,0), // ray origin
uSunPos, // position of the sun
22.0, // intensity of the sun
6371e3, // radius of the planet in meters
6471e3, // radius of the atmosphere in meters
vec3(5.5e-6, 13.0e-6, 22.4e-6), // Rayleigh scattering coefficient
21e-6, // Mie scattering coefficient
8e3, // Rayleigh scale height
1.2e3, // Mie scale height
0.758 // Mie preferred scattering direction
);
// Apply exposure.
color = 1.0 - exp(-1.0 * color);
fragcolor = vec4(color, 1);
}
// [src] https://github.com/wwwtyro/glsl-atmosphere by wwwtyro (Unlicensed)
// For more information, please refer to <http://unlicense.org>
#define PI 3.141592
#define iSteps 16
#define jSteps 8
vec2 rsi(vec3 r0, vec3 rd, float sr) {
// ray-sphere intersection that assumes
// the sphere is centered at the origin.
// No intersection when result.x > result.y
float a = dot(rd, rd);
float b = 2.0 * dot(rd, r0);
float c = dot(r0, r0) - (sr * sr);
@ -49,90 +49,90 @@ vec2 rsi(vec3 r0, vec3 rd, float sr) {
}
vec3 atmosphere(vec3 r, vec3 r0, vec3 pSun, float iSun, float rPlanet, float rAtmos, vec3 kRlh, float kMie, float shRlh, float shMie, float g) {
// Normalize the sun and view directions.
pSun = normalize(pSun);
r = normalize(r);
// Calculate the step size of the primary ray.
vec2 p = rsi(r0, r, rAtmos);
if (p.x > p.y) return vec3(0,0,0);
p.y = min(p.y, rsi(r0, r, rPlanet).x);
float iStepSize = (p.y - p.x) / float(iSteps);
// Initialize the primary ray time.
float iTime = 0.0;
// Initialize accumulators for Rayleigh and Mie scattering.
vec3 totalRlh = vec3(0,0,0);
vec3 totalMie = vec3(0,0,0);
// Initialize optical depth accumulators for the primary ray.
float iOdRlh = 0.0;
float iOdMie = 0.0;
// Calculate the Rayleigh and Mie phases.
float mu = dot(r, pSun);
float mumu = mu * mu;
float gg = g * g;
float pRlh = 3.0 / (16.0 * PI) * (1.0 + mumu);
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));
// Sample the primary ray.
for (int i = 0; i < iSteps; i++) {
// Calculate the primary ray sample position.
vec3 iPos = r0 + r * (iTime + iStepSize * 0.5);
// Calculate the height of the sample.
float iHeight = length(iPos) - rPlanet;
// Calculate the optical depth of the Rayleigh and Mie scattering for this step.
float odStepRlh = exp(-iHeight / shRlh) * iStepSize;
float odStepMie = exp(-iHeight / shMie) * iStepSize;
// Accumulate optical depth.
iOdRlh += odStepRlh;
iOdMie += odStepMie;
// Calculate the step size of the secondary ray.
float jStepSize = rsi(iPos, pSun, rAtmos).y / float(jSteps);
// Initialize the secondary ray time.
float jTime = 0.0;
// Initialize optical depth accumulators for the secondary ray.
float jOdRlh = 0.0;
float jOdMie = 0.0;
// Sample the secondary ray.
for (int j = 0; j < jSteps; j++) {
// Calculate the secondary ray sample position.
vec3 jPos = iPos + pSun * (jTime + jStepSize * 0.5);
// Calculate the height of the sample.
float jHeight = length(jPos) - rPlanet;
// Accumulate the optical depth.
jOdRlh += exp(-jHeight / shRlh) * jStepSize;
jOdMie += exp(-jHeight / shMie) * jStepSize;
// Increment the secondary ray time.
jTime += jStepSize;
}
// Calculate attenuation.
vec3 attn = exp(-(kMie * (iOdMie + jOdMie) + kRlh * (iOdRlh + jOdRlh)));
// Accumulate scattering.
totalRlh += odStepRlh * attn;
totalMie += odStepMie * attn;
// Increment the primary ray time.
iTime += iStepSize;
}
// Calculate and return the final color.
return iSun * (pRlh * kRlh * totalRlh + pMie * kMie * totalMie);
}

View File

@ -3,6 +3,6 @@ out vec2 uv;
void main() {
float x = float(((uint(gl_VertexID) + 2u) / 3u)%2u);
float y = float(((uint(gl_VertexID) + 1u) / 3u)%2u);
gl_Position = vec4(-1.0 + x*2.0, 0.0+(-1.0+y*2.0), 0.0, 1.0);
uv = vec2(x, y);
gl_Position = vec4(-1.0 + x*2.0, 0.0+(-1.0+y*2.0), 0.0, 1.0); // normal(0+),flipped(0-)
uv = vec2(x, y); // normal(y),flipped(1.0-y)
}

View File

@ -3,6 +3,6 @@ out vec2 uv;
void main() {
float x = float(((uint(gl_VertexID) + 2u) / 3u)%2u);
float y = float(((uint(gl_VertexID) + 1u) / 3u)%2u);
gl_Position = vec4(-1.0 + x*2.0, 0.0-(-1.0+y*2.0), 0.0, 1.0);
uv = vec2(x, y);
gl_Position = vec4(-1.0 + x*2.0, 0.0-(-1.0+y*2.0), 0.0, 1.0); // normal(0+),flipped(0-)
uv = vec2(x, y); // normal(y),flipped(1.0-y)
}

View File

@ -3,11 +3,11 @@
#endif
uniform mat3x4 vsBoneMatrix[MAX_BONES];
uniform bool SKINNED = false;
// uniform mat4 M; // RIM
uniform mat4 VP;
#if 0
// Fetch blend channels from all attached blend deformers.
for (size_t di = 0; di < mesh->blend_deformers.count; di++) {
ufbx_blend_deformer *deformer = mesh->blend_deformers.data[di];
for (size_t ci = 0; ci < deformer->channels.count; ci++) {
@ -33,31 +33,31 @@ for (size_t i = 0; i < mesh->num_blend_shapes; i++) {
sg_image blend_shapes = mesh->num_blend_shapes > 0 ? mesh->blend_shape_image : view->empty_blend_shape_image;
#endif
// for blendshapes
#ifndef MAX_BLENDSHAPES
#define MAX_BLENDSHAPES 16
#endif
uniform vec4 blend_weights[MAX_BLENDSHAPES];
uniform float f_num_blend_shapes;
uniform sampler2DArray blend_shapes;
uniform vec4 blend_weights[MAX_BLENDSHAPES]; // @todo: implement me
uniform float f_num_blend_shapes; // @todo: implement me
uniform sampler2DArray blend_shapes; // @todo: implement me
in vec3 att_position;
in vec3 att_position; // @todo: reorder ass2iqe to emit p3 n3 u2 t3 b3 c4B i4 w4 instead
in vec2 att_texcoord;
in vec3 att_normal;
in vec4 att_tangent;
in mat4 att_instanced_matrix;
in vec4 att_indexes;
in vec4 att_weights;
in float att_vertexindex;
in vec4 att_tangent; // vec3 + bi sign
in mat4 att_instanced_matrix; // for instanced rendering
in vec4 att_indexes; // @fixme: gles might use ivec4 instead?
in vec4 att_weights; // @todo: downgrade from float to byte
in float att_vertexindex; // for blendshapes
in vec4 att_color;
in vec3 att_bitangent;
in vec3 att_bitangent; // @todo: remove? also, ass2iqe might output this
out vec4 v_color;
out vec3 v_position;
out vec3 v_normal, v_normal_ws;
out vec2 v_texcoord;
// shadow
uniform mat4 model, view;
uniform mat4 cameraToShadowProjector;
out vec4 vneye;
@ -69,7 +69,7 @@ void do_shadow() {
sc = cameraToShadowProjector * model * vec4(att_position, 1.0f);
}
// blendshapes
vec3 evaluate_blend_shape(int vertex_index) {
ivec2 coord = ivec2(vertex_index & (2048 - 1), vertex_index >> 11);
int num_blend_shapes = int(f_num_blend_shapes);
@ -94,17 +94,17 @@ void main() {
m += vsBoneMatrix[int(att_indexes.w)] * att_weights.w;
objPos = vec4(att_position, 1.0) * m;
// blendshapes
// objPos += evaluate_blend_shape(int(att_vertexindex));
v_normal = vec4(att_normal, 0.0) * m;
//@todo: tangents
}
// vec3 tangent = att_tangent.xyz;
// vec3 bitangent = cross(att_normal, att_tangent.xyz) * att_tangent.w;
v_normal_ws = normalize(vec3(model * vec4(v_normal, 0.)));
v_normal_ws = normalize(vec3(model * vec4(v_normal, 0.))); // normal to world/model space
v_normal = normalize(v_normal);
v_position = att_position;
v_texcoord = att_texcoord;

View File

@ -1,3 +1,4 @@
//uniform mat4 u_model, u_view, u_proj;
uniform mat4 u_mvp;
in vec3 att_position;
@ -9,12 +10,12 @@ out vec3 v_normal;
out vec3 v_normal_ws;
out vec2 v_texcoord;
// shadow
uniform mat4 model, view, proj;
uniform mat4 cameraToShadowProjector;
uniform mat4 cameraToShadowProjector; // !VSMCUBE
out vec4 vneye;
out vec4 vpeye;
out vec4 sc;
out vec4 sc; // !VSMCUBE
void do_shadow() {
vneye = view * model * vec4(att_normal, 0.0f);
vpeye = view * model * vec4(att_position, 1.0);
@ -22,10 +23,10 @@ void do_shadow() {
}
void main() {
// gl_Position = proj * view * model * vec4(att_position, 1.0);
gl_Position = u_mvp * vec4(att_position, 1.0);
v_normal = normalize(att_normal);
v_normal_ws = normalize(vec3(model * vec4(att_normal, 0.)));
v_normal_ws = normalize(vec3(model * vec4(att_normal, 0.))); // normal world/model space
v_texcoord = att_texcoord;
v_color = att_color;
do_shadow();

View File

@ -1,26 +1,31 @@
static const char *const fs_0_0_shadowmap_lit = "//" FILELINE "\n"
"// #version 140 // inverse() requires v140\n"
"// FILELINE\n"
"\n"
"\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;\n"
"uniform samplerCube shadowMap; // VSMCUBE\n"
#else
"uniform sampler2D shadowMap;\n"
"uniform sampler2D shadowMap; // !VSMCUBE\n"
#endif
"\n"
"struct light {\n"
" vec3 position;\n"
" vec3 position; // world-space\n"
" vec4 diffuse;\n"
" vec4 specular;\n"
" float constantAttenuation, linearAttenuation, quadraticAttenuation;\n"
" };\n"
" light light0 = light(\n"
" lightPos,\n"
" vec4(1,1,1,1),\n"
" vec4(1,1,1,1),\n"
" 1.0, 0.0, 0.0\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"
" \n"
" // From http://fabiensanglard.net/shadowmappingVSM/index.php\n"
#if VSMCUBE
" float chebyshevUpperBound(float distance, vec3 dir) {\n"
" distance = distance/20 ;\n"
@ -29,14 +34,14 @@ static const char *const fs_0_0_shadowmap_lit = "//" FILELINE "\n"
" float chebyshevUpperBound(float distance, vec4 scPostW) {\n"
" vec2 moments = texture(shadowMap,scPostW.xy).rg;\n"
#endif
" \n"
" // Surface is fully lit. as the current fragment is before the light occluder\n"
" if (distance <= moments.x)\n"
" return 1.0;\n"
" \n"
" \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"
" \n"
" //variance = max(variance, 0.000002);\n"
" variance = max(variance, 0.00002);\n"
" \n"
" float d = distance - moments.x;\n"
@ -54,24 +59,24 @@ static const char *const fs_0_0_shadowmap_lit = "//" FILELINE "\n"
" vec3 normal = vec3(normalize(vneye));\n"
" vec3 viewDir = normalize(-fragment);\n"
" \n"
" \n"
" \n"
" // Lighting\n"
" // Convert to eye-space\n"
" vec3 light = vec3(view * vec4(light0.position, 1.0));\n"
" \n"
#if VSMCUBE
" \n"
" // Vectors\n"
" vec3 fragmentToLight = light - fragment;\n"
" vec3 fragmentToLightDir = normalize(fragmentToLight);\n"
" \n"
" \n"
" // Shadows\n"
" vec4 fragmentToLight_world = inverse(view) * vec4(fragmentToLightDir, 0.0);\n"
" float shadowFactor = chebyshevUpperBound(length(fragmentToLight), -fragmentToLight_world.xyz);\n"
#else
" \n"
" // Shadows\n"
" vec4 scPostW = sc / sc.w;\n"
" scPostW = scPostW * 0.5 + 0.5;\n"
" \n"
" float shadowFactor = 1.0;\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"
@ -90,7 +95,7 @@ static const char *const fs_0_0_shadowmap_lit = "//" FILELINE "\n"
" vec3 positionToLight = light - fragment;\n"
" vec3 lightDir = normalize(positionToLight);\n"
" \n"
" \n"
" // Angle between fragment-normal and incoming light\n"
" float cosAngIncidence = dot(lightDir, normal);\n"
" cosAngIncidence = clamp(cosAngIncidence, 0, 1);\n"
" \n"
@ -100,8 +105,8 @@ static const char *const fs_0_0_shadowmap_lit = "//" FILELINE "\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;\n"
" total_lighting += diffuse * shadowFactor;\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
@ -110,6 +115,7 @@ static const char *const fs_0_0_shadowmap_lit = "//" FILELINE "\n"
" }\n";
static 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"
@ -125,21 +131,21 @@ static const char *const fs_24_4_sprite = "//" FILELINE "\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"
" \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"
" \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"
@ -148,12 +154,12 @@ static const char *const fs_24_4_sprite = "//" FILELINE "\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"
" // ---\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"
@ -191,7 +197,7 @@ static const char *const fs_2_4_preamble = "//" FILELINE "\n"
"out vec4 fragColor;\n";
static const char *const fs_2_4_texel_inv_gamma = "//" FILELINE "\n"
"uniform sampler2D texture0;\n"
"uniform sampler2D texture0; /*unit0*/\n"
"uniform float u_inv_gamma;\n"
"\n"
"in vec2 uv;\n"
@ -200,13 +206,13 @@ static const char *const fs_2_4_texel_inv_gamma = "//" FILELINE "\n"
"void main() {\n"
" vec4 texel = texture( texture0, uv );\n"
" fragcolor = texel;\n"
" fragcolor.rgb = pow( fragcolor.rgb, vec3( u_inv_gamma ) );\n"
" fragcolor.rgb = pow( fragcolor.rgb, vec3( u_inv_gamma ) ); // defaults: 1.0/2.2 gamma\n"
"}\n";
static const char *const fs_2_4_texel_ycbr_gamma_saturation = "//" FILELINE "\n"
"uniform sampler2D u_texture_y;\n"
"uniform sampler2D u_texture_cb;\n"
"uniform sampler2D u_texture_cr;\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"
"in vec2 uv;\n"
@ -224,11 +230,16 @@ static const char *const fs_2_4_texel_ycbr_gamma_saturation = "//" FILELINE "\n"
" -0.7010, 0.5291, -0.8860, 1.0000\n"
" );\n"
" vec4 texel = to_rgb * vec4(y, cb, cr, 1.0);\n"
" \n"
" \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"
" \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"
@ -262,9 +273,9 @@ static const char *const fs_32_4_model = "//" FILELINE "\n"
"}\n"
"\n"
"void main() {\n"
"vec3 n = (v_normal);\n"
"\n"
"vec3 n = /*normalize*/(v_normal);\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"
@ -283,31 +294,31 @@ static const char *const fs_32_4_model = "//" FILELINE "\n"
"\n"
"\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);\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;\n"
" diffuse = u_diffuse; // * v_color;\n"
" }\n"
" \n"
" \n"
" // lighting mix\n"
" fragcolor = diffuse * lit * shadowing();\n"
" \n"
" \n"
" // rimlight\n"
#ifdef RIM
" {vec3 n = normalize(mat3(M) * v_normal);\n"
" vec3 p = (M * vec4(v_position,1.0)).xyz;\n"
" vec3 v = normalize(-p);\n"
" float rim = 1.0 - max(dot(v, n), 0.0);\n"
" rim = smoothstep(1.0-0.01, 1.0, rim);\n"
" fragcolor += vec4(0.0, 0.0, rim, 1.0);}\n"
#endif
" \n"
"}\n";
" {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"
" }\n";
static const char *const fs_32_4_model_basic = "//" FILELINE "\n"
"uniform sampler2D fsDiffTex;\n"
@ -321,8 +332,8 @@ static const char *const fs_32_4_model_basic = "//" FILELINE "\n"
"\n"
"void main() {\n"
" vec4 diff = texture(fsDiffTex, v_texcoord).rgba;\n"
" vec3 n = normalize(mat3(MVP) * v_normal);\n"
" fragColor = diff;\n"
" vec3 n = normalize(mat3(MVP) * v_normal); // transform normal to eye space\n"
" fragColor = diff;// * vec4(v_normal.xyz, 1);\n"
"}\n";
static const char *const fs_3_4_skybox = "//" FILELINE "\n"
@ -336,7 +347,7 @@ static const char *const fs_3_4_skybox = "//" FILELINE "\n"
"}\n";
static const char *const fs_3_4_skybox_rayleigh = "//" FILELINE "\n"
"uniform vec3 uSunPos = vec3( 0, 0.1, -1 );\n"
"uniform vec3 uSunPos = vec3( 0, 0.1, -1 ); // = [0, Math.cos(theta) * 0.3 + 0.2, -1];\n"
"\n"
"in vec3 v_direction;\n"
"out vec4 fragcolor;\n"
@ -345,36 +356,36 @@ static const char *const fs_3_4_skybox_rayleigh = "//" FILELINE "\n"
"\n"
"void main() {\n"
" vec3 color = atmosphere(\n"
" normalize(v_direction),\n"
" vec3(0,6372e3,0),\n"
" uSunPos,\n"
" 22.0,\n"
" 6371e3,\n"
" 6471e3,\n"
" vec3(5.5e-6, 13.0e-6, 22.4e-6),\n"
" 21e-6,\n"
" 8e3,\n"
" 1.2e3,\n"
" 0.758\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"
" \n"
" // Apply exposure.\n"
" color = 1.0 - exp(-1.0 * color);\n"
" \n"
" fragcolor = vec4(color, 1);\n"
"}\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"
"#define PI 3.141592\n"
"#define iSteps 16\n"
"#define jSteps 8\n"
"\n"
"vec2 rsi(vec3 r0, vec3 rd, float sr) {\n"
" \n"
" \n"
" \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"
@ -387,91 +398,91 @@ static const char *const fs_3_4_skybox_rayleigh = "//" FILELINE "\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"
" // Normalize the sun and view directions.\n"
" pSun = normalize(pSun);\n"
" r = normalize(r);\n"
" \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"
" \n"
" // Initialize the primary ray time.\n"
" float iTime = 0.0;\n"
" \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"
" \n"
" // Initialize optical depth accumulators for the primary ray.\n"
" float iOdRlh = 0.0;\n"
" float iOdMie = 0.0;\n"
" \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"
" \n"
" // Sample the primary ray.\n"
" for (int i = 0; i < iSteps; i++) {\n"
" \n"
" \n"
" // Calculate the primary ray sample position.\n"
" vec3 iPos = r0 + r * (iTime + iStepSize * 0.5);\n"
" \n"
" \n"
" // Calculate the height of the sample.\n"
" float iHeight = length(iPos) - rPlanet;\n"
" \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"
" \n"
" // Accumulate optical depth.\n"
" iOdRlh += odStepRlh;\n"
" iOdMie += odStepMie;\n"
" \n"
" \n"
" // Calculate the step size of the secondary ray.\n"
" float jStepSize = rsi(iPos, pSun, rAtmos).y / float(jSteps);\n"
" \n"
" \n"
" // Initialize the secondary ray time.\n"
" float jTime = 0.0;\n"
" \n"
" \n"
" // Initialize optical depth accumulators for the secondary ray.\n"
" float jOdRlh = 0.0;\n"
" float jOdMie = 0.0;\n"
" \n"
" \n"
" // Sample the secondary ray.\n"
" for (int j = 0; j < jSteps; j++) {\n"
" \n"
" \n"
" // Calculate the secondary ray sample position.\n"
" vec3 jPos = iPos + pSun * (jTime + jStepSize * 0.5);\n"
" \n"
" \n"
" // Calculate the height of the sample.\n"
" float jHeight = length(jPos) - rPlanet;\n"
" \n"
" \n"
" // Accumulate the optical depth.\n"
" jOdRlh += exp(-jHeight / shRlh) * jStepSize;\n"
" jOdMie += exp(-jHeight / shMie) * jStepSize;\n"
" \n"
" \n"
" // Increment the secondary ray time.\n"
" jTime += jStepSize;\n"
" }\n"
" \n"
" \n"
" // Calculate attenuation.\n"
" vec3 attn = exp(-(kMie * (iOdMie + jOdMie) + kRlh * (iOdRlh + jOdRlh)));\n"
" \n"
" \n"
" // Accumulate scattering.\n"
" totalRlh += odStepRlh * attn;\n"
" totalMie += odStepMie * attn;\n"
" \n"
" \n"
" // Increment the primary ray time.\n"
" iTime += iStepSize;\n"
" \n"
" }\n"
" \n"
" \n"
" // Calculate and return the final color.\n"
" return iSun * (pRlh * kRlh * totalRlh + pMie * kMie * totalMie);\n"
"}\n";
@ -495,8 +506,8 @@ static const char *const vs_0_2_fullscreen_quad_B = "//" FILELINE "\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);\n"
" uv = vec2(x, y);\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";
static const char *const vs_0_2_fullscreen_quad_B_flipped = "//" FILELINE "\n"
@ -505,8 +516,8 @@ static const char *const vs_0_2_fullscreen_quad_B_flipped = "//" FILELINE "\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);\n"
" uv = vec2(x, y);\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";
static const char *const vs_323444143_16_332_model = "//" FILELINE "\n"
@ -515,11 +526,11 @@ static const char *const vs_323444143_16_332_model = "//" FILELINE "\n"
#endif
"uniform mat3x4 vsBoneMatrix[MAX_BONES];\n"
"uniform bool SKINNED = false;\n"
"\n"
"// uniform mat4 M; // RIM\n"
"uniform mat4 VP;\n"
"\n"
#if 0
"\n"
"// 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"
@ -545,31 +556,31 @@ static const char *const vs_323444143_16_332_model = "//" FILELINE "\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];\n"
"uniform float f_num_blend_shapes;\n"
"uniform sampler2DArray blend_shapes;\n"
"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"
"in vec3 att_position;\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;\n"
"in mat4 att_instanced_matrix;\n"
"in vec4 att_indexes;\n"
"in vec4 att_weights;\n"
"in float att_vertexindex;\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;\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"
"// shadow\n"
"uniform mat4 model, view;\n"
"uniform mat4 cameraToShadowProjector;\n"
"out vec4 vneye;\n"
@ -581,7 +592,7 @@ static const char *const vs_323444143_16_332_model = "//" FILELINE "\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"
@ -606,17 +617,17 @@ static const char *const vs_323444143_16_332_model = "//" FILELINE "\n"
" m += vsBoneMatrix[int(att_indexes.w)] * att_weights.w;\n"
" objPos = vec4(att_position, 1.0) * m;\n"
" \n"
" \n"
" \n"
" // blendshapes\n"
" // objPos += evaluate_blend_shape(int(att_vertexindex));\n"
" \n"
" v_normal = vec4(att_normal, 0.0) * m;\n"
" \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"
" \n"
" \n"
" v_normal_ws = normalize(vec3(model * vec4(v_normal, 0.)));\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"
@ -641,6 +652,7 @@ static const char *const vs_324_24_sprite = "//" FILELINE "\n"
"}\n";
static const char *const vs_332_32 = "//" FILELINE "\n"
"//uniform mat4 u_model, u_view, u_proj;\n"
"uniform mat4 u_mvp;\n"
"\n"
"in vec3 att_position;\n"
@ -652,12 +664,12 @@ static const char *const vs_332_32 = "//" FILELINE "\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;\n"
"uniform mat4 cameraToShadowProjector; // !VSMCUBE\n"
"out vec4 vneye;\n"
"out vec4 vpeye;\n"
"out vec4 sc;\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"
@ -665,10 +677,10 @@ static const char *const vs_332_32 = "//" FILELINE "\n"
"}\n"
"\n"
"void main() {\n"
" \n"
" // gl_Position = proj * view * model * vec4(att_position, 1.0);\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.)));\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"

View File

@ -10138,28 +10138,33 @@ void network_rpc_send(unsigned id, const char *cmdline) {
#line 1 "v4k_shaders.c"
static const char *const fs_0_0_shadowmap_lit = "//" FILELINE "\n"
"// #version 140 // inverse() requires v140\n"
"// FILELINE\n"
"\n"
"\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;\n"
"uniform samplerCube shadowMap; // VSMCUBE\n"
#else
"uniform sampler2D shadowMap;\n"
"uniform sampler2D shadowMap; // !VSMCUBE\n"
#endif
"\n"
"struct light {\n"
" vec3 position;\n"
" vec3 position; // world-space\n"
" vec4 diffuse;\n"
" vec4 specular;\n"
" float constantAttenuation, linearAttenuation, quadraticAttenuation;\n"
" };\n"
" light light0 = light(\n"
" lightPos,\n"
" vec4(1,1,1,1),\n"
" vec4(1,1,1,1),\n"
" 1.0, 0.0, 0.0\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"
" \n"
" // From http://fabiensanglard.net/shadowmappingVSM/index.php\n"
#if VSMCUBE
" float chebyshevUpperBound(float distance, vec3 dir) {\n"
" distance = distance/20 ;\n"
@ -10168,14 +10173,14 @@ static const char *const fs_0_0_shadowmap_lit = "//" FILELINE "\n"
" float chebyshevUpperBound(float distance, vec4 scPostW) {\n"
" vec2 moments = texture(shadowMap,scPostW.xy).rg;\n"
#endif
" \n"
" // Surface is fully lit. as the current fragment is before the light occluder\n"
" if (distance <= moments.x)\n"
" return 1.0;\n"
" \n"
" \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"
" \n"
" //variance = max(variance, 0.000002);\n"
" variance = max(variance, 0.00002);\n"
" \n"
" float d = distance - moments.x;\n"
@ -10193,24 +10198,24 @@ static const char *const fs_0_0_shadowmap_lit = "//" FILELINE "\n"
" vec3 normal = vec3(normalize(vneye));\n"
" vec3 viewDir = normalize(-fragment);\n"
" \n"
" \n"
" \n"
" // Lighting\n"
" // Convert to eye-space\n"
" vec3 light = vec3(view * vec4(light0.position, 1.0));\n"
" \n"
#if VSMCUBE
" \n"
" // Vectors\n"
" vec3 fragmentToLight = light - fragment;\n"
" vec3 fragmentToLightDir = normalize(fragmentToLight);\n"
" \n"
" \n"
" // Shadows\n"
" vec4 fragmentToLight_world = inverse(view) * vec4(fragmentToLightDir, 0.0);\n"
" float shadowFactor = chebyshevUpperBound(length(fragmentToLight), -fragmentToLight_world.xyz);\n"
#else
" \n"
" // Shadows\n"
" vec4 scPostW = sc / sc.w;\n"
" scPostW = scPostW * 0.5 + 0.5;\n"
" \n"
" float shadowFactor = 1.0;\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"
@ -10229,7 +10234,7 @@ static const char *const fs_0_0_shadowmap_lit = "//" FILELINE "\n"
" vec3 positionToLight = light - fragment;\n"
" vec3 lightDir = normalize(positionToLight);\n"
" \n"
" \n"
" // Angle between fragment-normal and incoming light\n"
" float cosAngIncidence = dot(lightDir, normal);\n"
" cosAngIncidence = clamp(cosAngIncidence, 0, 1);\n"
" \n"
@ -10239,8 +10244,8 @@ static const char *const fs_0_0_shadowmap_lit = "//" FILELINE "\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;\n"
" total_lighting += diffuse * shadowFactor;\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
@ -10249,6 +10254,7 @@ static const char *const fs_0_0_shadowmap_lit = "//" FILELINE "\n"
" }\n";
static 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"
@ -10264,21 +10270,21 @@ static const char *const fs_24_4_sprite = "//" FILELINE "\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"
" \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"
" \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"
@ -10287,12 +10293,12 @@ static const char *const fs_24_4_sprite = "//" FILELINE "\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"
" // ---\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"
@ -10330,7 +10336,7 @@ static const char *const fs_2_4_preamble = "//" FILELINE "\n"
"out vec4 fragColor;\n";
static const char *const fs_2_4_texel_inv_gamma = "//" FILELINE "\n"
"uniform sampler2D texture0;\n"
"uniform sampler2D texture0; /*unit0*/\n"
"uniform float u_inv_gamma;\n"
"\n"
"in vec2 uv;\n"
@ -10339,13 +10345,13 @@ static const char *const fs_2_4_texel_inv_gamma = "//" FILELINE "\n"
"void main() {\n"
" vec4 texel = texture( texture0, uv );\n"
" fragcolor = texel;\n"
" fragcolor.rgb = pow( fragcolor.rgb, vec3( u_inv_gamma ) );\n"
" fragcolor.rgb = pow( fragcolor.rgb, vec3( u_inv_gamma ) ); // defaults: 1.0/2.2 gamma\n"
"}\n";
static const char *const fs_2_4_texel_ycbr_gamma_saturation = "//" FILELINE "\n"
"uniform sampler2D u_texture_y;\n"
"uniform sampler2D u_texture_cb;\n"
"uniform sampler2D u_texture_cr;\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"
"in vec2 uv;\n"
@ -10363,11 +10369,16 @@ static const char *const fs_2_4_texel_ycbr_gamma_saturation = "//" FILELINE "\n"
" -0.7010, 0.5291, -0.8860, 1.0000\n"
" );\n"
" vec4 texel = to_rgb * vec4(y, cb, cr, 1.0);\n"
" \n"
" \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"
" \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"
@ -10401,9 +10412,9 @@ static const char *const fs_32_4_model = "//" FILELINE "\n"
"}\n"
"\n"
"void main() {\n"
"vec3 n = (v_normal);\n"
"\n"
"vec3 n = /*normalize*/(v_normal);\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"
@ -10422,31 +10433,31 @@ static const char *const fs_32_4_model = "//" FILELINE "\n"
"\n"
"\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);\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;\n"
" diffuse = u_diffuse; // * v_color;\n"
" }\n"
" \n"
" \n"
" // lighting mix\n"
" fragcolor = diffuse * lit * shadowing();\n"
" \n"
" \n"
" // rimlight\n"
#ifdef RIM
" {vec3 n = normalize(mat3(M) * v_normal);\n"
" vec3 p = (M * vec4(v_position,1.0)).xyz;\n"
" vec3 v = normalize(-p);\n"
" float rim = 1.0 - max(dot(v, n), 0.0);\n"
" rim = smoothstep(1.0-0.01, 1.0, rim);\n"
" fragcolor += vec4(0.0, 0.0, rim, 1.0);}\n"
#endif
" \n"
"}\n";
" {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"
" }\n";
static const char *const fs_32_4_model_basic = "//" FILELINE "\n"
"uniform sampler2D fsDiffTex;\n"
@ -10460,8 +10471,8 @@ static const char *const fs_32_4_model_basic = "//" FILELINE "\n"
"\n"
"void main() {\n"
" vec4 diff = texture(fsDiffTex, v_texcoord).rgba;\n"
" vec3 n = normalize(mat3(MVP) * v_normal);\n"
" fragColor = diff;\n"
" vec3 n = normalize(mat3(MVP) * v_normal); // transform normal to eye space\n"
" fragColor = diff;// * vec4(v_normal.xyz, 1);\n"
"}\n";
static const char *const fs_3_4_skybox = "//" FILELINE "\n"
@ -10475,7 +10486,7 @@ static const char *const fs_3_4_skybox = "//" FILELINE "\n"
"}\n";
static const char *const fs_3_4_skybox_rayleigh = "//" FILELINE "\n"
"uniform vec3 uSunPos = vec3( 0, 0.1, -1 );\n"
"uniform vec3 uSunPos = vec3( 0, 0.1, -1 ); // = [0, Math.cos(theta) * 0.3 + 0.2, -1];\n"
"\n"
"in vec3 v_direction;\n"
"out vec4 fragcolor;\n"
@ -10484,36 +10495,36 @@ static const char *const fs_3_4_skybox_rayleigh = "//" FILELINE "\n"
"\n"
"void main() {\n"
" vec3 color = atmosphere(\n"
" normalize(v_direction),\n"
" vec3(0,6372e3,0),\n"
" uSunPos,\n"
" 22.0,\n"
" 6371e3,\n"
" 6471e3,\n"
" vec3(5.5e-6, 13.0e-6, 22.4e-6),\n"
" 21e-6,\n"
" 8e3,\n"
" 1.2e3,\n"
" 0.758\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"
" \n"
" // Apply exposure.\n"
" color = 1.0 - exp(-1.0 * color);\n"
" \n"
" fragcolor = vec4(color, 1);\n"
"}\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"
"#define PI 3.141592\n"
"#define iSteps 16\n"
"#define jSteps 8\n"
"\n"
"vec2 rsi(vec3 r0, vec3 rd, float sr) {\n"
" \n"
" \n"
" \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"
@ -10526,91 +10537,91 @@ static const char *const fs_3_4_skybox_rayleigh = "//" FILELINE "\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"
" // Normalize the sun and view directions.\n"
" pSun = normalize(pSun);\n"
" r = normalize(r);\n"
" \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"
" \n"
" // Initialize the primary ray time.\n"
" float iTime = 0.0;\n"
" \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"
" \n"
" // Initialize optical depth accumulators for the primary ray.\n"
" float iOdRlh = 0.0;\n"
" float iOdMie = 0.0;\n"
" \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"
" \n"
" // Sample the primary ray.\n"
" for (int i = 0; i < iSteps; i++) {\n"
" \n"
" \n"
" // Calculate the primary ray sample position.\n"
" vec3 iPos = r0 + r * (iTime + iStepSize * 0.5);\n"
" \n"
" \n"
" // Calculate the height of the sample.\n"
" float iHeight = length(iPos) - rPlanet;\n"
" \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"
" \n"
" // Accumulate optical depth.\n"
" iOdRlh += odStepRlh;\n"
" iOdMie += odStepMie;\n"
" \n"
" \n"
" // Calculate the step size of the secondary ray.\n"
" float jStepSize = rsi(iPos, pSun, rAtmos).y / float(jSteps);\n"
" \n"
" \n"
" // Initialize the secondary ray time.\n"
" float jTime = 0.0;\n"
" \n"
" \n"
" // Initialize optical depth accumulators for the secondary ray.\n"
" float jOdRlh = 0.0;\n"
" float jOdMie = 0.0;\n"
" \n"
" \n"
" // Sample the secondary ray.\n"
" for (int j = 0; j < jSteps; j++) {\n"
" \n"
" \n"
" // Calculate the secondary ray sample position.\n"
" vec3 jPos = iPos + pSun * (jTime + jStepSize * 0.5);\n"
" \n"
" \n"
" // Calculate the height of the sample.\n"
" float jHeight = length(jPos) - rPlanet;\n"
" \n"
" \n"
" // Accumulate the optical depth.\n"
" jOdRlh += exp(-jHeight / shRlh) * jStepSize;\n"
" jOdMie += exp(-jHeight / shMie) * jStepSize;\n"
" \n"
" \n"
" // Increment the secondary ray time.\n"
" jTime += jStepSize;\n"
" }\n"
" \n"
" \n"
" // Calculate attenuation.\n"
" vec3 attn = exp(-(kMie * (iOdMie + jOdMie) + kRlh * (iOdRlh + jOdRlh)));\n"
" \n"
" \n"
" // Accumulate scattering.\n"
" totalRlh += odStepRlh * attn;\n"
" totalMie += odStepMie * attn;\n"
" \n"
" \n"
" // Increment the primary ray time.\n"
" iTime += iStepSize;\n"
" \n"
" }\n"
" \n"
" \n"
" // Calculate and return the final color.\n"
" return iSun * (pRlh * kRlh * totalRlh + pMie * kMie * totalMie);\n"
"}\n";
@ -10634,8 +10645,8 @@ static const char *const vs_0_2_fullscreen_quad_B = "//" FILELINE "\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);\n"
" uv = vec2(x, y);\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";
static const char *const vs_0_2_fullscreen_quad_B_flipped = "//" FILELINE "\n"
@ -10644,8 +10655,8 @@ static const char *const vs_0_2_fullscreen_quad_B_flipped = "//" FILELINE "\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);\n"
" uv = vec2(x, y);\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";
static const char *const vs_323444143_16_332_model = "//" FILELINE "\n"
@ -10654,11 +10665,11 @@ static const char *const vs_323444143_16_332_model = "//" FILELINE "\n"
#endif
"uniform mat3x4 vsBoneMatrix[MAX_BONES];\n"
"uniform bool SKINNED = false;\n"
"\n"
"// uniform mat4 M; // RIM\n"
"uniform mat4 VP;\n"
"\n"
#if 0
"\n"
"// 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"
@ -10684,31 +10695,31 @@ static const char *const vs_323444143_16_332_model = "//" FILELINE "\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];\n"
"uniform float f_num_blend_shapes;\n"
"uniform sampler2DArray blend_shapes;\n"
"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"
"in vec3 att_position;\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;\n"
"in mat4 att_instanced_matrix;\n"
"in vec4 att_indexes;\n"
"in vec4 att_weights;\n"
"in float att_vertexindex;\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;\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"
"// shadow\n"
"uniform mat4 model, view;\n"
"uniform mat4 cameraToShadowProjector;\n"
"out vec4 vneye;\n"
@ -10720,7 +10731,7 @@ static const char *const vs_323444143_16_332_model = "//" FILELINE "\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"
@ -10745,17 +10756,17 @@ static const char *const vs_323444143_16_332_model = "//" FILELINE "\n"
" m += vsBoneMatrix[int(att_indexes.w)] * att_weights.w;\n"
" objPos = vec4(att_position, 1.0) * m;\n"
" \n"
" \n"
" \n"
" // blendshapes\n"
" // objPos += evaluate_blend_shape(int(att_vertexindex));\n"
" \n"
" v_normal = vec4(att_normal, 0.0) * m;\n"
" \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"
" \n"
" \n"
" v_normal_ws = normalize(vec3(model * vec4(v_normal, 0.)));\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"
@ -10780,6 +10791,7 @@ static const char *const vs_324_24_sprite = "//" FILELINE "\n"
"}\n";
static const char *const vs_332_32 = "//" FILELINE "\n"
"//uniform mat4 u_model, u_view, u_proj;\n"
"uniform mat4 u_mvp;\n"
"\n"
"in vec3 att_position;\n"
@ -10791,12 +10803,12 @@ static const char *const vs_332_32 = "//" FILELINE "\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;\n"
"uniform mat4 cameraToShadowProjector; // !VSMCUBE\n"
"out vec4 vneye;\n"
"out vec4 vpeye;\n"
"out vec4 sc;\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"
@ -10804,10 +10816,10 @@ static const char *const vs_332_32 = "//" FILELINE "\n"
"}\n"
"\n"
"void main() {\n"
" \n"
" // gl_Position = proj * view * model * vec4(att_position, 1.0);\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.)));\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"

View File

@ -596,7 +596,7 @@ details > summary::-webkit-details-marker {
|Version: | 2023.7 |
|:--------------|:------------|
|Branch: | main |
|Commit: | 19 |
|Commit: | 22 |
<!--| Documentation last modified | { {LAST_MODIFIED} } |-->
# [V·4·K 2023.7 ](https://dev.v4.games/zaklaus/v4k)

View File

@ -44,8 +44,8 @@ def c_to_glsl(input_filename: str):
if line.strip().endswith('";'):
shader_code += line.rstrip('";\n')
# Process the captured shader code
shader_code = re.sub(r'/\*.*?\*/', '', shader_code, flags=re.DOTALL) # Remove C-style comments
shader_code = re.sub(r'//.*', '', shader_code) # Remove C++ style comments
# shader_code = re.sub(r'/\*.*?\*/', '', shader_code, flags=re.DOTALL) # Remove C-style comments
# shader_code = re.sub(r'//.*', '', shader_code) # Remove C++ style comments
shader_code = shader_code.replace(r'"\n"', '\n').replace(r'\n', '').replace(r'"', '')
# Save to a .glsl file