Skip to content

Instantly share code, notes, and snippets.

Created February 5, 2013 00:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/4711083 to your computer and use it in GitHub Desktop.
Save anonymous/4711083 to your computer and use it in GitHub Desktop.
pyalot 'at' gmail 'dot' com's SH fragment shader, translated via ANGLE and modified (unsuccessfully) to try to avoid pathological compile times. Compile with: fxc.exe /E main /T ps_3_0 /Fo shader.obj /Gec /O1 pyalot-pixelshader.txt pyalot-pixelshader-orig.txt is the verbatim output of ANGLE. pyalot-pixelshader.txt is the hand-modified version.
float2 vec2(float x0, float x1)
{
return float2(x0, x1);
}
float3 vec3(float2 x0, float x1)
{
return float3(x0, x1);
}
float4 vec4(float3 x0, float x1)
{
return float4(x0, x1);
}
// Varyings
static float4 gl_Color[1] = {float4(0, 0, 0, 0)};
static float4 gl_FragCoord = float4(0, 0, 0, 0);
uniform float4 dx_Coord;
uniform float2 dx_Depth;
uniform sampler2D _source;
float4 gl_texture2D(sampler2D s, float2 t)
{
return tex2D(s, t);
}
float4 gl_texture2DLod0(sampler2D s, float2 t)
{
return tex2Dlod(s, float4(t.x, t.y, 0, 0));
}
#define GL_USES_FRAG_COORD
float mod(float x, float y)
{
return x - y * floor(x / y);
}
;
static float3x3 _front = float3x3(1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0);
static float3x3 _back = float3x3(-1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, -1.0);
static float3x3 _left = float3x3(0.0, 0.0, -1.0, 0.0, 1.0, 0.0, 1.0, 0.0, 0.0);
static float3x3 _right = float3x3(0.0, 0.0, 1.0, 0.0, 1.0, 0.0, -1.0, 0.0, 0.0);
static float3x3 _up = float3x3(1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, -1.0, 0.0);
static float3x3 _down = float3x3(1.0, 0.0, 0.0, 0.0, 0.0, -1.0, 0.0, 1.0, 0.0);
float _coefficient(in float3 _normal)
{
{
int _index = int(gl_FragCoord.x);
float _x = _normal.x;
float _y = _normal.y;
float _z = _normal.z;
if((_index == 0))
{
{
return 1.0;
;
}
;
}
else
{
if((_index == 1))
{
{
return _y;
;
}
;
}
else
{
if((_index == 2))
{
{
return _z;
;
}
;
}
else
{
if((_index == 3))
{
{
return _x;
;
}
;
}
else
{
if((_index == 4))
{
{
return (_x * _y);
;
}
;
}
else
{
if((_index == 5))
{
{
return (_y * _z);
;
}
;
}
else
{
if((_index == 6))
{
{
return (((3.0 * _z) * _z) - 1.0);
;
}
;
}
else
{
if((_index == 7))
{
{
return (_x * _z);
;
}
;
}
else
{
{
return ((_x * _x) - (_y * _y));
;
}
;
}
;
}
;
}
;
}
;
}
;
}
;
}
;
}
;
}
}
float _coefficientLod0(in float3 _normal)
{
{
int _index = int(gl_FragCoord.x);
float _x = _normal.x;
float _y = _normal.y;
float _z = _normal.z;
if((_index == 0))
{
{
return 1.0;
;
}
;
}
else
{
if((_index == 1))
{
{
return _y;
;
}
;
}
else
{
if((_index == 2))
{
{
return _z;
;
}
;
}
else
{
if((_index == 3))
{
{
return _x;
;
}
;
}
else
{
if((_index == 4))
{
{
return (_x * _y);
;
}
;
}
else
{
if((_index == 5))
{
{
return (_y * _z);
;
}
;
}
else
{
if((_index == 6))
{
{
return (((3.0 * _z) * _z) - 1.0);
;
}
;
}
else
{
if((_index == 7))
{
{
return (_x * _z);
;
}
;
}
else
{
{
return ((_x * _x) - (_y * _y));
;
}
;
}
;
}
;
}
;
}
;
}
;
}
;
}
;
}
;
}
}
;
float3 _sample(in float _cidx, in float3x3 _side)
{
{
float3 _result = float3(0.0, 0.0, 0.0);
float _divider = 0.0;
{for(int _i = 0; (_i < 256); (_i++))
{
{
float _x = mod(float(_i), 16.0);
float _y = float((_i / 16));
float2 _texcoord = ((vec2((_x + (_cidx * 16.0)), (_y + (floor(gl_FragCoord.y) * 16.0))) + 0.5) / 6.0);
float2 _sidecoord = ((((vec2(_x, _y) + float2(0.5, 0.5)) / float2(16.0, 16.0)) * 2.0) - 1.0);
float3 _normal = normalize(vec3(_sidecoord, -1.0));
float3 _texel = gl_texture2D(_source, _texcoord).xyz;
(_result += ((_coefficient(mul(transpose(_side), _normal)) * _texel) * (-_normal.z)));
(_divider += (-_normal.z));
}
;}
}
;
return (_result / _divider);
;
}
}
float3 _sampleLod0(in float _cidx, in float3x3 _side)
{
{
float3 _result = float3(0.0, 0.0, 0.0);
float _divider = 0.0;
{for(int _i = 0; (_i < 256); (_i++))
{
{
float _x = mod(float(_i), 16.0);
float _y = float((_i / 16));
float2 _texcoord = ((vec2((_x + (_cidx * 16.0)), (_y + (floor(gl_FragCoord.y) * 16.0))) + 0.5) / 6.0);
float2 _sidecoord = ((((vec2(_x, _y) + float2(0.5, 0.5)) / float2(16.0, 16.0)) * 2.0) - 1.0);
float3 _normal = normalize(vec3(_sidecoord, -1.0));
float3 _texel = gl_texture2DLod0(_source, _texcoord).xyz;
(_result += ((_coefficientLod0(mul(transpose(_side), _normal)) * _texel) * (-_normal.z)));
(_divider += (-_normal.z));
}
;}
}
;
return (_result / _divider);
;
}
}
;
void gl_main()
{
{
float3 _result = ((((_sample(2.0, _left) + _sample(3.0, _right)) + _sample(4.0, _up)) + _sample(5.0, _down)) / 6.0);
(gl_Color[0] = vec4(_result, 1.0));
}
}
;
struct PS_INPUT
{
float4 gl_FragCoord : TEXCOORD0;
float2 dx_VPos : VPOS;
};
struct PS_OUTPUT
{
float4 gl_Color[1] : COLOR;
};
PS_OUTPUT main(PS_INPUT input)
{
float rhw = 1.0 / input.gl_FragCoord.w;
gl_FragCoord.x = input.dx_VPos.x + 0.5;
gl_FragCoord.y = input.dx_VPos.y + 0.5;
gl_FragCoord.z = (input.gl_FragCoord.z * rhw) * dx_Depth.x + dx_Depth.y;
gl_FragCoord.w = rhw;
gl_main();
PS_OUTPUT output;
output.gl_Color[0] = gl_Color[0];
return output;
}
float2 vec2(float x0, float x1)
{
return float2(x0, x1);
}
float3 vec3(float2 x0, float x1)
{
return float3(x0, x1);
}
float4 vec4(float3 x0, float x1)
{
return float4(x0, x1);
}
// Varyings
static float4 gl_Color[1] = {float4(0, 0, 0, 0)};
static float4 gl_FragCoord = float4(0, 0, 0, 0);
uniform float4 dx_Coord;
uniform float2 dx_Depth;
uniform sampler2D _source;
float4 gl_texture2D(sampler2D s, float2 t)
{
return tex2D(s, t);
}
float4 gl_texture2DLod0(sampler2D s, float2 t)
{
return tex2Dlod(s, float4(t.x, t.y, 0, 0));
}
#define GL_USES_FRAG_COORD
float mod(float x, float y)
{
return x - y * floor(x / y);
}
;
static float3x3 _front = float3x3(1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0);
static float3x3 _back = float3x3(-1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, -1.0);
static float3x3 _left = float3x3(0.0, 0.0, -1.0, 0.0, 1.0, 0.0, 1.0, 0.0, 0.0);
static float3x3 _right = float3x3(0.0, 0.0, 1.0, 0.0, 1.0, 0.0, -1.0, 0.0, 0.0);
static float3x3 _up = float3x3(1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, -1.0, 0.0);
static float3x3 _down = float3x3(1.0, 0.0, 0.0, 0.0, 0.0, -1.0, 0.0, 1.0, 0.0);
float _coefficientLod0(in float3 _normal)
{
{
int _index = int(gl_FragCoord.x);
float _x = _normal.x;
float _y = _normal.y;
float _z = _normal.z;
if((_index == 0))
{
{
return 1.0;
;
}
;
}
else
{
if((_index == 1))
{
{
return _y;
;
}
;
}
else
{
if((_index == 2))
{
{
return _z;
;
}
;
}
else
{
if((_index == 3))
{
{
return _x;
;
}
;
}
else
{
if((_index == 4))
{
{
return (_x * _y);
;
}
;
}
else
{
if((_index == 5))
{
{
return (_y * _z);
;
}
;
}
else
{
if((_index == 6))
{
{
return (((3.0 * _z) * _z) - 1.0);
;
}
;
}
else
{
if((_index == 7))
{
{
return (_x * _z);
;
}
;
}
else
{
{
return ((_x * _x) - (_y * _y));
;
}
;
}
;
}
;
}
;
}
;
}
;
}
;
}
;
}
;
}
}
;
float3 _sampleLod0(in float _cidx, in float3x3 _side)
{
{
float3 _result = float3(0.0, 0.0, 0.0);
float _divider = 0.0;
{[loop] for(int _i = 0; (_i < 254); (_i++))
{
{
float _x = mod(float(_i), 16.0);
float _y = floor((float(_i) / 16.0));
float2 _texcoord = ((vec2((_x + (_cidx * 16.0)), (_y + (floor(gl_FragCoord.y) * 16.0))) + 0.5) / 6.0);
float2 _sidecoord = ((((vec2(_x, _y) + float2(0.5, 0.5)) / float2(16.0, 16.0)) * 2.0) - 1.0);
float3 _normal = normalize(vec3(_sidecoord, -1.0));
float3 _texel = gl_texture2DLod0(_source, _texcoord).xyz;
(_result += ((_coefficientLod0(mul(transpose(_side), _normal)) * _texel) * (-_normal.z)));
(_divider += (-_normal.z));
}
;}
}
;
return (_result / _divider);
;
}
}
;
void gl_main()
{
{
float3 _result = ((((_sampleLod0(2.0, _left) + _sampleLod0(3.0, _right)) + _sampleLod0(4.0, _up)) + _sampleLod0(5.0, _down)) / 6.0);
(gl_Color[0] = vec4(_result, 1.0));
}
}
;
struct PS_INPUT
{
float4 gl_FragCoord : TEXCOORD0;
float4 dx_VPos : VPOS;
};
struct PS_OUTPUT
{
float4 gl_Color[1] : COLOR;
};
PS_OUTPUT main(PS_INPUT input)
{
float rhw = 1.0 / input.gl_FragCoord.w;
gl_FragCoord.x = input.dx_VPos.x + 0.5;
gl_FragCoord.y = input.dx_VPos.y + 0.5;
gl_FragCoord.z = (input.gl_FragCoord.z * rhw) * dx_Depth.x + dx_Depth.y;
gl_FragCoord.w = rhw;
gl_main();
PS_OUTPUT output;
output.gl_Color[0] = gl_Color[0];
return output;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment