{"author_link":"\/users\/ava-skoog","author_name":"Ava Skoog","author_uid":"ava-skoog","comments":[],"epoch":1494683344,"event":"LD38","format":"md","ldjam_node_id":31002,"likes":3,"metadata":{"p_key":"93438","p_author":"Ava Skoog","p_authorkey":"1000196","p_urlkey":"306356","p_title":"Blomst : sunlight and fresnel","p_cat":"LDJam ","p_event":"LD38","p_time":"1494683344","p_likes":"3","p_comments":"0","p_status":"WAYBACK","us_key":"1000196","us_name":"Ava Skoog","us_username":"ava-skoog","event_start":"1492732800","event_key":"69","event_name":"LD 38"},"node":{"_collation":{"body_sanitizer":"TextUtils::SanitizeHTML via existing importer","event":"LD38","removed_author":false},"_superparent":9405,"_trust":15,"author":196,"body":"All right! This will be the third, and probably final, post in the serious on various technical stuff and graphical effects in our jam game, [Blomst \ud83c\udf3b](https:\/\/ldjam.com\/events\/ludum-dare\/38\/blomst\/). You can also check out [part one](https:\/\/ldjam.com\/events\/ludum-dare\/38\/blomst\/blomst-procedural-planets-shaders) about procedural planets and [part two](https:\/\/ldjam.com\/events\/ludum-dare\/38\/blomst\/blomst-atmosphere-saturation-fx\/) about shader effects!\n\n[**Go here if you want to play Blomst \ud83c\udf3b!**](https:\/\/ldjam.com\/events\/ludum-dare\/38\/blomst\/)\n\nIn this one, the subject is *lighting*! Plays both visual and functional roles in this game.\n\nThe *fresnel* (or *rim light*) looks nice, but it also makes it a little easier to see where things are on the dark side of the planet.\n\nThe *sunlight* not only illuminates the planet and brings out its eventual colours, but also makes plants grow and produce seeds when facing them throughout the cycling days on the sphere.\n\n# Rim light\n\nNo matter how dark the planet itself is, there is always a little bit of \"backlighting\" on the plants and the character to make them pop out and help the player find their way around. And it looks neat too! There is also one on the whole planet itself.\n\n![fresnel.png](\/\/\/raw\/4c\/z\/4468.png)\n\nThe effect is actually quite simple in theory, but requires a little bit of shader work. What it basically boils down to is shining a light at the object from behind, exactly towards the camera, so that some light ends up creeping up along the sides, giving that characteristic look with glowing edges:\n\n![fresnel2.png](\/\/\/raw\/4c\/z\/446b.png)\n\nAnd indeed, if we look at it from a different angle than that of the camera that the rim light is pointing toward, we can see how the opposite side is just entirely washed out by light:\n\n![fresnel3.png](\/\/\/raw\/4c\/z\/446c.png)\n\nThe trick lies in the fact that the rim light always points straight at the camera, so if the camera moves and rotates, so does the rim light, and we never actually see the washed out side, only the glowing edges, making the effect work. Cheap but pretty trick!\n\n# Sun\n\nThis is even simpler. The sun is just a regular *directional light*, and works with a little bit of cheating, as it is actually the sky and sun circling the planet rather than the other way around, the planet's transform being the parent of these two, so that they follow along with it as it turns (another cheat here, you see\u2014it's technically the planet rotating while the character stays in place as the player moves!).\n\nEvery time the sun completes a full 360\u00b0 rotation, the game counts a new day, and as the sun passes over plants on each day, they *grow* or might *produce seeds* depending on their current state.\n\nThe solution was to use the same maths that are also used in shader to calculate the actual lighting. The N\u2022L calculation does the trick, as the dot product between the surface normal and the direction of the light represents how directly the light is shining upon the geometry, and how much it should be lit, as demonstrated by this figure from [here](http:\/\/www.bigmessowires.com\/2009\/04\/30\/3d-breakdown\/):\n\n![lightequation.gif](\/\/\/raw\/4c\/z\/4475.gif)\n\nUsing the same calculation in the game logic, I could check whether the sun was passing over a plant, and have something happen to it, such as this \"sapling\" flower growing into its fullest as a new day dawns upon it:\n\n![ld38_solveks_optimert.gif](\/\/\/raw\/4c\/z\/4479.gif)","comments":0,"created":"2017-05-13T12:49:56Z","files":[],"files-timestamp":0,"id":31002,"love":3,"love-timestamp":"2017-05-13T16:39:53Z","meta":[],"modified":"2017-05-13T16:39:53Z","name":"Blomst \ud83c\udf3b: sunlight and fresnel","node-timestamp":"2017-05-13T13:49:04Z","parent":26124,"parents":[1,5,9,9405,26124],"path":"\/events\/ludum-dare\/38\/blomst\/blomst-sunlight-and-fresnel","published":"2017-05-13T13:49:04Z","scope":"public","slug":"blomst-sunlight-and-fresnel","subsubtype":"","subtype":"","type":"post","version":82505},"node_metadata":{"n_key":"31002","n_urlkey":"306356","n_parent":"26124","n_path":"\/events\/ludum-dare\/38\/blomst\/blomst-sunlight-and-fresnel","n_slug":"blomst-sunlight-and-fresnel","n_type":"post","n_subtype":"","n_subsubtype":"","n_author":"196","n_created":"1494679796","n_modified":"1494693593","n_version":"82505","n_status":"WAYBACK"},"source_url":"https:\/\/ldjam.com\/events\/ludum-dare\/38\/blomst\/blomst-sunlight-and-fresnel","text":"All right! This will be the third, and probably final, post in the serious on various technical stuff and graphical effects in our jam game, [Blomst \ud83c\udf3b](https:\/\/ldjam.com\/events\/ludum-dare\/38\/blomst\/). You can also check out [part one](https:\/\/ldjam.com\/events\/ludum-dare\/38\/blomst\/blomst-procedural-planets-shaders) about procedural planets and [part two](https:\/\/ldjam.com\/events\/ludum-dare\/38\/blomst\/blomst-atmosphere-saturation-fx\/) about shader effects!\n\n[**Go here if you want to play Blomst \ud83c\udf3b!**](https:\/\/ldjam.com\/events\/ludum-dare\/38\/blomst\/)\n\nIn this one, the subject is *lighting*! Plays both visual and functional roles in this game.\n\nThe *fresnel* (or *rim light*) looks nice, but it also makes it a little easier to see where things are on the dark side of the planet.\n\nThe *sunlight* not only illuminates the planet and brings out its eventual colours, but also makes plants grow and produce seeds when facing them throughout the cycling days on the sphere.\n\n# Rim light\n\nNo matter how dark the planet itself is, there is always a little bit of \"backlighting\" on the plants and the character to make them pop out and help the player find their way around. And it looks neat too! There is also one on the whole planet itself.\n\n![fresnel.png](\/\/\/raw\/4c\/z\/4468.png)\n\nThe effect is actually quite simple in theory, but requires a little bit of shader work. What it basically boils down to is shining a light at the object from behind, exactly towards the camera, so that some light ends up creeping up along the sides, giving that characteristic look with glowing edges:\n\n![fresnel2.png](\/\/\/raw\/4c\/z\/446b.png)\n\nAnd indeed, if we look at it from a different angle than that of the camera that the rim light is pointing toward, we can see how the opposite side is just entirely washed out by light:\n\n![fresnel3.png](\/\/\/raw\/4c\/z\/446c.png)\n\nThe trick lies in the fact that the rim light always points straight at the camera, so if the camera moves and rotates, so does the rim light, and we never actually see the washed out side, only the glowing edges, making the effect work. Cheap but pretty trick!\n\n# Sun\n\nThis is even simpler. The sun is just a regular *directional light*, and works with a little bit of cheating, as it is actually the sky and sun circling the planet rather than the other way around, the planet's transform being the parent of these two, so that they follow along with it as it turns (another cheat here, you see\u2014it's technically the planet rotating while the character stays in place as the player moves!).\n\nEvery time the sun completes a full 360\u00b0 rotation, the game counts a new day, and as the sun passes over plants on each day, they *grow* or might *produce seeds* depending on their current state.\n\nThe solution was to use the same maths that are also used in shader to calculate the actual lighting. The N\u2022L calculation does the trick, as the dot product between the surface normal and the direction of the light represents how directly the light is shining upon the geometry, and how much it should be lit, as demonstrated by this figure from [here](http:\/\/www.bigmessowires.com\/2009\/04\/30\/3d-breakdown\/):\n\n![lightequation.gif](\/\/\/raw\/4c\/z\/4475.gif)\n\nUsing the same calculation in the game logic, I could check whether the sun was passing over a plant, and have something happen to it, such as this \"sapling\" flower growing into its fullest as a new day dawns upon it:\n\n![ld38_solveks_optimert.gif](\/\/\/raw\/4c\/z\/4479.gif)","title":"Blomst : sunlight and fresnel","wayback_source":[]}