Skip to content

SnowySnow

Michael edited this page Sep 9, 2021 · 5 revisions

What's this, I didn't name something after a bird? Impossible! I couldn't find a good snow-themed bird name that I liked (and I've already used "Penguin" for something else) so I just named it like a five-year-old.

A long time ago one of my CS teachers mentioned writing a shader that dynamically adds snow texture to the top sides of rotated objects (usually rocks). Ever since then I've had a minor obsession with that idea, so I finally did one myself.

To get started, download the YYMP from the Itch page and import it into GameMaker (Tools > Import Local Package).

Links

  • Snowy Snow can be found on Itch here.
  • If Yoyo ever fixes their marketplace I'll (probably) put it there too

Snowy Snow was written using GameMaker Studio 2.3.4. It relies on some of the language features added in 2.3.0, and won't work in anything older. I haven't tested it on anything other than 2.3.4, but it's pretty simple so it should work.

Demo program

The demo program should give you a pretty good idea of what this is for.

API

There's not too much to this one.

I'm going to refer to the texture that you blend onto the objects as "snow," but you can use it for other things. Moss comes to mind; see the demo program.

snowy_snow_apply(shader)

Returns: N/A

Parameter Type Description
shader shader The shader that you would like to apply. The only default option is shd_snowy_snow.

Enables the shader, and sets the appropriate shader uniforms. Use in place of shader_set unless you want to set the uniforms yourself.

snowy_snow_color(color, alpha)

Returns: N/A

Parameter Type Description
color color The color that the snow is to be blended with.
alpha real The maximum intensity of the blended snow.

If you want to tint the snow with some other color, you can use this function. In addition, the alpha value will determine the maximum blending of the snow texture with its base surface (eg an alpha value of 0.5 will mean that sky-facing faces are only 50% blended with the snow).

Yellow snow, etc etc etc, hahaha.

snowy_snow_cutoff(minor_cutoff, [major_cutoff])

Returns: N/A

Parameter Type Description
minor_cutoff real The angle where the snow begins to fade out, in degrees.
major_cutoff real The angle where the snow finishes fading out. Optional; defaults to the same value as minor_cutoff.

The cutoff is the angle after which the snow will disappear. You can also specify major and minor cutoff angles, which will cause the snow to fade smoothly on slopes rather than disappearing all at once. The angles should be in degrees; I recommend values somewhere between 30 and 45.

snowy_snow_texture(texture)

Returns: N/A

Parameter Type Description
texture texture The texture that you would like to apply to the snow. Note that this needs to be a texture, and not a sprite or surface resource.

The snow texture itself. Polyhaven has a number of good ones (warning: 4k textures use a lot of memory).

snowy_snow_up(xup, yup, zup)

Returns: N/A

Parameter Type Description
xup real The x component of the direction that will receive maximal blending with the snow.
yup real The y component of the direction that will receive maximal blending with the snow.
zup real The z component of the direction that will receive maximal blending with the snow.

The direction which the accumulation will be focused on. If you're making snow, that should probably be the direction of the sky. If you're making moss, that should probably be the direction of "north" (or south, if you're in the southern hemisphere). This is a normal vector.

snowy_snow_init()

Returns: N/A

You don't really have to worry about this one.

Extending the shader

This shader by default only computes the snow effect; it does not do things such as 3D lighting or other fancy effects. If you want to add anything of the sort yourself, there's a comment in the bottom of the fragment shader where you likely would want to do that.

Credits

  • The chicken walking sprite was created by @alemunin
  • The rock meshes in the demo were created by polyhaven.com
  • The snow texture in the demo was also created by polyhaven.com (although I honestly can't remember which one it was)
  • The skybox in the demo was created by Spiney
  • The iconigraphy is based on Snow by Loritas Aventura from the Noun Project
Clone this wiki locally