F
Freddie The Potato
Guest
Heya, I've run into a problem whilst developing a shader for a 3D game.
The shader is intended to create a kind of "colored glass" effect, wherein everything viewed through the object using the shader will be colorized with the specified color.
However, calling this shader via shader_set(); results in all objects and primitives becoming completely invisible, even the objects which do not use the shader. Esentially it leaves the screen blank.
Vertex Shader:
Fragment Shader:
Draw Code:
Interestingly, if I remove the texture2D() function from the shader and set originalColor to some arbitrary value - for example: originalColor = vec4(1.0, 1.0, 1.0, 1.0) - then everything becomes visible once more.
Manually specifying texture coordinates to the texture2D() function - for example: texture2D(u_Tex, vec2(0.5, 0.5)) - has no effect; everything remains invisible.
I've tested this shader in a 2D game (albeit with a different method of calculating texture coordinates) and it worked fine with no problems.
Any help of advice would be greatly appreciated
Thank you.
The shader is intended to create a kind of "colored glass" effect, wherein everything viewed through the object using the shader will be colorized with the specified color.
However, calling this shader via shader_set(); results in all objects and primitives becoming completely invisible, even the objects which do not use the shader. Esentially it leaves the screen blank.
Vertex Shader:
Code:
attribute vec3 in_Position;
varying vec4 v_Position;
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_Position = gl_Position;
}
Code:
varying vec4 v_Position;
uniform sampler2D u_Tex;
uniform vec3 u_Color;
void main()
{
//Pull original color from surface texture
vec4 originalColor = texture2D(u_Tex, vec2(
((v_Position.x / v_Position.w) + 1.0) * 0.5,
(-(v_Position.y / v_Position.w) + 1.0) * 0.5
));
//Calculate greyscale value from original color
float greyscale = ((originalColor.r * 0.2) + (originalColor.g * 0.7) + (originalColor.b * 0.1));
//Get final color by multiplying the greyscale by the colorize color.
gl_FragColor = vec4(
u_Color.r * greyscale,
u_Color.g * greyscale,
u_Color.b * greyscale,
1.0);
}
Code:
//Temporary variables
var
_shader = shadColorize,
_col = make_color_rgb(150, 75, 100),
_tex = surface_get_texture(application_surface);
//Get shader uniform handles
var
_uTex = shader_get_sampler_index(_shader, "u_Tex"),
_uColor = shader_get_uniform(_shader, "u_Color");
shader_set(_shader);
//Assign shader uniforms
texture_set_stage(_uTex, _tex);
shader_set_uniform_f(_uColor, color_get_red(_col) / 255, color_get_green(_col) / 255, color_get_blue(_col) / 255);
//Draw the box
d3d_draw_block(x, y, z, x + 32, y + 32, z + 32, sprite_get_texture(sprTex, 0), 1, 1);
shader_reset();
Manually specifying texture coordinates to the texture2D() function - for example: texture2D(u_Tex, vec2(0.5, 0.5)) - has no effect; everything remains invisible.
I've tested this shader in a 2D game (albeit with a different method of calculating texture coordinates) and it worked fine with no problems.
Any help of advice would be greatly appreciated
Thank you.
Last edited by a moderator: