Erayd
Member
I'm getting a syntax error at line 20 in my fragment shader and I'm unclear as to what is wrong. Line 20 is the one that is: color2 = vec3(texture2D(colorMap, vec2(1.0, i/mapHeight))
The general goal of this shader is to compare the colors of a sprite in an object with the colors in a vertical 2 line pallet, on the left side would be the sprites colors and the right side next to it would be the color I want to transition to over a period of time, a blink basically.
Fragment Shader:
Vertex Shader:
Object Draw Event:
The general goal of this shader is to compare the colors of a sprite in an object with the colors in a vertical 2 line pallet, on the left side would be the sprites colors and the right side next to it would be the color I want to transition to over a period of time, a blink basically.
Fragment Shader:
Code:
varying vec4 v_vColour;
uniform float time;
uniform sampler2D colorMap;
uniform float mapHeight;
varying vec2 v_vTexcoord_A;
varying vec2 v_vTexcoord_B;
void main()
{
vec4 color1 = texture2D(gm_BaseTexture, v_vTexcoord_A);
vec3 color2 = vec3(0.0);
for(float i = 0.0; i < mapHeight; i++;){
if(vec3(color1) == vec3(texture2D(colorMap, vec2(0.0, i/mapHeight)))){
color2 = vec3(texture2D(colorMap, vec2(1.0, i/mapHeight)));
}
}
gl_FragColor.rgb = mix(color1.rgb, color2.rgb, time);
gl_FragColor.a = color1.a;
}
Code:
// Simple passthrough vertex shader
//
attribute vec3 in_Position; // (x,y,z)
//attribute vec3 in_Normal; // (x,y,z) unused in this shader.
attribute vec4 in_Colour; // (r,g,b,a)
attribute vec2 in_TextureCoord; // (u,v)
varying vec4 v_vColour;
//UVs
uniform vec4 uv_a;
uniform vec4 uv_b;
varying vec2 v_vTexcoord_A;
varying vec2 v_vTexcoord_B;
void main()
{
vec4 object_space_pos = vec4( in_Position.x, in_Position.y, in_Position.z, 1.0);
gl_Position = gm_Matrices[MATRIX_WORLD_VIEW_PROJECTION] * object_space_pos;
v_vColour = in_Colour;
v_vTexcoord_A = in_TextureCoord;
//v_vTexcoord_B = uv_b.xy + (in_TextureCoord - uv_a.xy) * uv_b.zw / uv_a.zw;
}
Code:
///Draw self
shader_set(testShader)
//Set Pallet
var palletSampler = shader_get_sampler_index(testShader, "colorMap");
var palletSprite = sprite_get_texture(my_pal_sprite, 0)
texture_set_stage(palletSampler, palletSprite);
shader_set_uniform_f(shader_get_uniform(testShader, "mapHeight"), my_pallet_sprite.sprite_height);
//Set Time
shader_set_uniform_f(shader_get_uniform(testShader, 'time'), timing);
//Set Locations
var uv_a = sprite_get_uvs(sprite_index, 0);
var uv_b = sprite_get_uvs(my_pal_sprite, 0);
shader_set_uniform_f(shader_get_uniform(testShader, "uv_a"), uv_a[0], uv_a[1], uv_a[2] - uv_a[0], uv_a[3] - uv_a[1]);
shader_set_uniform_f(shader_get_uniform(testShader, "uv_b"), uv_b[0], uv_b[1], uv_b[2] - uv_b[0], uv_b[3] - uv_b[1]);
draw_self();
shader_reset();
Last edited: