God Rays

author:
Daniel Sperl
description:
Atmospheric lighting, like the typical effects you see underwater or in a forest.
compatible:
v2.2
tag:
light, god ray, sun ray
homepage:
https://gist.github.com/PrimaryFeather/e05a738e60c4253564d8a0f7866c5384

Overview

A quad that efficiently draws a 2D light ray effect on its surface. That's useful for adding atmospheric effects, like the typical effects you see underwater or in a forest. (Demo Source.)

Play around with the different settings to make it suit the style you want. In addition to the class-specific properties, you can also assign an overall color or different colors per vertex.

Add it to a juggler or call advanceTime so that the effect becomes animated.

var godRays:GodRayPlane = new GodRayPlane(320, 200);
godRays.color = 0xff8000;
godRays.speed = 0.1;  // animation speed
godRays.size = 0.1;   // number of rays ~= 1 / size
godRays.skew = 0;     // angle of rays
godRays.shear = 0;    // spread of angle
godRays.fade = 1;     // rays fade out towards the bottom
godRays.contrast = 1; // distinctiveness and brightness of the rays
 
addChild(godRays);
Starling.juggler.add(godRays);
Internally, the class creates a Perlin noise texture. Each frame, only one pixel row of this texture is displayed – stretched from top to bottom. The displayed row changes over time: this is what causes the rays to twinkle. By adjusting the texture coordinates, the angle and spread of rays can be determined.

Since most of the work is done in a shader, this effect is very lightweight and renders really fast. A MeshStyle, together with a MeshEffect, does the heavy lifting.

Changelog

  • 2017/10/10: First public version
  • 2021/01/15: Exposed 'textureOffset' property. Thanks to aureliendc for the pull request!

Feel free to edit this part of the page if you want to add information that's lacking in the above description.
Questions are better asked in the forum, though.

  extensions/god_rays.txt · Last modified: 2021/01/15 09:54 by daniel
 
Powered by DokuWiki
{"cc_re__cc_re__cc_by_sa_4_0_en": ["  <form class=\"button btn_index\" method=\"get\" action=\"/extensions/god_rays\"><div class=\"no\"><input type=\"hidden\" name=\"do\" value=\"index\" /><button type=\"submit\" accesskey=\"x\" title=\"Sitemap [X]\">Sitemap</button></div></form>      </div>\n      <div class=\"clearer\"></div>\n    </div>\n\n    <div class=\"credits\">Powered by <a href=\"http://www.dokuwiki.org\">DokuWiki</a></div>\n\n    <!-- <div class=\"license\">Except where otherwise noted, content on this wiki is licensed under the following license: <bdi><a href=\"https://creativecommons.org/licenses/by-sa/4.0/deed.en\" rel=\"license\" class=\"urlextern\">CC Attribution-Share Alike 4.0 International</a></bdi></div> -->\n    <!--  -->\n    \n  </div>\n\n</div>\n\n<div class=\"no\"><img src=\"/lib/exe/taskrunner.php?id=extensions%3Agod_rays&amp;1675742897\" width=\"2\" height=\"1\" alt=\"\" /></div>\n</body>\n</html>\n"]}