Skip to main content

Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
TagsGame Engines

Understanding Shaders in Fauxton3D

A topic by ratratratrats created Mar 15, 2023 Views: 371 Replies: 8
Viewing posts 1 to 2
(+1)

Hi!

I am currently aiming to add a 'flash' effect on sprites in my game when they get hurt/hit or whatever. Historically, I have achieved this effect by setting a shader, redrawing the sprite over top of the existing one with an alpha which decreases over time, and then disabling the shader.

Of course, while using fauxton a lot of the nitty-gritty control is handled within the engine. No longer can I simply drop something into the draw event.

I've gone over the nice little segment on setting up the buffers and shaders within the documentation, but I'm still at a loss as to how I could tackle this problem.

PS. If there is a solution to this problem which doesn't require shaders at all, that's just as fine with me!

Hey! So you can manually control drawing using the draw_override function (so that the engine does not automatically draw the model for you). You can also set up a custom shader for the model as well to achieve the desired effect.

If I'm understanding correctly, I can set the override in the create. Then in the draw I can do something like this:


So where I left the comment I would have to do my own sprite-stacking, to achieve my desired effect? This seems a little risky, I figure my own draw events wouldn't integrate too nicely into your engine. If this is the case I don't want to work against your system. What would you recommend in this situation - you mentioned setting up a custom shader for the model, could that be  a better alternative?

So you can set `fauxton_model_draw_enable(mode, false)` in the create event, and use the `fauxton_model_draw_override()` in the draw event of any object you like. This will work fine with the system, as essentially the system just automatically calls draw events from a single object.

(+1)

I see! It's working beatifully now, thank you!

(+1)

Sorry for reopening but even after this explanaition I still have a prolbem with this.
I set 

fauxton_model_draw_enable(model, false)

in create event

and in draw event Im trying to draw a circle with shader

shader_set(shd_bloom);

draw_circle(x, y, 20, false);

shader_reset();

shader_set(shd_default);

fauxton_model_draw_override(model);

shader_reset();

Model is drawn correctly but circle is nowher to be found. No matter what shader I put shd_default, shd_gmdefault, my shaders, circle just disappear. If there is no shader set the circle is drawn in correct position and angle.

Is there something wrong with how i set up this thing?

(1 edit)

This is due to the fact that things draw differently in 3D than traditional 2D. There could be a number of reasons the shader isn't appearing. Gamemaker doesn't supply a Z value by default to primitives (only vec2 in_Position). A couple of things you can try:

  • Use matrix_set(matrix_world, matrix_build(...)) and set the circle x/y to 0, 0 and only use the matrix to set the x, y and z values
  • Make sure the circle is rotated accordingly (using the matrix build functionality)
  • If you want the circle to just draw and not account for z values you can turn ztest/zwriteenable off
  • Draw the circle to a surface and apply the shader there. The bloom will only work on the bounds of the vertex triangles for the circle, and thus not produce the effect you want (you can see this if you also apply your bloom shader to a circle in 2D instead of to an entire surface)

If the last point is the issue, one thing to remember is that shaders only effect the graphical rendering within the vertices of a quad, so the shader can only grab pixels / extend pixels within those bounds. 

These are just a few examples of things you can test. Fauxton uses more traditional 3D techniques, and as such, requires you to draw things differently than you would in standard gamemaker. 

I highly recommend giving DragoniteSpams Gamemaker 3D tutorials a good watch through to understand some of the concepts used in fauxton at a much deeper level. :)

(+1)

the problem was not that the shader does not give its effect, but that setting the shader makes the correctly drawn circle disappear. The suggestions with matrixes did not work, but that is because the circle, as I wrote, is drawn in the right position with the right rotation already. The solution with the surface worked, but out of curiosity I checked other shapes and I am wondering about things you can see in attached screenshots. Why does only the circle behave like this under the influence of any shader?

In any case, thanks a lot.

(1 edit)

Interesting that it is only circles. It could just be the order GM renders the vertices. You can try turning off culling to see if that fixes it? Or rotate the circle around. If GM creates circles (for whatever reason) clockwise, then its probably trying to show you the 'back' of the circle instead. 

gpu_set_cullmode(cull_noculling)

Other than that though, Maybe the shader format is wrong? Idk that is really strange. haha.