Dynamic sun WIP

Hey Ya.
To begin with, if the copyrights of other parties are not affected, then the idea (start, as well as the continuation) of CC0 1.0

What did I think of such a thing, if there is no such thing of course? I even try to work out / refine it.

You know that in Blender there is a binding of the sun to the tops of the player - it moves behind it and does not rotate.
I thought about this:

  • The sun has the resolution of the shadows, it is placed (in the shadows) along the center of the player, but in this case 3/4 of the shadows are always out of the review - the “dead” zone.
    And so I decided to make a script - dynamic sun, where the sun with the same resolution of shadows moves depending on the position and rotation of the character. That is, it actually uses a 100% shadow buffer, and this is that if you have 1024 classics, then with this script you will get 2048 - the resolution of the shadows. And this is a saving of 4 times video memory. There may be 4096, just not 1/4 in the camera review, but all ~ 100% (there is a couple% loss all exactly) …
    While there are developments, and I would not want that somewhere that someone did NOT licensed for themselves exclusively - the theory in CC0 1.0 is what I started WIP for. I love the GPL, I love copyright and I love the Blender community - better that everyone would have it. And there, though under Unity®, even under Unreal® or … (if there is no such technique) - everything is exactly for me.

Here is the scheme of work (principal):

Thank you for attention.

Here is the first working example - you can connect to the development, and you can make yourself separately …
Since I’m trying to develop a more universal script (at all angles), while the logic is far from the final one, but already there is something - the principle of work, and the angles and variations can be completed.
dynamic_sun01.blend (1.2 MB)
Thank`s.

1 Like

Usually I do:

def alignSunWithCamera(controller):
    sun = controller.owner
    camera = sun.scene.active_camera
    offset = sun.get('sun.offset', 16) # gameproperty
    sun.worldPosition = camera.worldPosition + sun.getAxisVect((0, 0, offset))

And this makes the sun to always be behind the player, so that shadows get computed around him.

1 Like

print(camera)
default__cam

name + vector ???

=========================
I have a cool idea?

1 Like

camera prints as its name, but it is a game object. Oh I made a mistake in the code, it should be camera.worldPosition not just camera, my bad. Fixed.

Fun fact: In Python you can make objects that can be printed:

class MyObject(object):
    def __init__(self, value):
        self.value = value

    def __str__(self):
        '''Return the string that should be displayed for your object'''
        return '<I am an object with value={}>'.format(self.value)

# usage:
>>> a = MyObject(12)
>>> print(a)
<I am an object with value=12>

Why do I tell you this ? Because the BGE most certainly used this mechanism to make GameObjects printable.

aww, but i like seeing all that memory space address number pile :smiley:

i thought about mentioning the worldPosition, but i wanted to see how long it took you to catch it. doesnt getVectTo() return [distance, global, local]?

anyway, back on topic… this is a good idea.

2 Likes

Indeed, getVectTo should be getAxisVect my bad. I will blame the current heat where I live for these mistakes :stuck_out_tongue:

But yes, the idea is pretty simple and I don’t see why we wouldn’t move the sun object with the point of view to shade the correct elements.

  • maybe yes :grinning: … 1/4 - this is not so much. 3/4 “dead” zone - it does not even sound awesome.