Coder Social home page Coder Social logo

volumetric-occlusion-mask-srp's Introduction

WANT TO BLOCK STUFF FROM GETTING WET?! I GOTCHU FAM

screenshot screenshot screenshot

Edit 7/23/2018 - The system works okay as is, but I'm not really satisfied. Will be looking into make a system based around mesh distance fields to achieve this effect.

Using Unity 2018.2.0b7 Package Manager: Lightweight Render Pipeline 1.1.10-preview and Post-processing 2.0.7-preview

Most of the code is in LightweightPipeline.Render, be sure to replace the version of LightweightPipeline.cs that comes from the package manager with the included one in the project.

Occluder objects need a convex closed mesh renderer and an Occluder behaviour.

Access the global shader texture _CustomOcclusionMask to use the generated mask in an object's shader (to mask it's colour or whatever) or use the incldued CustomOcclusionMask.Asset Amplify Shader Function with ASE.

There is also an included ShowOcclusionDepth post process that shows the mask

Is probably slow and unoptimized, has some issues I'm still working out, but is a good starting point if someone is looking for a system like this.


https://www.youtube.com/watch?v=wDp5uLv2HrU

Been learning about the new scriptable render pipeline in unity 2018, stumbling along because I have no idea what I'm doing.

I wanted to make a system that would allow me to mask out shader effects based on other geometry and work properly with masking by depth. For example, in a snowy forest, I would like to control snow coverage with a global shader variable to affect all meshes, however some meshes (like inside a house) shouldn't get snow on them. I could manually paint masks for individual geometry but that sounds dumb.

Instead I create a cube (or any other concave closed mesh) and mark it with a special two pass shader. This shader renders the backface and frontface depth of the cube to calculate the cubes volume, and uses that to compare with the depth texture. If the pixel we're trying has a depth that falls between the frontface and backface depths, we know that pixel is within the blocking volume and should be masked out.

Volumes are baked into a OcclusionMask texture which I can sample in any shader to access the mask.

I will use this to easily make it so shader wet-ness effects (like animated water dripping on rocks) or snow on the ground doesn't appear in places they shouldnt (like inside houses, caves, etc). What's cool is that it obeys depth properly, so if we're looking "through" a occlusion mesh, only the pixels within the volume are masked, pixels "behind" the mask but off in the distance are not affected (as they would be if it was a simple screen space effect!)

More info of me trying to work through this problem on reddit: https://www.reddit.com/r/Unity3D/comments/8f2stm/how_would_you_go_about_making_a_shader_that_color/?st=jidwwnr0&sh=c9ff5f64


Do whatever you want with this code. Have questions?

volumetric-occlusion-mask-srp's People

Contributors

dmeville avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

Forkers

ignore444

volumetric-occlusion-mask-srp's Issues

Too Many Passes?

Could probably combine the backface and frontface depth passes into a single pass (cutting down on half the rendertexture swaps and clears).

We can get the sign of the face in the shader with the vface param, there's some sorting issues though that I need to work through because SHADERS ARE HARD and I don't know what I'm doing.

Should be able to render the backface depth to rt.r, frontface to rt.g, backface mask to rt.b, and frontface mask to rt.a. I think. Would be way better

Depth Issues

If we stick the camera so that only backface is rendered to the temp mask, things break because it doesn't have a corresponding frontface to test against so the mask disappears.

Mask Softness

Right now it's only sharp edges [0 or 1] values in the mask. It would be nice to have a "softness" falloff somehow. Can't really do thickness [frontface - backface depth] because that results in an object getting "thinner" the farther away from the camera it is. Precision issues or non-linear depth values? idk

Could maybe reconstruct world position from depth, and use that and the distance to the (closest?) face? not sure.

Shadows broke

dunno, probably an issue with one of my custom shaders

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.