Jump to content
  • Advertisement

WhiskyAndCode

Member
  • Content Count

    10
  • Joined

  • Last visited

Community Reputation

0 Neutral

About WhiskyAndCode

  • Rank
    Member

Personal Information

  • Interests
    Programming

Recent Profile Visitors

The recent visitors block is disabled and is not being shown to other users.

  1. WhiskyAndCode

    FrameBuffer / Multi light

    Dont work. I give up. Thank for all;
  2. WhiskyAndCode

    FrameBuffer / Multi light

    Yeah, but my question is about "How we really use light volumes" HAHAHAHAHAH It's difficult for me to get
  3. WhiskyAndCode

    FrameBuffer / Multi light

    Hello CCEL. Thank u for reply. But i would like to know how to render contless light using geometry. I'm following several tutorials, but I can not get this result. I do not know if any "LearnOpenGL" settings prevent the result. This is a personal goal, I have no interest in using engines, this is a goal for knowledge. If u can follow: https://stackoverflow.com/questions/53549406/how-to-add-countless-lights-in-framebuffer
  4. WhiskyAndCode

    FrameBuffer / Multi light

    Thank you all.
  5. WhiskyAndCode

    FrameBuffer / Multi light

    Hi _Silence_, thank u for reply. Because my project will have countless sources of lights, the weapons will be laser-type and the players will be able to shoot fire (there's fire light too), put up campfires. That is, I will focus a lot on lighting.
  6. WhiskyAndCode

    FrameBuffer / Multi light

    Yeah, I've been looking for this for at least 6 months.
  7. WhiskyAndCode

    FrameBuffer / Multi light

    Hey guys, thank u for all reply. English is not my native language and I find it difficult to express myself. But come on, following the learnopengl tutorial: https://learnopengl.com/Advanced-Lighting/Deferred-Shading the author leaves fixed the amount of light (32 lights) as shown by the GLSL: #version 330 core out vec4 FragColor; in vec2 TexCoords; uniform sampler2D gPosition; uniform sampler2D gNormal; uniform sampler2D gAlbedoSpec; struct Light { vec3 Position; color; }; const int NR_LIGHTS = 32; uniform Light lights [NR_LIGHTS]; uniform vec3 viewPos; void main () { // retrieve data from G-buffer vec3 FragPos = texture (gPosition, TexCoords) .rgb; vec3 Normal = texture (gNormal, TexCoords) .rgb; vec3 Albedo = texture (gAlbedoSpec, TexCoords) .rgb; float Specular = texture (gAlbedoSpec, TexCoords) .a; // then calculate lighting as usual vec3 lighting = Albedo * 0.1; // hard-coded ambient component vec3 viewDir = normalize (viewPos - FragPos); for (int i = 0; i <NR_LIGHTS; ++ i) { // diffuse vec3 lightDir = normalize (lights [i] .Position - FragPos); vec3 diffuse = max (dot (Normal, lightDir), 0.0) * Albedo * lights [i] .Color; lighting + = diffuse; } FragColor = vec4 (lighting, 1.0); } And when it comes to applying the lights: glBindFramebuffer (GL_FRAMEBUFFER, 0); // 2. lighting pass: calculate lighting by iterating over screen filled quad pixel-by-pixel using the gbuffer's content. glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); shaderLightingPass.use (); glActiveTexture (GL_TEXTURE0); glBindTexture (GL_TEXTURE_2D, gPosition); glActiveTexture (GL_TEXTURE1); glBindTexture (GL_TEXTURE_2D, gNormal); glActiveTexture (GL_TEXTURE2); glBindTexture (GL_TEXTURE_2D, gAlbedoSpec); // send light relevant uniforms for (unsigned int i = 0; i <lightPositions.size (); i ++) { shaderLightingPass.setVec3 ("lights [" + std :: to_string (i) + "] .Position", lightPositions [i]); shaderLightingPass.setVec3 ("lights [" + std :: to_string (i) + "] .Color", lightColors [i]); // update attenuation parameters and calculate radius const float constant = 1.0; // note that we do not send this to the shader, we assume it is always 1.0 (in our case) const float linear = 0.7; const float quadratic = 1.8; shaderLightingPass.setFloat ("lights [" + std :: to_string (i) + "] .Linear", linear); shaderLightingPass.setFloat ("lights [" + std :: to_string (i) + "] .Quadratic", quadratic); } shaderLightingPass.setVec3 ("viewPos", camera.Position); // finally render quad renderQuad (); I wish I could do this: uniform Light lights; uniform vec3 viewPos; void main () { // retrieve data from gbuffer vec3 FragPos = texture (gPosition, TexCoords) .rgb; vec3 Normal = texture (gNormal, TexCoords) .rgb; vec3 Diffuse = texture (gAlbedoSpec, TexCoords) .rgb; float Specular = texture (gAlbedoSpec, TexCoords) .a; // then calculate lighting as usual vec3 lighting = Diffuse * 0.1; // hard-coded ambient component vec3 viewDir = normalize (viewPos - FragPos); // diffuse vec3 lightDir = normalize (lights.Position - FragPos); vec3 diffuse = max (dot (Normal, lightDir), 0.0) * Diffuse * lights.Color; // specular vec3 halfwayDir = normalize (lightDir + viewDir); float spec = pow (max (dot (Normal, halfwayDir), 0.0), 16.0); vec3 specular = lights.Color * spec * Specular; // attenuation float distance = length (lights.Position - FragPos); float attenuation = 1.0 / (1.0 + lights.Linear * distance + lights.Quadratic * distance * distance); diffuse * = attenuation; specular * = attenuation; lighting + = diffuse + specular; FragColor = vec4 (lighting, 1.0); } And in C ++: glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); shaderLightingPass.use(); glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, gPosition); glActiveTexture(GL_TEXTURE1); glBindTexture(GL_TEXTURE_2D, gNormal); glActiveTexture(GL_TEXTURE2); glBindTexture(GL_TEXTURE_2D, gAlbedoSpec); // send light relevant uniforms for (unsigned int i = 0; i < lightPositions.size(); i++) { shaderLightingPass.setVec3("lights.Position", lightPositions[i]); shaderLightingPass.setVec3("lights.Color", lightColors[i]); // update attenuation parameters and calculate radius const float constant = 1.0; // note that we don't send this to the shader, we assume it is always 1.0 (in our case) const float linear = 0.7; const float quadratic = 1.8; shaderLightingPass.setFloat("lights.Linear", linear); shaderLightingPass.setFloat("lights.Quadratic", quadratic); shaderLightingPass.setVec3("viewPos", camera.Position); //My doubt is here } renderQuad(); My doubt is here, as I apply the lights above in the framebuffer, as if it were: configures light, persists in framebuffer, configures light, persists in framebuffer, configures light, persists in framebuffer, configures light, persists in framebuffer .... I'm sorry if I'm bothering too much, but this is very complicated to understand only in theory.
  8. WhiskyAndCode

    FrameBuffer / Multi light

    can anybody help me ?
  9. WhiskyAndCode

    FrameBuffer / Multi light

    Hello CrazyCdn, thanks for the reply. Up to this point I understood and implemented. However, what I want to know is how to accumulate lights in the framebuffer so I can use the amount of light source I want in a dynamic way. I found this tutorial (http://www.redway3d.com/downloads/public/documentation/wf_deferred_shading.html), and a very interesting pseudocode: for each object { render object to the g-buffer } for each light { render light geometry using the g-buffer to perform lighting } which is almost the same in nvidia pdf that you informed me: For Each Object: Render lighting properties to "G-buffer" For Each Light: framebuffer + = brdf (G-buffer, light) But I do not know how to "render light geometry using the g-buffer to perform lighting" / framebuffer + = brdf (G-buffer, light) (accumulate lights in framebuffer) when I add the lights in a loop, only the last one is active (blue light): glm::vec3 lightColor[] = {glm::vec3(1,0,0), glm::vec3(0,1,0), glm::vec3(0,0,1)}; //Red, Green and blue glm::vec3 lightPos[] = {glm::vec3(0,3,0), glm::vec3(-2.09, 3, 7), glm::vec3(-2,3,-3)}; for(int i = 0; i < 3; i++){ glBindFramebuffer(GL_FRAMEBUFFER, framebuffer); glEnable(GL_DEPTH_TEST); glClearColor(0.1f, 0.1f, 0.1f, 1.0f); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); shaderCubeLight.use(); //glUseProgram(programID); //..............// //summarizing the draw cube (already setted MVP)....... shaderCubeLight.setVec3("lightPosition", lightPos[i]); shaderCubeLight.setVec3("lightColor", lightColor[i]); glBindVertexArray(cubeVAO); glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, cubeTexture); glDrawArrays(GL_TRIANGLES, 0, 36); glBindFramebuffer(GL_FRAMEBUFFER, 0); glDisable(GL_DEPTH_TEST); // clear all relevant buffers glClearColor(1.0f, 1.0f, 1.0f, 1.0f); glClear(GL_COLOR_BUFFER_BIT); }
  10. Hello everyone. I'm following lessons from learnopengl.com and concludes the chapter on "Deferred Shading". I confess that I am a lighting enthusiast in games. And unfortunately I did not find anything to explain with using as many lights as I want at runtime, I just found examples showing with limited light source: for (int i = 0; i <NR_LIGHTS; ++ i) { vec3 lightDir = normalize (lights [i] .Position - FragPos); vec3 diffuse = max (dot (Normal, lightDir), 0.0) * Albedo * lights [i] .Color; lighting + = diffuse; } Looking at google I found some things about accumulating information in framebuffer, however I did not find a code or anything else explained. Could someone explain to me how I could do this? A pseudocode with the openGL commands would be fine. Right now I thank you all.
  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!