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

Added directional lights #2

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

freaknbigpanda
Copy link
Collaborator

So I just did the super simple way of doing this and added a new shader for the directional lights and then inside the render loop I am switching between the two shaders using glUseProgram (i.e. instantiating a ProgramContext with the appropriate ProgramResource).

I do want to try to use the same shader for everything so I am going to look into that next, I think it will simplify the code. Let me know what you think too!

Copy link
Owner

@eyebrowsoffire eyebrowsoffire left a comment

Choose a reason for hiding this comment

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

Thank you for doing this! Looks mostly good, although there are some issues with the handling of the uniforms, which I commented on.

This approach is fine for now, but I'd eventually like to get the lights to work a little more like the objects work, where the objects are encapsulated in a group, and that group has a subsystem that owns its shader program and all the uniforms and such. The solution where I'm passing the uniforms down into the scene when rendering the lights is pretty awkward.

@@ -5,17 +5,36 @@
namespace rev {

class Light {
Copy link
Owner

Choose a reason for hiding this comment

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

I think having a shared base class here isn't really worth it, IMO. They only really share the one member and some getters, and the inheritance looks kind of like polymorphism even though they can't be polymorphic (no virtual functions). I they do share some properties and there may be a way to leverage that at some point, but let's not worry about that right now. After all, the fragment shaders they use are mostly copy/pasted anyway even though they share a lot of the same code.

const glm::vec3& getBaseColor() const;
void setBaseColor(const glm::vec3& color);

const glm::mat4x4& getLightSpaceTransform() const;
Copy link
Owner

Choose a reason for hiding this comment

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

I think these are unimplemented and uncalled.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Forgot to delete these


uniform vec3 lightDirection;
uniform vec3 lightBaseColor;
uniform vec3 camPosition;
Copy link
Owner

Choose a reason for hiding this comment

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

OMFG this uniform was never set before! I knew there was something weird about how the specular highlights were moving in relation to the camera.

Copy link
Owner

Choose a reason for hiding this comment

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

Actually it was set above, nevermind.

// Render all point lights
{
ProgramContext programContext(_pointLightingProgram);
_lightPosition = _pointLightingProgram.getUniform<glm::vec3>("lightPosition");
Copy link
Owner

Choose a reason for hiding this comment

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

You should get these uniforms once, and store them (probably above, where all the other uniforms are initialized). This also means you'll have to store separate versions of base color and cam position for the two shaders.

Also, make sure you actually set the value of the camera uniform before you actually call renderAll[Directional|Point]Lights on the scene. As of right now, it is only being set above right after getting the render context, which means the first time the uniform object is bound to nothing (not sure what the behavior is there), and all subsequent times it is only bound to the last bound shader (which in this case would be the directional one.

@freaknbigpanda freaknbigpanda force-pushed the adding_directional_lights branch from 7cc04e5 to 4bdd4b0 Compare February 3, 2019 19:08
@freaknbigpanda freaknbigpanda force-pushed the adding_directional_lights branch from 4bdd4b0 to 1132b88 Compare February 11, 2019 17:53
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