Created
December 10, 2020 20:49
-
-
Save thatcosmonaut/ea211fddaeba4c5f7541cb583bde945e to your computer and use it in GitHub Desktop.
Busted mojoshader GLSL output
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#version 120 | |
uniform vec4 ps_uniforms_vec4[1]; | |
uniform ivec4 ps_uniforms_ivec4[1]; | |
const float FLT_MAX = 1e38; | |
const vec4 ps_c1 = vec4(0.0, 0.0, 1.0, 0.0); | |
vec4 ps_r0; | |
vec4 ps_r1; | |
vec4 ps_r2; | |
vec4 ps_r3; | |
vec4 ps_r4; | |
#define ps_c0 ps_uniforms_vec4[0] | |
#define ps_i0 ps_uniforms_ivec4[0] | |
uniform sampler2D ps_s0; | |
uniform sampler2D ps_s1; | |
#define ps_v0 gl_TexCoord[0] | |
#define ps_oC0 gl_FragColor | |
void main() | |
{ | |
ps_r0 = texture2D(ps_s0, ps_v0.xy); | |
ps_r1.x = ((ps_c0.x == 0.0) ? FLT_MAX : 1.0 / ps_c0.x); | |
ps_r2.y = ps_c1.x; | |
ps_r3 = ps_c1.xxxy; | |
ps_r1.y = ps_c1.x; | |
for (int rep1 = 0; rep1 < ps_i0.x; rep1++) { | |
ps_r2.x = ps_r1.x * ps_r1.y; | |
ps_r4 = texture2D(ps_s1, ps_r2.xy); | |
ps_r2.xzw = -ps_r0.xyz + ps_r4.xyz; | |
ps_r1.z = dot(ps_r2.xzw, ps_r2.xzw); | |
ps_r1.z = ((ps_r1.z == 0.0) ? FLT_MAX : inversesqrt(abs(ps_r1.z))); | |
ps_r4.w = ((ps_r1.z == 0.0) ? FLT_MAX : 1.0 / ps_r1.z); | |
ps_r1.z = -ps_r3.w + ps_r4.w; | |
ps_r3 = ((ps_r1.z >= 0.0) ? ps_r3 : ps_r4); | |
ps_r1.y = ps_r1.y + ps_c1.z; | |
} | |
ps_oC0.xyz = ps_r3.xyz; | |
ps_oC0.w = ps_r0.w; | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "Macros.fxh" | |
#define FLT_MAX 3.402823466e+38 | |
DECLARE_TEXTURE(Texture, 0); | |
DECLARE_TEXTURE(Palette, 1); | |
BEGIN_CONSTANTS | |
int PaletteWidth _ps(c0) _cb(c0); | |
END_CONSTANTS | |
struct VertexInput | |
{ | |
float4 Position : POSITION; | |
float2 TexCoord : TEXCOORD; | |
}; | |
struct PixelInput | |
{ | |
float4 Position : SV_POSITION; | |
float2 TexCoord : TEXCOORD0; | |
}; | |
PixelInput main_vs(VertexInput input) | |
{ | |
PixelInput output; | |
output.Position = input.Position; | |
output.TexCoord = input.TexCoord; | |
return output; | |
} | |
float4 main_ps(PixelInput input) : SV_TARGET0 | |
{ | |
float4 sampled = SAMPLE_TEXTURE(Texture, input.TexCoord); | |
float3 sampled_color = sampled.rgb; | |
float3 closest_color = float3(0, 0, 0); | |
float closest_dist = FLT_MAX; | |
for (int i = 0; i < PaletteWidth; i++) | |
{ | |
float3 palette_color = SAMPLE_TEXTURE(Palette, float2(i / (float)PaletteWidth, 0)); | |
float dist = distance(palette_color, sampled_color); | |
if (dist < closest_dist) | |
{ | |
closest_dist = dist; | |
closest_color = palette_color; | |
} | |
} | |
return float4(closest_color, sampled.a); | |
} | |
Technique PaletteCrush | |
{ | |
Pass | |
{ | |
VertexShader = compile vs_3_0 main_vs(); | |
PixelShader = compile ps_3_0 main_ps(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment