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

Correct point light attributes #211

Merged
merged 1 commit into from
Mar 12, 2024
Merged

Conversation

sercero
Copy link
Collaborator

@sercero sercero commented Mar 12, 2024

Based on the information here: https://wiki.ogre3d.org/-Point+Light+Attenuation

I changed the calculation for the Point Light parameters.

Had to introduce 10x factor because otherwise it does not look like in Blender.

This also solves the crash reported in #209

@sercero sercero merged commit 81b3b85 into OGRECave:master Mar 12, 2024
1 check passed
@sercero sercero deleted the light_distance branch March 12, 2024 03:20
@paroj
Copy link
Member

paroj commented Mar 12, 2024

sorry for being a little late here. See this for how light attenuation works in Ogre:
https://ogrecave.github.io/ogre/api/latest/class_ogre_1_1_light.html#details

however I cannot find anything on how light attenuation works in Blender mathematically..

@sercero
Copy link
Collaborator Author

sercero commented Mar 12, 2024

In the end I found a formula in the Wiki and used that.

Then I had to adjust 10x for some reason for it to look more closely to Blender.

However Blenders shaders are of course different than OGREs

light_range = ob.data.cutoff_distance * 10
if light_range == 0:
light_range = 0.001
a.setAttribute('range', light_range)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should be the same as cutoff_distance

a.setAttribute('range', light_range)
a.setAttribute('constant', '1.0')
a.setAttribute('linear', '%6f' % (4.5 / light_range))
a.setAttribute('quadratic', '%6f' % (75.0 / (light_range * light_range)))
Copy link
Member

@paroj paroj Mar 13, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should be 2/distance*distance if I read the blender docs and this correctly: http://learnwebgl.brown37.net/09_lights/lights_attenuation.html

the linear parameter should be 0

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, I'll look into it.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is very little difference, but I think that its better using 1/d^2.

  • With the formula: 1+4,5 / (10 *d) + 7,5 / (10 * d)^2
    screenshot20240314_223113852

  • Using the formula proposed in the site (1+ 1 / d^2):
    screenshot20240314_223247667

  • Blender:
    image

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there is a much clearer test that you can use:
grafik

Copy link
Member

@paroj paroj Mar 15, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

part of the issue is that powerScale in ogre is not the same as ob.data.energy:

forcing power scale to 1.0, instead of 1000 (energy) gives you:
grafik

the remaining issue is the ambient light setting, that ogre-meshviewer currently ignores (which is ok I think) and I guess blender does something special at the cutoff distance. some sort of fade-out whereas Ogre just does a hard cut.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There seems to be some sort of ambient lighting in Blender.

In OGRE I got a hard cut at 5 "meters" which was the range or distance.

In my case I was using shaders from https://learnopengl.com/

But yes, your idea of using a plane is much better.

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

Successfully merging this pull request may close these issues.

2 participants