Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add shadow to buildings #575

Closed
schedul-xor opened this issue Aug 29, 2018 · 9 comments
Closed

Add shadow to buildings #575

schedul-xor opened this issue Aug 29, 2018 · 9 comments
Milestone

Comments

@schedul-xor
Copy link

Since buildings are a kind of polygons, it should be possible to add shadows by tracing well known techniques (for example "shadow mapping"). It will be nice to add a directional light using the sun's ray.

TL;DR

I've tried shadow mapping implementation, but it's not finished. I think I'm almost there, but I need help.

Not-finished product (INTENSE FLASHING CAUTION): schedul-xor@2c6294b
(To run the product, (1) rewrite vtm-playground/build.gradle mainClassName = "org.oscim.test.SimpleMapTest" (2) ./gradlew :vtm-playground:run)

image

My strategy

It was to integrate this technology. Depth packing functions are (almost) copied from this page.

What I've done:

  • Copy the source of OffscreenRenderer, rename it to ShadowRenderer.
  • Build an orthogonal projection matrix, because it's a directional light.
  • Build shadow map texture by rendering "building" polygons (actually the depth) to the frame buffer.
  • Read the shadow texture from frame buffer and render the final shadow.

As a result

I succeeded to render shadow map, but failed to render the final shadow.

Problems

  • Shadow maps are flashing. It should affect to the shadow rendering. Why flashing? Double buffering not working correctly?
  • Buildings are expected to be rendered twice (first when building shadow map, second when rendering directly), but the second rendering failed unless mRenderer.update() was called. I'm not sure why.
  • I've prepared 800x800 plane to check if it works, checked out that it works, but not sure why 800 is enough.
  • The final shadow is not rendered. Where did I mistake?
  • I've been working on this for eight days, but no progress. It's nearly uncontrollable. This feature needs technical support.
@Gustl22
Copy link

Gustl22 commented Dec 16, 2018

Thanks @schedul-xor: Gettin closer :)

screenshot from 2018-12-16 17-57-34

@devemux86 devemux86 changed the title Add shadow to buildings (need help!) Add shadow to buildings Jan 22, 2019
@Gustl22
Copy link

Gustl22 commented Jan 22, 2019

We have to clarify some design decisions (checkout my branch):
Since shadow feature (ShadowRenderer) is much more dependent on the ExtrustionRenderer than other Renderers we have the following options:

  1. Extend ShadowRenderer from ExtrusionRenderer and decouple BuildingRenderer from ExtrusionRenderer, so depending on wether the shadow is activated use the one of them. (seems difficult, and needs setters)
  2. provide setters in ExtrusionRenderer to be more flexible with ShadowRenderer and must of course be synchronized.
  3. fully integrate shadow feature in ExtrusionRenderer with clearly distinguishable on/off toggle. (simplest solution)

Second solution, is the one of schedul-xor and mine. But there are these bugs to solve:

  • the tiles have to be released to remove flickering, so we have to use the commonly render(GLViewport viewport) and use following setters.
  • setter for current shader
  • setter for usage of light
  • setter for light to shadowMap matrix

@devemux86
Copy link
Collaborator

A user intuitive solution would be to toggle on/off the shadows without changing renderer classes.

Something like the current extrusion height change happening nicely in real time (#462).

@Gustl22
Copy link

Gustl22 commented Jan 23, 2019

As said...without modyfing the ExtrusionRenderer, wouldn't be possible (at least the setters).

@schedul-xor
Copy link
Author

ShadowRenderer is currently depending on ExtrusionRenderer, but is probably expected to stand on it's own feet in the future. Building polygons are currently generated only from extrusion, and is better to leave room for improvement ... for example, to support additional 3d polygon data (using com.badlogic.gdx.graphics.g3d.model.*) later. Extending ExtrusionRenderer, in my opinion, is not a good idea.

How about adding multiple "Shadowable renderer" to ShadowRenderer, and let ExtrusionRenderer implement "Shadowable renderer" interfaces?

Can ExtrusionRenderer be used only as a rule-based 3d polygon generator? Actually it currently is, but it also contains complex building shaders.

@Gustl22
Copy link

Gustl22 commented Feb 3, 2019

How about adding multiple "Shadowable renderer" to ShadowRenderer, and let ExtrusionRenderer implement "Shadowable renderer" interfaces?

Can be possible, but would only be a more abstract version of a fully integration of shadow into ExtrusionRenderer. I will try out some constellation and can discuss them on PR :)

Can ExtrusionRenderer be used only as a rule-based 3d polygon generator?

Would be a good approach, to isolate rendering from the shaders and have a more modular / customizable ExtrusionRenderer...

This was referenced Feb 8, 2019
@devemux86
Copy link
Collaborator

After latest merges, what is the state of this feature?

Gustl22 added a commit to Gustl22/vtm that referenced this issue Feb 20, 2019
@devemux86 devemux86 added this to the 0.11.0 milestone Feb 20, 2019
@devemux86
Copy link
Collaborator

Closed via #668.

@devemux86
Copy link
Collaborator

Another sample of the nice work and the library's power:

3d_shadows

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants