Luminous Chicken - 3D Lighting Shaders for GameMaker
A downloadable shader
There are three basic 3D light types: directional lights, point lights, and spot lights. These can be implemented using shaders. Here's a set of shaders (and a demo project) to do just that!
Because fog is also something one often wishes to make use of in addition to lighting, this also includes fog.
The asset package is for GameMaker Studio 2.3. I'm going to assume this is fine with everyone since 2.3 is now officially released.
What's Included
- Directional lights - defined by an XYZ direction vector and a light color.
- Point lights - defined by an XYZ position, a light color, and a range. Optionally you may specify an inner range where the light will start to fade.
- Spot lights - defined by an XYZ position, an XYZ direction vector, a light color, and a cutoff angle. Optionally you may specify an inner cutoff angle where the light will start to fade.
- The option to calculate the lighting in the fragment shader (looks better - this is what one usually wants) or the vertex shader (marginally faster - looks terrible with large triangles, particularly with spot lights).
- Pixel fog - defined by a color, a start distance, and an end distance. Optionally you may specify a strength modifier that will affect the amount that fog at the maximum distance will be blended to the color.
Optional Stuff
- Xpanda is a tool for sharing common code between shaders. Some may find it useful. You may find it useful if you want to implement 3D lighting as a part of multiple shaders, or if you want to have the effects work in HLSL. (I find it extremely useful.) Reformatting the code to conform to work in Panda isn't too much work, especially compared to actually using 3D in GameMaker, but if you want I've done it for $2.
- Documentation can be found here.
Vertex Formats
The shaders expect a 36-byte vertex format defined with a 3D position, a 3D normal, a 2D texture coordinate, and a 4D color. If your game builds vertex buffers with a different format, you will need to edit the attribute list in each shader. I won't do this for you; that's on you. Generally speaking, position/normal/texture/color is sufficient for just about everything and you're probably already using this anyway.
How Lighting Works
I've got a 3D GameMaker tutorial series going, which includes writing lighting shaders. Even if you use this asset, I strongly recommend having a rough idea of how the shaders work because it will make your life much easier in the future.
- 3D Directional Lights
- 3D Point Lights
- Fragment Shader Lighting (vs vertex shader)
- 3D Spot Lights
- 3D Spot Lights (advanced stuff)
- 3D Fog
Editing the Shaders
For the most part, basic lighting shaders do exactly one thing and you won't ever need to edit them - but in the case of point and spot lights, you may sometimes wish to edit the attenuation values to change the way light fades out. Those calculations can be found on the lines that contain float att = ... in each of the relevant shaders.
Don't do this unless you're experienced with shaders. As usual, I recommend Desmos or another graphing calculator to model falloff equations.
Price
As usual, the asset is free as-is. I'll fix simple or game-breaking bugs but more involved support requires payment via either Itch or Patreon. With that said, I don't imagine much about this asset will change going forward.
Notes
- The icon is based off of my late chicken. Appropriately, we named her "Noches" many years before I decided to name a lighting shaders after her. RIP Noches :(
- Alternatively, you can get it on the GameMaker Marketplace here.
Repository
N/A this time.
Credits
- The chicken icon and walking sprite was created by @alemunin
- The 3D meshes in the demo were created by kenney.nl
- The skybox in the demo was created by Spiney
- Xpanda is a tool for using shader includes in GameMaker by @kraifpatrik
Download
Click download now to get access to the following files:
Development log
- Some optimiz(s)ations and other minor additionsApr 23, 2022
- Added Xpanda includes, and other small changesSep 29, 2020
- Fixed some bugsAug 21, 2020
Comments
Log in with itch.io to leave a comment.
She was a good chicken :(