Fix renderer selection issue in gui. Use raw strings for shader source
This commit is contained in:
parent
07958f08ae
commit
5e4dacfa67
|
@ -22,275 +22,279 @@ GLuint pixel_buffer_size = 512 * 1024 * 1024; // Initial size 512 MB
|
||||||
|
|
||||||
#define MAX_PIXELS_PER_FRAGMENT "32"
|
#define MAX_PIXELS_PER_FRAGMENT "32"
|
||||||
|
|
||||||
static const char *final_shader_source = SHADER_HEADER "\
|
static const char *final_shader_source = SHADER_HEADER
|
||||||
#define DEPTH_SORTED %d \n\
|
"#define MAX_PIXELS_PER_FRAGMENT " MAX_PIXELS_PER_FRAGMENT
|
||||||
#define MAX_PIXELS_PER_FRAGMENT " MAX_PIXELS_PER_FRAGMENT " \n\
|
R"(
|
||||||
\n\
|
#define DEPTH_SORTED %d
|
||||||
layout(binding = 0) uniform sampler2D tex; \n\
|
|
||||||
uniform highp float shade_scale_factor; \n\
|
|
||||||
\n\
|
|
||||||
out vec4 FragColor; \n\
|
|
||||||
\n\
|
|
||||||
uint pixel_list[MAX_PIXELS_PER_FRAGMENT]; \n\
|
|
||||||
\n\
|
|
||||||
\n\
|
|
||||||
int fillAndSortFragmentArray(ivec2 coords) \n\
|
|
||||||
{ \n\
|
|
||||||
// Load fragments into a local memory array for sorting \n\
|
|
||||||
uint idx = imageLoad(abufferPointerImg, coords).x; \n\
|
|
||||||
int count = 0; \n\
|
|
||||||
for (; idx != EOL && count < MAX_PIXELS_PER_FRAGMENT; count++) \n\
|
|
||||||
{ \n\
|
|
||||||
const Pixel p = pixels[idx]; \n\
|
|
||||||
int j = count - 1; \n\
|
|
||||||
Pixel jp = pixels[pixel_list[j]]; \n\
|
|
||||||
#if DEPTH_SORTED == 1 \n\
|
|
||||||
while (j >= 0 \n\
|
|
||||||
&& (jp.depth > p.depth \n\
|
|
||||||
|| (jp.depth == p.depth && getPolyNumber(jp) > getPolyNumber(p)))) \n\
|
|
||||||
#else \n\
|
|
||||||
while (j >= 0 && getPolyNumber(jp) > getPolyNumber(p)) \n\
|
|
||||||
#endif \n\
|
|
||||||
{ \n\
|
|
||||||
pixel_list[j + 1] = pixel_list[j]; \n\
|
|
||||||
j--; \n\
|
|
||||||
jp = pixels[pixel_list[j]]; \n\
|
|
||||||
} \n\
|
|
||||||
pixel_list[j + 1] = idx; \n\
|
|
||||||
idx = p.next; \n\
|
|
||||||
} \n\
|
|
||||||
return count; \n\
|
|
||||||
} \n\
|
|
||||||
\n\
|
|
||||||
// Blend fragments back-to-front \n\
|
|
||||||
vec4 resolveAlphaBlend(ivec2 coords) { \n\
|
|
||||||
\n\
|
|
||||||
// Copy and sort fragments into a local array \n\
|
|
||||||
int num_frag = fillAndSortFragmentArray(coords); \n\
|
|
||||||
\n\
|
|
||||||
vec4 finalColor = texture(tex, gl_FragCoord.xy / textureSize(tex, 0)); \n\
|
|
||||||
vec4 secondaryBuffer = vec4(0.0); // Secondary accumulation buffer \n\
|
|
||||||
float depth = 1.0; \n\
|
|
||||||
\n\
|
|
||||||
bool do_depth_test = false; \n\
|
|
||||||
for (int i = 0; i < num_frag; i++) \n\
|
|
||||||
{ \n\
|
|
||||||
const Pixel pixel = pixels[pixel_list[i]]; \n\
|
|
||||||
const PolyParam pp = tr_poly_params[getPolyNumber(pixel)]; \n\
|
|
||||||
#if DEPTH_SORTED != 1 \n\
|
|
||||||
const float frag_depth = pixel.depth; \n\
|
|
||||||
if (do_depth_test) \n\
|
|
||||||
{ \n\
|
|
||||||
switch (getDepthFunc(pp)) \n\
|
|
||||||
{ \n\
|
|
||||||
case 0: // Never \n\
|
|
||||||
continue; \n\
|
|
||||||
case 1: // Less \n\
|
|
||||||
if (frag_depth >= depth) \n\
|
|
||||||
continue; \n\
|
|
||||||
break; \n\
|
|
||||||
case 2: // Equal \n\
|
|
||||||
if (frag_depth != depth) \n\
|
|
||||||
continue; \n\
|
|
||||||
break; \n\
|
|
||||||
case 3: // Less or equal \n\
|
|
||||||
if (frag_depth > depth) \n\
|
|
||||||
continue; \n\
|
|
||||||
break; \n\
|
|
||||||
case 4: // Greater \n\
|
|
||||||
if (frag_depth <= depth) \n\
|
|
||||||
continue; \n\
|
|
||||||
break; \n\
|
|
||||||
case 5: // Not equal \n\
|
|
||||||
if (frag_depth == depth) \n\
|
|
||||||
continue; \n\
|
|
||||||
break; \n\
|
|
||||||
case 6: // Greater or equal \n\
|
|
||||||
if (frag_depth < depth) \n\
|
|
||||||
continue; \n\
|
|
||||||
break; \n\
|
|
||||||
case 7: // Always \n\
|
|
||||||
break; \n\
|
|
||||||
} \n\
|
|
||||||
} \n\
|
|
||||||
\n\
|
|
||||||
if (getDepthMask(pp)) \n\
|
|
||||||
{ \n\
|
|
||||||
depth = frag_depth; \n\
|
|
||||||
do_depth_test = true; \n\
|
|
||||||
} \n\
|
|
||||||
#endif \n\
|
|
||||||
bool area1 = false; \n\
|
|
||||||
bool shadowed = false; \n\
|
|
||||||
if (isShadowed(pixel)) \n\
|
|
||||||
{ \n\
|
|
||||||
if (isTwoVolumes(pp)) \n\
|
|
||||||
area1 = true; \n\
|
|
||||||
else \n\
|
|
||||||
shadowed = true; \n\
|
|
||||||
} \n\
|
|
||||||
vec4 srcColor; \n\
|
|
||||||
if (getSrcSelect(pp, area1)) \n\
|
|
||||||
srcColor = secondaryBuffer; \n\
|
|
||||||
else \n\
|
|
||||||
{ \n\
|
|
||||||
srcColor = pixel.color; \n\
|
|
||||||
if (shadowed) \n\
|
|
||||||
srcColor.rgb *= shade_scale_factor; \n\
|
|
||||||
} \n\
|
|
||||||
vec4 dstColor = getDstSelect(pp, area1) ? secondaryBuffer : finalColor; \n\
|
|
||||||
vec4 srcCoef; \n\
|
|
||||||
vec4 dstCoef; \n\
|
|
||||||
\n\
|
|
||||||
int srcBlend = getSrcBlendFunc(pp, area1); \n\
|
|
||||||
switch (srcBlend) \n\
|
|
||||||
{ \n\
|
|
||||||
case ZERO: \n\
|
|
||||||
srcCoef = vec4(0.0); \n\
|
|
||||||
break; \n\
|
|
||||||
case ONE: \n\
|
|
||||||
srcCoef = vec4(1.0); \n\
|
|
||||||
break; \n\
|
|
||||||
case OTHER_COLOR: \n\
|
|
||||||
srcCoef = finalColor; \n\
|
|
||||||
break; \n\
|
|
||||||
case INVERSE_OTHER_COLOR: \n\
|
|
||||||
srcCoef = vec4(1.0) - dstColor; \n\
|
|
||||||
break; \n\
|
|
||||||
case SRC_ALPHA: \n\
|
|
||||||
srcCoef = vec4(srcColor.a); \n\
|
|
||||||
break; \n\
|
|
||||||
case INVERSE_SRC_ALPHA: \n\
|
|
||||||
srcCoef = vec4(1.0 - srcColor.a); \n\
|
|
||||||
break; \n\
|
|
||||||
case DST_ALPHA: \n\
|
|
||||||
srcCoef = vec4(dstColor.a); \n\
|
|
||||||
break; \n\
|
|
||||||
case INVERSE_DST_ALPHA: \n\
|
|
||||||
srcCoef = vec4(1.0 - dstColor.a); \n\
|
|
||||||
break; \n\
|
|
||||||
} \n\
|
|
||||||
int dstBlend = getDstBlendFunc(pp, area1); \n\
|
|
||||||
switch (dstBlend) \n\
|
|
||||||
{ \n\
|
|
||||||
case ZERO: \n\
|
|
||||||
dstCoef = vec4(0.0); \n\
|
|
||||||
break; \n\
|
|
||||||
case ONE: \n\
|
|
||||||
dstCoef = vec4(1.0); \n\
|
|
||||||
break; \n\
|
|
||||||
case OTHER_COLOR: \n\
|
|
||||||
dstCoef = srcColor; \n\
|
|
||||||
break; \n\
|
|
||||||
case INVERSE_OTHER_COLOR: \n\
|
|
||||||
dstCoef = vec4(1.0) - srcColor; \n\
|
|
||||||
break; \n\
|
|
||||||
case SRC_ALPHA: \n\
|
|
||||||
dstCoef = vec4(srcColor.a); \n\
|
|
||||||
break; \n\
|
|
||||||
case INVERSE_SRC_ALPHA: \n\
|
|
||||||
dstCoef = vec4(1.0 - srcColor.a); \n\
|
|
||||||
break; \n\
|
|
||||||
case DST_ALPHA: \n\
|
|
||||||
dstCoef = vec4(dstColor.a); \n\
|
|
||||||
break; \n\
|
|
||||||
case INVERSE_DST_ALPHA: \n\
|
|
||||||
dstCoef = vec4(1.0 - dstColor.a); \n\
|
|
||||||
break; \n\
|
|
||||||
} \n\
|
|
||||||
const vec4 result = clamp(dstColor * dstCoef + srcColor * srcCoef, 0.0, 1.0); \n\
|
|
||||||
if (getDstSelect(pp, area1)) \n\
|
|
||||||
secondaryBuffer = result; \n\
|
|
||||||
else \n\
|
|
||||||
finalColor = result; \n\
|
|
||||||
} \n\
|
|
||||||
\n\
|
|
||||||
return finalColor; \n\
|
|
||||||
\n\
|
|
||||||
} \n\
|
|
||||||
\n\
|
|
||||||
void main(void) \n\
|
|
||||||
{ \n\
|
|
||||||
ivec2 coords = ivec2(gl_FragCoord.xy); \n\
|
|
||||||
// Compute and output final color for the frame buffer \n\
|
|
||||||
// Visualize the number of layers in use \n\
|
|
||||||
//FragColor = vec4(float(fillAndSortFragmentArray(coords)) / MAX_PIXELS_PER_FRAGMENT * 4, 0, 0, 1); \n\
|
|
||||||
FragColor = resolveAlphaBlend(coords); \n\
|
|
||||||
} \n\
|
|
||||||
";
|
|
||||||
|
|
||||||
static const char *clear_shader_source = SHADER_HEADER "\
|
layout(binding = 0) uniform sampler2D tex;
|
||||||
\n\
|
uniform highp float shade_scale_factor;
|
||||||
void main(void) \n\
|
|
||||||
{ \n\
|
|
||||||
ivec2 coords = ivec2(gl_FragCoord.xy); \n\
|
|
||||||
\n\
|
|
||||||
// Reset pointers \n\
|
|
||||||
imageStore(abufferPointerImg, coords, uvec4(EOL)); \n\
|
|
||||||
\n\
|
|
||||||
// Discard fragment so nothing is written to the framebuffer \n\
|
|
||||||
discard; \n\
|
|
||||||
} \n\
|
|
||||||
";
|
|
||||||
|
|
||||||
static const char *tr_modvol_shader_source = SHADER_HEADER "\
|
out vec4 FragColor;
|
||||||
#define MV_MODE %d \n\
|
|
||||||
#define MAX_PIXELS_PER_FRAGMENT " MAX_PIXELS_PER_FRAGMENT " \n\
|
uint pixel_list[MAX_PIXELS_PER_FRAGMENT];
|
||||||
\n\
|
|
||||||
// Must match ModifierVolumeMode enum values \n\
|
|
||||||
#define MV_XOR 0 \n\
|
int fillAndSortFragmentArray(ivec2 coords)
|
||||||
#define MV_OR 1 \n\
|
{
|
||||||
#define MV_INCLUSION 2 \n\
|
// Load fragments into a local memory array for sorting
|
||||||
#define MV_EXCLUSION 3 \n\
|
uint idx = imageLoad(abufferPointerImg, coords).x;
|
||||||
\n\
|
int count = 0;
|
||||||
void main(void) \n\
|
for (; idx != EOL && count < MAX_PIXELS_PER_FRAGMENT; count++)
|
||||||
{ \n\
|
{
|
||||||
#if MV_MODE == MV_XOR || MV_MODE == MV_OR \n\
|
const Pixel p = pixels[idx];
|
||||||
setFragDepth(); \n\
|
int j = count - 1;
|
||||||
#endif \n\
|
Pixel jp = pixels[pixel_list[j]];
|
||||||
ivec2 coords = ivec2(gl_FragCoord.xy); \n\
|
#if DEPTH_SORTED == 1
|
||||||
\n\
|
while (j >= 0
|
||||||
uint idx = imageLoad(abufferPointerImg, coords).x; \n\
|
&& (jp.depth > p.depth
|
||||||
int list_len = 0; \n\
|
|| (jp.depth == p.depth && getPolyNumber(jp) > getPolyNumber(p))))
|
||||||
while (idx != EOL && list_len < MAX_PIXELS_PER_FRAGMENT) \n\
|
#else
|
||||||
{ \n\
|
while (j >= 0 && getPolyNumber(jp) > getPolyNumber(p))
|
||||||
const Pixel pixel = pixels[idx]; \n\
|
#endif
|
||||||
const PolyParam pp = tr_poly_params[getPolyNumber(pixel)]; \n\
|
{
|
||||||
if (getShadowEnable(pp)) \n\
|
pixel_list[j + 1] = pixel_list[j];
|
||||||
{ \n\
|
j--;
|
||||||
#if MV_MODE == MV_XOR \n\
|
jp = pixels[pixel_list[j]];
|
||||||
if (gl_FragDepth >= pixel.depth) \n\
|
}
|
||||||
atomicXor(pixels[idx].seq_num, SHADOW_STENCIL); \n\
|
pixel_list[j + 1] = idx;
|
||||||
#elif MV_MODE == MV_OR \n\
|
idx = p.next;
|
||||||
if (gl_FragDepth >= pixel.depth) \n\
|
}
|
||||||
atomicOr(pixels[idx].seq_num, SHADOW_STENCIL); \n\
|
return count;
|
||||||
#elif MV_MODE == MV_INCLUSION \n\
|
}
|
||||||
uint prev_val = atomicAnd(pixels[idx].seq_num, ~(SHADOW_STENCIL)); \n\
|
|
||||||
if ((prev_val & (SHADOW_STENCIL|SHADOW_ACC)) == SHADOW_STENCIL) \n\
|
// Blend fragments back-to-front
|
||||||
pixels[idx].seq_num = bitfieldInsert(pixel.seq_num, 1u, 31, 1); \n\
|
vec4 resolveAlphaBlend(ivec2 coords) {
|
||||||
#elif MV_MODE == MV_EXCLUSION \n\
|
|
||||||
uint prev_val = atomicAnd(pixels[idx].seq_num, ~(SHADOW_STENCIL|SHADOW_ACC)); \n\
|
// Copy and sort fragments into a local array
|
||||||
if ((prev_val & (SHADOW_STENCIL|SHADOW_ACC)) == SHADOW_ACC) \n\
|
int num_frag = fillAndSortFragmentArray(coords);
|
||||||
pixels[idx].seq_num = bitfieldInsert(pixel.seq_num, 1u, 31, 1); \n\
|
|
||||||
#endif \n\
|
vec4 finalColor = texture(tex, gl_FragCoord.xy / textureSize(tex, 0));
|
||||||
} \n\
|
vec4 secondaryBuffer = vec4(0.0); // Secondary accumulation buffer
|
||||||
idx = pixel.next; \n\
|
float depth = 1.0;
|
||||||
list_len++; \n\
|
|
||||||
} \n\
|
bool do_depth_test = false;
|
||||||
\n\
|
for (int i = 0; i < num_frag; i++)
|
||||||
discard; \n\
|
{
|
||||||
} \n\
|
const Pixel pixel = pixels[pixel_list[i]];
|
||||||
";
|
const PolyParam pp = tr_poly_params[getPolyNumber(pixel)];
|
||||||
|
#if DEPTH_SORTED != 1
|
||||||
|
const float frag_depth = pixel.depth;
|
||||||
|
if (do_depth_test)
|
||||||
|
{
|
||||||
|
switch (getDepthFunc(pp))
|
||||||
|
{
|
||||||
|
case 0: // Never
|
||||||
|
continue;
|
||||||
|
case 1: // Less
|
||||||
|
if (frag_depth >= depth)
|
||||||
|
continue;
|
||||||
|
break;
|
||||||
|
case 2: // Equal
|
||||||
|
if (frag_depth != depth)
|
||||||
|
continue;
|
||||||
|
break;
|
||||||
|
case 3: // Less or equal
|
||||||
|
if (frag_depth > depth)
|
||||||
|
continue;
|
||||||
|
break;
|
||||||
|
case 4: // Greater
|
||||||
|
if (frag_depth <= depth)
|
||||||
|
continue;
|
||||||
|
break;
|
||||||
|
case 5: // Not equal
|
||||||
|
if (frag_depth == depth)
|
||||||
|
continue;
|
||||||
|
break;
|
||||||
|
case 6: // Greater or equal
|
||||||
|
if (frag_depth < depth)
|
||||||
|
continue;
|
||||||
|
break;
|
||||||
|
case 7: // Always
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (getDepthMask(pp))
|
||||||
|
{
|
||||||
|
depth = frag_depth;
|
||||||
|
do_depth_test = true;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
bool area1 = false;
|
||||||
|
bool shadowed = false;
|
||||||
|
if (isShadowed(pixel))
|
||||||
|
{
|
||||||
|
if (isTwoVolumes(pp))
|
||||||
|
area1 = true;
|
||||||
|
else
|
||||||
|
shadowed = true;
|
||||||
|
}
|
||||||
|
vec4 srcColor;
|
||||||
|
if (getSrcSelect(pp, area1))
|
||||||
|
srcColor = secondaryBuffer;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
srcColor = pixel.color;
|
||||||
|
if (shadowed)
|
||||||
|
srcColor.rgb *= shade_scale_factor;
|
||||||
|
}
|
||||||
|
vec4 dstColor = getDstSelect(pp, area1) ? secondaryBuffer : finalColor;
|
||||||
|
vec4 srcCoef;
|
||||||
|
vec4 dstCoef;
|
||||||
|
|
||||||
|
int srcBlend = getSrcBlendFunc(pp, area1);
|
||||||
|
switch (srcBlend)
|
||||||
|
{
|
||||||
|
case ZERO:
|
||||||
|
srcCoef = vec4(0.0);
|
||||||
|
break;
|
||||||
|
case ONE:
|
||||||
|
srcCoef = vec4(1.0);
|
||||||
|
break;
|
||||||
|
case OTHER_COLOR:
|
||||||
|
srcCoef = finalColor;
|
||||||
|
break;
|
||||||
|
case INVERSE_OTHER_COLOR:
|
||||||
|
srcCoef = vec4(1.0) - dstColor;
|
||||||
|
break;
|
||||||
|
case SRC_ALPHA:
|
||||||
|
srcCoef = vec4(srcColor.a);
|
||||||
|
break;
|
||||||
|
case INVERSE_SRC_ALPHA:
|
||||||
|
srcCoef = vec4(1.0 - srcColor.a);
|
||||||
|
break;
|
||||||
|
case DST_ALPHA:
|
||||||
|
srcCoef = vec4(dstColor.a);
|
||||||
|
break;
|
||||||
|
case INVERSE_DST_ALPHA:
|
||||||
|
srcCoef = vec4(1.0 - dstColor.a);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
int dstBlend = getDstBlendFunc(pp, area1);
|
||||||
|
switch (dstBlend)
|
||||||
|
{
|
||||||
|
case ZERO:
|
||||||
|
dstCoef = vec4(0.0);
|
||||||
|
break;
|
||||||
|
case ONE:
|
||||||
|
dstCoef = vec4(1.0);
|
||||||
|
break;
|
||||||
|
case OTHER_COLOR:
|
||||||
|
dstCoef = srcColor;
|
||||||
|
break;
|
||||||
|
case INVERSE_OTHER_COLOR:
|
||||||
|
dstCoef = vec4(1.0) - srcColor;
|
||||||
|
break;
|
||||||
|
case SRC_ALPHA:
|
||||||
|
dstCoef = vec4(srcColor.a);
|
||||||
|
break;
|
||||||
|
case INVERSE_SRC_ALPHA:
|
||||||
|
dstCoef = vec4(1.0 - srcColor.a);
|
||||||
|
break;
|
||||||
|
case DST_ALPHA:
|
||||||
|
dstCoef = vec4(dstColor.a);
|
||||||
|
break;
|
||||||
|
case INVERSE_DST_ALPHA:
|
||||||
|
dstCoef = vec4(1.0 - dstColor.a);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
const vec4 result = clamp(dstColor * dstCoef + srcColor * srcCoef, 0.0, 1.0);
|
||||||
|
if (getDstSelect(pp, area1))
|
||||||
|
secondaryBuffer = result;
|
||||||
|
else
|
||||||
|
finalColor = result;
|
||||||
|
}
|
||||||
|
|
||||||
|
return finalColor;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void main(void)
|
||||||
|
{
|
||||||
|
ivec2 coords = ivec2(gl_FragCoord.xy);
|
||||||
|
// Compute and output final color for the frame buffer
|
||||||
|
// Visualize the number of layers in use
|
||||||
|
//FragColor = vec4(float(fillAndSortFragmentArray(coords)) / MAX_PIXELS_PER_FRAGMENT * 4, 0, 0, 1);
|
||||||
|
FragColor = resolveAlphaBlend(coords);
|
||||||
|
}
|
||||||
|
)";
|
||||||
|
|
||||||
|
static const char *clear_shader_source = SHADER_HEADER
|
||||||
|
R"(
|
||||||
|
void main(void)
|
||||||
|
{
|
||||||
|
ivec2 coords = ivec2(gl_FragCoord.xy);
|
||||||
|
|
||||||
|
// Reset pointers
|
||||||
|
imageStore(abufferPointerImg, coords, uvec4(EOL));
|
||||||
|
|
||||||
|
// Discard fragment so nothing is written to the framebuffer
|
||||||
|
discard;
|
||||||
|
}
|
||||||
|
)";
|
||||||
|
|
||||||
|
static const char *tr_modvol_shader_source = SHADER_HEADER
|
||||||
|
"#define MAX_PIXELS_PER_FRAGMENT " MAX_PIXELS_PER_FRAGMENT
|
||||||
|
R"(
|
||||||
|
#define MV_MODE %d
|
||||||
|
|
||||||
|
// Must match ModifierVolumeMode enum values
|
||||||
|
#define MV_XOR 0
|
||||||
|
#define MV_OR 1
|
||||||
|
#define MV_INCLUSION 2
|
||||||
|
#define MV_EXCLUSION 3
|
||||||
|
|
||||||
|
void main(void)
|
||||||
|
{
|
||||||
|
#if MV_MODE == MV_XOR || MV_MODE == MV_OR
|
||||||
|
setFragDepth();
|
||||||
|
#endif
|
||||||
|
ivec2 coords = ivec2(gl_FragCoord.xy);
|
||||||
|
|
||||||
|
uint idx = imageLoad(abufferPointerImg, coords).x;
|
||||||
|
int list_len = 0;
|
||||||
|
while (idx != EOL && list_len < MAX_PIXELS_PER_FRAGMENT)
|
||||||
|
{
|
||||||
|
const Pixel pixel = pixels[idx];
|
||||||
|
const PolyParam pp = tr_poly_params[getPolyNumber(pixel)];
|
||||||
|
if (getShadowEnable(pp))
|
||||||
|
{
|
||||||
|
#if MV_MODE == MV_XOR
|
||||||
|
if (gl_FragDepth >= pixel.depth)
|
||||||
|
atomicXor(pixels[idx].seq_num, SHADOW_STENCIL);
|
||||||
|
#elif MV_MODE == MV_OR
|
||||||
|
if (gl_FragDepth >= pixel.depth)
|
||||||
|
atomicOr(pixels[idx].seq_num, SHADOW_STENCIL);
|
||||||
|
#elif MV_MODE == MV_INCLUSION
|
||||||
|
uint prev_val = atomicAnd(pixels[idx].seq_num, ~(SHADOW_STENCIL));
|
||||||
|
if ((prev_val & (SHADOW_STENCIL|SHADOW_ACC)) == SHADOW_STENCIL)
|
||||||
|
pixels[idx].seq_num = bitfieldInsert(pixel.seq_num, 1u, 31, 1);
|
||||||
|
#elif MV_MODE == MV_EXCLUSION
|
||||||
|
uint prev_val = atomicAnd(pixels[idx].seq_num, ~(SHADOW_STENCIL|SHADOW_ACC));
|
||||||
|
if ((prev_val & (SHADOW_STENCIL|SHADOW_ACC)) == SHADOW_ACC)
|
||||||
|
pixels[idx].seq_num = bitfieldInsert(pixel.seq_num, 1u, 31, 1);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
idx = pixel.next;
|
||||||
|
list_len++;
|
||||||
|
}
|
||||||
|
|
||||||
|
discard;
|
||||||
|
}
|
||||||
|
)";
|
||||||
|
|
||||||
static const char* VertexShaderSource =
|
static const char* VertexShaderSource =
|
||||||
"#version 430 \n"
|
R"(
|
||||||
"\
|
#version 430
|
||||||
in highp vec3 in_pos; \n\
|
|
||||||
\n\
|
in highp vec3 in_pos;
|
||||||
void main() \n\
|
|
||||||
{ \n\
|
void main()
|
||||||
gl_Position = vec4(in_pos, 1.0); \n\
|
{
|
||||||
}";
|
gl_Position = vec4(in_pos, 1.0);
|
||||||
|
}
|
||||||
|
)";
|
||||||
|
|
||||||
void initABuffer()
|
void initABuffer()
|
||||||
{
|
{
|
||||||
|
|
|
@ -12,384 +12,384 @@
|
||||||
|
|
||||||
//Fragment and vertex shaders code
|
//Fragment and vertex shaders code
|
||||||
|
|
||||||
static const char* VertexShaderSource =
|
static const char* VertexShaderSource = R"(
|
||||||
"\
|
#version 140
|
||||||
#version 140 \n\
|
#define pp_Gouraud %d
|
||||||
#define pp_Gouraud %d \n\
|
|
||||||
\n\
|
#if pp_Gouraud == 0
|
||||||
#if pp_Gouraud == 0 \n\
|
#define INTERPOLATION flat
|
||||||
#define INTERPOLATION flat \n\
|
#else
|
||||||
#else \n\
|
#define INTERPOLATION smooth
|
||||||
#define INTERPOLATION smooth \n\
|
#endif
|
||||||
#endif \n\
|
|
||||||
\n\
|
/* Vertex constants*/
|
||||||
/* Vertex constants*/ \n\
|
uniform highp vec4 scale;
|
||||||
uniform highp vec4 scale; \n\
|
uniform highp mat4 normal_matrix;
|
||||||
uniform highp mat4 normal_matrix; \n\
|
/* Vertex input */
|
||||||
/* Vertex input */ \n\
|
in highp vec4 in_pos;
|
||||||
in highp vec4 in_pos; \n\
|
in lowp vec4 in_base;
|
||||||
in lowp vec4 in_base; \n\
|
in lowp vec4 in_offs;
|
||||||
in lowp vec4 in_offs; \n\
|
in mediump vec2 in_uv;
|
||||||
in mediump vec2 in_uv; \n\
|
in lowp vec4 in_base1;
|
||||||
in lowp vec4 in_base1; \n\
|
in lowp vec4 in_offs1;
|
||||||
in lowp vec4 in_offs1; \n\
|
in mediump vec2 in_uv1;
|
||||||
in mediump vec2 in_uv1; \n\
|
/* output */
|
||||||
/* output */ \n\
|
INTERPOLATION out lowp vec4 vtx_base;
|
||||||
INTERPOLATION out lowp vec4 vtx_base; \n\
|
INTERPOLATION out lowp vec4 vtx_offs;
|
||||||
INTERPOLATION out lowp vec4 vtx_offs; \n\
|
out mediump vec2 vtx_uv;
|
||||||
out mediump vec2 vtx_uv; \n\
|
INTERPOLATION out lowp vec4 vtx_base1;
|
||||||
INTERPOLATION out lowp vec4 vtx_base1; \n\
|
INTERPOLATION out lowp vec4 vtx_offs1;
|
||||||
INTERPOLATION out lowp vec4 vtx_offs1; \n\
|
out mediump vec2 vtx_uv1;
|
||||||
out mediump vec2 vtx_uv1; \n\
|
void main()
|
||||||
void main() \n\
|
{
|
||||||
{ \n\
|
vtx_base = in_base;
|
||||||
vtx_base = in_base; \n\
|
vtx_offs = in_offs;
|
||||||
vtx_offs = in_offs; \n\
|
vtx_uv = in_uv;
|
||||||
vtx_uv = in_uv; \n\
|
vtx_base1 = in_base1;
|
||||||
vtx_base1 = in_base1; \n\
|
vtx_offs1 = in_offs1;
|
||||||
vtx_offs1 = in_offs1; \n\
|
vtx_uv1 = in_uv1;
|
||||||
vtx_uv1 = in_uv1; \n\
|
vec4 vpos = in_pos;
|
||||||
vec4 vpos = in_pos; \n\
|
if (vpos.z < 0.0 || vpos.z > 3.4e37)
|
||||||
if (vpos.z < 0.0 || vpos.z > 3.4e37) \n\
|
{
|
||||||
{ \n\
|
gl_Position = vec4(0.0, 0.0, 1.0, 1.0 / vpos.z);
|
||||||
gl_Position = vec4(0.0, 0.0, 1.0, 1.0 / vpos.z); \n\
|
return;
|
||||||
return; \n\
|
}
|
||||||
} \n\
|
|
||||||
\n\
|
vpos = normal_matrix * vpos;
|
||||||
vpos = normal_matrix * vpos; \n\
|
vpos.w = 1.0 / vpos.z;
|
||||||
vpos.w = 1.0 / vpos.z; \n\
|
vpos.z = vpos.w;
|
||||||
vpos.z = vpos.w; \n\
|
vpos.xy *= vpos.w;
|
||||||
vpos.xy *= vpos.w; \n\
|
gl_Position = vpos;
|
||||||
gl_Position = vpos; \n\
|
}
|
||||||
}";
|
)";
|
||||||
|
|
||||||
const char* gl4PixelPipelineShader = SHADER_HEADER
|
const char* gl4PixelPipelineShader = SHADER_HEADER
|
||||||
"\
|
R"(
|
||||||
#define cp_AlphaTest %d \n\
|
#define cp_AlphaTest %d
|
||||||
#define pp_ClipTestMode %d \n\
|
#define pp_ClipTestMode %d
|
||||||
#define pp_UseAlpha %d \n\
|
#define pp_UseAlpha %d
|
||||||
#define pp_Texture %d \n\
|
#define pp_Texture %d
|
||||||
#define pp_IgnoreTexA %d \n\
|
#define pp_IgnoreTexA %d
|
||||||
#define pp_ShadInstr %d \n\
|
#define pp_ShadInstr %d
|
||||||
#define pp_Offset %d \n\
|
#define pp_Offset %d
|
||||||
#define pp_FogCtrl %d \n\
|
#define pp_FogCtrl %d
|
||||||
#define pp_TwoVolumes %d \n\
|
#define pp_TwoVolumes %d
|
||||||
#define pp_DepthFunc %d \n\
|
#define pp_DepthFunc %d
|
||||||
#define pp_Gouraud %d \n\
|
#define pp_Gouraud %d
|
||||||
#define pp_BumpMap %d \n\
|
#define pp_BumpMap %d
|
||||||
#define FogClamping %d \n\
|
#define FogClamping %d
|
||||||
#define PASS %d \n\
|
#define PASS %d
|
||||||
#define PI 3.1415926 \n\
|
#define PI 3.1415926
|
||||||
\n\
|
|
||||||
#if PASS <= 1 \n\
|
#if PASS <= 1
|
||||||
out vec4 FragColor; \n\
|
out vec4 FragColor;
|
||||||
#endif \n\
|
#endif
|
||||||
\n\
|
|
||||||
#if pp_TwoVolumes == 1 \n\
|
#if pp_TwoVolumes == 1
|
||||||
#define IF(x) if (x) \n\
|
#define IF(x) if (x)
|
||||||
#else \n\
|
#else
|
||||||
#define IF(x) \n\
|
#define IF(x)
|
||||||
#endif \n\
|
#endif
|
||||||
\n\
|
|
||||||
#if pp_Gouraud == 0 \n\
|
#if pp_Gouraud == 0
|
||||||
#define INTERPOLATION flat \n\
|
#define INTERPOLATION flat
|
||||||
#else \n\
|
#else
|
||||||
#define INTERPOLATION smooth \n\
|
#define INTERPOLATION smooth
|
||||||
#endif \n\
|
#endif
|
||||||
\n\
|
|
||||||
/* Shader program params*/ \n\
|
/* Shader program params*/
|
||||||
uniform lowp float cp_AlphaTestValue; \n\
|
uniform lowp float cp_AlphaTestValue;
|
||||||
uniform lowp vec4 pp_ClipTest; \n\
|
uniform lowp vec4 pp_ClipTest;
|
||||||
uniform lowp vec3 sp_FOG_COL_RAM,sp_FOG_COL_VERT; \n\
|
uniform lowp vec3 sp_FOG_COL_RAM,sp_FOG_COL_VERT;
|
||||||
uniform highp float sp_FOG_DENSITY; \n\
|
uniform highp float sp_FOG_DENSITY;
|
||||||
uniform highp float shade_scale_factor; \n\
|
uniform highp float shade_scale_factor;
|
||||||
uniform sampler2D tex0, tex1; \n\
|
uniform sampler2D tex0, tex1;
|
||||||
layout(binding = 5) uniform sampler2D fog_table; \n\
|
layout(binding = 5) uniform sampler2D fog_table;
|
||||||
uniform int pp_Number; \n\
|
uniform int pp_Number;
|
||||||
uniform usampler2D shadow_stencil; \n\
|
uniform usampler2D shadow_stencil;
|
||||||
uniform sampler2D DepthTex; \n\
|
uniform sampler2D DepthTex;
|
||||||
uniform lowp float trilinear_alpha; \n\
|
uniform lowp float trilinear_alpha;
|
||||||
uniform lowp vec4 fog_clamp_min; \n\
|
uniform lowp vec4 fog_clamp_min;
|
||||||
uniform lowp vec4 fog_clamp_max; \n\
|
uniform lowp vec4 fog_clamp_max;
|
||||||
\n\
|
|
||||||
uniform ivec2 blend_mode[2]; \n\
|
uniform ivec2 blend_mode[2];
|
||||||
#if pp_TwoVolumes == 1 \n\
|
#if pp_TwoVolumes == 1
|
||||||
uniform bool use_alpha[2]; \n\
|
uniform bool use_alpha[2];
|
||||||
uniform bool ignore_tex_alpha[2]; \n\
|
uniform bool ignore_tex_alpha[2];
|
||||||
uniform int shading_instr[2]; \n\
|
uniform int shading_instr[2];
|
||||||
uniform int fog_control[2]; \n\
|
uniform int fog_control[2];
|
||||||
#endif \n\
|
#endif
|
||||||
\n\
|
|
||||||
uniform highp float extra_depth_scale; \n\
|
uniform highp float extra_depth_scale;
|
||||||
/* Vertex input*/ \n\
|
/* Vertex input*/
|
||||||
INTERPOLATION in lowp vec4 vtx_base; \n\
|
INTERPOLATION in lowp vec4 vtx_base;
|
||||||
INTERPOLATION in lowp vec4 vtx_offs; \n\
|
INTERPOLATION in lowp vec4 vtx_offs;
|
||||||
in mediump vec2 vtx_uv; \n\
|
in mediump vec2 vtx_uv;
|
||||||
INTERPOLATION in lowp vec4 vtx_base1; \n\
|
INTERPOLATION in lowp vec4 vtx_base1;
|
||||||
INTERPOLATION in lowp vec4 vtx_offs1; \n\
|
INTERPOLATION in lowp vec4 vtx_offs1;
|
||||||
in mediump vec2 vtx_uv1; \n\
|
in mediump vec2 vtx_uv1;
|
||||||
\n\
|
|
||||||
lowp float fog_mode2(highp float w) \n\
|
lowp float fog_mode2(highp float w)
|
||||||
{ \n\
|
{
|
||||||
highp float z = clamp(w * extra_depth_scale * sp_FOG_DENSITY, 1.0, 255.9999); \n\
|
highp float z = clamp(w * extra_depth_scale * sp_FOG_DENSITY, 1.0, 255.9999);
|
||||||
highp float exp = floor(log2(z)); \n\
|
highp float exp = floor(log2(z));
|
||||||
highp float m = z * 16.0 / pow(2.0, exp) - 16.0; \n\
|
highp float m = z * 16.0 / pow(2.0, exp) - 16.0;
|
||||||
float idx = floor(m) + exp * 16.0 + 0.5; \n\
|
float idx = floor(m) + exp * 16.0 + 0.5;
|
||||||
vec4 fog_coef = texture(fog_table, vec2(idx / 128.0, 0.75 - (m - floor(m)) / 2.0)); \n\
|
vec4 fog_coef = texture(fog_table, vec2(idx / 128.0, 0.75 - (m - floor(m)) / 2.0));
|
||||||
return fog_coef.r; \n\
|
return fog_coef.r;
|
||||||
} \n\
|
}
|
||||||
\n\
|
|
||||||
highp vec4 fog_clamp(highp vec4 col) \n\
|
highp vec4 fog_clamp(highp vec4 col)
|
||||||
{ \n\
|
{
|
||||||
#if FogClamping == 1 \n\
|
#if FogClamping == 1
|
||||||
return clamp(col, fog_clamp_min, fog_clamp_max); \n\
|
return clamp(col, fog_clamp_min, fog_clamp_max);
|
||||||
#else \n\
|
#else
|
||||||
return col; \n\
|
return col;
|
||||||
#endif \n\
|
#endif
|
||||||
} \n\
|
}
|
||||||
\n\
|
|
||||||
void main() \n\
|
void main()
|
||||||
{ \n\
|
{
|
||||||
setFragDepth(); \n\
|
setFragDepth();
|
||||||
\n\
|
|
||||||
#if PASS == 3 \n\
|
#if PASS == 3
|
||||||
// Manual depth testing \n\
|
// Manual depth testing
|
||||||
highp float frontDepth = texture(DepthTex, gl_FragCoord.xy / textureSize(DepthTex, 0)).r; \n\
|
highp float frontDepth = texture(DepthTex, gl_FragCoord.xy / textureSize(DepthTex, 0)).r;
|
||||||
#if pp_DepthFunc == 0 // Never \n\
|
#if pp_DepthFunc == 0 // Never
|
||||||
discard; \n\
|
discard;
|
||||||
#elif pp_DepthFunc == 1 // Less \n\
|
#elif pp_DepthFunc == 1 // Less
|
||||||
if (gl_FragDepth >= frontDepth) \n\
|
if (gl_FragDepth >= frontDepth)
|
||||||
discard; \n\
|
discard;
|
||||||
#elif pp_DepthFunc == 2 // Equal \n\
|
#elif pp_DepthFunc == 2 // Equal
|
||||||
if (gl_FragDepth != frontDepth) \n\
|
if (gl_FragDepth != frontDepth)
|
||||||
discard; \n\
|
discard;
|
||||||
#elif pp_DepthFunc == 3 // Less or equal \n\
|
#elif pp_DepthFunc == 3 // Less or equal
|
||||||
if (gl_FragDepth > frontDepth) \n\
|
if (gl_FragDepth > frontDepth)
|
||||||
discard; \n\
|
discard;
|
||||||
#elif pp_DepthFunc == 4 // Greater \n\
|
#elif pp_DepthFunc == 4 // Greater
|
||||||
if (gl_FragDepth <= frontDepth) \n\
|
if (gl_FragDepth <= frontDepth)
|
||||||
discard; \n\
|
discard;
|
||||||
#elif pp_DepthFunc == 5 // Not equal \n\
|
#elif pp_DepthFunc == 5 // Not equal
|
||||||
if (gl_FragDepth == frontDepth) \n\
|
if (gl_FragDepth == frontDepth)
|
||||||
discard; \n\
|
discard;
|
||||||
#elif pp_DepthFunc == 6 // Greater or equal \n\
|
#elif pp_DepthFunc == 6 // Greater or equal
|
||||||
if (gl_FragDepth < frontDepth) \n\
|
if (gl_FragDepth < frontDepth)
|
||||||
discard; \n\
|
discard;
|
||||||
#endif \n\
|
#endif
|
||||||
#endif \n\
|
#endif
|
||||||
\n\
|
|
||||||
// Clip outside the box \n\
|
// Clip outside the box
|
||||||
#if pp_ClipTestMode==1 \n\
|
#if pp_ClipTestMode==1
|
||||||
if (gl_FragCoord.x < pp_ClipTest.x || gl_FragCoord.x > pp_ClipTest.z \n\
|
if (gl_FragCoord.x < pp_ClipTest.x || gl_FragCoord.x > pp_ClipTest.z
|
||||||
|| gl_FragCoord.y < pp_ClipTest.y || gl_FragCoord.y > pp_ClipTest.w) \n\
|
|| gl_FragCoord.y < pp_ClipTest.y || gl_FragCoord.y > pp_ClipTest.w)
|
||||||
discard; \n\
|
discard;
|
||||||
#endif \n\
|
#endif
|
||||||
// Clip inside the box \n\
|
// Clip inside the box
|
||||||
#if pp_ClipTestMode==-1 \n\
|
#if pp_ClipTestMode==-1
|
||||||
if (gl_FragCoord.x >= pp_ClipTest.x && gl_FragCoord.x <= pp_ClipTest.z \n\
|
if (gl_FragCoord.x >= pp_ClipTest.x && gl_FragCoord.x <= pp_ClipTest.z
|
||||||
&& gl_FragCoord.y >= pp_ClipTest.y && gl_FragCoord.y <= pp_ClipTest.w) \n\
|
&& gl_FragCoord.y >= pp_ClipTest.y && gl_FragCoord.y <= pp_ClipTest.w)
|
||||||
discard; \n\
|
discard;
|
||||||
#endif \n\
|
#endif
|
||||||
\n\
|
|
||||||
highp vec4 color = vtx_base; \n\
|
highp vec4 color = vtx_base;
|
||||||
lowp vec4 offset = vtx_offs; \n\
|
lowp vec4 offset = vtx_offs;
|
||||||
mediump vec2 uv = vtx_uv; \n\
|
mediump vec2 uv = vtx_uv;
|
||||||
bool area1 = false; \n\
|
bool area1 = false;
|
||||||
ivec2 cur_blend_mode = blend_mode[0]; \n\
|
ivec2 cur_blend_mode = blend_mode[0];
|
||||||
\n\
|
|
||||||
#if pp_TwoVolumes == 1 \n\
|
#if pp_TwoVolumes == 1
|
||||||
bool cur_use_alpha = use_alpha[0]; \n\
|
bool cur_use_alpha = use_alpha[0];
|
||||||
bool cur_ignore_tex_alpha = ignore_tex_alpha[0]; \n\
|
bool cur_ignore_tex_alpha = ignore_tex_alpha[0];
|
||||||
int cur_shading_instr = shading_instr[0]; \n\
|
int cur_shading_instr = shading_instr[0];
|
||||||
int cur_fog_control = fog_control[0]; \n\
|
int cur_fog_control = fog_control[0];
|
||||||
#if PASS == 1 \n\
|
#if PASS == 1
|
||||||
uvec4 stencil = texture(shadow_stencil, gl_FragCoord.xy / textureSize(shadow_stencil, 0)); \n\
|
uvec4 stencil = texture(shadow_stencil, gl_FragCoord.xy / textureSize(shadow_stencil, 0));
|
||||||
if (stencil.r == 0x81u) { \n\
|
if (stencil.r == 0x81u) {
|
||||||
color = vtx_base1; \n\
|
color = vtx_base1;
|
||||||
offset = vtx_offs1; \n\
|
offset = vtx_offs1;
|
||||||
uv = vtx_uv1; \n\
|
uv = vtx_uv1;
|
||||||
area1 = true; \n\
|
area1 = true;
|
||||||
cur_blend_mode = blend_mode[1]; \n\
|
cur_blend_mode = blend_mode[1];
|
||||||
cur_use_alpha = use_alpha[1]; \n\
|
cur_use_alpha = use_alpha[1];
|
||||||
cur_ignore_tex_alpha = ignore_tex_alpha[1]; \n\
|
cur_ignore_tex_alpha = ignore_tex_alpha[1];
|
||||||
cur_shading_instr = shading_instr[1]; \n\
|
cur_shading_instr = shading_instr[1];
|
||||||
cur_fog_control = fog_control[1]; \n\
|
cur_fog_control = fog_control[1];
|
||||||
} \n\
|
}
|
||||||
#endif\n\
|
#endif
|
||||||
#endif\n\
|
#endif
|
||||||
\n\
|
|
||||||
#if pp_UseAlpha==0 || pp_TwoVolumes == 1 \n\
|
#if pp_UseAlpha==0 || pp_TwoVolumes == 1
|
||||||
IF(!cur_use_alpha) \n\
|
IF(!cur_use_alpha)
|
||||||
color.a=1.0; \n\
|
color.a=1.0;
|
||||||
#endif\n\
|
#endif
|
||||||
#if pp_FogCtrl==3 || pp_TwoVolumes == 1 // LUT Mode 2 \n\
|
#if pp_FogCtrl==3 || pp_TwoVolumes == 1 // LUT Mode 2
|
||||||
IF(cur_fog_control == 3) \n\
|
IF(cur_fog_control == 3)
|
||||||
color=vec4(sp_FOG_COL_RAM.rgb,fog_mode2(gl_FragCoord.w)); \n\
|
color=vec4(sp_FOG_COL_RAM.rgb,fog_mode2(gl_FragCoord.w));
|
||||||
#endif\n\
|
#endif
|
||||||
#if pp_Texture==1 \n\
|
#if pp_Texture==1
|
||||||
{ \n\
|
{
|
||||||
highp vec4 texcol; \n\
|
highp vec4 texcol;
|
||||||
if (area1) \n\
|
if (area1)
|
||||||
texcol = texture(tex1, uv); \n\
|
texcol = texture(tex1, uv);
|
||||||
else \n\
|
else
|
||||||
texcol = texture(tex0, uv); \n\
|
texcol = texture(tex0, uv);
|
||||||
#if pp_BumpMap == 1 \n\
|
#if pp_BumpMap == 1
|
||||||
highp float s = PI / 2.0 * (texcol.a * 15.0 * 16.0 + texcol.r * 15.0) / 255.0; \n\
|
highp float s = PI / 2.0 * (texcol.a * 15.0 * 16.0 + texcol.r * 15.0) / 255.0;
|
||||||
highp float r = 2.0 * PI * (texcol.g * 15.0 * 16.0 + texcol.b * 15.0) / 255.0; \n\
|
highp float r = 2.0 * PI * (texcol.g * 15.0 * 16.0 + texcol.b * 15.0) / 255.0;
|
||||||
texcol.a = clamp(vtx_offs.a + vtx_offs.r * sin(s) + vtx_offs.g * cos(s) * cos(r - 2.0 * PI * vtx_offs.b), 0.0, 1.0); \n\
|
texcol.a = clamp(vtx_offs.a + vtx_offs.r * sin(s) + vtx_offs.g * cos(s) * cos(r - 2.0 * PI * vtx_offs.b), 0.0, 1.0);
|
||||||
texcol.rgb = vec3(1.0, 1.0, 1.0); \n\
|
texcol.rgb = vec3(1.0, 1.0, 1.0);
|
||||||
#else\n\
|
#else
|
||||||
#if pp_IgnoreTexA==1 || pp_TwoVolumes == 1 \n\
|
#if pp_IgnoreTexA==1 || pp_TwoVolumes == 1
|
||||||
IF(cur_ignore_tex_alpha) \n\
|
IF(cur_ignore_tex_alpha)
|
||||||
texcol.a=1.0; \n\
|
texcol.a=1.0;
|
||||||
#endif\n\
|
#endif
|
||||||
\n\
|
|
||||||
#if cp_AlphaTest == 1 \n\
|
#if cp_AlphaTest == 1
|
||||||
if (cp_AlphaTestValue>texcol.a) discard;\n\
|
if (cp_AlphaTestValue>texcol.a) discard;
|
||||||
#endif \n\
|
#endif
|
||||||
#endif\n\
|
#endif
|
||||||
#if pp_ShadInstr==0 || pp_TwoVolumes == 1 // DECAL \n\
|
#if pp_ShadInstr==0 || pp_TwoVolumes == 1 // DECAL
|
||||||
IF(cur_shading_instr == 0) \n\
|
IF(cur_shading_instr == 0)
|
||||||
{ \n\
|
{
|
||||||
color=texcol; \n\
|
color=texcol;
|
||||||
} \n\
|
}
|
||||||
#endif\n\
|
#endif
|
||||||
#if pp_ShadInstr==1 || pp_TwoVolumes == 1 // MODULATE \n\
|
#if pp_ShadInstr==1 || pp_TwoVolumes == 1 // MODULATE
|
||||||
IF(cur_shading_instr == 1) \n\
|
IF(cur_shading_instr == 1)
|
||||||
{ \n\
|
{
|
||||||
color.rgb*=texcol.rgb; \n\
|
color.rgb*=texcol.rgb;
|
||||||
color.a=texcol.a; \n\
|
color.a=texcol.a;
|
||||||
} \n\
|
}
|
||||||
#endif\n\
|
#endif
|
||||||
#if pp_ShadInstr==2 || pp_TwoVolumes == 1 // DECAL ALPHA \n\
|
#if pp_ShadInstr==2 || pp_TwoVolumes == 1 // DECAL ALPHA
|
||||||
IF(cur_shading_instr == 2) \n\
|
IF(cur_shading_instr == 2)
|
||||||
{ \n\
|
{
|
||||||
color.rgb=mix(color.rgb,texcol.rgb,texcol.a); \n\
|
color.rgb=mix(color.rgb,texcol.rgb,texcol.a);
|
||||||
} \n\
|
}
|
||||||
#endif\n\
|
#endif
|
||||||
#if pp_ShadInstr==3 || pp_TwoVolumes == 1 // MODULATE ALPHA \n\
|
#if pp_ShadInstr==3 || pp_TwoVolumes == 1 // MODULATE ALPHA
|
||||||
IF(cur_shading_instr == 3) \n\
|
IF(cur_shading_instr == 3)
|
||||||
{ \n\
|
{
|
||||||
color*=texcol; \n\
|
color*=texcol;
|
||||||
} \n\
|
}
|
||||||
#endif\n\
|
#endif
|
||||||
\n\
|
|
||||||
#if pp_Offset==1 && pp_BumpMap == 0 \n\
|
#if pp_Offset==1 && pp_BumpMap == 0
|
||||||
{ \n\
|
{
|
||||||
color.rgb += offset.rgb; \n\
|
color.rgb += offset.rgb;
|
||||||
} \n\
|
}
|
||||||
#endif\n\
|
#endif
|
||||||
} \n\
|
}
|
||||||
#endif\n\
|
#endif
|
||||||
#if PASS == 1 && pp_TwoVolumes == 0 \n\
|
#if PASS == 1 && pp_TwoVolumes == 0
|
||||||
uvec4 stencil = texture(shadow_stencil, gl_FragCoord.xy / textureSize(shadow_stencil, 0)); \n\
|
uvec4 stencil = texture(shadow_stencil, gl_FragCoord.xy / textureSize(shadow_stencil, 0));
|
||||||
if (stencil.r == 0x81u) \n\
|
if (stencil.r == 0x81u)
|
||||||
color.rgb *= shade_scale_factor; \n\
|
color.rgb *= shade_scale_factor;
|
||||||
#endif \n\
|
#endif
|
||||||
\n\
|
|
||||||
color = fog_clamp(color); \n\
|
color = fog_clamp(color);
|
||||||
\n\
|
|
||||||
#if pp_FogCtrl==0 || pp_TwoVolumes == 1 // LUT \n\
|
#if pp_FogCtrl==0 || pp_TwoVolumes == 1 // LUT
|
||||||
IF(cur_fog_control == 0) \n\
|
IF(cur_fog_control == 0)
|
||||||
{ \n\
|
{
|
||||||
color.rgb=mix(color.rgb,sp_FOG_COL_RAM.rgb,fog_mode2(gl_FragCoord.w)); \n\
|
color.rgb=mix(color.rgb,sp_FOG_COL_RAM.rgb,fog_mode2(gl_FragCoord.w));
|
||||||
} \n\
|
}
|
||||||
#endif\n\
|
#endif
|
||||||
#if pp_Offset==1 && pp_BumpMap == 0 && (pp_FogCtrl == 1 || pp_TwoVolumes == 1) // Per vertex \n\
|
#if pp_Offset==1 && pp_BumpMap == 0 && (pp_FogCtrl == 1 || pp_TwoVolumes == 1) // Per vertex
|
||||||
IF(cur_fog_control == 1) \n\
|
IF(cur_fog_control == 1)
|
||||||
{ \n\
|
{
|
||||||
color.rgb=mix(color.rgb, sp_FOG_COL_VERT.rgb, offset.a); \n\
|
color.rgb=mix(color.rgb, sp_FOG_COL_VERT.rgb, offset.a);
|
||||||
} \n\
|
}
|
||||||
#endif\n\
|
#endif
|
||||||
\n\
|
|
||||||
color *= trilinear_alpha; \n\
|
color *= trilinear_alpha;
|
||||||
\n\
|
|
||||||
#if cp_AlphaTest == 1 \n\
|
#if cp_AlphaTest == 1
|
||||||
color.a=1.0; \n\
|
color.a=1.0;
|
||||||
#endif \n\
|
#endif
|
||||||
\n\
|
|
||||||
//color.rgb=vec3(gl_FragCoord.w * sp_FOG_DENSITY / 128.0); \n\
|
//color.rgb=vec3(gl_FragCoord.w * sp_FOG_DENSITY / 128.0);
|
||||||
\n\
|
|
||||||
#if PASS == 1 \n\
|
#if PASS == 1
|
||||||
FragColor = color; \n\
|
FragColor = color;
|
||||||
#elif PASS > 1 \n\
|
#elif PASS > 1
|
||||||
// Discard as many pixels as possible \n\
|
// Discard as many pixels as possible
|
||||||
switch (cur_blend_mode.y) // DST \n\
|
switch (cur_blend_mode.y) // DST
|
||||||
{ \n\
|
{
|
||||||
case ONE: \n\
|
case ONE:
|
||||||
switch (cur_blend_mode.x) // SRC \n\
|
switch (cur_blend_mode.x) // SRC
|
||||||
{ \n\
|
{
|
||||||
case ZERO: \n\
|
case ZERO:
|
||||||
discard; \n\
|
discard;
|
||||||
case ONE: \n\
|
case ONE:
|
||||||
case OTHER_COLOR: \n\
|
case OTHER_COLOR:
|
||||||
case INVERSE_OTHER_COLOR: \n\
|
case INVERSE_OTHER_COLOR:
|
||||||
if (color == vec4(0.0)) \n\
|
if (color == vec4(0.0))
|
||||||
discard; \n\
|
discard;
|
||||||
break; \n\
|
break;
|
||||||
case SRC_ALPHA: \n\
|
case SRC_ALPHA:
|
||||||
if (color.a == 0.0 || color.rgb == vec3(0.0)) \n\
|
if (color.a == 0.0 || color.rgb == vec3(0.0))
|
||||||
discard; \n\
|
discard;
|
||||||
break; \n\
|
break;
|
||||||
case INVERSE_SRC_ALPHA: \n\
|
case INVERSE_SRC_ALPHA:
|
||||||
if (color.a == 1.0 || color.rgb == vec3(0.0)) \n\
|
if (color.a == 1.0 || color.rgb == vec3(0.0))
|
||||||
discard; \n\
|
discard;
|
||||||
break; \n\
|
break;
|
||||||
} \n\
|
}
|
||||||
break; \n\
|
break;
|
||||||
case OTHER_COLOR: \n\
|
case OTHER_COLOR:
|
||||||
if (cur_blend_mode.x == ZERO && color == vec4(1.0)) \n\
|
if (cur_blend_mode.x == ZERO && color == vec4(1.0))
|
||||||
discard; \n\
|
discard;
|
||||||
break; \n\
|
break;
|
||||||
case INVERSE_OTHER_COLOR: \n\
|
case INVERSE_OTHER_COLOR:
|
||||||
if (cur_blend_mode.x <= SRC_ALPHA && color == vec4(0.0)) \n\
|
if (cur_blend_mode.x <= SRC_ALPHA && color == vec4(0.0))
|
||||||
discard; \n\
|
discard;
|
||||||
break; \n\
|
break;
|
||||||
case SRC_ALPHA: \n\
|
case SRC_ALPHA:
|
||||||
if ((cur_blend_mode.x == ZERO || cur_blend_mode.x == INVERSE_SRC_ALPHA) && color.a == 1.0) \n\
|
if ((cur_blend_mode.x == ZERO || cur_blend_mode.x == INVERSE_SRC_ALPHA) && color.a == 1.0)
|
||||||
discard; \n\
|
discard;
|
||||||
break; \n\
|
break;
|
||||||
case INVERSE_SRC_ALPHA: \n\
|
case INVERSE_SRC_ALPHA:
|
||||||
switch (cur_blend_mode.x) // SRC \n\
|
switch (cur_blend_mode.x) // SRC
|
||||||
{ \n\
|
{
|
||||||
case ZERO: \n\
|
case ZERO:
|
||||||
case SRC_ALPHA: \n\
|
case SRC_ALPHA:
|
||||||
if (color.a == 0.0) \n\
|
if (color.a == 0.0)
|
||||||
discard; \n\
|
discard;
|
||||||
break; \n\
|
break;
|
||||||
case ONE: \n\
|
case ONE:
|
||||||
case OTHER_COLOR: \n\
|
case OTHER_COLOR:
|
||||||
case INVERSE_OTHER_COLOR: \n\
|
case INVERSE_OTHER_COLOR:
|
||||||
if (color == vec4(0.0)) \n\
|
if (color == vec4(0.0))
|
||||||
discard; \n\
|
discard;
|
||||||
break; \n\
|
break;
|
||||||
} \n\
|
}
|
||||||
break; \n\
|
break;
|
||||||
} \n\
|
}
|
||||||
\n\
|
|
||||||
ivec2 coords = ivec2(gl_FragCoord.xy); \n\
|
ivec2 coords = ivec2(gl_FragCoord.xy);
|
||||||
uint idx = getNextPixelIndex(); \n\
|
uint idx = getNextPixelIndex();
|
||||||
\n\
|
|
||||||
Pixel pixel; \n\
|
Pixel pixel;
|
||||||
pixel.color = color; \n\
|
pixel.color = color;
|
||||||
pixel.depth = gl_FragDepth; \n\
|
pixel.depth = gl_FragDepth;
|
||||||
pixel.seq_num = uint(pp_Number); \n\
|
pixel.seq_num = uint(pp_Number);
|
||||||
pixel.next = imageAtomicExchange(abufferPointerImg, coords, idx); \n\
|
pixel.next = imageAtomicExchange(abufferPointerImg, coords, idx);
|
||||||
pixels[idx] = pixel; \n\
|
pixels[idx] = pixel;
|
||||||
\n\
|
|
||||||
discard; \n\
|
discard;
|
||||||
\n\
|
|
||||||
#endif \n\
|
#endif
|
||||||
}";
|
}
|
||||||
|
)";
|
||||||
|
|
||||||
static const char* ModifierVolumeShader = SHADER_HEADER
|
static const char* ModifierVolumeShader = SHADER_HEADER
|
||||||
" \
|
R"(
|
||||||
/* Vertex input*/ \n\
|
void main()
|
||||||
void main() \n\
|
{
|
||||||
{ \n\
|
setFragDepth();
|
||||||
setFragDepth(); \n\
|
}
|
||||||
\n\
|
)";
|
||||||
}";
|
|
||||||
|
|
||||||
gl4_ctx gl4;
|
gl4_ctx gl4;
|
||||||
|
|
||||||
|
|
|
@ -25,365 +25,369 @@
|
||||||
float fb_scale_x, fb_scale_y; // FIXME
|
float fb_scale_x, fb_scale_y; // FIXME
|
||||||
|
|
||||||
//Fragment and vertex shaders code
|
//Fragment and vertex shaders code
|
||||||
const char* VertexShaderSource =
|
const char* VertexShaderSource = R"(
|
||||||
"\
|
%s
|
||||||
%s \n\
|
#define TARGET_GL %s
|
||||||
#define TARGET_GL %s \n\
|
#define pp_Gouraud %d
|
||||||
#define pp_Gouraud %d \n\
|
|
||||||
\n\
|
#define GLES2 0
|
||||||
#define GLES2 0 \n\
|
#define GLES3 1
|
||||||
#define GLES3 1 \n\
|
#define GL2 2
|
||||||
#define GL2 2 \n\
|
#define GL3 3
|
||||||
#define GL3 3 \n\
|
|
||||||
\n\
|
#if TARGET_GL == GL2
|
||||||
#if TARGET_GL == GL2 \n\
|
#define highp
|
||||||
#define highp \n\
|
#define lowp
|
||||||
#define lowp \n\
|
#define mediump
|
||||||
#define mediump \n\
|
#endif
|
||||||
#endif \n\
|
#if TARGET_GL == GLES2 || TARGET_GL == GL2
|
||||||
#if TARGET_GL == GLES2 || TARGET_GL == GL2 \n\
|
#define in attribute
|
||||||
#define in attribute \n\
|
#define out varying
|
||||||
#define out varying \n\
|
#endif
|
||||||
#endif \n\
|
|
||||||
\n\
|
|
||||||
\n\
|
#if TARGET_GL == GL3 || TARGET_GL == GLES3
|
||||||
#if TARGET_GL == GL3 || TARGET_GL == GLES3 \n\
|
#if pp_Gouraud == 0
|
||||||
#if pp_Gouraud == 0 \n\
|
#define INTERPOLATION flat
|
||||||
#define INTERPOLATION flat \n\
|
#else
|
||||||
#else \n\
|
#define INTERPOLATION smooth
|
||||||
#define INTERPOLATION smooth \n\
|
#endif
|
||||||
#endif \n\
|
#else
|
||||||
#else \n\
|
#define INTERPOLATION
|
||||||
#define INTERPOLATION \n\
|
#endif
|
||||||
#endif \n\
|
|
||||||
\n\
|
/* Vertex constants*/
|
||||||
/* Vertex constants*/ \n\
|
uniform highp vec4 scale;
|
||||||
uniform highp vec4 scale; \n\
|
uniform highp vec4 depth_scale;
|
||||||
uniform highp vec4 depth_scale; \n\
|
uniform highp mat4 normal_matrix;
|
||||||
uniform highp mat4 normal_matrix; \n\
|
/* Vertex input */
|
||||||
/* Vertex input */ \n\
|
in highp vec4 in_pos;
|
||||||
in highp vec4 in_pos; \n\
|
in lowp vec4 in_base;
|
||||||
in lowp vec4 in_base; \n\
|
in lowp vec4 in_offs;
|
||||||
in lowp vec4 in_offs; \n\
|
in mediump vec2 in_uv;
|
||||||
in mediump vec2 in_uv; \n\
|
/* output */
|
||||||
/* output */ \n\
|
INTERPOLATION out lowp vec4 vtx_base;
|
||||||
INTERPOLATION out lowp vec4 vtx_base; \n\
|
INTERPOLATION out lowp vec4 vtx_offs;
|
||||||
INTERPOLATION out lowp vec4 vtx_offs; \n\
|
out mediump vec2 vtx_uv;
|
||||||
out mediump vec2 vtx_uv; \n\
|
void main()
|
||||||
void main() \n\
|
{
|
||||||
{ \n\
|
vtx_base = in_base;
|
||||||
vtx_base = in_base; \n\
|
vtx_offs = in_offs;
|
||||||
vtx_offs = in_offs; \n\
|
vtx_uv = in_uv;
|
||||||
vtx_uv = in_uv; \n\
|
highp vec4 vpos = in_pos;
|
||||||
highp vec4 vpos = in_pos; \n\
|
if (vpos.z < 0.0 || vpos.z > 3.4e37)
|
||||||
if (vpos.z < 0.0 || vpos.z > 3.4e37) \n\
|
{
|
||||||
{ \n\
|
gl_Position = vec4(0.0, 0.0, 1.0, 1.0 / vpos.z);
|
||||||
gl_Position = vec4(0.0, 0.0, 1.0, 1.0 / vpos.z); \n\
|
return;
|
||||||
return; \n\
|
}
|
||||||
} \n\
|
|
||||||
\n\
|
vpos = normal_matrix * vpos;
|
||||||
vpos = normal_matrix * vpos; \n\
|
vpos.w = 1.0 / vpos.z;
|
||||||
vpos.w = 1.0 / vpos.z; \n\
|
#if TARGET_GL != GLES2
|
||||||
#if TARGET_GL != GLES2 \n\
|
vpos.z = vpos.w;
|
||||||
vpos.z = vpos.w; \n\
|
#else
|
||||||
#else \n\
|
vpos.z = depth_scale.x + depth_scale.y * vpos.w;
|
||||||
vpos.z = depth_scale.x + depth_scale.y * vpos.w; \n\
|
#endif
|
||||||
#endif \n\
|
vpos.xy *= vpos.w;
|
||||||
vpos.xy *= vpos.w; \n\
|
gl_Position = vpos;
|
||||||
gl_Position = vpos; \n\
|
}
|
||||||
}";
|
)";
|
||||||
|
|
||||||
const char* PixelPipelineShader =
|
const char* PixelPipelineShader =
|
||||||
"\
|
R"(
|
||||||
%s \n\
|
%s
|
||||||
#define TARGET_GL %s \n\
|
#define TARGET_GL %s
|
||||||
\n\
|
|
||||||
#define cp_AlphaTest %d \n\
|
#define cp_AlphaTest %d
|
||||||
#define pp_ClipTestMode %d \n\
|
#define pp_ClipTestMode %d
|
||||||
#define pp_UseAlpha %d \n\
|
#define pp_UseAlpha %d
|
||||||
#define pp_Texture %d \n\
|
#define pp_Texture %d
|
||||||
#define pp_IgnoreTexA %d \n\
|
#define pp_IgnoreTexA %d
|
||||||
#define pp_ShadInstr %d \n\
|
#define pp_ShadInstr %d
|
||||||
#define pp_Offset %d \n\
|
#define pp_Offset %d
|
||||||
#define pp_FogCtrl %d \n\
|
#define pp_FogCtrl %d
|
||||||
#define pp_Gouraud %d \n\
|
#define pp_Gouraud %d
|
||||||
#define pp_BumpMap %d \n\
|
#define pp_BumpMap %d
|
||||||
#define FogClamping %d \n\
|
#define FogClamping %d
|
||||||
#define pp_TriLinear %d \n\
|
#define pp_TriLinear %d
|
||||||
#define PI 3.1415926 \n\
|
#define PI 3.1415926
|
||||||
\n\
|
|
||||||
#define GLES2 0 \n\
|
#define GLES2 0
|
||||||
#define GLES3 1 \n\
|
#define GLES3 1
|
||||||
#define GL2 2 \n\
|
#define GL2 2
|
||||||
#define GL3 3 \n\
|
#define GL3 3
|
||||||
\n\
|
|
||||||
#if TARGET_GL == GL2 \n\
|
#if TARGET_GL == GL2
|
||||||
#define highp \n\
|
#define highp
|
||||||
#define lowp \n\
|
#define lowp
|
||||||
#define mediump \n\
|
#define mediump
|
||||||
#endif \n\
|
#endif
|
||||||
#if TARGET_GL == GLES3 \n\
|
#if TARGET_GL == GLES3
|
||||||
out highp vec4 FragColor; \n\
|
out highp vec4 FragColor;
|
||||||
#define gl_FragColor FragColor \n\
|
#define gl_FragColor FragColor
|
||||||
#define FOG_CHANNEL a \n\
|
#define FOG_CHANNEL a
|
||||||
#elif TARGET_GL == GL3 \n\
|
#elif TARGET_GL == GL3
|
||||||
out highp vec4 FragColor; \n\
|
out highp vec4 FragColor;
|
||||||
#define gl_FragColor FragColor \n\
|
#define gl_FragColor FragColor
|
||||||
#define FOG_CHANNEL r \n\
|
#define FOG_CHANNEL r
|
||||||
#else \n\
|
#else
|
||||||
#define in varying \n\
|
#define in varying
|
||||||
#define texture texture2D \n\
|
#define texture texture2D
|
||||||
#define FOG_CHANNEL a \n\
|
#define FOG_CHANNEL a
|
||||||
#endif \n\
|
#endif
|
||||||
\n\
|
|
||||||
\n\
|
|
||||||
#if TARGET_GL == GL3 || TARGET_GL == GLES3 \n\
|
#if TARGET_GL == GL3 || TARGET_GL == GLES3
|
||||||
#if pp_Gouraud == 0 \n\
|
#if pp_Gouraud == 0
|
||||||
#define INTERPOLATION flat \n\
|
#define INTERPOLATION flat
|
||||||
#else \n\
|
#else
|
||||||
#define INTERPOLATION smooth \n\
|
#define INTERPOLATION smooth
|
||||||
#endif \n\
|
#endif
|
||||||
#else \n\
|
#else
|
||||||
#define INTERPOLATION \n\
|
#define INTERPOLATION
|
||||||
#endif \n\
|
#endif
|
||||||
\n\
|
|
||||||
/* Shader program params*/ \n\
|
/* Shader program params*/
|
||||||
/* gles has no alpha test stage, so its emulated on the shader */ \n\
|
/* gles has no alpha test stage, so its emulated on the shader */
|
||||||
uniform lowp float cp_AlphaTestValue; \n\
|
uniform lowp float cp_AlphaTestValue;
|
||||||
uniform lowp vec4 pp_ClipTest; \n\
|
uniform lowp vec4 pp_ClipTest;
|
||||||
uniform lowp vec3 sp_FOG_COL_RAM,sp_FOG_COL_VERT; \n\
|
uniform lowp vec3 sp_FOG_COL_RAM,sp_FOG_COL_VERT;
|
||||||
uniform highp float sp_FOG_DENSITY; \n\
|
uniform highp float sp_FOG_DENSITY;
|
||||||
uniform sampler2D tex,fog_table; \n\
|
uniform sampler2D tex,fog_table;
|
||||||
uniform lowp float trilinear_alpha; \n\
|
uniform lowp float trilinear_alpha;
|
||||||
uniform lowp vec4 fog_clamp_min; \n\
|
uniform lowp vec4 fog_clamp_min;
|
||||||
uniform lowp vec4 fog_clamp_max; \n\
|
uniform lowp vec4 fog_clamp_max;
|
||||||
uniform highp float extra_depth_scale; \n\
|
uniform highp float extra_depth_scale;
|
||||||
/* Vertex input*/ \n\
|
/* Vertex input*/
|
||||||
INTERPOLATION in lowp vec4 vtx_base; \n\
|
INTERPOLATION in lowp vec4 vtx_base;
|
||||||
INTERPOLATION in lowp vec4 vtx_offs; \n\
|
INTERPOLATION in lowp vec4 vtx_offs;
|
||||||
in mediump vec2 vtx_uv; \n\
|
in mediump vec2 vtx_uv;
|
||||||
\n\
|
|
||||||
lowp float fog_mode2(highp float w) \n\
|
lowp float fog_mode2(highp float w)
|
||||||
{ \n\
|
{
|
||||||
highp float z = clamp(w * extra_depth_scale * sp_FOG_DENSITY, 1.0, 255.9999); \n\
|
highp float z = clamp(w * extra_depth_scale * sp_FOG_DENSITY, 1.0, 255.9999);
|
||||||
highp float exp = floor(log2(z)); \n\
|
highp float exp = floor(log2(z));
|
||||||
highp float m = z * 16.0 / pow(2.0, exp) - 16.0; \n\
|
highp float m = z * 16.0 / pow(2.0, exp) - 16.0;
|
||||||
lowp float idx = floor(m) + exp * 16.0 + 0.5; \n\
|
lowp float idx = floor(m) + exp * 16.0 + 0.5;
|
||||||
highp vec4 fog_coef = texture(fog_table, vec2(idx / 128.0, 0.75 - (m - floor(m)) / 2.0)); \n\
|
highp vec4 fog_coef = texture(fog_table, vec2(idx / 128.0, 0.75 - (m - floor(m)) / 2.0));
|
||||||
return fog_coef.FOG_CHANNEL; \n\
|
return fog_coef.FOG_CHANNEL;
|
||||||
} \n\
|
}
|
||||||
\n\
|
|
||||||
highp vec4 fog_clamp(lowp vec4 col) \n\
|
highp vec4 fog_clamp(lowp vec4 col)
|
||||||
{ \n\
|
{
|
||||||
#if FogClamping == 1 \n\
|
#if FogClamping == 1
|
||||||
return clamp(col, fog_clamp_min, fog_clamp_max); \n\
|
return clamp(col, fog_clamp_min, fog_clamp_max);
|
||||||
#else \n\
|
#else
|
||||||
return col; \n\
|
return col;
|
||||||
#endif \n\
|
#endif
|
||||||
} \n\
|
}
|
||||||
\n\
|
|
||||||
void main() \n\
|
void main()
|
||||||
{ \n\
|
{
|
||||||
// Clip outside the box \n\
|
// Clip outside the box
|
||||||
#if pp_ClipTestMode==1 \n\
|
#if pp_ClipTestMode==1
|
||||||
if (gl_FragCoord.x < pp_ClipTest.x || gl_FragCoord.x > pp_ClipTest.z \n\
|
if (gl_FragCoord.x < pp_ClipTest.x || gl_FragCoord.x > pp_ClipTest.z
|
||||||
|| gl_FragCoord.y < pp_ClipTest.y || gl_FragCoord.y > pp_ClipTest.w) \n\
|
|| gl_FragCoord.y < pp_ClipTest.y || gl_FragCoord.y > pp_ClipTest.w)
|
||||||
discard; \n\
|
discard;
|
||||||
#endif \n\
|
#endif
|
||||||
// Clip inside the box \n\
|
// Clip inside the box
|
||||||
#if pp_ClipTestMode==-1 \n\
|
#if pp_ClipTestMode==-1
|
||||||
if (gl_FragCoord.x >= pp_ClipTest.x && gl_FragCoord.x <= pp_ClipTest.z \n\
|
if (gl_FragCoord.x >= pp_ClipTest.x && gl_FragCoord.x <= pp_ClipTest.z
|
||||||
&& gl_FragCoord.y >= pp_ClipTest.y && gl_FragCoord.y <= pp_ClipTest.w) \n\
|
&& gl_FragCoord.y >= pp_ClipTest.y && gl_FragCoord.y <= pp_ClipTest.w)
|
||||||
discard; \n\
|
discard;
|
||||||
#endif \n\
|
#endif
|
||||||
\n\
|
|
||||||
lowp vec4 color=vtx_base; \n\
|
lowp vec4 color=vtx_base;
|
||||||
#if pp_UseAlpha==0 \n\
|
#if pp_UseAlpha==0
|
||||||
color.a=1.0; \n\
|
color.a=1.0;
|
||||||
#endif\n\
|
#endif
|
||||||
#if pp_FogCtrl==3 \n\
|
#if pp_FogCtrl==3
|
||||||
color=vec4(sp_FOG_COL_RAM.rgb,fog_mode2(gl_FragCoord.w)); \n\
|
color=vec4(sp_FOG_COL_RAM.rgb,fog_mode2(gl_FragCoord.w));
|
||||||
#endif\n\
|
#endif
|
||||||
#if pp_Texture==1 \n\
|
#if pp_Texture==1
|
||||||
{ \n\
|
{
|
||||||
lowp vec4 texcol=texture(tex, vtx_uv); \n\
|
lowp vec4 texcol=texture(tex, vtx_uv);
|
||||||
\n\
|
|
||||||
#if pp_BumpMap == 1 \n\
|
#if pp_BumpMap == 1
|
||||||
highp float s = PI / 2.0 * (texcol.a * 15.0 * 16.0 + texcol.r * 15.0) / 255.0; \n\
|
highp float s = PI / 2.0 * (texcol.a * 15.0 * 16.0 + texcol.r * 15.0) / 255.0;
|
||||||
highp float r = 2.0 * PI * (texcol.g * 15.0 * 16.0 + texcol.b * 15.0) / 255.0; \n\
|
highp float r = 2.0 * PI * (texcol.g * 15.0 * 16.0 + texcol.b * 15.0) / 255.0;
|
||||||
texcol.a = clamp(vtx_offs.a + vtx_offs.r * sin(s) + vtx_offs.g * cos(s) * cos(r - 2.0 * PI * vtx_offs.b), 0.0, 1.0); \n\
|
texcol.a = clamp(vtx_offs.a + vtx_offs.r * sin(s) + vtx_offs.g * cos(s) * cos(r - 2.0 * PI * vtx_offs.b), 0.0, 1.0);
|
||||||
texcol.rgb = vec3(1.0, 1.0, 1.0); \n\
|
texcol.rgb = vec3(1.0, 1.0, 1.0);
|
||||||
#else\n\
|
#else
|
||||||
#if pp_IgnoreTexA==1 \n\
|
#if pp_IgnoreTexA==1
|
||||||
texcol.a=1.0; \n\
|
texcol.a=1.0;
|
||||||
#endif\n\
|
#endif
|
||||||
\n\
|
|
||||||
#if cp_AlphaTest == 1 \n\
|
#if cp_AlphaTest == 1
|
||||||
if (cp_AlphaTestValue > texcol.a) \n\
|
if (cp_AlphaTestValue > texcol.a)
|
||||||
discard; \n\
|
discard;
|
||||||
#endif \n\
|
#endif
|
||||||
#endif \n\
|
#endif
|
||||||
#if pp_ShadInstr==0 \n\
|
#if pp_ShadInstr==0
|
||||||
{ \n\
|
{
|
||||||
color=texcol; \n\
|
color=texcol;
|
||||||
} \n\
|
}
|
||||||
#endif\n\
|
#endif
|
||||||
#if pp_ShadInstr==1 \n\
|
#if pp_ShadInstr==1
|
||||||
{ \n\
|
{
|
||||||
color.rgb*=texcol.rgb; \n\
|
color.rgb*=texcol.rgb;
|
||||||
color.a=texcol.a; \n\
|
color.a=texcol.a;
|
||||||
} \n\
|
}
|
||||||
#endif\n\
|
#endif
|
||||||
#if pp_ShadInstr==2 \n\
|
#if pp_ShadInstr==2
|
||||||
{ \n\
|
{
|
||||||
color.rgb=mix(color.rgb,texcol.rgb,texcol.a); \n\
|
color.rgb=mix(color.rgb,texcol.rgb,texcol.a);
|
||||||
} \n\
|
}
|
||||||
#endif\n\
|
#endif
|
||||||
#if pp_ShadInstr==3 \n\
|
#if pp_ShadInstr==3
|
||||||
{ \n\
|
{
|
||||||
color*=texcol; \n\
|
color*=texcol;
|
||||||
} \n\
|
}
|
||||||
#endif\n\
|
#endif
|
||||||
\n\
|
|
||||||
#if pp_Offset==1 && pp_BumpMap == 0 \n\
|
#if pp_Offset==1 && pp_BumpMap == 0
|
||||||
{ \n\
|
{
|
||||||
color.rgb+=vtx_offs.rgb; \n\
|
color.rgb+=vtx_offs.rgb;
|
||||||
} \n\
|
}
|
||||||
#endif\n\
|
#endif
|
||||||
} \n\
|
}
|
||||||
#endif\n\
|
#endif
|
||||||
\n\
|
|
||||||
color = fog_clamp(color); \n\
|
color = fog_clamp(color);
|
||||||
\n\
|
|
||||||
#if pp_FogCtrl == 0 \n\
|
#if pp_FogCtrl == 0
|
||||||
{ \n\
|
{
|
||||||
color.rgb=mix(color.rgb,sp_FOG_COL_RAM.rgb,fog_mode2(gl_FragCoord.w)); \n\
|
color.rgb=mix(color.rgb,sp_FOG_COL_RAM.rgb,fog_mode2(gl_FragCoord.w));
|
||||||
} \n\
|
}
|
||||||
#endif\n\
|
#endif
|
||||||
#if pp_FogCtrl == 1 && pp_Offset==1 && pp_BumpMap == 0 \n\
|
#if pp_FogCtrl == 1 && pp_Offset==1 && pp_BumpMap == 0
|
||||||
{ \n\
|
{
|
||||||
color.rgb=mix(color.rgb,sp_FOG_COL_VERT.rgb,vtx_offs.a); \n\
|
color.rgb=mix(color.rgb,sp_FOG_COL_VERT.rgb,vtx_offs.a);
|
||||||
} \n\
|
}
|
||||||
#endif\n\
|
#endif
|
||||||
\n\
|
|
||||||
#if pp_TriLinear == 1 \n\
|
#if pp_TriLinear == 1
|
||||||
color *= trilinear_alpha; \n\
|
color *= trilinear_alpha;
|
||||||
#endif \n\
|
#endif
|
||||||
\n\
|
|
||||||
#if cp_AlphaTest == 1 \n\
|
#if cp_AlphaTest == 1
|
||||||
color.a=1.0; \n\
|
color.a=1.0;
|
||||||
#endif \n\
|
#endif
|
||||||
//color.rgb=vec3(gl_FragCoord.w * sp_FOG_DENSITY / 128.0);\n\
|
//color.rgb=vec3(gl_FragCoord.w * sp_FOG_DENSITY / 128.0);
|
||||||
#if TARGET_GL != GLES2 \n\
|
#if TARGET_GL != GLES2
|
||||||
highp float w = gl_FragCoord.w * 100000.0; \n\
|
highp float w = gl_FragCoord.w * 100000.0;
|
||||||
gl_FragDepth = log2(1.0 + w) / 34.0; \n\
|
gl_FragDepth = log2(1.0 + w) / 34.0;
|
||||||
#endif \n\
|
#endif
|
||||||
gl_FragColor =color; \n\
|
gl_FragColor =color;
|
||||||
}";
|
}
|
||||||
|
)";
|
||||||
|
|
||||||
const char* ModifierVolumeShader =
|
const char* ModifierVolumeShader =
|
||||||
"\
|
R"(
|
||||||
%s \n\
|
%s
|
||||||
#define TARGET_GL %s \n\
|
#define TARGET_GL %s
|
||||||
\n\
|
|
||||||
#define GLES2 0 \n\
|
#define GLES2 0
|
||||||
#define GLES3 1 \n\
|
#define GLES3 1
|
||||||
#define GL2 2 \n\
|
#define GL2 2
|
||||||
#define GL3 3 \n\
|
#define GL3 3
|
||||||
\n\
|
|
||||||
#if TARGET_GL == GL2 \n\
|
#if TARGET_GL == GL2
|
||||||
#define highp \n\
|
#define highp
|
||||||
#define lowp \n\
|
#define lowp
|
||||||
#define mediump \n\
|
#define mediump
|
||||||
#endif \n\
|
#endif
|
||||||
#if TARGET_GL != GLES2 && TARGET_GL != GL2 \n\
|
#if TARGET_GL != GLES2 && TARGET_GL != GL2
|
||||||
out highp vec4 FragColor; \n\
|
out highp vec4 FragColor;
|
||||||
#define gl_FragColor FragColor \n\
|
#define gl_FragColor FragColor
|
||||||
#endif \n\
|
#endif
|
||||||
\n\
|
|
||||||
uniform lowp float sp_ShaderColor; \n\
|
uniform lowp float sp_ShaderColor;
|
||||||
/* Vertex input*/ \n\
|
/* Vertex input*/
|
||||||
void main() \n\
|
void main()
|
||||||
{ \n\
|
{
|
||||||
#if TARGET_GL != GLES2 \n\
|
#if TARGET_GL != GLES2
|
||||||
highp float w = gl_FragCoord.w * 100000.0; \n\
|
highp float w = gl_FragCoord.w * 100000.0;
|
||||||
gl_FragDepth = log2(1.0 + w) / 34.0; \n\
|
gl_FragDepth = log2(1.0 + w) / 34.0;
|
||||||
#endif \n\
|
#endif
|
||||||
gl_FragColor=vec4(0.0, 0.0, 0.0, sp_ShaderColor); \n\
|
gl_FragColor=vec4(0.0, 0.0, 0.0, sp_ShaderColor);
|
||||||
}";
|
}
|
||||||
|
)";
|
||||||
|
|
||||||
const char* OSD_VertexShader =
|
const char* OSD_VertexShader =
|
||||||
"\
|
R"(
|
||||||
%s \n\
|
%s
|
||||||
#define TARGET_GL %s \n\
|
#define TARGET_GL %s
|
||||||
\n\
|
|
||||||
#define GLES2 0 \n\
|
#define GLES2 0
|
||||||
#define GLES3 1 \n\
|
#define GLES3 1
|
||||||
#define GL2 2 \n\
|
#define GL2 2
|
||||||
#define GL3 3 \n\
|
#define GL3 3
|
||||||
\n\
|
|
||||||
#if TARGET_GL == GL2 \n\
|
#if TARGET_GL == GL2
|
||||||
#define highp \n\
|
#define highp
|
||||||
#define lowp \n\
|
#define lowp
|
||||||
#define mediump \n\
|
#define mediump
|
||||||
#endif \n\
|
#endif
|
||||||
#if TARGET_GL == GLES2 || TARGET_GL == GL2 \n\
|
#if TARGET_GL == GLES2 || TARGET_GL == GL2
|
||||||
#define in attribute \n\
|
#define in attribute
|
||||||
#define out varying \n\
|
#define out varying
|
||||||
#endif \n\
|
#endif
|
||||||
\n\
|
|
||||||
uniform highp vec4 scale; \n\
|
uniform highp vec4 scale;
|
||||||
\n\
|
|
||||||
in highp vec4 in_pos; \n\
|
in highp vec4 in_pos;
|
||||||
in lowp vec4 in_base; \n\
|
in lowp vec4 in_base;
|
||||||
in mediump vec2 in_uv; \n\
|
in mediump vec2 in_uv;
|
||||||
\n\
|
|
||||||
out lowp vec4 vtx_base; \n\
|
out lowp vec4 vtx_base;
|
||||||
out mediump vec2 vtx_uv; \n\
|
out mediump vec2 vtx_uv;
|
||||||
\n\
|
|
||||||
void main() \n\
|
void main()
|
||||||
{ \n\
|
{
|
||||||
vtx_base = in_base; \n\
|
vtx_base = in_base;
|
||||||
vtx_uv = in_uv; \n\
|
vtx_uv = in_uv;
|
||||||
highp vec4 vpos = in_pos; \n\
|
highp vec4 vpos = in_pos;
|
||||||
\n\
|
|
||||||
vpos.w = 1.0; \n\
|
vpos.w = 1.0;
|
||||||
vpos.z = vpos.w; \n\
|
vpos.z = vpos.w;
|
||||||
vpos.xy = vpos.xy * scale.xy - scale.zw; \n\
|
vpos.xy = vpos.xy * scale.xy - scale.zw;
|
||||||
gl_Position = vpos; \n\
|
gl_Position = vpos;
|
||||||
}";
|
}
|
||||||
|
)";
|
||||||
|
|
||||||
const char* OSD_Shader =
|
const char* OSD_Shader =
|
||||||
"\
|
R"(
|
||||||
%s \n\
|
%s
|
||||||
#define TARGET_GL %s \n\
|
#define TARGET_GL %s
|
||||||
\n\
|
|
||||||
#define GLES2 0 \n\
|
#define GLES2 0
|
||||||
#define GLES3 1 \n\
|
#define GLES3 1
|
||||||
#define GL2 2 \n\
|
#define GL2 2
|
||||||
#define GL3 3 \n\
|
#define GL3 3
|
||||||
\n\
|
|
||||||
#if TARGET_GL == GL2 \n\
|
#if TARGET_GL == GL2
|
||||||
#define highp \n\
|
#define highp
|
||||||
#define lowp \n\
|
#define lowp
|
||||||
#define mediump \n\
|
#define mediump
|
||||||
#endif \n\
|
#endif
|
||||||
#if TARGET_GL != GLES2 && TARGET_GL != GL2 \n\
|
#if TARGET_GL != GLES2 && TARGET_GL != GL2
|
||||||
out highp vec4 FragColor; \n\
|
out highp vec4 FragColor;
|
||||||
#define gl_FragColor FragColor \n\
|
#define gl_FragColor FragColor
|
||||||
#else \n\
|
#else
|
||||||
#define in varying \n\
|
#define in varying
|
||||||
#define texture texture2D \n\
|
#define texture texture2D
|
||||||
#endif \n\
|
#endif
|
||||||
\n\
|
|
||||||
in lowp vec4 vtx_base; \n\
|
in lowp vec4 vtx_base;
|
||||||
in mediump vec2 vtx_uv; \n\
|
in mediump vec2 vtx_uv;
|
||||||
\n\
|
|
||||||
uniform sampler2D tex; \n\
|
uniform sampler2D tex;
|
||||||
void main() \n\
|
void main()
|
||||||
{ \n\
|
{
|
||||||
gl_FragColor = vtx_base * texture(tex, vtx_uv); \n\
|
gl_FragColor = vtx_base * texture(tex, vtx_uv);
|
||||||
}";
|
}
|
||||||
|
)";
|
||||||
|
|
||||||
GLCache glcache;
|
GLCache glcache;
|
||||||
gl_ctx gl;
|
gl_ctx gl;
|
||||||
|
|
|
@ -642,8 +642,8 @@ static void gui_display_settings()
|
||||||
ImGui::NewFrame();
|
ImGui::NewFrame();
|
||||||
|
|
||||||
int dynarec_enabled = settings.dynarec.Enable;
|
int dynarec_enabled = settings.dynarec.Enable;
|
||||||
int renderer = settings.pvr.rend;
|
int pvr_rend = settings.pvr.rend;
|
||||||
bool vulkan = renderer == 4;
|
bool vulkan = pvr_rend == 4;
|
||||||
|
|
||||||
if (!settings_opening && settings.pvr.IsOpenGL())
|
if (!settings_opening && settings.pvr.IsOpenGL())
|
||||||
ImGui_ImplOpenGL3_DrawBackground();
|
ImGui_ImplOpenGL3_DrawBackground();
|
||||||
|
@ -952,7 +952,6 @@ static void gui_display_settings()
|
||||||
if (ImGui::BeginTabItem("Video"))
|
if (ImGui::BeginTabItem("Video"))
|
||||||
{
|
{
|
||||||
ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, normal_padding);
|
ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, normal_padding);
|
||||||
int renderer = settings.pvr.rend == 3 ? 2 : settings.rend.PerStripSorting ? 1 : 0;
|
|
||||||
#if HOST_OS != OS_DARWIN
|
#if HOST_OS != OS_DARWIN
|
||||||
bool has_per_pixel = !theGLContext.IsGLES() && theGLContext.GetMajorVersion() >= 4 && !vulkan;
|
bool has_per_pixel = !theGLContext.IsGLES() && theGLContext.GetMajorVersion() >= 4 && !vulkan;
|
||||||
#else
|
#else
|
||||||
|
@ -960,6 +959,7 @@ static void gui_display_settings()
|
||||||
#endif
|
#endif
|
||||||
if (ImGui::CollapsingHeader("Transparent Sorting", ImGuiTreeNodeFlags_DefaultOpen))
|
if (ImGui::CollapsingHeader("Transparent Sorting", ImGuiTreeNodeFlags_DefaultOpen))
|
||||||
{
|
{
|
||||||
|
int renderer = pvr_rend == 3 ? 2 : settings.rend.PerStripSorting ? 1 : 0;
|
||||||
ImGui::Columns(has_per_pixel ? 3 : 2, "renderers", false);
|
ImGui::Columns(has_per_pixel ? 3 : 2, "renderers", false);
|
||||||
ImGui::RadioButton("Per Triangle", &renderer, 0);
|
ImGui::RadioButton("Per Triangle", &renderer, 0);
|
||||||
ImGui::SameLine();
|
ImGui::SameLine();
|
||||||
|
@ -980,16 +980,16 @@ static void gui_display_settings()
|
||||||
{
|
{
|
||||||
case 0:
|
case 0:
|
||||||
if (settings.pvr.rend == 3)
|
if (settings.pvr.rend == 3)
|
||||||
settings.pvr.rend = 0;
|
pvr_rend = 0;
|
||||||
settings.rend.PerStripSorting = false;
|
settings.rend.PerStripSorting = false;
|
||||||
break;
|
break;
|
||||||
case 1:
|
case 1:
|
||||||
if (settings.pvr.rend == 3)
|
if (settings.pvr.rend == 3)
|
||||||
settings.pvr.rend = 0;
|
pvr_rend = 0;
|
||||||
settings.rend.PerStripSorting = true;
|
settings.rend.PerStripSorting = true;
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
settings.pvr.rend = 3;
|
pvr_rend = 3;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1348,8 +1348,8 @@ static void gui_display_settings()
|
||||||
ImGui_impl_RenderDrawData(ImGui::GetDrawData(), false);
|
ImGui_impl_RenderDrawData(ImGui::GetDrawData(), false);
|
||||||
|
|
||||||
if (vulkan ^ (settings.pvr.rend == 4))
|
if (vulkan ^ (settings.pvr.rend == 4))
|
||||||
renderer = settings.pvr.rend == 4 ? 0 : 4;
|
pvr_rend = settings.pvr.rend == 4 ? 0 : 4;
|
||||||
renderer_changed = renderer;
|
renderer_changed = pvr_rend;
|
||||||
settings.dynarec.Enable = (bool)dynarec_enabled;
|
settings.dynarec.Enable = (bool)dynarec_enabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue