Giter Site home page Giter Site logo

plannarshadowforunity's Introduction

PlannarShadowForUnity

Although Planar Shadow is a kind of old school, it is very cheap and useful for mobile games. Unity’s default shadow system use Shadowmap. It needs more power of Pixel Shader and Render Targets. That means that Shadowmap system is expensive especially on mobile devices. Not only for Unity, other engins are the same.

Actually, the Planar Shadow is not real shadow. It is just a mesh. But, it looks like a shadow by pressing/projecting into plan using Vertex Shader. It doesn’t need much power of Pixel Shader. It uses a little bit of math, but, simple trigonometric function. See image below : P is a point of the mesh and P' is a point of the shadow.

image

float4 vPosWorld = mul( _Object2World, v.vertex);
float4 lightDirection = -normalize(_WorldSpaceLightPos0); 
float opposite = vPosWorld.y - _PlaneHeight;
float cosTheta = -lightDirection.y;	// = lightDirection dot (0,-1,0)
float hypotenuse = opposite / cosTheta;
float3 vPos = vPosWorld.xyz + ( lightDirection * hypotenuse );
o.pos = mul (UNITY_MATRIX_VP, float4(vPos.x, _PlaneHeight, vPos.z ,1));  

Detailed explain(Korean) : http://ozlael.tistory.com/10

Pros is : cheap

  1. Core part is only for VS. PS handles only color and alpha (plus, Stencil)
  2. You can use LOD mesh for shadows. While, Shadowmap(Unity’s shadow) have to draw original mesh twice at least.
  3. Shadow doesn’t looks blocky. Mobile devices have to use blocky hard shadow because they doesn't have enough power to use soft shadows.

Cons

  1. Only for planar floor.
  2. Only sharp edge.
  3. Use Stencil. But, It is not a big deal nowadays because mobile devices are support it.

image Sample asset : https://www.assetstore.unity3d.com/kr/#!/content/45319

plannarshadowforunity's People

Contributors

ozlael avatar maryada6 avatar ozlael81 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.