0% found this document useful (0 votes)
57 views7 pages

Dkeksks

The document contains shader code for a pixel shader. It defines macros, uniforms, attributes and fragment outputs. The main function samples a texture using UV coordinates, applies two TEV stages of lighting/color operations, and writes the output color to a fragment output variable. Precision and binding qualifiers are used to interface the shader with the OpenGL API and hardware.

Uploaded by

Bruno Silva
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
57 views7 pages

Dkeksks

The document contains shader code for a pixel shader. It defines macros, uniforms, attributes and fragment outputs. The main function samples a texture using UV coordinates, applies two TEV stages of lighting/color operations, and writes the output color to a fragment output variable. Precision and binding qualifiers are used to interface the shader with the OpenGL API and hardware.

Uploaded by

Bruno Silva
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 7

#version 320 es

#define FORCE_EARLY_Z layout(early_fragment_tests) in

#define ATTRIBUTE_LOCATION(x)
#define FRAGMENT_OUTPUT_LOCATION(x)
#define FRAGMENT_OUTPUT_LOCATION_INDEXED(x, y)
#define UBO_BINDING(packing, x) layout(packing, binding = x)
#define SAMPLER_BINDING(x) layout(binding = x)
#define TEXEL_BUFFER_BINDING(x) layout(binding = x)
#define SSBO_BINDING(x) layout(std430, binding = x)
#define IMAGE_BINDING(format, x) layout(format, binding = x)

#define VARYING_LOCATION(x)

#extension GL_ANDROID_extension_pack_es31a : enable

#extension GL_EXT_blend_func_extended : enable

#extension GL_EXT_shader_framebuffer_fetch: enable


#define FRAGMENT_INOUT inout

precision highp float;


precision highp int;
precision highp sampler2DArray;
precision highp usamplerBuffer;
precision highp sampler2DMS;
precision highp image2DArray;
#define API_OPENGL 1
#define float2 vec2
#define float3 vec3
#define float4 vec4
#define uint2 uvec2
#define uint3 uvec3
#define uint4 uvec4
#define int2 ivec2
#define int3 ivec3
#define int4 ivec4
#define frac fract
#define lerp mix
struct Light {
int4 color;
float4 cosatt;
float4 distatt;
float4 pos;
float4 dir;
};
UBO_BINDING(std140, 2) uniform VSBlock {
uint components;
uint xfmem_dualTexInfo;
uint xfmem_numColorChans;
uint missing_color_hex;
float4 missing_color_value;
float4 cpnmtx[6];
float4 cproj[4];
int4 cmtrl[4];
Light clights[8];
float4 ctexmtx[24];
float4 ctrmtx[64];
float4 cnmtx[32];
float4 cpostmtx[64];
float4 cpixelcenter;
float2 cviewport;
uint4 xfmem_pack1[8];
float4 ctangent;
float4 cbinormal;
#define xfmem_texMtxInfo(i) (xfmem_pack1[(i)].x)
#define xfmem_postMtxInfo(i) (xfmem_pack1[(i)].y)
#define xfmem_color(i) (xfmem_pack1[(i)].z)
#define xfmem_alpha(i) (xfmem_pack1[(i)].w)
};
struct VS_OUTPUT {
float4 pos;
float4 colors_0;
float4 colors_1;
float3 tex0;
float4 clipPos;
};

#define dolphin_isnan(f) isnan(f)


ATTRIBUTE_LOCATION(0) in float4 rawpos;
ATTRIBUTE_LOCATION(1) in uint4 posmtx;
ATTRIBUTE_LOCATION(2) in float3 rawnormal;
ATTRIBUTE_LOCATION(8) in float2 rawtex0;
VARYING_LOCATION(0) out float4 colors_0;
VARYING_LOCATION(1) out float4 colors_1;
VARYING_LOCATION(2) out float3 tex0;
VARYING_LOCATION(3) out float4 clipPos;
void main()
{
VS_OUTPUT o;
float4 vertex_color_0, vertex_color_1;
vertex_color_0 = missing_color_value;
vertex_color_1 = missing_color_value;
int posidx = int(posmtx.r);
float4 P0 = ctrmtx[posidx];
float4 P1 = ctrmtx[posidx + 1];
float4 P2 = ctrmtx[posidx + 2];
int normidx = posidx & 31;
float3 N0 = cnmtx[normidx].xyz;
float3 N1 = cnmtx[normidx + 1].xyz;
float3 N2 = cnmtx[normidx + 2].xyz;
// Multiply the position vector by the position matrix
float4 pos = float4(dot(P0, rawpos), dot(P1, rawpos), dot(P2, rawpos), 1.0);
float3 rawtangent = ctangent.xyz;
float3 rawbinormal = cbinormal.xyz;
float3 _normal = normalize(float3(dot(N0, rawnormal), dot(N1, rawnormal), dot(N2,
rawnormal)));
float3 _tangent = float3(dot(N0, rawtangent), dot(N1, rawtangent), dot(N2,
rawtangent));
float3 _binormal = float3(dot(N0, rawbinormal), dot(N1, rawbinormal), dot(N2,
rawbinormal));
o.pos = float4(dot(cproj[0], pos), dot(cproj[1], pos), dot(cproj[2], pos),
dot(cproj[3], pos));
int4 lacc;
float3 ldir, h, cosAttn, distAttn;
float dist, dist2, attn;
{
int4 mat = cmtrl[2];
lacc = cmtrl[0];
lacc.w = 255;
ldir = clights[0].pos.xyz - pos.xyz;
dist2 = dot(ldir, ldir);
dist = sqrt(dist2);
ldir = ldir / dist;
attn = max(0.0, dot(ldir, clights[0].dir.xyz));
attn = max(0.0, clights[0].cosatt.x + clights[0].cosatt.y*attn +
clights[0].cosatt.z*attn*attn) / dot(clights[0].distatt.xyz,
float3(1.0,dist,dist2));
lacc.rgb += int3(round(attn * max(0.0,dot(ldir, _normal)) *
float3(clights[0].color.rgb)));

lacc = clamp(lacc, 0, 255);


o.colors_0 = float4((mat * (lacc + (lacc >> 7))) >> 8) / 255.0;
}
{
int4 mat = cmtrl[3];
lacc = cmtrl[1];
lacc.w = 255;
lacc = clamp(lacc, 0, 255);
o.colors_1 = float4((mat * (lacc + (lacc >> 7))) >> 8) / 255.0;
}
float4 coord = float4(0.0, 0.0, 1.0, 1.0);
{
coord = float4(0.0, 0.0, 1.0, 1.0);
coord = float4(rawtex0.x, rawtex0.y, 1.0, 1.0);
coord.z = 1.0;
// Convert NaN to 1
if (dolphin_isnan(coord.x)) coord.x = 1.0;
if (dolphin_isnan(coord.y)) coord.y = 1.0;
if (dolphin_isnan(coord.z)) coord.z = 1.0;
o.tex0.xyz = float3(dot(coord, ctexmtx[0]), dot(coord, ctexmtx[1]), 1);
float4 P0 = cpostmtx[61];
float4 P1 = cpostmtx[62];
float4 P2 = cpostmtx[63];
o.tex0.xyz = float3(dot(P0.xyz, o.tex0.xyz) + P0.w, dot(P1.xyz, o.tex0.xyz) + P1.w,
dot(P2.xyz, o.tex0.xyz) + P2.w);
if(o.tex0.z == 0.0f)
o.tex0.xy = clamp(o.tex0.xy / 2.0f, float2(-1.0f,-1.0f), float2(1.0f,1.0f));
}
o.colors_1 = float4(0.0, 0.0, 0.0, 0.0);
o.clipPos = o.pos;
o.pos.z = o.pos.z * (1.0 - 1e-7);
o.pos.z = o.pos.w * cpixelcenter.w - o.pos.z * cpixelcenter.z;
o.pos.z = o.pos.z * 2.0 - o.pos.w;
o.pos.xy *= sign(cpixelcenter.xy * float2(1.0, -1.0));
o.pos.xy = o.pos.xy - o.pos.w * cpixelcenter.xy;
tex0.xyz = o.tex0;
clipPos = o.clipPos;
colors_0 = o.colors_0;
colors_1 = o.colors_1;
gl_Position = o.pos;
}

#version 320 es

#define FORCE_EARLY_Z layout(early_fragment_tests) in

#define ATTRIBUTE_LOCATION(x)
#define FRAGMENT_OUTPUT_LOCATION(x)
#define FRAGMENT_OUTPUT_LOCATION_INDEXED(x, y)
#define UBO_BINDING(packing, x) layout(packing, binding = x)
#define SAMPLER_BINDING(x) layout(binding = x)
#define TEXEL_BUFFER_BINDING(x) layout(binding = x)
#define SSBO_BINDING(x) layout(std430, binding = x)
#define IMAGE_BINDING(format, x) layout(format, binding = x)

#define VARYING_LOCATION(x)

#extension GL_ANDROID_extension_pack_es31a : enable

#extension GL_EXT_blend_func_extended : enable

#extension GL_EXT_shader_framebuffer_fetch: enable


#define FRAGMENT_INOUT inout

precision highp float;


precision highp int;
precision highp sampler2DArray;
precision highp usamplerBuffer;
precision highp sampler2DMS;
precision highp image2DArray;
#define API_OPENGL 1
#define float2 vec2
#define float3 vec3
#define float4 vec4
#define uint2 uvec2
#define uint3 uvec3
#define uint4 uvec4
#define int2 ivec2
#define int3 ivec3
#define int4 ivec4
#define frac fract
#define lerp mix
// Pixel Shader for TEV stages
// 2 TEV stages, 1 texgens, 0 IND stages
int idot(int3 x, int3 y)
{
int3 tmp = x * y;
return tmp.x + tmp.y + tmp.z;
}
int idot(int4 x, int4 y)
{
int4 tmp = x * y;
return tmp.x + tmp.y + tmp.z + tmp.w;
}

int iround(float x) { return int (round(x)); }


int2 iround(float2 x) { return int2(round(x)); }
int3 iround(float3 x) { return int3(round(x)); }
int4 iround(float4 x) { return int4(round(x)); }

SAMPLER_BINDING(0) uniform sampler2DArray samp[8];

UBO_BINDING(std140, 1) uniform PSBlock {


int4 color[4];
int4 k[4];
int4 alphaRef;
int4 texdim[8];
int4 czbias[2];
int4 cindscale[2];
int4 cindmtx[6];
int4 cfogcolor;
int4 cfogi;
float4 cfogf;
float4 cfogrange[3];
float4 czslope;
float2 cefbscale;
uint bpmem_genmode;
uint bpmem_alphaTest;
uint bpmem_fogParam3;
uint bpmem_fogRangeBase;
uint bpmem_dstalpha;
uint bpmem_ztex_op;
bool bpmem_late_ztest;
bool bpmem_rgba6_format;
bool bpmem_dither;
bool bpmem_bounding_box;
uint4 bpmem_pack1[16];
uint4 bpmem_pack2[8];
int4 konstLookup[32];
bool blend_enable;
uint blend_src_factor;
uint blend_src_factor_alpha;
uint blend_dst_factor;
uint blend_dst_factor_alpha;
bool blend_subtract;
bool blend_subtract_alpha;
bool logic_op_enable;
uint logic_op_mode;
};

#define bpmem_combiners(i) (bpmem_pack1[(i)].xy)


#define bpmem_tevind(i) (bpmem_pack1[(i)].z)
#define bpmem_iref(i) (bpmem_pack1[(i)].w)
#define bpmem_tevorder(i) (bpmem_pack2[(i)].x)
#define bpmem_tevksel(i) (bpmem_pack2[(i)].y)
#define samp_texmode0(i) (bpmem_pack2[(i)].z)
#define samp_texmode1(i) (bpmem_pack2[(i)].w)

int4 sampleTexture(uint texmap, in sampler2DArray tex, int2 uv, int layer) {


float size_s = float(texdim[texmap].x * 128);
float size_t = float(texdim[texmap].y * 128);
float3 coords = float3(float(uv.x) / size_s, float(uv.y) / size_t, layer);
uint texmode0 = samp_texmode0(texmap);
float lod_bias = float(bitfieldExtract(int(texmode0), 8, 16)) / 256.0f;
return iround(255.0 * texture(tex, coords, lod_bias));
}

#define sampleTextureWrapper(texmap, uv, layer) sampleTexture(texmap, samp[texmap],


uv, layer)
FRAGMENT_OUTPUT_LOCATION_INDEXED(0, 0) out vec4 ocol0;
FRAGMENT_OUTPUT_LOCATION_INDEXED(0, 1) out vec4 ocol1;
#define depth gl_FragDepth
VARYING_LOCATION(0) in float4 colors_0;
VARYING_LOCATION(1) in float4 colors_1;
VARYING_LOCATION(2) in float3 tex0;
VARYING_LOCATION(3) in float4 clipPos;
void main()
{
float4 rawpos = gl_FragCoord;
int layer = 0;
int4 c0 = color[1], c1 = color[2], c2 = color[3], prev = color[0];
int4 rastemp = int4(0, 0, 0, 0), textemp = int4(0, 0, 0, 0), konsttemp =
int4(0, 0, 0, 0);
int3 comp16 = int3(1, 256, 0), comp24 = int3(1, 256, 256*256);
int alphabump=0;
int3 tevcoord=int3(0, 0, 0);
int2 wrappedcoord=int2(0,0), tempcoord=int2(0,0);
int4
tevin_a=int4(0,0,0,0),tevin_b=int4(0,0,0,0),tevin_c=int4(0,0,0,0),tevin_d=int4(0,0,
0,0);

float4 col0 = colors_0;


float4 col1 = colors_1;
int2 fixpoint_uv0 = int2((tex0.z == 0.0 ? tex0.xy : tex0.xy / tex0.z) *
float2(texdim[0].zw * 128));

// TEV stage 0
// indirect op
int2 indtevtrans0 = int2(0, 0);
wrappedcoord.x = fixpoint_uv0.x;
wrappedcoord.y = fixpoint_uv0.y;
tevcoord.xy = wrappedcoord + indtevtrans0;
tevcoord.xy = (tevcoord.xy << 8) >> 8;
rastemp = iround(col0 * 255.0).rgba;
textemp = sampleTextureWrapper(0u, tevcoord.xy, layer).rgba;
konsttemp = int4(k[0].rgb, k[0].a);
tevin_a = int4(konsttemp.rgb, 0)&int4(255, 255, 255, 255);
tevin_b = int4(rastemp.rgb, 0)&int4(255, 255, 255, 255);
tevin_c = int4(rastemp.rgb, 0)&int4(255, 255, 255, 255);
tevin_d = int4(c0.rgb, 0);
// color combine
prev.rgb = clamp((((tevin_d.rgb - 128) << 2) + (((((tevin_a.rgb<<8) +
(tevin_b.rgb-tevin_a.rgb)*(tevin_c.rgb+(tevin_c.rgb>>7))) << 2) + 128)>>8)),
int3(0,0,0), int3(255,255,255));
// alpha combine
prev.a = clamp((((tevin_d.a)) - (((((tevin_a.a<<8) + (tevin_b.a-
tevin_a.a)*(tevin_c.a+(tevin_c.a>>7)))) + 127)>>8)), 0, 255);

// TEV stage 1
// indirect op
int2 indtevtrans1 = int2(0, 0);
wrappedcoord.x = fixpoint_uv0.x;
wrappedcoord.y = fixpoint_uv0.y;
tevcoord.xy = wrappedcoord + indtevtrans1;
tevcoord.xy = (tevcoord.xy << 8) >> 8;
textemp = sampleTextureWrapper(0u, tevcoord.xy, layer).rgba;
konsttemp = int4(k[1].rgb, k[0].a);
tevin_a = int4(konsttemp.rgb, textemp.a)&int4(255, 255, 255, 255);
tevin_b = int4(c1.rgb, 0)&int4(255, 255, 255, 255);
tevin_c = int4(prev.rgb, 0)&int4(255, 255, 255, 255);
tevin_d = int4(textemp.rgb, 0);
// color combine
prev.rgb = clamp((((tevin_d.rgb)) + (((((tevin_a.rgb<<8) + (tevin_b.rgb-
tevin_a.rgb)*(tevin_c.rgb+(tevin_c.rgb>>7)))) + 128)>>8)), int3(0,0,0),
int3(255,255,255));
// alpha combine
prev.a = clamp((((tevin_d.a)) + (((((tevin_a.a<<8) + (tevin_b.a-
tevin_a.a)*(tevin_c.a+(tevin_c.a>>7)))) + 128)>>8)), 0, 255);
prev = prev & 255;
// Hardware testing indicates that an alpha of 1 can pass an alpha test,
// but doesn't do anything in blending
if (prev.a == 1) prev.a = 0;
int zCoord = czbias[1].x + int((clipPos.z / clipPos.w) * float(czbias[1].y));
zCoord = clamp(zCoord, 0, 0xFFFFFF);
depth = float(zCoord) / 16777216.0;
float ze = (cfogf.x * 16777216.0) / float(cfogi.y - (zCoord >> cfogi.w));
float offset = (2.0 * (rawpos.x / cfogf.w)) - 1.0 - cfogf.z;
float floatindex = clamp(9.0 - abs(offset) * 9.0, 0.0, 9.0);
uint indexlower = uint(floatindex);
uint indexupper = indexlower + 1u;
float klower = cfogrange[indexlower >> 2u][indexlower & 3u];
float kupper = cfogrange[indexupper >> 2u][indexupper & 3u];
float k = lerp(klower, kupper, frac(floatindex));
float x_adjust = sqrt(offset * offset + k * k) / k;
ze *= x_adjust;
float fog = clamp(ze - cfogf.y, 0.0, 1.0);
int ifog = iround(fog * 256.0);
prev.rgb = (prev.rgb * (256 - ifog) + cfogcolor.rgb * ifog) >> 8;
ocol0.rgb = float3(prev.rgb) / 255.0;
ocol0.a = float(prev.a >> 2) / 63.0;
ocol1 = float4(0.0, 0.0, 0.0, float(prev.a) / 255.0);
}

Dolphin Version: Dolphin 2.0-15108-121


Video Backend: OpenGL ES

You might also like