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

kb.DirectionalLight does not work with spherical world #191

Open
taiya opened this issue Mar 26, 2022 · 11 comments · May be fixed by #218
Open

kb.DirectionalLight does not work with spherical world #191

taiya opened this issue Mar 26, 2022 · 11 comments · May be fixed by #218

Comments

@taiya
Copy link
Collaborator

taiya commented Mar 26, 2022

Need add functionality to disable the spherical floor for being a shadow caster. Directional lights are modelled as lights positioned at infinity, causing world sphere to cast shadow on the object.

(incomplete) example from examples/keyframing.py

import logging
import kubric as kb
import numpy as np
from kubric.renderer.blender import Blender as KubricRenderer

logging.basicConfig(level="INFO")

# --- create scene and attach a renderer to it
scene = kb.Scene(resolution=(256, 256), frame_start=1, frame_end=20)
renderer = KubricRenderer(scene)

# --- populate the scene with objects, lights, cameras
scene += kb.Sphere(name="floor", scale=1000, position=(0, 0, +1000), background=True)
scene += kb.Cube(name="floor", scale=(.5,.7,1.0), position=(0, 0, 1.1))
scene += kb.PerspectiveCamera(name="camera", position=(3, -1, 4), look_at=(0, 0, 1))

# --- Add Klevr-like lights to the scene
scene += kb.assets.utils.get_clevr_lights()
scene.ambient_illumination = kb.Color(0.05, 0.05, 0.05)
# WARNING: HEMISPHERE WORLD BREAKS DIRECTIONAL LIGHTS!
# scene += kb.DirectionalLight(name="sun", position=(-1, -0.5, 3), look_at=(0, 0, 0), intensity=1.5)

...
@MrXandbadas
Copy link
Contributor

MrXandbadas commented Apr 1, 2022

Hello Taiya!
In the keyframing example mentioned above are the objects supposed to be inside the sphere or on the outer-side of the sphere?
I tried changing the value from +1000 to -1000 in the Spheres positioning. The resulting light across the scene changed dramatically:
rgba_00000
VS default:
rgba_00005

I'm not sure if this is helpful is any way, I just noticed while exploring that the objects rendered in the scene are on the inner side of the sphere at the bottom and thought it may be helpful to take the time to change it around; maybe even inquire further about the issue 😄 This project excites me!

@taiya
Copy link
Collaborator Author

taiya commented Apr 1, 2022

I am using the sphere as a "floor" – objects are inside the very large sphere at the bottom of it.
The advantage is that you won't have a horizon line, or at least it'll be smooth.
It's just an example, change as you see fit :)

@taiya taiya closed this as completed Apr 1, 2022
@taiya taiya reopened this Apr 1, 2022
@MrXandbadas
Copy link
Contributor

MrXandbadas commented Apr 6, 2022

Hi there,
I'm attempting to add a visible_shadows parameter onto the Object class. Yet I'm hitting a rock when it comes to actually getting it as a Trait. Where do I define a new trait/how do I successfully add one on as it isn't the same process I went through with the SpotLight addition I did. Changing the below setting in Blender will achieve the result we are looking for with this issue. I just cant for the life of me find out how to add it xD
I'll be digging though the code but thought It might help to actually just ask.

bpy.data.objects.visible_shadows = "Opaque" Default Setting causing the issue

bpy.data.objects.visible_shadows = "None" Setting required to fix Patch the Issue

image

@taiya
Copy link
Collaborator Author

taiya commented Apr 6, 2022

I cannot say I am the best person to attempt this, but let me give it a try and create a PR – shouldn't be too bad (last famous words). I wrote the first version of the sync logic, but then @Qwlouse changes it to an observer pattern based on traitlets. It works well but the logic is not trivial.

TL;DR you need to modify this file:
~/kubric/kubric/renderer/blender.py

@taiya
Copy link
Collaborator Author

taiya commented Apr 6, 2022

I think it might be bpy.context.object.cycles_visibility.shadow = False
And this is what I am basing it on link

@taiya
Copy link
Collaborator Author

taiya commented Apr 6, 2022

Assuming this scene:

scene += kb.Sphere(name="floor", scale=1000, position=(0, 0, +1000), background=True)
scene.ambient_illumination = kb.Color(0.05, 0.05, 0.05)
scene += kb.DirectionalLight(name="sun", position=(1, 0, 0), look_at=(0, 0, 0), intensity=1.5)

This is how you hack it by importing bpy:

from kubric.safeimport.bpy import bpy
bpy.data.objects["floor"].cycles_visibility.shadow = False

Let me try to push that property to core, as it's a pretty nice one to have.

@taiya taiya linked a pull request Apr 6, 2022 that will close this issue
@taiya
Copy link
Collaborator Author

taiya commented Apr 6, 2022

Alright, as far as the pull request gets merged, this can be closed.
Result: I used a "sun" (i.e. DirectionalLight) and keyframed the sun (because... why not):

keyframing

@MrXandbadas
Copy link
Contributor

MrXandbadas commented Apr 6, 2022

Yay! I'm glad you could fix the issue. I came across that same link in my searching's but am not yet as adept as you.
I cant wait To review see what you did to get it working!
🕺

@MrXandbadas
Copy link
Contributor

MrXandbadas commented Apr 6, 2022

~/kubric/kubric/renderer/blender.py

I was so close !!! xD
Had my head berried in there but was looking for a consistent way to implement it although this explains a bit :D

@taiya
Copy link
Collaborator Author

taiya commented Apr 6, 2022

adept lol I am not adept at all, it's the first time I touch this part of the code.
You can see it, it's here: https://github.com/google-research/kubric/pull/218/files

@MrXandbadas
Copy link
Contributor

🤣 In comparison to me you are
Take the damn compliment, at one stage this was an issue, now we have a solution 🥳

Yeah I was facepalming at line 135 in blender.py where you called the super() for the class and then pass it the shadow and the init value. Maybe I'll catch it next time xD

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

Successfully merging a pull request may close this issue.

2 participants