Free Fauxton 3D - A 2.5D sprite-stacking engine

Gizmo199

Member
version 2.2.2
Logo.png
Demo | Download | Docs / Github
Update - v 2.2.0


About

Fauxton 3D is a powerful and efficient sprite-stacking engine that not only makes 3D games possible in Game Maker but also INSANELY easy! There are many hurdles when attempting to do 3D rendering in Game Maker and it can be daunting trying to learn it all, but with Fauxton, I have tried to design it so that it is efficient, quick, and easy. So easy that a complete beginner to 3D can have a scene up and running in no time at all!

Testimonials
You made something super cool and inspiring! I've never been able to render a 3d scene so easily in gamemaker before
-
Rologfos

This is simply amazing man, the best asset of this kind for gms anywhere that i can find, and ive looked for a lot of 2.5d and sprite stacking solutions
-
Wurmhole

it's amazing, much easier to create rooms and objects as you want and add shaders
-
Baiter Yamato

What is sprite-stacking?

From an article by Avis:
Sprite-stacking is where a voxel model is sliced into many horizontal slices, these slices are then drawn in GameMaker from the bottom to the top, with each one slightly higher. This gives the effect of a sort of 3d model in a purely 2d game

What can it do?

This engine includes plenty of functionality fully compatible with most things you might do with a standard Game Maker 2D game. Some of the things you can do with the downloadable & playable demo include Volumetric fog, Object particle effects, Unlimited static buffers, and more! Once you initiate the engine using the function FAUXTON_START(), getting a model into a scene takes only 1 line of code fauxton_model_create() and that's it!! I tried to design this project for beginners and artists, so you can focus on your games, not learning about buffers!



You can read more about the functionality, as well as a brief tutorial, in the Documentation!
Follow me on Twitter to keep up-to-date on progress!

Code:
V 2.2.2 Patch
[FIXED] Scaling issues when adding scaled models to static buffers
Code:
V 2.2.1 Patch
[FIXED] Camera control right-stick axes were flipped (vertical was Angle, horizontal was Pitch).
Code:
V 2.2.0 Update
[ADDED] World Environment Node 
[ADDED] Point light node 
[ADDED] Spot light node 
[ADDED] fauxton_buffer_set_uniform_script(buffer_name_or_id, uniform_control_script) 
[MODIFIED] draw_sprite_3d OPTIONAL parameter 'enable_lighting' 
[MODIFIED] draw_sprite_3d_ext OPTIONAL parameter 'enable_lighting' 
[FIXED] fauxton_buffer_set (Would return an error)
Code:
V 2.1.1 Update
- [FIXED] - 'missing reference id' message for the Camera and RenderPipeline object nodes
Code:
V 2.1.0 Update
- [ADDED] - fauxton_model_texcube, fauxton_model_texcube_destroy, fauxton_model_create_ext
- [ADDED] - Full demo with examples of Static buffers, Particles, Volumetric Fog, and Player movement/animation
- [FIXED] - Bug fixes here and there, syntax highlighting fixed
- [ADDED] - HTML5 and mobile camera rotation support to Camera
Code:
V 2.0.0 Update
- [ADDED] - Completely new workflow,
- [ADDED] - Static buffers that models can be added to
 
Last edited:

Shut

Member
Whoa, looks like you put in a great effort into this. Looks really cool! I experimented with sprite stacking some time ago and I'll definitely try to use this if I decide to start a new project again.

Does this support vertical movement/collisions as well?
 

rui.r6o

Member
Looks cool, I will definitely check it out later as the project I want to start will use sprite stacking! Just a question: does it support lighting and different types of materials (e.g. diffuse, metal, glass, emissive)?
 

Gizmo199

Member
Whoa, looks like you put in a great effort into this. Looks really cool! I experimented with sprite stacking some time ago and I'll definitely try to use this if I decide to start a new project again.

Does this support vertical movement/collisions as well?
Currently no. This is purely a rendering engine. I would, however, suggest using @TheSnidr Colmesh library with it though! ColMesh comes with a bunch of predefined shapes so you shouldn't have to mess with OBJs or anything

Looks cool, I will definitely check it out later as the project I want to start will use sprite stacking! Just a question: does it support lighting and different types of materials (e.g. diffuse, metal, glass, emissive)?
Currently, it does not. It is planned for the future to include lighting / True shadow casting. Idk about full materials though. Been thinking of creating a sprite-stack modeling tool, and if I do that then It would probably be a lot easier to add in materials. Essentially it's just a bunch of stacked quads, so normals can be tricky with them.
 

Pixel-Team

Master of Pixel-Fu
Damn! This looks awesome! My favorite was that little dude's legs when he's running. I'm gonna have to look into this once the Jam is over. Nice job!
 

gnysek

Member
At first I thought that it's one of those sprite stacking only engines, which generally are slow for more complex games, but seems it's not, and also have something similar to bilboards, which make things smooth enough to make a game!
 
Last edited:

Gizmo199

Member
At first I thought that it's one of those sprite stacking only engines, which generally are slow for more complex games, but seems it's not, and also have something similar to bilboards, which make things smooth enough to make a game!
Yeah, it's a 'fake 3d' engine but I use actual vertex buffers and projection matrices, so performance is actually maintainable. :) I plan to add in OBJ importation eventually so you can go the more 'true' 3d route if you wish. :)
 

Gizmo199

Member
Is there any possible make 2D multi-sprites faceing to the screen sametime?
not exactly sure what you mean? If you use draw_sprite_3d and set the facing_camera parameter to true it's the same as drawing a regular sprite that faces the camera at all times.
 

Gizmo199

Member
Not find the facing_camera in DOC 😂 😂

Implement that, thank your work again!
Sorry, its technically face_camera :p
Capture.PNG

Glad you found it! :D Can't wait to see what you come up with! I'm working on lighting and shadow casting now, so hopefully, soon that will be available! :D
 

gnysek

Member
but I use actual vertex buffers and projection matrices
I know that there's big performance issue with matrices on Xbox UWP, I will try to benchmark your code at some point and then report to YYG (cause maybe I was just using matrices wrong and your example will solve my problems xD).
 

Gizmo199

Member
I know that there's big performance issue with matrices on Xbox UWP, I will try to benchmark your code at some point and then report to YYG (cause maybe I was just using matrices wrong and your example will solve my problems xD).
Oh interesting! I have only been able to port/test on html5 and PC unfortunately. Was that with the YYC? Might have to write my own matrix functions but idk how well that would even work if it's an internal thing with GM.
 

Gizmo199

Member
V 2.2.0

GET VERSION 2.2.0 HERE

Nodes
  • [ADDED] World Environment Node
  • [ADDED] Point light node
  • [ADDED] Spot light node
Functions
  • [ADDED] fauxton_buffer_set_uniform_script(buffer_name_or_id, uniform_control_script)
  • [MODIFIED] draw_sprite_3d OPTIONAL parameter 'enable_lighting'
  • [MODIFIED] draw_sprite_3d_ext OPTIONAL parameter 'enable_lighting'
Fixed
  • [FIXED] fauxton_buffer_set (Would return an error)

Lighting is here!! With Fauxton 3D you can easily add lighting to a scene by just adding an instance of WorldEnvironment and either point lights or spotlights! Fauxton supports up to 64 different spot/point lights. This can be changed, however, by going into shd_default and change all numbers in the fragment shader that are 64. Let's look at what each of these nodes contains!

** NOTE **

If you override buffer shaders with your own you will have to calculate lighting in your new shader! It is suggested that you should duplicate the shd_default shader and its uniform script found in:

RenderPipeline

> pipeline_initiate()

> default_world_shader_set()


And then proceed to make your changes.



World Environment
First, we have the WorldEnvironment node. This node MUST be added to a room in order to enable lighting. There are a few options in this node under the Variable Definitions button.



AmbientColorThe ambient color of our scene. The ‘Shadow’ color in a sense.
SunColorThe Color of our directional light
SunIntensityThe intensity of our directional light
SunPositionThe position of our directional light
The AmbientColor will be the color of the ‘shadows’ or rather the color of the scene facing away from the sun. Setting this to white ( $ffffff / c_white ) will make it so that the shadows are completely illuminated.

The SunColor is the color of our scene lit from the SunPosition. The sun position is an array that contains an X, Y, and Z. These values should be between a value of -1 and 1. So for example:

[ -1, -1, 0 ]The sun is at the TOP-LEFT corner of the room at a z of 0 (straight on)
[ 1, 1, 1 ]The sun is at the BOTTOM-RIGHT corner of the point DOWN in z-space
Due to the fact that sprite-stacks are just a series of stacked planes on top of one another it should generally be avoided setting the sun's z-position to -1 (as you will not easily be able to see them illuminated from the bottom).

Point Lights
Point lights are SUPER easy to add-in. Once you have an instance of WorldEnvironment added to your room you can add up to 64 point or spot lights! You can find the attributes for point lights in the Variable Definitions:



zThe z position of the light
colorThe Color of the light
rangeThe radius or ‘range’ of the light

Spot Lights
Spotlights are SUPER easy to add-in. Once you have an instance of WorldEnvironment added to your room you can add up to 64 point or spot lights! You can find the attributes for spotlights in the Variable Definitions:



zThe z position of the light
colorThe Color of the light
rangeThe radius or ‘range’ of the light
cutoff_angleHow many degrees to cut light to (smaller = spike, larger = bowl)
angleThe x/y angle of the light (imagine this like image_angle)
z_angleThe z angle of the light (how much the light points up or down)

fauxton_buffer_set_uniform_script
This function allows you to set a custom shader uniform control script for a buffer created using fauxton_buffer_create.

Syntax:

fauxton_buffer_set_uniform_script( buffer_id_or_name, uniform_control_script);
ArgumentDescription
buffer_nameThe name (string) or ID (index) of the buffer to set
uniform_control_scriptThe shader uniform control script for the buffer
Returns:

N/A
Example:

GML:
var uniform_script = function(){

    var uni = shader_get_uniform(shd_grass_sway, "time");

    shader_set_uniform_f(uni, current_time/250);

}

fauxton_buffer_create("GrassBuffer", shd_grass_sway);

fauxton_buffer_set_uniform_script(“GrassBuffer, uniform_script);
First we create a script to control our grass shader called uniform_script. We then create a buffer, set the shader to shd_grass_sway and set the uniform control script to our uniform_script.
 
Last edited:

gnysek

Member
OK, I've tested it on UWP+Xbox One export and... I must say that it works better than on my PC :p
On Fidelity=2/Res=200%, first 3 demos are giving 60 FPS, and fourth one have 28-29 FPS (60 fps with fid/res=1).

What's fun, my PC with GTX 950M is showing 50 FPS at max on last one, so seems that Xbox One is better here (while as I mentioned earlier UWP sucks when having lot of matrix function calls per frame). Seems that UWP is buffer friendly. I did't checked Xbox Series X as it for sure wouldn't have worse results, and I got some suspended games there :p I'm not sure however why my PC was showing that only integrated GPU from Intel was used instead of GTX, I'm not sure if it shared some usage with it, or score was so bad cause GMS games won't run using Geforce.

Btw. camera for controller seems to be flipped, as up-down rotates it, and left-right changes height.

Edit: I've found a way to force to use GTX card, from "Screen settings/Display" in new Win10 fancy Settings panel there's "Graphic Settings" on very bottom, and by clicking there apps can be added an forced to use one of GPUs. Bad that GM isn't able to do run on proper card by itself.
 
Last edited:

Gizmo199

Member
OK, I've tested it on UWP+Xbox One export and... I must say that it works better than on my PC :p
On Fidelity=2/Res=200%, first 3 demos are giving 60 FPS, and fourth one have 28-29 FPS (60 fps with fid/res=1).

What's fun, my PC with GTX 950M is showing 50 FPS at max on last one, so seems that Xbox One is better here (while as I mentioned earlier UWP sucks when having lot of matrix function calls per frame). Seems that UWP is buffer friendly. I did't checked Xbox Series X as it for sure wouldn't have worse results, and I got some suspended games there :p I'm not sure however why my PC was showing that only integrated GPU from Intel was used instead of GTX, I'm not sure if it shared some usage with it, or score was so bad cause GMS games won't run using Geforce.

Btw. camera for controller seems to be flipped, as up-down rotates it, and left-right changes height.

Edit: I've found a way to force to use GTX card, from "Screen settings/Display" in new Win10 fancy Settings panel there's "Graphic Settings" on very bottom, and by clicking there apps can be added an forced to use one of GPUs. Bad that GM isn't able to do run on proper card by itself.
Omg thank you so much for all that info!!! You are a king! Strange that the axes are flipped?? I will look into that. Was that tested with v2.1 (I just release a newer version that has forward lighting). Eithet way thanks so much!!
 

gnysek

Member
Was that tested with v2.1
It was version with lighting, I've downloaded it yesterday right before testing, and I've used latest GMS2 beta to test it. I've only added code so R1/L1 was switching between rooms, also there was no cursor so I wasn't able to spawn grenades :p Generally it worked better than I thought, so I need to look deeply to take inspiration how to optimize code with buffers :)
 

Gizmo199

Member
It was version with lighting, I've downloaded it yesterday right before testing, and I've used latest GMS2 beta to test it. I've only added code so R1/L1 was switching between rooms, also there was no cursor so I wasn't able to spawn grenades :p Generally it worked better than I thought, so I need to look deeply to take inspiration how to optimize code with buffers :)
Nice! Well thanks again! Biggest optimizations are limiting matrix building. If possible (like static buffers) build the matrix once and re-use matrices if possible. Also (if you know the matrices you want) you can alter things like position with by just doing 'matrix[13] += speed' or whatever and that can help you avoid rebuilding matrices for small simple stuff.

Edit: and of course always batch as many vertices/models as possible to 1 vertex buffer.
Edit 2: Fixed the axes issue. Hadn't use the game-pad for testing since I switched some stuff around. haha woops! :p
 
Last edited:

Gizmo199

Member
what-is-github-1-1.png
LINK
Fauxton 3D is now on GitHub! I plan to use GitHub for minor changes, bug fixes, and any other non-major alterations to Fauxton 3D! Anything major ( eg shadow mapping, collisions, OBJ importing, ect ) will still be updated on the Itch.io page, but you will have access to it FIRST from the Github page! :D
 

Gizmo199

Member
Was trying this today, and I got this message. (When using fauxton_buffer_create)
View attachment 47055

Any ideas 😅
Oh interesting! Do you have win7? I know gm in general has been having a lot of issues lately with win7. I am just using the standard vertex buffer functions, so that looks like something internal with GM (VertexBuilderM.cpp). Wish I could help! :(

First version was pretty good (have used it), but this looks like a whole new ballgame (didn't use it, but I get a feeling 😂 )!
Nice job, bud!
Thanks! Yeah it has much more stuff than v1. Haha. Hopefully you get a chance to try it out. :)
 

rui.r6o

Member
Still haven't had the time to look into using this :( (I also forgot about it tbh 😅)

I do have a question though, how's the multiplatform support? I'm particularly interested in GXC and HTML5 (potentially even mobile devices through HTML5) as I plan on using those two platforms for some upcoming projects (as an attempt to reach as wide an audience possible with relative ease, plus I'm assuming Windows is pretty well covered by the engine).
 

Gizmo199

Member
Still haven't had the time to look into using this :( (I also forgot about it tbh 😅)

I do have a question though, how's the multiplatform support? I'm particularly interested in GXC and HTML5 (potentially even mobile devices through HTML5) as I plan on using those two platforms for some upcoming projects (as an attempt to reach as wide an audience possible with relative ease, plus I'm assuming Windows is pretty well covered by the engine).
Thanks for considering it! It's a bit outdated and could definitely be updated, but if you go to the itch.io page you can play the html5 demo I have on the page! :) and it should run fine on GXC though I haven't tested GXC specifically. It's mostly best used as a good jumping off point to make more simple 2.5d games. Hopefully one day I can update it to be even more robust, but as is the performance is pretty solid. Gnysek tested it on Xbox and mentioned it ran pretty well. It uses forward rendering for the lighting as well so it should get good performance on mobile devices as well. :)
 

rui.r6o

Member
Thanks for considering it! It's a bit outdated and could definitely be updated, but if you go to the itch.io page you can play the html5 demo I have on the page! :) and it should run fine on GXC though I haven't tested GXC specifically. It's mostly best used as a good jumping off point to make more simple 2.5d games. Hopefully one day I can update it to be even more robust, but as is the performance is pretty solid. Gnysek tested it on Xbox and mentioned it ran pretty well. It uses forward rendering for the lighting as well so it should get good performance on mobile devices as well. :)
Thanks for the quick reply! I'll definitely play around with it in the near future :)
 

Mert

Member
Oh interesting! Do you have win7? I know gm in general has been having a lot of issues lately with win7. I am just using the standard vertex buffer functions, so that looks like something internal with GM (VertexBuilderM.cpp). Wish I could help! :(
No I use Windows 10.

The demo works perfectly, but if I use fauxton_buffer_create in my project, it gives that error. Idk tho 😅
(Try to import Fauxton, but without the demo part. Try to create buffer with that)
 

Gizmo199

Member
No I use Windows 10.

The demo works perfectly, but if I use fauxton_buffer_create in my project, it gives that error. Idk tho 😅
(Try to import Fauxton, but without the demo part. Try to create buffer with that)
Oh interesting! Maybe the buffer was empty for some reason? If the demo is working fine then check to make sure models are added to the buffers before destroying either the models or the buffer.
 

Old2DGuy

Member
....but as is the performance is pretty solid. Gnysek tested it on Xbox and mentioned it ran pretty well. It uses forward rendering for the lighting as well so it should get good performance on mobile devices as well. :)
Can I ask what your development system specs are? The .exe demo runs on my system but only around 15fps. Don't worry, this is a very old system, I was just wondering what system spec you developed this on? Thx.
 

Gizmo199

Member
Can I ask what your development system specs are? The .exe demo runs on my system but only around 15fps. Don't worry, this is a very old system, I was just wondering what system spec you developed this on? Thx.
Sure! These are the specs for what I developed the engine on:
Screenshot_20220328-182911_Discord.jpg
It runs around 750+ without screen capture.

Also windows 7.
 
Absolutely! Though I would recommending grabbing it from the Github Repo since I haven't had time to update the itch page just yet. There was a bug with ds_* deletion from the latest GM update
Noted, I'm implementing a stacking system through a tutorial to familiarize myself with how it works first but I will be trying your engine tonight thank you.

The forest's blessings be upon you.

blessed-export.gif
 
Having a lick of trouble, exporting with a background causes this stripped effect on the sprite used on the BackFloor every time you move the camera. Getting around it for now by disabling the background.


rats-export.gif
(HTML5)
 

Gizmo199

Member
Having a lick of trouble, exporting with a background causes this stripped effect on the sprite used on the BackFloor every time you move the camera. Getting around it for now by disabling the background.


View attachment 58914
(HTML5)
This is called z-fighting. This is commone among all 3d engines / frameworks. To fix this, you can just move the model up along the z-axis by like .01 or something. :)
 
This is called z-fighting. This is commone among all 3d engines / frameworks. To fix this, you can just move the model up along the z-axis by like .01 or something.
I see, thank you for the knowledge. I took a look and couldn't find where in your engine I can modify the z-axis applied to a sprite drawn in a background layer, but if it became a necessity I could get around this by making the background sprite an object instead so I can modify its z-axis through fauxton_model_create.

I do would like to ask, is there a way to make the PointLight return an object's colour instead of just painting it white? Sprite-0042158.png (or whichever colour the light you picked is)

I'm using World Environment to darken all objects then a PointLight to brighten the ones closer to the rat player, but they are just getting whitewashed.

It's okay if not, I would just have to adapt the art to this limitation.



Sprit42e-0057.png
ratty light.gif
 
Last edited:

CMAllen

Member
Well, I can sort of get results. But there seems to be an issue with the, uh...texture map? UVs?
TextureIssues.jpg
It looks like it's intermittently using texture coordinates from the wrong spaces, because I can see layers of the sprite I created and are in the right places, and layers that are drawing from some other layer entirely, or from other sprites that definitely aren't mine (like the fog sprite). I tried moving my sprite to its own texture group but that just made things worse.

Forgive the color. It's a quick hack job on a 3d model that's using a 3-color palette system,based on RGB values, hence the garish colors.
 

Gizmo199

Member
I see, thank you for the knowledge. I took a look and couldn't find where in your engine I can modify the z-axis applied to a sprite drawn in a background layer, but if it became a necessity I could get around this by making the background sprite an object instead so I can modify its z-axis through fauxton_model_create.

I do would like to ask, is there a way to make the PointLight return an object's colour instead of just painting it white? View attachment 58936 (or whichever colour the light you picked is)

I'm using World Environment to darken all objects then a PointLight to brighten the ones closer to the rat player, but they are just getting whitewashed.

It's okay if not, I would just have to adapt the art to this limitation.



View attachment 58935
View attachment 58934
Background layers are just normal GM layers, so they aren't rendered by the engine, and thus by default will be set to 0 on the z-axis. You will want to make a background an object for this anyway if you want the lighting to affect it. :) IIRC this is what I am doing in the demo project as well. :) As for point light colors, you can get it by referencing the point light and getting the color variable from the light object. You can then use the color_get_red/green/blue to separate the channels if you need. Is that what you mean?

Well, I can sort of get results. But there seems to be an issue with the, uh...texture map? UVs?
View attachment 58940
It looks like it's intermittently using texture coordinates from the wrong spaces, because I can see layers of the sprite I created and are in the right places, and layers that are drawing from some other layer entirely, or from other sprites that definitely aren't mine (like the fog sprite). I tried moving my sprite to its own texture group but that just made things worse.

Forgive the color. It's a quick hack job on a 3d model that's using a 3-color palette system,based on RGB values, hence the garish colors.
Hmm interesting! First you can try turning off the 'auto cropping' option in GM. If that doesnt work, see if modifying the fauxton_model_create() by changing texture struct value to be the sprite texture instead like so:
GML:
function fauxton_model_create(sprite, _x, _y, _z, _xr, _yr, _zr, _xs, _ys, _zs)
    {
        ///@func fauxton_model_create(sprite, x, y, z, xrot, yrot, zrot, xscale, yscale, zscale)
        var _m = {
            spref        : sprite,
            texture        : sprite_get_texture(sprite, 0),
            pos_id        : ds_list_size(RENDER_QUEUE),
            model_id    : __FauxtonWriteSpriteStack(sprite, 0, 0, 0, c_white, 1, 0),
            position    : new vector3(_x, _y, _z),
            rotation    : new vector3(_xr, _yr, _zr),
            scale        : new vector3(_xs, _ys, _zs),
            matrix_id    : -1,
            draw_enable : true,
            isBBoard    : false,
            color       : c_white,
            alpha        : 1
        }
        _m.matrix_id = matrix_vec_build(_m.position, _m.rotation, _m.scale);
        RENDER_QUEUE[| _m.pos_id] = _m;
        fauxton_model_set(_m.pos_id, _x, _y, _z, _xr, _yr, _zr, _xs, _ys, _zs);
       
        return _m.pos_id;
    }
if the latter works, then you will need to also change this for the fauxton_model_create_ext() function as well. I will try to update this soon once I get the chance. :)
 
Background layers are just normal GM layers, so they aren't rendered by the engine, and thus by default will be set to 0 on the z-axis. You will want to make a background an object for this anyway if you want the lighting to affect it. :) IIRC this is what I am doing in the demo project as well. :) As for point light colors, you can get it by referencing the point light and getting the color variable from the light object. You can then use the color_get_red/green/blue to separate the channels if you need. Is that what you mean?
Not quite what I mean!

Here these cubes are red, the world lightning darkens them to black then the point light instead of turning them back red (Or the more complex colours of a proper sprite) it just turns them white (or the light colour) so any detail the sprites had will be lost.


Sp424rite-0061.png

I would like to know if it is possible to show the original sprites rather than just painting them the colour of the point light. Sprite-0042158.png

Sort of like a darkness system like I used here for my (award-winning rat_king87.PNG) game forest shack.
(Pushes off the desk the glue and paper strips with which he hastily paper-mached the award)

ratty lightr-export.gif
 
Last edited:

Gizmo199

Member
Not quite what I mean!

Here these cubes are red, the world lightning darkens them to black then the point light instead of turning them back red (Or the more complex colours of a proper sprite) it just turns them white (or the light colour) so any detail the sprites had will be lost.


View attachment 58944

I would like to know if it is possible to show the original sprites rather than just painting them the colour of the point light. View attachment 58945

Sort of like a darkness system like I used here for my award-winning game forest shack.
(Pushes behind the desk the glue and paper strips with which he paper-mached the award)

View attachment 58946
Ooh I see. I think its actually because my shader code is wrong!
Try changing the void main() for shd_default.fsh to this instead:
Code:
void main()
{
    vec4 col = texture2D( gm_BaseTexture, v_vTexcoord ) * v_vColour;

    // Alpha
    if ( col.a < 0.05 ) { discard; }

    // Diffuse and ambient
    float nDot = max(dot(v_vNormal, normalize(sun_pos)), 0.);
    col.rgb *= ( ambient_color ) + ( sun_color * sun_intensity ) * nDot;

    // Spot & Point lights
    vec3 col_add = vec3(0);
    if ( lightTotal > 0. ){
        float eval = 0.;
        for ( int i=0; i<64; i++ )
        {
            if ( float(i) > lightTotal ) { break; }
        
            if ( lightIsCone[i] == 1. ) {
                eval = evaluate_cone_light(v_vWorldPosition, v_vNormal, lightDirection[i], lightCutoffAngle[i], lightPos[i], lightRange[i]);
            } else {
                eval = evaluate_point_light(v_vWorldPosition, v_vNormal, lightPos[i], lightRange[i]);
            }
            col_add += eval * lightColor[i];
        }
    }

    // Final color
    col_add /= max(lightTotal, 1.);
    gl_FragColor = vec4(col.rgb + col_add, col.a);
}
I am pretty much using the same methodology as DragoniteSpams 3D Point & Spot lighting. So you can copy from his code as well if this doesn't work
 
Last edited:
My compile errors list lit up like a christmas light!

GML:
String not found:  at line 1 : HLSL11 compiler failed with exit code -1
Vertex Shader: shd_default at line 21 : 'texture2D'
Vertex Shader: shd_default at line 24 : 'discard'
Vertex Shader: shd_default at line 27 : 'sun_pos'
Vertex Shader: shd_default at line 27 : 'dot'
Vertex Shader: shd_default at line 28 : 'ambient_color'
Vertex Shader: shd_default at line 28 : 'sun_color'
Vertex Shader: shd_default at line 28 : 'sun_intensity'
Vertex Shader: shd_default at line 32 : 'lightTotal'
Vertex Shader: shd_default at line 38 : 'lightIsCone'
Vertex Shader: shd_default at line 38 : 'lightIsCone'
Vertex Shader: shd_default at line 39 : 'lightDirection'
Vertex Shader: shd_default at line 39 : 'lightDirection'
Vertex Shader: shd_default at line 39 : 'lightCutoffAngle'
Vertex Shader: shd_default at line 39 : 'lightCutoffAngle'
Vertex Shader: shd_default at line 39 : 'lightPos'
Vertex Shader: shd_default at line 39 : 'lightPos'
Vertex Shader: shd_default at line 39 : 'lightRange'
Vertex Shader: shd_default at line 39 : 'lightRange'
Vertex Shader: shd_default at line 39 : 'evaluate_cone_light'
Vertex Shader: shd_default at line 41 : 'lightPos'
Vertex Shader: shd_default at line 41 : 'lightPos'
Vertex Shader: shd_default at line 41 : 'lightRange'
Vertex Shader: shd_default at line 41 : 'lightRange'
Vertex Shader: shd_default at line 41 : 'evaluate_point_light'
Vertex Shader: shd_default at line 43 : 'lightColor'
Vertex Shader: shd_default at line 43 : 'lightColor'
Vertex Shader: shd_default at line 49 : 'gl_FragColor'
Vertex Shader: shd_default at line 49 : 'assign'
Vertex Shader: shd_default at line 21 : 'gm_BaseTexture'
Unfortunately I am not familiar enough with shaders vectors and matrices to be able to implement Dragonite's work.

Cursed be my ratty brain.

ratstothat2.PNG
 
Last edited:
Top