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 demo can take a few moments to load, but it should perform pretty well.

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.

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.

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 skybox and 3D meshes in the demo were created by the excellent synty studios

Other Relevant Projects

I've made a bunch of other things for 3D in Gamemaker that you might be interested in:

  • Collisions
  • Basic 3D lighting
  • Toon shading
  • Terrain editor
  • 3D model converter
  • Better D3D emulation


StatusReleased
CategoryAssets
Rating
Rated 5.0 out of 5 stars
(2 total ratings)
AuthorDragonite
Made withGameMaker
Tags3D, GameMaker, lighting, Shaders

Download

Download NowName your own price

Click download now to get access to the following files:

ChickenDemo.zip 6 MB
chickens.yymps 38 kB

Development log

Comments

Log in with itch.io to leave a comment.

Deleted 1 year ago
(+3)

She was a good chicken :(