688 lines
21 KiB
C
688 lines
21 KiB
C
static const char *const fs_0_0_shadowmap_lit = "//" FILELINE "\n"
|
|
"uniform vec3 lightPos = vec3(1.0);\n"
|
|
"uniform float doTexture = 1.;\n"
|
|
#if VSMCUBE
|
|
"uniform samplerCube shadowMap;\n"
|
|
#else
|
|
"uniform sampler2D shadowMap;\n"
|
|
#endif
|
|
"\n"
|
|
"struct light {\n"
|
|
" vec3 position;\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"
|
|
" );\n"
|
|
" \n"
|
|
" \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
|
|
" \n"
|
|
" if (distance <= moments.x)\n"
|
|
" return 1.0;\n"
|
|
" \n"
|
|
" \n"
|
|
" \n"
|
|
" float variance = moments.y - (moments.x*moments.x);\n"
|
|
" \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"
|
|
" \n"
|
|
" \n"
|
|
" vec3 light = vec3(view * vec4(light0.position, 1.0));\n"
|
|
" \n"
|
|
#if VSMCUBE
|
|
" \n"
|
|
" vec3 fragmentToLight = light - fragment;\n"
|
|
" vec3 fragmentToLightDir = normalize(fragmentToLight);\n"
|
|
" \n"
|
|
" \n"
|
|
" vec4 fragmentToLight_world = inverse(view) * vec4(fragmentToLightDir, 0.0);\n"
|
|
" float shadowFactor = chebyshevUpperBound(length(fragmentToLight), -fragmentToLight_world.xyz);\n"
|
|
#else
|
|
" \n"
|
|
" vec4 scPostW = sc / sc.w;\n"
|
|
" scPostW = scPostW * 0.5 + 0.5;\n"
|
|
" \n"
|
|
" float shadowFactor = 1.0;\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"
|
|
" \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;\n"
|
|
" total_lighting += diffuse * shadowFactor;\n"
|
|
#else
|
|
" vec4 total_lighting = diffColor;\n"
|
|
#endif
|
|
" return vec4(clamp(vec3(total_lighting), 0., 1.), 1.0);\n"
|
|
#endif
|
|
" }\n";
|
|
|
|
static const char *const fs_0_0_shadowmap_unlit = "//" FILELINE "\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";
|
|
|
|
static 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"
|
|
"\n"
|
|
"vec4 texture_AA(sampler2D tx, vec2 uv) {\n"
|
|
" vec2 res = vec2(textureSize(tx, 0));\n"
|
|
" uv = uv*res + 0.5;\n"
|
|
" \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"
|
|
" uv = (fl+fr-0.5) / res;\n"
|
|
" return texture(tx, uv);\n"
|
|
"}\n"
|
|
"\n"
|
|
"\n"
|
|
"vec4 texture_AA2( sampler2D tex, vec2 uv) {\n"
|
|
" vec2 res = vec2(textureSize(tex,0));\n"
|
|
" uv = uv*res;\n"
|
|
" vec2 seam = floor(uv+0.5);\n"
|
|
" uv = seam + clamp( (uv-seam)/fwidth(uv), -0.5, 0.5);\n"
|
|
" return texture(tex, uv/res);\n"
|
|
"}\n"
|
|
"\n"
|
|
"\n"
|
|
"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";
|
|
|
|
static 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";
|
|
|
|
static const char *const fs_2_4_texel_inv_gamma = "//" FILELINE "\n"
|
|
"uniform sampler2D texture0;\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 ) );\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 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"
|
|
" \n"
|
|
" \n"
|
|
" texel.rgb = pow(texel.rgb, vec3(1.0 / u_gamma));\n"
|
|
" \n"
|
|
" \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";
|
|
|
|
static 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 = (v_normal);\n"
|
|
"\n"
|
|
"\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"
|
|
"if( (result.x*result.x+result.y*result.y+result.z*result.z) > 0.0 ) lit = vec4(result, 1.0);\n"
|
|
"\n"
|
|
"\n"
|
|
"\n"
|
|
"\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"
|
|
" 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"
|
|
" }\n"
|
|
" \n"
|
|
" \n"
|
|
" fragcolor = diffuse * lit * shadowing();\n"
|
|
" \n"
|
|
" \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";
|
|
|
|
static 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);\n"
|
|
" fragColor = diff;\n"
|
|
"}\n";
|
|
|
|
static 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";
|
|
|
|
static const char *const fs_3_4_skybox_rayleigh = "//" FILELINE "\n"
|
|
"uniform vec3 uSunPos = vec3( 0, 0.1, -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),\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"
|
|
" );\n"
|
|
" \n"
|
|
" \n"
|
|
" color = 1.0 - exp(-1.0 * color);\n"
|
|
" \n"
|
|
" fragcolor = vec4(color, 1);\n"
|
|
"}\n"
|
|
"\n"
|
|
"\n"
|
|
"\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"
|
|
" 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"
|
|
" \n"
|
|
" pSun = normalize(pSun);\n"
|
|
" r = normalize(r);\n"
|
|
" \n"
|
|
" \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"
|
|
" float iTime = 0.0;\n"
|
|
" \n"
|
|
" \n"
|
|
" vec3 totalRlh = vec3(0,0,0);\n"
|
|
" vec3 totalMie = vec3(0,0,0);\n"
|
|
" \n"
|
|
" \n"
|
|
" float iOdRlh = 0.0;\n"
|
|
" float iOdMie = 0.0;\n"
|
|
" \n"
|
|
" \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"
|
|
" for (int i = 0; i < iSteps; i++) {\n"
|
|
" \n"
|
|
" \n"
|
|
" vec3 iPos = r0 + r * (iTime + iStepSize * 0.5);\n"
|
|
" \n"
|
|
" \n"
|
|
" float iHeight = length(iPos) - rPlanet;\n"
|
|
" \n"
|
|
" \n"
|
|
" float odStepRlh = exp(-iHeight / shRlh) * iStepSize;\n"
|
|
" float odStepMie = exp(-iHeight / shMie) * iStepSize;\n"
|
|
" \n"
|
|
" \n"
|
|
" iOdRlh += odStepRlh;\n"
|
|
" iOdMie += odStepMie;\n"
|
|
" \n"
|
|
" \n"
|
|
" float jStepSize = rsi(iPos, pSun, rAtmos).y / float(jSteps);\n"
|
|
" \n"
|
|
" \n"
|
|
" float jTime = 0.0;\n"
|
|
" \n"
|
|
" \n"
|
|
" float jOdRlh = 0.0;\n"
|
|
" float jOdMie = 0.0;\n"
|
|
" \n"
|
|
" \n"
|
|
" for (int j = 0; j < jSteps; j++) {\n"
|
|
" \n"
|
|
" \n"
|
|
" vec3 jPos = iPos + pSun * (jTime + jStepSize * 0.5);\n"
|
|
" \n"
|
|
" \n"
|
|
" float jHeight = length(jPos) - rPlanet;\n"
|
|
" \n"
|
|
" \n"
|
|
" jOdRlh += exp(-jHeight / shRlh) * jStepSize;\n"
|
|
" jOdMie += exp(-jHeight / shMie) * jStepSize;\n"
|
|
" \n"
|
|
" \n"
|
|
" jTime += jStepSize;\n"
|
|
" }\n"
|
|
" \n"
|
|
" \n"
|
|
" vec3 attn = exp(-(kMie * (iOdMie + jOdMie) + kRlh * (iOdRlh + jOdRlh)));\n"
|
|
" \n"
|
|
" \n"
|
|
" totalRlh += odStepRlh * attn;\n"
|
|
" totalMie += odStepMie * attn;\n"
|
|
" \n"
|
|
" \n"
|
|
" iTime += iStepSize;\n"
|
|
" \n"
|
|
" }\n"
|
|
" \n"
|
|
" \n"
|
|
" return iSun * (pRlh * kRlh * totalRlh + pMie * kMie * totalMie);\n"
|
|
"}\n";
|
|
|
|
static 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";
|
|
|
|
static 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";
|
|
|
|
static 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);\n"
|
|
" uv = vec2(x, y);\n"
|
|
"}\n";
|
|
|
|
static 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);\n"
|
|
" uv = vec2(x, y);\n"
|
|
"}\n";
|
|
|
|
static 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"
|
|
"\n"
|
|
"uniform mat4 VP;\n"
|
|
"\n"
|
|
#if 0
|
|
"\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"
|
|
"\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"
|
|
"\n"
|
|
"in vec3 att_position;\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_color;\n"
|
|
"in vec3 att_bitangent;\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"
|
|
"uniform mat4 model, view;\n"
|
|
"uniform mat4 cameraToShadowProjector;\n"
|
|
"out vec4 vneye;\n"
|
|
"out vec4 vpeye;\n"
|
|
"out vec4 sc;\n"
|
|
"void do_shadow() {\n"
|
|
" vneye = view * model * vec4(att_normal, 0.0f);\n"
|
|
" vpeye = view * model * vec4(att_position, 1.0);\n"
|
|
" sc = cameraToShadowProjector * model * vec4(att_position, 1.0f);\n"
|
|
"}\n"
|
|
"\n"
|
|
"\n"
|
|
"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"
|
|
" \n"
|
|
" \n"
|
|
" \n"
|
|
" v_normal = vec4(att_normal, 0.0) * m;\n"
|
|
" \n"
|
|
" }\n"
|
|
" \n"
|
|
" \n"
|
|
" \n"
|
|
" \n"
|
|
" v_normal_ws = normalize(vec3(model * vec4(v_normal, 0.)));\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";
|
|
|
|
static 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";
|
|
|
|
static const char *const vs_332_32 = "//" FILELINE "\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"
|
|
"\n"
|
|
"uniform mat4 model, view, proj;\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"
|
|
"void main() {\n"
|
|
" \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_texcoord = att_texcoord;\n"
|
|
" v_color = att_color;\n"
|
|
" do_shadow();\n"
|
|
"}\n";
|
|
|
|
static 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";
|