Coder Social home page Coder Social logo

2d-3d-visibility's Introduction

Some 2D-3D visibility experiment

Demo

I had an idea for a simple 2d/3d visibility effect, and this is the result in Unity. Basically it applies the "soft shadows" effect from here to a 3d world.

Basically, what's happening is that there's two cameras: one 2d camera and one 3d camera. The 2d camera projects the walls into an "occlusion texture", and that texture is used to generate the 2d visibility texture. That visibility map is then rendered into a "cumulative visibility texture", which represents the black/white areas in the scene.

When it comes time to render the 3d objects, you pass the VP matrix of the orthographic camera to the shader and project every point in the orthographic cameras space. The UV coordinate of each vertex in the visibility textures is passed to the fragment shader. In the fragment shader, the interpolated value is used to figure out how to render by sampling the visibility textures.

Obviously, many optimizations and visual improvements can be made, the most obvious one being applying a circular blur to the visibility texture to give it a soft blur. There are also some annoying visual artifacts, mostly related to the visibility calculation algorithm (though those might go away as well with some blurring).

But this was just a weekend project for me, and I think it's kind-of a neat trick. With some work this could be used in a proper game.

Just a warning: I haven't one through and properly cleaned up the source and shader code, so it might be a bit messy. If you have any questions, let me know! My email is my github username @ gmail.com.

The code is MIT licensed, so you can pretty much do whatever with it, but if you do use it for something, I would really appreciate to hear about it!

2d-3d-visibility's People

Contributors

oskarsigvardsson avatar

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.