• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

CGA Shader

Heavybrush

Member
Hi , I'm trying to make a simple CGA shader

//
// Simple passthrough fragment shader
//
uniform sampler2D gm_BaseTexture;

varying vec2 v_vTexcoord;
varying vec4 v_vColour;

const mat3 rgb_to_wcm = mat3(1,-1, 0, 1, 0,-1, -1, 1, 1);

void main()
{
vec4 rgba = v_vColour * texture2D(gm_BaseTexture, v_vTexcoord);
vec3 wcm = rgb_to_wcm * rgba.rgb;
vec3 rgb = dot(wcm,vec3(1,1,1)) < 0.5
? vec3(0,0,0)
: wcm.x > wcm.y
? (wcm.x > wcm.z ? vec3(1,1,1) : vec3(1,0,1))
: (wcm.y > wcm.z ? vec3(0,1,1) : vec3(1,0,1));
gl_FragColor = vec4(rgb, rgba.a);
}

there is something wrong that I cannot recognise
can you help me??
 
E

elementbound

Guest
By CGA you mean you are trying to reproduce the color palette? And what's exactly wrong? Does it compile? And if it does, what kind of results do you get?
Your pixel shader is a bit convoluted because of the ?:'s for me. I've rarely use nested ternary operators. Can you give me a version with some if-else if's?
 

Heavybrush

Member
Reading project file....Error compiling fragment shader:
In Shader shd_CGA at line 2 : 'gm_BaseTexture' : redefinition
Compile Failed - Please check the Compile window for any additional information

it doesn't give additional information

------------------------------------------------------------------

ok I had to leave the declaration of the uniform variable
now the code is that

varying vec2 v_vTexcoord;
varying vec4 v_vColour;

const mat3 rgb_to_wcm = mat3(1,-1, 0, 1, 0,-1, -1, 1, 1);

void main()
{
vec4 rgba = v_vColour * texture2D(gm_BaseTexture, v_vTexcoord);
vec3 wcm = rgb_to_wcm * rgba.rgb;
vec3 rgb = dot(wcm,vec3(1,1,1)) < 0.5
? vec3(0,0,0)
: wcm.x > wcm.y
? (wcm.x > wcm.z ? vec3(1,1,1) : vec3(1,0,1))
: (wcm.y > wcm.z ? vec3(0,1,1) : vec3(1,0,1));
gl_FragColor = vec4(rgb, rgba.a);
}

it works but is only black and white
how to add also the other colors??
 
Last edited:
M

manoloon

Guest
man , I took your shader code and just comment //uniform sampler2D gm_BaseTexture; the line with problem - and voila , CGA it is!
 

Binsk

Member
This is because gm_BaseTexture is implicitly defined by GameMaker itself. Because it auto generates that value in every shader your definition was conflicting with it.
 
Top