v4k-git-backup/engine/split/v4k_shaders.c

697 lines
25 KiB
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"
"struct light {\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), // 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"
" vec4 shadowmap(in vec4 vpeye, in vec4 vneye, in vec2 uv, in vec4 sc) {\n"
#ifndef VSMCUBE
" return vec4(1.);\n"
#else
" \n"
" 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"
"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"
"in vec2 vTexCoord;\n"
"in vec4 vColor;\n"
"out vec4 fragColor;\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"
"// [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"
"// [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"
"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"
"in vec2 uv;\n"
"out vec4 fragcolor;\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"
"in vec2 uv;\n"
"out vec4 fragcolor;\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"
"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"
#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"
"{{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"
"void main() {\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"
" 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"
" // 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"
"\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"
"in vec3 v_normal;\n"
"in vec2 v_texcoord;\n"
"out vec4 fragColor;\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"
"in vec3 v_direction;\n"
"out vec4 fragcolor;\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"
"in vec3 v_direction;\n"
"out vec4 fragcolor;\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"
"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"
"// [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"
" // 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"
"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 vs_0_2_fullscreen_quad_A = "//" FILELINE "\n"
"out vec2 texcoord;\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"
"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"
"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"
#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"
"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"
"sg_image blend_shapes = mesh->num_blend_shapes > 0 ? mesh->blend_shape_image : view->empty_blend_shape_image;\n"
#endif
"\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"
"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"
"// 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"
"// 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"
"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"
"\n";
const char *const vs_324_24_sprite = "//" FILELINE "\n"
"uniform mat4 u_mvp;\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"
"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_model, u_view, u_proj;\n"
"uniform mat4 u_mvp;\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"
"// 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"
"void main() {\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.))); // 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"
"in vec3 att_position;\n"
"out vec3 v_direction;\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";