D
dannyjenn
Guest
I'm new to shaders, but I'm trying to make a simple palette swapper (for a 4-color retro game). So far it works, but my palettes are all hard-coded into the shader. I was wondering whether there was any way I could make it so that it pulls the color data from in-game variables? e.g.
I want to be able to change new_white, new_lgray, new_dgray, and new_black at runtime. Perhaps by setting their values to the values of some in-game global variables
edit - e.g.
Somehow pass those values into the shader, and then convert them to vec4. Is this sort of thing possible?
Code:
varying vec2 v_vTexcoord;
varying vec4 v_vColour;
vec4 white = vec4(1.0,1.0,1.0,1.0);
vec4 lgray = vec4((208.0/255.0),(208.0/255.0),(208.0/255.0),1.0);
vec4 dgray = vec4((168.0/255.0),(168.0/255.0),(168.0/255.0),1.0);
vec4 black = vec4(0.0,0.0,0.0,1.0);
vec4 new_white = vec4((247.0/255.0),(229.0/255.0),(247.0/255.0),1.0);
vec4 new_lgray = vec4((193.0/255.0),(219.0/255.0),(211.0/255.0),1.0);
vec4 new_dgray = vec4((150.0/255.0),(202.0/255.0),(247.0/255.0),1.0);
vec4 new_black = vec4((23.0/255.0),(17.0/255.0),(17.0/255.0),1.0);
vec4 colorless = vec4(0.0,0.0,0.0,0.0);
vec4 error = vec4(1.0,0.0,0.5,1.0);
void main(){
gl_FragColor = v_vColour*texture2D(gm_BaseTexture,v_vTexcoord);
if(gl_FragColor.a<1.0){
gl_FragColor = colorless;
}
else if(gl_FragColor==white){
gl_FragColor = new_white;
}
else if(gl_FragColor==lgray){
gl_FragColor = new_lgray;
}
else if(gl_FragColor==dgray){
gl_FragColor = new_dgray;
}
else if(gl_FragColor==black){
gl_FragColor = new_black;
}
else{
gl_FragColor = error;
}
}
edit - e.g.
Code:
global.new_white = $F7E5F7;
global.new_lgray = $D3DBC1;
global.new_dgray = $F7CA96;
global.new_black = $111117;
Last edited by a moderator: