Skip to content

Instantly share code, notes, and snippets.

@simias
Created May 28, 2016 23:43
Show Gist options
  • Select an option

  • Save simias/357def187a1871e9d039bb7afda0bb78 to your computer and use it in GitHub Desktop.

Select an option

Save simias/357def187a1871e9d039bb7afda0bb78 to your computer and use it in GitHub Desktop.
Shader compilation failed:
#version 330 core
uniform sampler2D fb_texture; uniform uint dither_scaling; uniform uint draw_semi_transparent; uniform uint texture_flt; uniform uint tww; uniform uint twh; uniform uint twx; uniform uint twy; in vec3 frag_shading_color; flat in uvec2 frag_texture_page; in vec2 frag_texture_coord; flat in uvec2 frag_clut; flat in uint frag_texture_blend_mode; flat in uint frag_depth_shift; flat in uint frag_dither; flat in uint frag_semi_transparent; out vec4 frag_color; const uint BLEND_MODE_NO_TEXTURE = 0U; const uint BLEND_MODE_RAW_TEXTURE = 1U; const uint BLEND_MODE_TEXTURE_BLEND = 2U; const uint FILTER_MODE_NEAREST = 0U; const uint FILTER_MODE_3POINT = 1U; vec4 vram_get_pixel(int x, int y) { return texelFetch(fb_texture, ivec2(x & 0x3ff, y & 1ff), 0); } uint rebuild_psx_color(vec4 color) { uint a = uint(floor(color.a + 0.5)); uint r = uint(floor(color.r * 31. + 0.5)); uint g = uint(floor(color.g * 31. + 0.5)); uint b = uint(floor(color.b * 31. + 0.5)); return (a << 15) | (b << 10) | (g << 5) | r; } bool is_transparent(vec4 texel) { return rebuild_psx_color(texel) == 0U; } const int dither_pattern[16] = int[16](-4, 0, -3, 1, 2, -2, 3, -1, -3, 1, -4, 0, 3, -1, 2, -2); vec4 sample_texel(vec2 coords) { uint pix_per_hw = 1U << frag_depth_shift; uint tex_x = uint(coords.x) & 0xffU; uint tex_y = uint(coords.y) & 0xffU; tex_x = (tex_x & (~(tww << 3))) | ((twx & tww) << 3); tex_y = (tex_y & (~(twh << 3))) | ((twy & twh) << 3); uint tex_x_pix = tex_x / pix_per_hw; tex_x_pix += frag_texture_page.x; tex_y += frag_texture_page.y; vec4 texel = vram_get_pixel(int(tex_x_pix), int(tex_y)); if (frag_depth_shift > 0U) { float tex_x_float = coords.x / float(pix_per_hw); uint icolor = rebuild_psx_color(texel); uint bpp = 16U >> frag_depth_shift; uint mask = ((1U << bpp) - 1U); uint align = tex_x_pix & ((1U << frag_depth_shift) - 1); uint shift = (align * bpp); uint index = (icolor >> shift) & mask; int clut_x = int(frag_clut.x + index); int clut_y = int(frag_clut.y); texel = vram_get_pixel(clut_x, clut_y); } return texel; } vec4 get_texel_3point(vec4 texel_00, float u_frac, float v_frac) { vec4 texel_10 = sample_texel(vec2(frag_texture_coord.x + 1, frag_texture_coord.y + 0)); vec4 texel_01 = sample_texel(vec2(frag_texture_coord.x + 0, frag_texture_coord.y + 1)); if (is_transparent(texel_10)) { texel_10 = texel_00; } if (is_transparent(texel_01)) { texel_01 = texel_00; } vec4 texel = texel_00 + u_frac * (texel_10 - texel_00) + v_frac * (texel_01 - texel_00); return texel; } void main() { vec4 color; if (frag_texture_blend_mode == BLEND_MODE_NO_TEXTURE) { color = vec4(frag_shading_color, 0.); } else { float u_frac = 0.0; float v_frac = 0.0; vec4 texel_00; if (texture_flt == FILTER_MODE_3POINT) { u_frac = fract(frag_texture_coord.x); v_frac = fract(frag_texture_coord.y); if (u_frac + v_frac < 1.0) { texel_00 = sample_texel(vec2(frag_texture_coord.x + 0, frag_texture_coord.y + 0)); } else { texel_00 = sample_texel(vec2(frag_texture_coord.x + 1, frag_texture_coord.y + 1)); float tmp = 1 - v_frac; v_frac = 1 - u_frac; u_frac = tmp; } } else { texel_00 = sample_texel(vec2(frag_texture_coord.x + 0, frag_texture_coord.y + 0)); } if (is_transparent(texel_00)) { discard; } vec4 texel; if (texture_flt == FILTER_MODE_3POINT) { texel = get_texel_3point(texel_00, u_frac, v_frac); } else { texel = texel_00; } uint transparency_flag = uint(floor(texel.a + 0.5)); uint is_texel_semi_transparent = transparency_flag & frag_semi_transparent; if (is_texel_semi_transparent != draw_semi_transparent) { discard; } if (frag_texture_blend_mode == BLEND_MODE_RAW_TEXTURE) { color = texel; } else { color = vec4(frag_shading_color * 2. * texel.rgb, texel.a); } } uint x_dither = (uint(gl_FragCoord.x) / dither_scaling) & 3U; uint y_dither = (uint(gl_FragCoord.y) / dither_scaling) & 3U; int dither_offset = dither_pattern[y_dither * 4U + x_dither] * int(frag_dither); float dither = float(dither_offset) / 255.; frag_color = color + vec4(dither, dither, dither, 0.); }
Shader info log:
0:2(742): error: syntax error, unexpected NEW_IDENTIFIER, expecting ')' or ','
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment