Coder Social home page Coder Social logo

krutibaraiya / curvedshadows Goto Github PK

View Code? Open in Web Editor NEW
1.0 2.0 1.0 7.71 MB

Algorithmic implementation of the research paper "Casting Curved Shadows on Curved Surfaces" by Lance Williams, 1978

CMake 0.10% C++ 1.19% GLSL 0.18% HTML 79.20% CSS 1.65% JavaScript 2.14% TeX 15.55%
shadow-mapping 3d-graphics shaders glfw

curvedshadows's Introduction

Casting Curved Shadows on Curved Surfaces

OpenGL implementation of shadow mapping as described in the research paper by Lance Williams, 1978.

Course Project for IS F311- Computer Graphics @ BITS Pilani, Hyderabad Campus.

Algorithm:

The algorithm described in the paper consists of two steps:

  • Consider a single light source. The entire view of the scene is constructed from the light source’s point of view by computing and storing only the Z values in a depth buffer/depth map.

  • Then the scene is constructed from the observer’s (camera) view by a linear transformation mapping of coordinates from observer’s view to the precomputed light source’s view. As each point is generated, it is tested for visibility i.e. if the point is not visible to the light source, then it lies in the shadow region. This is then shaded accordingly.

obsview lightview
From observer's view From light source's view

Doxygen documentation

Html Documentation

Challenges:

1) Shadow acne

withshadowacne withoutshadowacne
With shadow acne Without shadow acne

Closer look of the above scene on left shows us distinct, alternating black lines and speckled patterns (Moire pattern). This is because of the resolution of the shadow map. When far away from the light source, multiple fragments can sample the same value from the depth map. This is an issue when the light source is inclined at an angle because the depth map is also rendered from that inclined angle. This tilted depth texel is used by multiple fragments, while some above and some are below the surface. The “raised” pixels cast small shadows onto their neighbours. Some fragments are considered to be the shadow and some aren’t, hence giving the speckled Moire pattern.

The solution to this issue is to add a “bias” (error margin) i.e we simply offset the z-coordinates by a bias so that they aren’t incorrectly considered below the surface. After adding the bias, all samples get a depth smaller than the surface's depth and hence those “raised” pixels can’t cast a shadow anymore. Thus, removing the self shadowing/ shadow acne.

2) Peter Panning

withpeterpan withoutpeterpan
With Peter Panning Without Peter Panning

After adding the bias, we notice that the objects seem detached from their shadows. It gives a hovering effect to the objects and the phenomenon is called Peter-Panning. This is because by applying bias, we are actually adding an offset to the depth. To correct this issue we keep a small, un-noticeable and varying bias which is dependent on the angle between the surface and light source. We also enable face culling with glEnable(GL_CULL_FACE); which solves Peter Panning for solid objects.

3) Aliasing

withjaggededge withoutjaggededge
With Jagged edges Without Jagged edges

In the above left image ,the edges of the shadows are extremely jagged. On the border, one pixel is white and the other is dark without any smooth transition in between them. This can be overcome by sampling the shadow map N times (16 times here) instead of one, this is PCF (Percentage Close Filtering). Use of Poisson sampling reduces aliasing. Neighbouring pixels in the small circular disc (called the Poisson disc) are sampled every time , thus creating a smooth shadow in the final output.

Final scene:

Final output scene

Camera Movements:

Control Action
W, S, A, D, ↑, ↓ front, back, left, right, up and down respectively
R Reset camera
Left click and drag Pan the scene
Scroll mouse Zoom
Q Quit

How to run:

  • The project is tested on Linux and built in C++ using the following libraries:
    • GLFW
    • GLEW
    • GLM
    • ASSIMP
    • CMake
  • To build : cmake -G "CodeBlocks - Unix Makefiles" /path/to/CurvedShadows
  • Run the output executable : ./CurvedShadows

Team members:

curvedshadows's People

Contributors

judyhopps24 avatar krutibaraiya avatar pjay20301 avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Forkers

pjay20301

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.