Basically what i want to do is draw a Particle System to a Surface and then use the Texture of that Surface to blend a Sprite.
Im using the relative difference in size of the Sprite/Surface Texels to determine the X/Y Texcoords of the Mask/Surface within the Fragment Shader for the Sprite.
Seperate Texture Page is enabled for the Sprite.
Thus far this is working on the Windows Target.
Screen 1: Left side is the Surface and right side the Sprite blended with the Surface
But when launching for the HTML Target the Sprite just turns completely black as seen in Screen 2.
What am i missing?
#Why is this Shader not working?
1 messages · Page 1 of 1 (latest)
Create Event:
surf = -1
surf_size = 256
part_sys = part_system_create(psTest)
part_system_automatic_draw(part_sys, false)
part_system_position(part_sys, 75, 250)
Draw Event:
//create surface 256x256
if !surface_exists(surf) {
surf = surface_create(surf_size, surf_size)
}
#region draw particle system to surface
surface_set_target(surf)
draw_clear_alpha(c_white, 1)
gpu_set_colorwriteenable(true, true, true, false)
part_system_drawit(part_sys)
var col = draw_get_color()
draw_set_color(c_black)
draw_rectangle(0, 0, sprite_get_width(sprTest), sprite_get_height(sprTest), true)
draw_set_color(col)
gpu_set_colorwriteenable(true, true, true, true)
surface_reset_target()
#endregion
#region draw sprite with shader
shader_set(shdTest)
//get relative size of texels to calculate new texcoord, see fragment shader
var spr_tex = sprite_get_texture(sprTest, 0)
var spr_txl_w = texture_get_texel_width(spr_tex)
var spr_txl_h = texture_get_texel_height(spr_tex)
var surf_tex = surface_get_texture(surf)
var surf_txl_w = texture_get_texel_width(surf_tex)
var surf_txl_h = texture_get_texel_height(surf_tex)
var uniform_xrel = shader_get_uniform(shdTest, "x_rel")
var uniform_yrel = shader_get_uniform(shdTest, "y_rel")
var sampler = shader_get_sampler_index(shdTest, "particles")
shader_set_uniform_f(uniform_xrel, surf_txl_w / spr_txl_w)
shader_set_uniform_f(uniform_yrel, surf_txl_h / spr_txl_h)
texture_set_stage(sampler, surf_tex)
draw_sprite_ext(sprTest, 0, 610, 10, 2, 2, 0, -1, 1)
shader_reset()
#endregion
//draw for debugging
draw_surface_ext(surf, 10, 10, 2, 2, 0, -1, 1)
Vertex Shader:
attribute vec3 in_Position; // (x,y,z)
attribute vec4 in_Colour; // (r,g,b,a)
attribute vec2 in_TextureCoord; // (u,v)
attribute vec2 in_TextureCoord1; // (u,v)
varying vec2 v_vTexcoord;
varying vec4 v_vColour;
varying vec2 v_vMaskcoord;
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_vTexcoord = in_TextureCoord;
v_vColour = in_Colour;
v_vMaskcoord = in_TextureCoord1;
}
Fragment Shader:
varying vec2 v_vTexcoord;
varying vec4 v_vColour;
varying vec2 v_vMaskcoord;
uniform sampler2D particles;
uniform float x_rel;
uniform float y_rel;
void main()
{
vec4 particle_color = texture2D(particles, vec2(v_vMaskcoord.x*x_rel, v_vMaskcoord.y*y_rel));
vec4 fragment_color = texture2D(gm_BaseTexture, v_vTexcoord);
gl_FragColor = v_vColour * particle_color * fragment_color;
}