|
13 | 13 | #include "BBE/OpenGL/OpenGLSphere.h" |
14 | 14 | #include <iostream> |
15 | 15 |
|
16 | | -// TODO: "ExampleRotatingCubeIntersections" has visual artifacts |
17 | | -// The effect gets worse with objects further away from (0/0/0). Floating Point Issue? |
18 | 16 | // TODO: "ExampleSandGame" performs much worse than on Vulkan - Why? |
19 | 17 | // TODO: Is every OpenGL Resource properly freed? How can we find that out? |
20 | 18 |
|
@@ -351,8 +349,8 @@ bbe::INTERNAL::openGl::Program bbe::INTERNAL::openGl::OpenGLManager::init3dShade |
351 | 349 | "{" |
352 | 350 | " vec4 worldPos = model * vec4(inPos, 1.0);" |
353 | 351 | " gl_Position = projection * view * worldPos * vec4(1.0, -1.0, 1.0, 1.0);" |
354 | | - " passPos = worldPos;" |
355 | | - " passNormal = model * vec4(inNormal, 0.0);" |
| 352 | + " passPos = view * worldPos;" |
| 353 | + " passNormal = view * model * vec4(inNormal, 0.0);" |
356 | 354 | " passAlbedo = vec4(inColor.xyz, 1.0);" |
357 | 355 | "}"; |
358 | 356 |
|
@@ -384,7 +382,6 @@ bbe::INTERNAL::openGl::Program bbe::INTERNAL::openGl::OpenGLManager::init3dShade |
384 | 382 | static GLint gPositionPos3dLight = 0; |
385 | 383 | static GLint gNormalPos3dLight = 0; |
386 | 384 | static GLint gAlbedoSpecPos3dLight = 0; |
387 | | -static GLint cameraPosPos3dLight = 0; |
388 | 385 | static GLint lightPosPos3dLight = 0; |
389 | 386 | static GLint lightStrengthPos3dLight = 0; |
390 | 387 | static GLint falloffModePos3dLight = 0; |
@@ -435,7 +432,7 @@ bbe::INTERNAL::openGl::Program bbe::INTERNAL::openGl::OpenGLManager::init3dShade |
435 | 432 | " vec3 pos = texture(gPosition, uvCoord).xyz;" |
436 | 433 | " vec3 albedo = texture(gAlbedoSpec, uvCoord).xyz;" |
437 | 434 | " vec3 toLight = lightPos - pos;" |
438 | | - " vec3 toCamera = cameraPos - pos;" |
| 435 | + " vec3 toCamera = -pos;" |
439 | 436 | " float distToLight = length(toLight);" |
440 | 437 | " float lightPower = lightStrength;" |
441 | 438 | " if(distToLight > 0.f)" |
@@ -477,15 +474,13 @@ bbe::INTERNAL::openGl::Program bbe::INTERNAL::openGl::OpenGLManager::init3dShade |
477 | 474 | {UT::UT_vec4 , "lightColor" , &lightColorPos3dLight }, |
478 | 475 | {UT::UT_vec4 , "specularColor", &specularColorPos3dLight }, |
479 | 476 | {UT::UT_vec3 , "lightPos" , &lightPosPos3dLight }, |
480 | | - {UT::UT_vec3 , "cameraPos" , &cameraPosPos3dLight }, |
481 | 477 | {UT::UT_float , "ambientFactor", &ambientFactorPos3dLight }, |
482 | 478 | }); |
483 | 479 |
|
484 | 480 | program.uniform1i(gPositionPos3dLight, 0); |
485 | 481 | program.uniform1i(gNormalPos3dLight, 1); |
486 | 482 | program.uniform1i(gAlbedoSpecPos3dLight, 2); |
487 | 483 |
|
488 | | - program.uniform3f(cameraPosPos3dLight, 0.f, 0.f, 0.f); |
489 | 484 | program.uniform3f(lightPosPos3dLight, 0.f, 0.f, 0.f); |
490 | 485 | program.uniform1f(lightStrengthPos3dLight, 0.f); |
491 | 486 | program.uniform1i(falloffModePos3dLight, 0); |
@@ -601,7 +596,9 @@ void bbe::INTERNAL::openGl::OpenGLManager::preDraw2D() |
601 | 596 | for (size_t i = 0; i < pointLights.getLength(); i++) |
602 | 597 | { |
603 | 598 | const bbe::PointLight& l = pointLights[i]; |
604 | | - m_program3dLight.uniform3f(lightPosPos3dLight, l.pos); |
| 599 | + bbe::Vector4 p(l.pos, 1.0f); |
| 600 | + p = m_view * p; |
| 601 | + m_program3dLight.uniform3f(lightPosPos3dLight, p.xyz()); |
605 | 602 | m_program3dLight.uniform1f(lightStrengthPos3dLight, l.lightStrength); |
606 | 603 | m_program3dLight.uniform1i(falloffModePos3dLight, (int)l.falloffMode); |
607 | 604 | m_program3dLight.uniform4f(lightColorPos3dLight, l.lightColor); |
@@ -840,7 +837,7 @@ void bbe::INTERNAL::openGl::OpenGLManager::setCamera3D(const Vector3& cameraPos, |
840 | 837 | { |
841 | 838 | m_program3dMrt.uniformMatrix4fv(viewPos3dMrt, GL_FALSE, view); |
842 | 839 | m_program3dMrt.uniformMatrix4fv(projectionPos3dMrt, GL_FALSE, projection); |
843 | | - m_program3dLight.uniform3f(cameraPosPos3dLight, cameraPos); |
| 840 | + m_view = view; |
844 | 841 | } |
845 | 842 |
|
846 | 843 | void bbe::INTERNAL::openGl::OpenGLManager::fillCube3D(const Cube& cube) |
|
0 commit comments