Search The Query
Search
how to make a simple sky-occlusion system

How to make a simple sky-occlusion system in Unreal by @DMeville

Continuing with our process or recompiling interesting twitter threads and in this case checking on an interesting tutorial on how to make a simple sky-occlusion system with Unreal by @DMeville.

Original Twitter Thread: how to make a simple sky-occlusion system

Edited witter Thread: how to make a simple sky-occlusion system

A breakdown thread of how to make a simple sky-occlusion system. I’m using this to block snow/rain from showing up on surfaces inside caves, under trees, in houses. Also can be used to mask particles! #gamedev #unrealengine #gameart

Starting from the third person template. Just moved up some of the geometry so we have something to stand under and act as a sky blocker. The heavy lifting of this effect is done by a SceneCapture2D, so lets add one of those too

The SceneCapture (going to shorten it to SC from now on) needs to have a rotation of (0, -90, -90), and also lets place it at (2000,2000,2000), which is approximately the center of our scene. Lets also set the capture source to "Final Color (LDR) in RGB"

A few more settings; Set projection to "Orthographic", Ortho width to "10000" and also disable ALL of the Show Flags except for: General – Landscape, Static Meshes, Translucency, Advanced – Instanced Static Meshes, Nanite Meshes, PP – Local Exposure, and Hidden – Post Processing

So now we have an ORTHOGRAPHIC top down scene capture, that will capture our entire scene. We turn of a lot of the show-flags do stop our SC from capturing things we don't need, so it gives a bit of a perf boost! (We don't need lighting, for example!)

It can be of Interest ;   Advices on how to get a job in the games industry by @NotSoLittleC

So now lets create a Render Target, and assign it to our SC so it can render into it. Changing our RT format to RTF R32F, because we only need the R channel to store data. As soon as we drop it into the SC, our scene shows up in the RT!

So at this point you might ask "Dylan, why is our RT only single channel (R), but we set our SC to render FINAL COLOR in RGB! WHY??". Shouldn't we use the Scene Depth capture? Turns out the Scene Depth capture is kind of weird, and ultimately we want scene height so…

We do this by giving our SC a post process, that just writes out the raw scene height to the RT! Create a new PP material, throw in worldpos.z into emission, and assign that to the Rendering Features/Post Process Materials slot on our SC! With this PP our RT changes a bit!

how to make a simple sky-occlusion system – Unreal Rendering Features

Now our RT is storing the RAW scene height! So we can just align this RT in worldspace to our objects so they match up, and then sample it to compare if we are below the stored height! So lets align it!

We create our material, assign it to the floor, and then do a little bit of math to calculate uvs that line up. Be sure to put in the right SC_Position, and SC_OrthoWidth, otherwise it won’t line up! Use these UVS to sample our RT!

Right now, our material is just outputting the raw depth, so anything above 0 is just white, but if we compare this depth to the depth of the pixel we're rendering, we can find out if it is above or below, and properly mask!

how to make a simple sky-occlusion system – Comparing a depth to depth Pixel rendering

So all that if is doing is returning 0 or 1 depending on if the ground surface is above or below our stored RT height. Bias is just a small value to offset the height if you want! Now we can use this mask to control a lerp or whatever you want in a material!

It can be of Interest ;   Twitter Thread:: Getting the most out of your grayscale noise textures by @tech_art_tyler

We can use this same material and throw it on some particles too!

how to make a simple sky-occlusion system – Particles Effect

Right now, the SC doesn't move, and so the area that is captured is always the same area. If you were to run 10000 units away, the capture wouldn't follow you…so lets fix that! We are going to do this with a simple blueprint that just moves the SC with the main camera..

We also are going to use a Material Parameter Collection, so lets create that first and add two variables for it, one scalar for OrthoWidth, and one Vector for the SC position. In our BP we are going to set the values here, and then in our material we can get these set values!

how to make a simple sky-occlusion system - Materials Edition
how to make a simple sky-occlusion system – Materials Edition

Next, create a BP with parent class actor. Add a new variable of type "Scene Capture 2D Object Reference" and set it to public and compile. Drag this BP into the scene, and assign the SC in our scene to our BP variable.

how to make a simple sky-occlusion system
how to make a simple sky-occlusion system

Here is our BP! Getting the player camera position, and moving our SC to match that position every tick. Also storing this new position in the MPC for our material to use in the aligning process. Also lets just hardcode our OrthoWidth in the MPC (forgot to do this earlier!)

If we press play and run around, we can see that our SC IS moving when our player moves, but now it's not aligned! This is because our material is still using the old (hardcoded) position when trying to align, but this position changes when we move now…so lets fix that!

how to make a simple sky-occlusion system

We just need to swap out our two variables to use Collection Parameters instead (the ones we set in the MPC)

It can be of Interest ;   Twitter Thread: The benefits of low-fidelity art styles in games by @bynineB
how to make a simple sky-occlusion system - Collections Parameters
how to make a simple sky-occlusion system – Collections Parameters

Aligned! But it's a bit WOBBLE-Y. This is because the SC is being positioned at values that when we try and align the RT it is "between pixels" so it kind of jitters around, but we can fix this by snapping the camera position in our BP to a nicer value!

how to make a simple sky-occlusion system

We can do this by adding in a "Vector Snapped To Grid" node, and for our "In Grid Size" we use "1/(RT Size)*(OrthoWidth)", which evaluates to 39.0625 for me. (thanks to @GhislainGir for this trick!). Compile it, press play and….

how to make a simple sky-occlusion system – Vector Snapped to grid

NO MORE JITTER!

how to make a simple sky-occlusion system – Without Jitter

A few notes; You could in BP begin play get the RT Size and SC Ortho Width and store them in the Material Parameter Collection instead of hard coding values. You probably should actually, but for brevity I'm skipping this step for now. Will fix this up at the end!

Additionally, You can change the RT size to be smaller/larger if you want. Smaller should be faster, but more pixely. The SC is also set to capture EVERY frame, which is probably unnecessary. Lets edit the BP to only recapture once the player moves some distance away

On the SC, uncheck "Capture Every Frame" and "Capture on Movement" and in our BP add this code. This checks to see if the current camera pos is at least X units away from the last capture position, and if so, recapture and store that as our latest position.

how to make a simple sky-occlusion system – Capture every frame

We added a print to display onscreen every time the SC recaptures, and you can see now it's every second now instead of every frame, this is much nicer on your framerate! The drawback here is that any blockers that move won't be picked up in the RT until the next capture happens

how to make a simple sky-occlusion system – Adding information

Sampling the mask on the player!

how to make a simple sky-occlusion system – Sampling the mask on the player

OK THATS ALL FOR NOW. May put together a ramble-y youtube video today also, but feel free to ask questions or offer suggestions if you have them!

YT version here:

Originally tweeted by Dylan Meville (@DMeville) on October 27, 2022.

9 Comments
  • Slot88 says:
    Your comment is awaiting moderation. This is a preview; your comment will be visible after it has been approved.
    I’d like too find out mⲟre? I’d lіke to find ᧐ut more detailѕ. Look into my page … Slot88
  • polio virus says:
    Your comment is awaiting moderation. This is a preview; your comment will be visible after it has been approved.
    Gammacoronavirus (Gamma-CoV) is without doubt one of the four genera (Alpha-, Beta-, Gamma-, and Delta-) of coronaviruses. It is within the subfamily Orthocoronavirinae of the household Coronaviridae. They’re enveloped, optimistic-sense, single-stranded RNA viruses of zoonotic origin. Coronaviruses infect both animals and humans. While the alpha and beta genera are derived from the bat gene pool, the gamma and delta genera are derived from the avian and pig gene pools. Gamma-CoV also referred to as coronavirus group 3 are the avian coronaviruses. Worldwide Committee on Taxonomy of Viruses. Woo Pc, Lau SK, Lam CS, Lau CC, Tsang AK, Lau JH, Bai R, Teng JL, Tsang CC, Wang M, Zheng BJ, Chan KH, Yuen KY (2012). “Discovery of seven novel Mammalian and avian coronaviruses in the genus deltacoronavirus supports bat coronaviruses because the gene source of alphacoronavirus and betacoronavirus and avian coronaviruses because the gene source of gammacoronavirus and deltacoronavirus”. J. Virol. 86 (7): 3995-4008. doi:10.1128/JVI.06540-11. This web page was last edited on 30 January 2023, at 12:48 (UTC). Text is obtainable below the Inventive Commons Attribution-ShareAlike License 3.0; further phrases could apply. Through the use of this site, you conform to the Phrases of Use and Privateness Policy. Wikipedia® is a registered trademark of the Wikimedia Basis, Inc., a non-profit organization.
  • gate io says:
    Your comment is awaiting moderation. This is a preview; your comment will be visible after it has been approved.
    At the beginning, I was still puzzled. Since I read your article, I have been very impressed. It has provided a lot of innovative ideas for my thesis related to gate.io. Thank u. But I still have some doubts, can you help me? Thanks.
  • Dyetetor says:
    Your comment is awaiting moderation. This is a preview; your comment will be visible after it has been approved.
    sex teen big ass http://www.angryforum.com/proxy.php?link=https://tubesweet.xyz/ https://en.8division.com/member/login.html?returnUrl=https://tubesweet.xyz/ https://sikanosuke.com/iframe/hatena_bookmark_comment?canonical_uri=https%3A%2F%2Ftubesweet.xyz http://www.polar.co.kr/member/login.html?noMemberOrder=&returnUrl=http%3a%2f%2ftubesweet.xyz
  • https://cstrade.ru/bitrix/rk.php?goto=https://parenting.ra6.org/responsive-parenting-and-sleep-training.htm says:
    Your comment is awaiting moderation. This is a preview; your comment will be visible after it has been approved.
    Great blog you’ve got here.. It’s difficult to find good quality writing like yours these days. I really appreciate people like you! Take care!!
  • Pay4d SLot says:
    Your comment is awaiting moderation. This is a preview; your comment will be visible after it has been approved.
    Good day! Would you mind if I share your blog with my myspace group? There’s a lot of people that I think would really enjoy your content. Please let me know. Thanks
  • gate.io says:
    Your comment is awaiting moderation. This is a preview; your comment will be visible after it has been approved.
    I may need your help. I tried many ways but couldn’t solve it, but after reading your article, I think you have a way to help me. I’m looking forward for your reply. Thanks.
  • Anmelden says:
    Your comment is awaiting moderation. This is a preview; your comment will be visible after it has been approved.
    I don’t think the title of your article matches the content lol. Just kidding, mainly because I had some doubts after reading the article. https://www.binance.com/de-CH/register?ref=S5H7X3LP
  • Открыть счет в binance says:
    Your comment is awaiting moderation. This is a preview; your comment will be visible after it has been approved.
    Thanks for sharing. I read many of your blog posts, cool, your blog is very good. https://accounts.binance.com/bn/register?ref=UM6SMJM3
  • Leave a Reply

    Your email address will not be published. Required fields are marked *