149
157
" gl_ClipDistance[0] = gl_Position.w - gl_Position.z; \n"
153
162
static const char* fragment_shader_header_common_variables =
154
"#version 330 core \n"
155
164
"uniform sampler2D uTex0; \n"
156
165
"uniform sampler2D uTex1; \n"
166
#ifdef GL_MULTISAMPLING_SUPPORT
167
"uniform sampler2DMS uMSTex0; \n"
168
"uniform sampler2DMS uMSTex1; \n"
169
"uniform lowp ivec2 uMSTexEnabled; \n"
157
171
"layout (std140) uniform ColorsBlock {\n"
158
172
" lowp vec4 uFogColor; \n"
159
173
" lowp vec4 uCenterColor; \n"
165
179
" lowp float uK4; \n"
166
180
" lowp float uK5; \n"
183
"uniform mediump vec2 uScreenScale; \n"
168
185
"uniform lowp int uAlphaCompareMode; \n"
169
186
"uniform lowp int uAlphaDitherMode; \n"
170
187
"uniform lowp int uColorDitherMode; \n"
171
188
"uniform lowp int uGammaCorrectionEnabled; \n"
172
189
"uniform lowp int uFogUsage; \n"
173
"uniform lowp int uFb8Bit; \n"
174
"uniform lowp int uFbFixedAlpha;\n"
190
"uniform lowp ivec2 uFb8Bit; \n"
191
"uniform lowp ivec2 uFbFixedAlpha;\n"
175
192
"uniform lowp int uSpecialBlendMode;\n"
176
193
"uniform lowp int uEnableAlphaTest; \n"
177
194
"uniform lowp float uAlphaTestValue;\n"
221
241
"void calc_light(in lowp float fLights, in lowp vec3 input_color, out lowp vec3 output_color);\n"
222
242
"mediump float mipmap(out lowp vec4 readtex0, out lowp vec4 readtex1); \n"
223
243
"lowp vec4 readTex(in sampler2D tex, in mediump vec2 texCoord, in bool fb8bit, in bool fbFixedAlpha); \n"
244
#ifdef GL_MULTISAMPLING_SUPPORT
245
"lowp vec4 readTexMS(in sampler2DMS mstex, in mediump vec2 texCoord, in bool fb8bit, in bool fbFixedAlpha); \n"
246
#endif // GL_MULTISAMPLING_SUPPORT
224
247
"bool depth_compare(); \n"
225
248
"void colorNoiseDither(in float _noise, inout vec3 _color); \n"
226
249
"void alphaNoiseDither(in float _noise, inout float _alpha);\n"
267
293
" gl_FragDepth = clamp((gl_FragCoord.z * 2.0 - 1.0) * uDepthScale.s + uDepthScale.t, 0.0, 1.0); \n"
268
295
" lowp vec4 vec_color, combined_color; \n"
269
296
" lowp float alpha1, alpha2; \n"
270
297
" lowp vec3 color1, color2; \n"
273
300
static const char* fragment_shader_dither =
274
"#version 330 core \n"
275
304
"void colorNoiseDither(in float _noise, inout vec3 _color) \n"
277
306
" mediump vec3 tmpColor = _color*255.0; \n"
342
371
static const char* fragment_shader_mipmap =
343
"#version 330 core \n"
344
374
"in mediump vec2 vTexCoord0; \n"
345
375
"in mediump vec2 vTexCoord1; \n"
346
376
"in mediump vec2 vLodTexCoord; \n"
347
377
"uniform sampler2D uTex0; \n"
348
378
"uniform sampler2D uTex1; \n"
379
"uniform mediump vec2 uScreenScale; \n"
381
"#ifdef GL_OES_standard_derivatives \n"
382
" #extension GL_OES_standard_derivatives : enable \n"
349
385
"uniform lowp float uPrimitiveLod; \n"
350
386
"uniform lowp int uEnableLod; \n"
351
"uniform mediump vec2 uScreenScale; \n"
352
387
"uniform mediump float uMinLod; \n"
353
388
"uniform lowp int uMaxTile; \n"
354
389
"uniform lowp int uTextureDetail; \n"
356
391
"mediump float mipmap(out lowp vec4 readtex0, out lowp vec4 readtex1) { \n"
357
" if (uEnableLod == 0) { \n"
358
" readtex0 = texture(uTex0, vTexCoord0); \n"
359
" readtex1 = texture(uTex1, vTexCoord1); \n"
360
" return uPrimitiveLod; \n"
392
" readtex0 = texture(uTex0, vTexCoord0); \n"
393
" readtex1 = texture(uTex1, vTexCoord1); \n"
394
" if (uEnableLod == 0) \n"
395
" return uPrimitiveLod; \n"
362
396
" if (uMaxTile == 0) { \n"
363
" readtex0 = texture(uTex0, vTexCoord0); \n"
364
397
" readtex1 = readtex0; \n"
365
398
" return uMinLod; \n"
383
416
" lod_tile = min(float(uMaxTile), floor(log2(floor(lod)))); \n"
384
417
" lod_frac = fract(lod/pow(2.0, lod_tile)); \n"
419
" lowp vec4 lod0 = textureLod(uTex1, vTexCoord1, 0.0); \n"
420
" lowp vec4 lod1 = textureLod(uTex1, vTexCoord1, 1.0); \n"
421
" lowp vec4 lodT = textureLod(uTex1, vTexCoord1, lod_tile); \n"
422
" lowp vec4 lodT_m1 = textureLod(uTex1, vTexCoord1, max(0.0, lod_tile - 1.0)); \n"
423
" lowp vec4 lodT_p1 = textureLod(uTex1, vTexCoord1, lod_tile + 1.0); \n"
386
424
" if (lod_tile < 1.0) { \n"
387
425
" if (magnifying) { \n"
388
" readtex0 = texture(uTex0, vTexCoord0); \n"
389
426
// !sharpen && !detail
390
427
" if (uTextureDetail == 0) readtex1 = readtex0; \n"
391
" else readtex1 = texture(uTex1, vTexCoord1); \n"
394
430
" if (uTextureDetail == 2) { \n"
395
" readtex0 = textureLod(uTex1, vTexCoord1, 0.0);\n"
396
" readtex1 = textureLod(uTex1, vTexCoord1, 1.0);\n"
398
" readtex0 = texture(uTex0, vTexCoord0); \n"
399
" readtex1 = texture(uTex1, vTexCoord1); \n"
431
" readtex0 = lod0; \n"
432
" readtex1 = lod1; \n"
403
436
" if (uTextureDetail == 2) { \n"
404
" readtex0 = textureLod(uTex1, vTexCoord1, lod_tile); \n"
405
" readtex1 = textureLod(uTex1, vTexCoord1, lod_tile + 1.0); \n"
407
" readtex0 = textureLod(uTex1, vTexCoord1, lod_tile - 1.0); \n"
408
" readtex1 = textureLod(uTex1, vTexCoord1, lod_tile); \n"
411
" return lod_frac; \n"
437
" readtex0 = lodT; \n"
438
" readtex1 = lodT_p1; \n"
440
" readtex0 = lodT_m1; \n"
441
" readtex1 = lodT; \n"
444
" return lod_frac; \n"
415
448
static const char* fragment_shader_readtex =
416
"#version 330 core \n"
417
452
"uniform lowp int uTextureFilterMode; \n"
418
"lowp vec4 filterNearest(in sampler2D tex, in mediump vec2 texCoord)\n"
420
" return textureLod(tex, texCoord, 0.0); \n"
422
453
// 3 point texture filtering.
423
454
// Original author: ArthurCarvalho
424
455
// GLSL implementation: twinaphex, mupen64plus-libretro project.
425
"#define TEX_OFFSET(off) textureLod(tex, texCoord - (off)/texSize, 0.0) \n"
456
"#define TEX_OFFSET(off) texture(tex, texCoord - (off)/texSize) \n"
426
457
"lowp vec4 filter3point(in sampler2D tex, in mediump vec2 texCoord) \n"
428
459
" mediump vec2 texSize = vec2(textureSize(tex,0)); \n"
436
467
"lowp vec4 readTex(in sampler2D tex, in mediump vec2 texCoord, in bool fb8bit, in bool fbFixedAlpha) \n"
438
" lowp vec4 texColor = uTextureFilterMode == 0 ? filterNearest(tex, texCoord) : filter3point(tex, texCoord); \n"
439
" if (fb8bit) texColor = vec4(texColor.r); \n"
440
" if (fbFixedAlpha) texColor.a = 0.825; \n"
441
" return texColor; \n"
469
" lowp vec4 texColor = uTextureFilterMode == 0 ? texture(tex, texCoord) : filter3point(tex, texCoord); \n"
470
" if (fb8bit) texColor = vec4(texColor.r); \n"
471
" if (fbFixedAlpha) texColor.a = 0.825; \n"
472
" return texColor; \n"
474
#ifdef GL_MULTISAMPLING_SUPPORT
475
"uniform lowp int uMSAASamples; \n"
476
"uniform lowp float uMSAAScale; \n"
477
"lowp vec4 sampleMS(in sampler2DMS mstex, in mediump ivec2 ipos) \n"
479
" lowp vec4 texel = vec4(0.0); \n"
480
" for (int i = 0; i < uMSAASamples; ++i) \n"
481
" texel += texelFetch(mstex, ipos, i); \n"
482
" return texel * uMSAAScale; \n"
485
"lowp vec4 readTexMS(in sampler2DMS mstex, in mediump vec2 texCoord, in bool fb8bit, in bool fbFixedAlpha) \n"
487
" mediump vec2 msTexSize = vec2(textureSize(mstex)); \n"
488
" mediump ivec2 itexCoord = ivec2(msTexSize * texCoord); \n"
489
" lowp vec4 texColor = sampleMS(mstex, itexCoord); \n"
490
" if (fb8bit) texColor = vec4(texColor.r); \n"
491
" if (fbFixedAlpha) texColor.a = 0.825; \n"
492
" return texColor; \n"
494
#endif // GL_MULTISAMPLING_SUPPORT
445
497
static const char* fragment_shader_noise =
446
"#version 330 core \n"
500
"uniform mediump vec2 uScreenScale; \n"
447
502
"uniform sampler2D uTexNoise; \n"
448
"uniform mediump vec2 uScreenScale; \n"
449
503
"lowp float snoise() \n"
451
505
" ivec2 coord = ivec2(gl_FragCoord.xy/uScreenScale); \n"
464
518
#ifdef GL_IMAGE_TEXTURES_SUPPORT
465
519
static const char* depth_compare_shader_float =
466
521
"#version 430 \n"
523
"#ifdef GL_OES_standard_derivatives \n"
524
" #extension GL_OES_standard_derivatives : enable \n"
467
527
//"uniform int uEnableDepth; \n"
468
528
"uniform lowp int uDepthMode; \n"
469
529
"uniform lowp int uDepthSource; \n"
529
589
"#version 420 core \n"
530
590
"layout(binding = 0) uniform sampler2D uDepthImage; \n"
531
591
"layout(binding = 0, r16ui) uniform readonly uimage2D uZlutImage;\n"
532
"layout(binding = 1, r16ui) uniform readonly uimage1D uTlutImage;\n"
592
"layout(binding = 1, r16ui) uniform readonly uimage2D uTlutImage;\n"
533
593
"uniform lowp vec4 uFogColor; \n"
534
594
"out lowp vec4 fragColor; \n"
535
595
"lowp float get_alpha() \n"
542
602
" uint iN64z = imageLoad(uZlutImage,ivec2(x0,y0)).r; \n"
543
603
" highp float n64z = clamp(float(iN64z)/65532.0, 0.0, 1.0);\n"
544
604
" int index = min(255, int(n64z*255.0)); \n"
545
" uint iAlpha = imageLoad(uTlutImage,index).r; \n"
605
" uint iAlpha = imageLoad(uTlutImage,ivec2(index,0)).r; \n"
546
606
" return float(iAlpha/256)/255.0; \n"
553
613
#endif // GL_IMAGE_TEXTURES_SUPPORT
615
#ifdef GL_IMAGE_TEXTURES_SUPPORT
555
616
#if 0 // Do palette based monochrome image. Exactly as N64 does
556
#ifdef GL_IMAGE_TEXTURES_SUPPORT
557
617
static const char* zelda_monochrome_fragment_shader =
558
618
"#version 420 core \n"
559
619
"layout(binding = 0) uniform sampler2D uColorImage; \n"
560
"layout(binding = 1, r16ui) uniform readonly uimage1D uTlutImage;\n"
620
"layout(binding = 1, r16ui) uniform readonly uimage2D uTlutImage;\n"
561
621
"out lowp vec4 fragColor; \n"
562
622
"lowp float get_color() \n"
568
628
//" int color16 = 32768 + r*1024 + g*32 + b; \n"
569
629
" int color16 = r*1024 + g*32 + b; \n"
570
630
" int index = min(255, color16/256); \n"
571
" uint iAlpha = imageLoad(uTlutImage,index).r; \n"
631
" uint iAlpha = imageLoad(uTlutImage,ivec2(index,0)).r; \n"
572
632
" memoryBarrier(); \n"
573
633
" return clamp(float((iAlpha&255) + index)/255.0, 0.0, 1.0); \n"