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

Light data appears to be inaccessible in shaders #9474

Closed
cart opened this issue Jul 2, 2017 · 4 comments
Closed

Light data appears to be inaccessible in shaders #9474

cart opened this issue Jul 2, 2017 · 4 comments

Comments

@cart
Copy link
Contributor

cart commented Jul 2, 2017

Operating system or device - Godot version:
Arch Linux, godot 3.0 bb9daac

Issue description:
I would like to access light data (specifically light positions) in my shaders, but it does not appear to be exposed.

First I tried accessing "omni_lights" and "omni_light_indices" (declared + used in scene.glsl) in my fragment() and light() shader functions. They were inaccessible.

Then I tried adding the following lines to shader_compiler_gles3.cpp:

	actions[VS::SHADER_SPATIAL].renames["OMNI_LIGHTS"] = "omni_lights";
	actions[VS::SHADER_SPATIAL].renames["OMNI_LIGHT_INDICES"] = "omni_light_indices";
	actions[VS::SHADER_SPATIAL].renames["OMNI_LIGHT_COUNT"] = "omni_light_count";
	actions[VS::SHADER_SPATIAL].usage_defines["OMNI_LIGHTS"] = "#define USE_FORWARD_LIGHTING\n";

But the new names (ex: "OMNI_LIGHTS") were also inaccessible. I'm guessing their types also need to be registered in shader_types.cpp, but it looks like theres no way to register struct or array types. Which is a problem because omni_lights is an array of LightData.

Unless I hear otherwise, I won't continue working on this as I'm guessing @reduz probably knows how this should be done.

Or maybe this functionality already exists and I'm totally wrong 😄

@karroffel karroffel added this to the 3.0 milestone Jul 2, 2017
@reduz
Copy link
Member

reduz commented Aug 7, 2017

light shaders are kinda broken, this is a reminder to myself to fix the,..

@curly-brace
Copy link

does it also concerns spatial shaders? i want to know light vector (and may be strength will be also good thing to know) to calculate stuff on the planet atmosphere, but there is nothing in spatial shader that concerns lights.

@reduz
Copy link
Member

reduz commented Nov 6, 2017

this is fixed now

@reduz reduz closed this as completed Nov 6, 2017
@cart
Copy link
Contributor Author

cart commented Nov 7, 2017

While we do have light shaders now (accessible via the light() function), they still aren't a full solve for me.

The specifics of my scenario:
I am selecting a texture to sample based on light intensity (calculated using light distance, attenuation, etc of the lights in the scene). The albedo is set to the sampled texture color. This is used to create a "sketchy shader" effect viewable here. I am currently hard coding light information but I have no way of accessing the real lights. I could try to recreate the effect by setting DIFFUSE_LIGHT to the sampled color in light shaders, but this is both more expensive (as I need to sample the texture once per light) and less flexible.

Exposing the raw light data would enable more shader types and it wouldn't be any more expensive. That information is already in scope for vertex and fragment shaders in scene.glsl, it just needs to be bound to godot's shading language.

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

4 participants