Legacy GM surface, shader displacement

Greetings,

I am trying to reproduce an effect from a previous project!



This is what it should look like...
correct.png


Unfortunately, this is what I am getting from the code below...
mistaken.png


if !surface_exists(img_surf)
{
img_surf = surface_create(obj_tunnel_spiral_top_bottom.sprite_width, obj_tunnel_spiral_top_bottom.sprite_height);
var_test_active_check = 1;
}

surface_set_target(img_surf);

// put your circles code here, centered
draw_circle_colour(obj_tunnel_spiral_top_bottom.sprite_width / 2, obj_tunnel_spiral_top_bottom.sprite_height / 2, global.var_base_y_value, var_wormhole_gradi_a_01, var_wormhole_gradi_a_02, false);

// this is needed to cover the unwanted draw
// the shape, including the black, centered
draw_sprite(spr_tunnel_spiral_top_bottom, 0, obj_tunnel_spiral_top_bottom.sprite_width / 2, obj_tunnel_spiral_top_bottom.sprite_height / 2);
surface_reset_target();

shader_set(sh_shapefx);

// the sprites are relatively centered
draw_surface(img_surf, obj_tunnel_spiral_top_bottom.x - obj_tunnel_spiral_top_bottom.sprite_width / 2, obj_tunnel_spiral_top_bottom.y - obj_tunnel_spiral_top_bottom.sprite_height / 2);

shader_reset();

surface_free(img_surf);


//
// 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 vec2 v_vTexcoord;
varying vec4 v_vColour;

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 = in_TextureCoord;
}


//
// Simple passthrough fragment shader
//
varying vec2 v_vTexcoord;
varying vec4 v_vColour;

void main()
{
vec4 color;
color = texture2D( gm_BaseTexture, v_vTexcoord ).rgba;
if (color.rgb == vec3(0.0, 0.0, 0.0)) {
color.a = 0.0;
}

gl_FragColor = v_vColour * texture2D( gm_BaseTexture, v_vTexcoord );
gl_FragColor.a = color.a;
}

I have already tried moving the sprites, the surface and the draw_circle_colour to different locations, with no success.
But I am guessing that location(s) is the primary cause of my failure.
Any help or ideas would be great!
 

Tyg

Member
Ok, sorry to over complicate things,
I thought you were talking about shaders as in your title
Good luck with your efforts :)
 
Last edited:
I guess I should have explained this a little more, but I was mentailly drained from my day and I had hoped by showing the example from my previous project, that someone would get the idea.

Allow me to illuminate...

why not just make a png sprite..lol
The reason I am not doing a fixed png sprite is because the end result is not to make a static image, but an image wherein the colors change and flow in an outward motion, according to the dynamics of draw_circle_colour
If you closely inspect the previous project you can see the colors flowing outward and inward.


all this shader does is basically try to take the base sprite of the object, and if the color is black sets the alpha to 0 (transparent)
your assignment to color does not follow the varying vec
so it is always pointing to the same top corner
while the gl_FragCoord varies
it looks like your trying to use the basetexture to mask itself,....
its like saying hey shader check this sprite out i drew on the screen, if you find and black in it make it invisible
for masking you would normally bring in a mask texture in another varying vec
also it has no resolution uniform so it doesnt know how big to draw it, just go until it has no more texture?
Moreover, your conclusions about the shader and its purpose are correct, given what I am trying to achieve.

However, asking me to make a complex shader such as the one made by Frank Force is parallel to spending three years to develop or adapt a new rearview mirror on a car, wherein the other 98.5% of the car only requres two years total.
A single draw command and surface along side a very simple shader is much simplier, less code, and less time consuming than learning how to rig some extremely complex shader to so the same.
To bring this further into perspective, this little project is but one cog inside a much grander system, which in turn, is part of a much larger project. Hence the car analogy.
I simply can't justify spending the time to learn complex shaders, right now.

Lastly, I can't use code that is licensed. Hence, I am on here looking for help with my code. :)


What I am hoping to do is realign the parameters of the following code so they play out correctly.

if !surface_exists(img_surf)
{
img_surf = surface_create(obj_tunnel_spiral_top_bottom.sprite_width, obj_tunnel_spiral_top_bottom.sprite_height);
var_test_active_check = 1;
}

surface_set_target(img_surf);

// put your circles code here, centered
draw_circle_colour(obj_tunnel_spiral_top_bottom.sprite_width / 2, obj_tunnel_spiral_top_bottom.sprite_height / 2, global.var_base_y_value, var_wormhole_gradi_a_01, var_wormhole_gradi_a_02, false);

// this is needed to cover the unwanted draw
// the shape, including the black, centered
draw_sprite(spr_tunnel_spiral_top_bottom, 0, obj_tunnel_spiral_top_bottom.sprite_width / 2, obj_tunnel_spiral_top_bottom.sprite_height / 2);
surface_reset_target();

shader_set(sh_shapefx);

// the sprites are relatively centered
draw_surface(img_surf, obj_tunnel_spiral_top_bottom.x - obj_tunnel_spiral_top_bottom.sprite_width / 2, obj_tunnel_spiral_top_bottom.y - obj_tunnel_spiral_top_bottom.sprite_height / 2);

shader_reset();

surface_free(img_surf);

That code worked beatifully before...

Wherein, this:
draw_circle_colour(obj_tunnel_spiral_top_bottom.sprite_width / 2, obj_tunnel_spiral_top_bottom.sprite_height / 2, global.var_base_y_value, var_wormhole_gradi_a_01, var_wormhole_gradi_a_02, false);

used to be this:
for (var_anime_sphere = 0; var_anime_sphere < var_clock_alpha_range - 1; var_anime_sphere++)
{
draw_circle_colour(var_track_id.sprite_width / 2, var_track_id.sprite_height / 2, var_anime_sphere, arr_clock_color_two[var_anime_sphere], arr_clock_color_two[var_anime_sphere], true);
}

Literrally, that is the only difference.
 
Last edited:

SoapSud39

Member
This is kinda weird, since your positioning should work out, if I'm understanding it right.

It might not be it, but I'm thinking the problem could be the surface size. Since you're using the same name for this surface (img_surf) as the one in the previous portion (I think), and you're also checking for its existence, it might be that it's not getting created at the correct size. So maybe try using a different name (e.g. spiral_surf or something, idk).

Sorry for the late reply, hope this helps bring you closer to the solution.
 
This is kinda weird, since your positioning should work out, if I'm understanding it right.

It might not be it, but I'm thinking the problem could be the surface size. Since you're using the same name for this surface (img_surf) as the one in the previous portion (I think), and you're also checking for its existence, it might be that it's not getting created at the correct size. So maybe try using a different name (e.g. spiral_surf or something, idk).

Sorry for the late reply, hope this helps bring you closer to the solution.
No worriss, any help is grateful.

Actually the instances of the two different surfaces are created in different objects, thus their use would not be mixed or reused by the same code.

I will check the surface size, though, something in this does need to be changed to match the difference in size and usage.
Figureing out what that change should be is the challenge.
 
Last edited:
Top