From ea17618c9816b03c5f6f16fc6197bb7505978b40 Mon Sep 17 00:00:00 2001 From: Ed94 Date: Mon, 17 Feb 2020 21:10:15 -0500 Subject: [PATCH] Added lithium grease between pieces of blue tape for phong shader. --- Actions.hpp | 4 +- CompGraphics.vcxproj | 175 +++++++++++++++++++++++++++++++++++ CompGraphics.vcxproj.filters | 93 +++++++++++++++++++ CompGraphics.vcxproj.user | 6 ++ DGL_Enum.hpp | 4 + DGL_MiscTypes.hpp | 6 +- DGL_Model.hpp | 113 +++++++++++----------- DGL_Shader.hpp | 68 +++++++++++--- DGL_Space.hpp | 5 + Execution.cpp | 70 ++++++++------ PhongShader.frag | 33 +++++-- PhongShader.vert | 21 ++--- Testing.hpp | 69 +++++++++++--- 13 files changed, 535 insertions(+), 132 deletions(-) create mode 100644 CompGraphics.vcxproj create mode 100644 CompGraphics.vcxproj.filters create mode 100644 CompGraphics.vcxproj.user diff --git a/Actions.hpp b/Actions.hpp index d7ce6c9..5e591c9 100644 --- a/Actions.hpp +++ b/Actions.hpp @@ -194,7 +194,7 @@ namespace Actions using QueueType = std::deque< ptr>; - + public: template sfn AddToQueue(Delegate< FunctionType> _actionToQueue, ActionParams... _paramsForAction) { @@ -243,6 +243,8 @@ namespace Actions } + private: + QueueType actionQueue; }; } diff --git a/CompGraphics.vcxproj b/CompGraphics.vcxproj new file mode 100644 index 0000000..9b4dff5 --- /dev/null +++ b/CompGraphics.vcxproj @@ -0,0 +1,175 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 16.0 + {4F39A7F3-8E88-4B30-A89D-44BE8F5DD0A9} + CompGraphics + 10.0 + + + + Application + true + v142 + MultiByte + + + Application + false + v142 + true + MultiByte + + + Application + true + v142 + MultiByte + + + Application + false + v142 + true + MultiByte + + + + + + + + + + + + + + + + + + + + + F:\Development\cpp_libs\glfw-3.3.2.bin.WIN64\include\GLFW;$(IncludePath) + F:\Development\cpp_libs\glfw-3.3.2.bin.WIN64\lib-vc2019;$(LibraryPath) + + + $(ExecutablePath) + F:\Development\cpp_libs\glfw-3.3.2.bin.WIN64\include\GLFW;F:\Development\cpp_libs\glew-2.1.0\include\GL;F:\Development\cpp_libs\glm;$(IncludePath) + F:\Development\cpp_libs\glfw-3.3.2.bin.WIN64\lib-vc2019;F:\Development\cpp_libs\glew-2.1.0\lib\Release\x64;$(LibraryPath) + + + + Level3 + Disabled + true + true + + + Console + glfw3.lib;opengl32.lib;%(AdditionalDependencies) + F:\Development\cpp_libs\glfw-3.3.2.bin.WIN64\lib-vc2019;%(AdditionalLibraryDirectories) + + + + + Level4 + Disabled + true + true + stdcpp17 + + + Console + F:\Development\cpp_libs\glfw-3.3.2.bin.WIN64\lib-vc2019;F:\Development\cpp_libs\glew-2.1.0\lib\x64;%(AdditionalLibraryDirectories) + glfw3.lib;opengl32.lib;glew32.lib;%(AdditionalDependencies) + + + + + Level3 + MaxSpeed + true + true + true + true + + + Console + true + true + + + + + Level3 + MaxSpeed + true + true + true + true + + + Console + true + true + + + + + + \ No newline at end of file diff --git a/CompGraphics.vcxproj.filters b/CompGraphics.vcxproj.filters new file mode 100644 index 0000000..96fca07 --- /dev/null +++ b/CompGraphics.vcxproj.filters @@ -0,0 +1,93 @@ + + + + + + Ducktape_GL + + + Ducktape_GL + + + Ducktape_GL + + + Ducktape_GL + + + Ducktape_GL + + + Ducktape_GL + + + Ducktape_GL + + + Ducktape_GL + + + Ducktape_GL + + + + + Ducktape_GL + + + + + + + + {dffb88da-bab3-4079-8f08-9bb1e7475f9d} + + + {05484b5d-cbf0-49d7-a593-8fffa98fadb3} + + + + + Shaders + + + Shaders + + + Shaders + + + Shaders + + + Shaders + + + Shaders + + + Shaders + + + Shaders + + + Shaders + + + Shaders + + + Shaders + + + Shaders + + + Shaders + + + Shaders + + + \ No newline at end of file diff --git a/CompGraphics.vcxproj.user b/CompGraphics.vcxproj.user new file mode 100644 index 0000000..5df420f --- /dev/null +++ b/CompGraphics.vcxproj.user @@ -0,0 +1,6 @@ + + + + false + + \ No newline at end of file diff --git a/DGL_Enum.hpp b/DGL_Enum.hpp index dc55bc7..48af0f2 100644 --- a/DGL_Enum.hpp +++ b/DGL_Enum.hpp @@ -119,6 +119,10 @@ namespace DGL A = GLFW_KEY_A , D = GLFW_KEY_D , E = GLFW_KEY_E , + I = GLFW_KEY_I , + J = GLFW_KEY_J , + K = GLFW_KEY_K , + L = GLFW_KEY_L , Q = GLFW_KEY_Q , S = GLFW_KEY_S , W = GLFW_KEY_W , diff --git a/DGL_MiscTypes.hpp b/DGL_MiscTypes.hpp index 32439a3..2560b54 100644 --- a/DGL_MiscTypes.hpp +++ b/DGL_MiscTypes.hpp @@ -29,12 +29,12 @@ namespace DGL // ID Reference Types class VertexBuffer ; - class NormalBuffer; - class Vec3 ; + class NormalBuffer ; + class Vec3 ; class Matrix ; class Shader ; class ShaderProgram; - class VertexArray ; + class VertexArray ; class ElementBuffer; diff --git a/DGL_Model.hpp b/DGL_Model.hpp index 6166429..44f47c3 100644 --- a/DGL_Model.hpp +++ b/DGL_Model.hpp @@ -63,33 +63,48 @@ namespace DGL } }; - /*struct Face - { - VecInt Vertexes, UVs, Normals; - };*/ - struct Face { - VecInt Vertexes, uvIndex, Normals; + VecInt Vertexes, UVs, Normals; }; + struct FaceVertexIndex + { + gUInt Vertex, UV, Normal; + + FaceVertexIndex() : Vertex(0), UV(0), Normal(0) {}; + + FaceVertexIndex(gUInt _vertex, gUInt _uv, gUInt _norm) : Vertex(_vertex), UV(_uv), Normal(_norm) {}; + }; + + using VertexIndexList = Generic::Vector3; + + + // A face primitive is a triangle. + //struct Face + //{ + // //FaceVertexIndex Indicies[3]; + + // gInt Vertex[3], Normal[3], UV[3]; + //}; + struct FaceGenerator { - using ComponentList = std::vector< gInt>; + using ComponentList = std::vector< gUInt>; ComponentList vertIndexes, uvIndexes, normals; - sfn AddVertexIndex(gInt _index) + sfn AddVertexIndex(gUInt _index) { vertIndexes.push_back(_index); } - sfn AddUVIndex(gInt _index) + sfn AddUVIndex(gUInt _index) { uvIndexes.push_back(_index); } - sfn AddNormalIndex(gInt _index) + sfn AddNormalIndex(gUInt _index) { normals.push_back(_index); } @@ -98,35 +113,33 @@ namespace DGL { Face generated; - if (vertIndexes.size() != 0) + for (int index = 0; index < 3; index++) { - for (int index = 0; index < vertIndexes.size(); index++) - { - generated.Vertexes[index] = vertIndexes.at(index); - } - } - if (uvIndexes.size() != 0) - { - for (int index = 0; index < uvIndexes.size(); index++) - { - generated.uvIndex[index] = uvIndexes.at(index); - } - } - if (normals.size() != 0) - { - for (int index = 0; index < normals.size(); index++) - { - generated.Normals[index] = normals.at(index); - } - } + generated.Vertexes[index] = vertIndexes[index]; - if (uvIndexes.size() == 0) - { - generated.uvIndex = VecInt(0, 0, 0); - } - if (normals.size() == 0) - { - generated.Normals = VecInt(0, 0, 0); + if (uvIndexes.size() > 0) + { + generated.UVs[index] = uvIndexes[index]; + } + + if (normals.size() > 0) + { + generated.Normals[index] = normals[index]; + } + + + + /*generated.Vertex[index] = vertIndexes[index]; + + if (uvIndexes.size() > 0) + { + generated.UV[index] = uvIndexes[index]; + } + + if (normals.size() > 0) + { + generated.Normal[index] = normals[index]; + }*/ } return generated; @@ -225,7 +238,7 @@ namespace DGL deduce processFace = [&](Ref(stringstream) _faceStream) { - FaceGenerator faceMade; gInt vertexIndex, textureIndex, normalIndex; + FaceGenerator faceMade; gUInt vertexIndex, textureIndex, normalIndex; while (not _faceStream.eof()) { @@ -325,33 +338,29 @@ namespace DGL BindVertexArray(VAO); - - BindBuffer(EBufferTarget::VertexAttributes, VBO); BufferData(Address(Verticies[0]), Verticies.size() * sizeof(Vector3), EBufferTarget::VertexAttributes, EBufferUsage::StaticDraw); + EnableVertexAttributeArray(0); + + FormatVertexAttributes(0, EDataType::Float, ZeroOffset(), 3, EBool::False); + if (VertNormals.size() != 0) { BindBuffer(EBufferTarget::VertexAttributes, NBO); BufferData(Address(VertNormals[0]), VertNormals.size() * sizeof(Vector3), EBufferTarget::VertexAttributes, EBufferUsage::StaticDraw); + + EnableVertexAttributeArray(1); + + FormatVertexAttributes(1, EDataType::Float, ZeroOffset(), 3, EBool::False); } - BindBuffer(EBufferTarget::VertexIndices, EBO); BufferData(Address(Faces[0]), Faces.size() * sizeof(Face), EBufferTarget::VertexIndices, EBufferUsage::StaticDraw); - //BufferData(Address(Indicies[0]), Indicies.size() * sizeof(gUInt), EBufferTarget::VertexIndices, EBufferUsage::StaticDraw); - - - - EnableVertexAttributeArray(0); - FormatVertexAttributes(0, EDataType::Float, ZeroOffset(), 3, EBool::False); - - /*EnableVertexAttributeArray(1); - FormatVertexAttributes(1, EDataType::Float, ZeroOffset(), 3, EBool::False);*/ - + BindVertexArray(0); } @@ -363,7 +372,7 @@ namespace DGL gInt Size; GetBufferParameterIV(EBufferTarget::VertexIndices, EBufferParam::Size, Address(Size)); - Size /= sizeof(gFloat); + Size /= sizeof(gInt); DrawElements(EPrimitives::Triangles, Size, EDataType::UnsignedInt, ZeroOffset()); diff --git a/DGL_Shader.hpp b/DGL_Shader.hpp index 18219de..a6dda18 100644 --- a/DGL_Shader.hpp +++ b/DGL_Shader.hpp @@ -1,9 +1,10 @@ #pragma once //DGL +#include "DGL_Enum.hpp" #include "DGL_FundamentalTypes.hpp" #include "DGL_MiscTypes.hpp" -#include "DGL_Enum.hpp" +#include "DGL_Buffers.hpp" #include "DGL_Space.hpp" @@ -384,7 +385,7 @@ namespace DGL LightColorID = GetUniformVariable(Shader, "LightColor" ); } - sfn SetupRender(Ref(CoordSpace) _cubeTransform, Ref(Vector3) _objectColor, Ref(Vector3) _lightColor) + sfn Use(Ref(CoordSpace) _cubeTransform, Ref(Vector3) _objectColor, Ref(Vector3) _lightColor) { UseProgramShader(Shader); @@ -392,6 +393,15 @@ namespace DGL SetUniformVariable_Vector3(ObjectColorID, 1, Address(_objectColor[0])); SetUniformVariable_Vector3(LightColorID , 1, Address(_lightColor [0])); + + EnableVertexAttributeArray(0); + EnableVertexAttributeArray(1); + } + + sfn Stop() + { + DisableVertexAttributeArray(0); + DisableVertexAttributeArray(1); } } @@ -413,6 +423,15 @@ namespace DGL UseProgramShader(Shader); SetUniformVariable_MVA(ScreenSpaceVarID, 1, EBool::False, Address(_lampTransform[0][0])); + + EnableVertexAttributeArray(0); + EnableVertexAttributeArray(1); + } + + sfn Stop() + { + DisableVertexAttributeArray(0); + DisableVertexAttributeArray(1); } } @@ -420,9 +439,9 @@ namespace DGL { ID ShaderID; - ID ModelScreenSpaceID, ModelSpaceID; + ID ModelSpaceID, InverseModelSpaceID, ViewportID, ProjectionID; - ID LightPositionID; + ID LightPositionID, ViewPositionID; ID ObjectColorID, LightColorID; @@ -430,32 +449,51 @@ namespace DGL { ShaderID = LoadShaders("PhongShader.vert", "PhongShader.frag"); - ModelScreenSpaceID = GetUniformVariable(ShaderID, "ModelScreenSpace"); - ModelSpaceID = GetUniformVariable(ShaderID, "ModelSpace" ); + InverseModelSpaceID = GetUniformVariable(ShaderID, "InverseModelSpace"); + ModelSpaceID = GetUniformVariable(ShaderID, "ModelSpace" ); + ProjectionID = GetUniformVariable(ShaderID, "Projection" ); + ViewportID = GetUniformVariable(ShaderID, "Viewport" ); - ObjectColorID = GetUniformVariable(ShaderID, "ObjectColor" ); - LightColorID = GetUniformVariable(ShaderID, "LightColor" ); - LightPositionID = GetUniformVariable(ShaderID, "LightPositionID"); + ObjectColorID = GetUniformVariable(ShaderID, "ObjectColor" ); + LightColorID = GetUniformVariable(ShaderID, "LightColor" ); + LightPositionID = GetUniformVariable(ShaderID, "LightPosition"); + ViewPositionID = GetUniformVariable(ShaderID, "ViewPosition" ); } sfn SetupRender ( - Ref(CoordSpace) _screenSapceTransform, + Ref(CoordSpace) _projection , + Ref(CoordSpace) _viewport , Ref(CoordSpace) _objectTransform , Ref(Vector3 ) _objectColor , Ref(Vector3 ) _lightPosition , - Ref(Vector3 ) _lightColor + Ref(Vector3 ) _lightColor , + Ref(Vector3 ) _viewPosition ) { + CoordSpace inverseTransform = Inverse(_objectTransform); + UseProgramShader(ShaderID); - SetUniformVariable_MVA(ModelScreenSpaceID, 1, EBool::False, Address(_screenSapceTransform[0][0])); - SetUniformVariable_MVA(ModelSpaceID , 1, EBool::False, Address(_objectTransform [0][0])); + SetUniformVariable_MVA(InverseModelSpaceID, 1, EBool::False, Address(inverseTransform[0][0])); + SetUniformVariable_MVA(ModelSpaceID , 1, EBool::False, Address(_objectTransform[0][0])); + SetUniformVariable_MVA(ProjectionID , 1, EBool::False, Address(_projection [0][0])); + SetUniformVariable_MVA(ViewportID , 1, EBool::False, Address(_viewport [0][0])); SetUniformVariable_Vector3(LightPositionID, 1, Address(_lightPosition[0])); - SetUniformVariable_Vector3(ObjectColorID, 1, Address(_objectColor[0])); - SetUniformVariable_Vector3(LightColorID , 1, Address(_lightColor [0])); + SetUniformVariable_Vector3(ObjectColorID , 1, Address(_objectColor [0])); + SetUniformVariable_Vector3(LightColorID , 1, Address(_lightColor [0])); + SetUniformVariable_Vector3(ViewPositionID, 1, Address(_viewPosition[0])); + + EnableVertexAttributeArray(0); + EnableVertexAttributeArray(1); + } + + sfn Stop() + { + DisableVertexAttributeArray(1); + DisableVertexAttributeArray(0); } } diff --git a/DGL_Space.hpp b/DGL_Space.hpp index 1c55f18..ef0443d 100644 --- a/DGL_Space.hpp +++ b/DGL_Space.hpp @@ -60,6 +60,11 @@ namespace DGL return glm::normalize(_vectorSpecified); } + sfn Inverse(const Matrix4x4 _matrix) + { + return glm::inverse(_matrix); + } + sfn Rotate(const Matrix4x4 _matrix, gFloat _rotationAngleAmount, Vector3 _axis) -> Matrix4x4 { return glm::rotate(_matrix, _rotationAngleAmount, _axis); diff --git a/Execution.cpp b/Execution.cpp index cb78a90..f6f6f06 100644 --- a/Execution.cpp +++ b/Execution.cpp @@ -88,6 +88,8 @@ namespace Execution double CursorX, CursorY; // Cursor axis position on the window. + bool CursorOff = true; + gFloat CamMoveSpeed = 8.0f, // Rate at which the camera should move. CamRotationSpeed = 27.0f ; // Rate at which the camera should rotate. @@ -199,7 +201,10 @@ namespace Execution _inputProcedure(DefaultWindow); - ResetCursor(DefaultWindow, ScreenCenterWidth, ScreenCenterHeight); + if (CursorOff) + { + ResetCursor(DefaultWindow, ScreenCenterWidth, ScreenCenterHeight); + } InputDelta = 0.0; } @@ -254,7 +259,7 @@ namespace Execution } deduce ModifyCamSpeedDelegate = Delegate(ModifyCamSpeed); - deduce SetPolyModeDelegate = Delegate(SetPolygonMode); + deduce SetPolyModeDelegate = Delegate(SetPolygonMode); sfn InputProcedure(ptr _currentWindowContext) { @@ -269,11 +274,15 @@ namespace Execution { ActionsToComplete.AddToQueue(delegate , _currentWindowContext, EMouseMode::Cursor , ECursorMode::Disable); ActionsToComplete.AddToQueue(delegateRaw, _currentWindowContext, EMouseMode::RawMouse, EBool ::True ); + + CursorOff = true; } else { ActionsToComplete.AddToQueue(delegate , _currentWindowContext, EMouseMode::Cursor , ECursorMode::Normal); ActionsToComplete.AddToQueue(delegateRaw, _currentWindowContext, EMouseMode::RawMouse, EBool ::False ); + + CursorOff = false; } } @@ -297,14 +306,17 @@ namespace Execution ActionsToComplete.AddToQueue(SetPolyModeDelegate, DGL::EFace::Front_and_Back, DGL::ERenderMode::Fill); } - if (CursorX != 0) + if (CursorOff) { - ActionsToComplete.AddToQueue(RotateCamDelegate, ERotationAxis::Yaw, CursorX * CamRotationSpeed, PhysicsDelta); - } + if (CursorX != 0) + { + ActionsToComplete.AddToQueue(RotateCamDelegate, ERotationAxis::Yaw, CursorX * CamRotationSpeed, PhysicsDelta); + } - if (CursorY != 0) - { - ActionsToComplete.AddToQueue(RotateCamDelegate, ERotationAxis::Pitch, CursorY * CamRotationSpeed, PhysicsDelta); + if (CursorY != 0) + { + ActionsToComplete.AddToQueue(RotateCamDelegate, ERotationAxis::Pitch, CursorY * CamRotationSpeed, PhysicsDelta); + } } if (KeyPressed(_currentWindowContext, EKeyCodes::E)) @@ -336,6 +348,26 @@ namespace Execution { ActionsToComplete.AddToQueue(MoveCamDelegate, EDirection::Backward, CamMoveSpeed, PhysicsDelta); } + + if (KeyPressed(_currentWindowContext, EKeyCodes::I)) + { + ActionsToComplete.AddToQueue(RotateCamDelegate, ERotationAxis::Pitch, -6.0f * CamRotationSpeed, PhysicsDelta); + } + + if (KeyPressed(_currentWindowContext, EKeyCodes::K)) + { + ActionsToComplete.AddToQueue(RotateCamDelegate, ERotationAxis::Pitch, 6.0f * CamRotationSpeed, PhysicsDelta); + } + + if (KeyPressed(_currentWindowContext, EKeyCodes::J)) + { + ActionsToComplete.AddToQueue(RotateCamDelegate, ERotationAxis::Yaw, -6.0f * CamRotationSpeed, PhysicsDelta); + } + + if (KeyPressed(_currentWindowContext, EKeyCodes::L)) + { + ActionsToComplete.AddToQueue(RotateCamDelegate, ERotationAxis::Yaw, 6.0f * CamRotationSpeed, PhysicsDelta); + } } @@ -360,6 +392,8 @@ namespace Execution //RAW_RotateLitCube(PhysicsDelta); + RAW_LightRotate(PhysicsDelta); + ProperCube::Rotate(PhysicsDelta); UpdateThisShit(); @@ -371,27 +405,9 @@ namespace Execution { glfwSetWindowTitle(DefaultWindow, somethingtoupdate.str().c_str()); - EnableVertexAttributeArray(VertexAttributeIndex); - - EnableVertexAttributeArray(1); - - - //UseProgramShader(DGL::SS_Transformed::Shader); - - //BindVertexArray(VertexArrayObj); - - //DrawElements(EPrimitives::Triangles, 6, EDataType::UnsignedInt, ZeroOffset()); - RAW_RenderLight(WorldCamera.Perspective, WorldCamera.Viewport); - - //RAW_RenderLitCube(WorldCamera.Perspective, WorldCamera.Viewport); - - ProperCube::Render(WorldCamera.Perspective, WorldCamera.Viewport); - - DisableVertexAttributeArray(VertexAttributeIndex); - - DisableVertexAttributeArray(1); + ProperCube::Render(WorldCamera.Perspective, WorldCamera.Viewport, WorldCamera.Position); } diff --git a/PhongShader.frag b/PhongShader.frag index cc82037..59fcf3f 100644 --- a/PhongShader.frag +++ b/PhongShader.frag @@ -3,32 +3,45 @@ out vec4 FragColor; -//in vec3 FragPosition; -//in vec3 Normal ; +in vec3 FragPosition; +in vec3 Normal ; uniform vec3 ObjectColor; -//uniform vec3 LightPosition; +uniform vec3 LightPosition; uniform vec3 LightColor ; +uniform vec3 ViewPosition; + void main() { - float AmbientStrength = 0.1; + float AmbientStrength = 0.1; + float SpecularStrength = 0.5; vec3 ambient = AmbientStrength * LightColor ; -// vec3 Direction = normalize(Normal ); -// vec3 LightDirection = normalize(LightPosition - FragPosition); -// -// float DiffuseStrength = max(dot(Normal, LightDirection), 0.0); -// vec3 diffuse = DiffuseStrength * LightColor ; + vec3 Direction = normalize(Normal ); + vec3 LightDirection = normalize(LightPosition - FragPosition); - vec3 result = (ambient ) * ObjectColor; + float DiffuseStrength = max(dot(Normal, LightDirection), 0.0); + + vec3 diffuse = DiffuseStrength * LightColor ; + + vec3 ViewDirection = normalize(ViewPosition - FragPosition); + + vec3 ReflectionDirection = reflect(-LightDirection, Normal); + + float Spec = pow(max(dot(ViewDirection, ReflectionDirection), 0.0), 32); + + vec3 specular = SpecularStrength * Spec * LightColor; + + vec3 result = (ambient + diffuse + specular) * ObjectColor; FragColor = vec4(result, 1.0); + } \ No newline at end of file diff --git a/PhongShader.vert b/PhongShader.vert index 9f6fc42..5a75172 100644 --- a/PhongShader.vert +++ b/PhongShader.vert @@ -1,26 +1,25 @@ #version 330 core layout (location = 0) in vec3 VertPosition; -//layout (location = 1) in vec3 VertNormal ; +layout (location = 1) in vec3 VertNormal ; +out vec3 FragPosition; +out vec3 Normal ; - -//out vec3 FragPosition; -//out vec3 Normal ; - - - -uniform mat4 ModelScreenSpace ; uniform mat4 ModelSpace ; +uniform mat4 Viewport ; +uniform mat4 Projection ; + uniform mat4 InverseModelSpace; void main() { - gl_Position = ModelScreenSpace * vec4(VertPosition, 1.0); + FragPosition = vec3(ModelSpace * vec4(VertPosition, 1.0)); -// FragPosition = vec3(ModelSpace * vec4(VertPosition, 1.0)); + Normal = mat3(transpose(InverseModelSpace)) * VertNormal; +// Normal = VertNormal; -// Normal = mat3(transpose(InverseModelSpace)); + gl_Position = Projection * Viewport * ModelSpace * vec4(FragPosition, 1.0); } \ No newline at end of file diff --git a/Testing.hpp b/Testing.hpp index b4faa31..5fb8722 100644 --- a/Testing.hpp +++ b/Testing.hpp @@ -370,7 +370,7 @@ sfn RAW_RenderCube() LinearColor CoralColor(1.0f, 0.5f, 0.31f, 1.0f); LinearColor LightColor(1.0f, 1.0f, 1.0f , 1.0f); -Vector3 LightPosition(1.2f, 1.0f, 2.0f); +Vector3 LightPosition(1.2f, 2.0f, 3.0f); Vector3 LightScale = Vector3(0.2f); @@ -397,6 +397,40 @@ sfn RAW_MakeLightVAO() LightTransform = DGL::Scale (LightTransform, LightScale ); } +sfn RAW_LightRotate(gFloat _delta) +{ + //LightTransform = DGL::Rotate(LightTransform, 0.1f, Vector3(1, 0, 0)); + + static bool test = true; + + LightTransform = CoordSpace(1.0f); + + if (test) + { + LightPosition.x += 0.001f + _delta; + + if (LightPosition.x > 4) + { + test = false; + } + + LightTransform = DGL::Translate(LightTransform, LightPosition); + LightTransform = DGL::Scale (LightTransform, LightScale ); + } + else + { + LightPosition.x -= 0.001f + _delta; + + if (LightPosition.x < -4) + { + test = true; + } + + LightTransform = DGL::Translate(LightTransform, LightPosition); + LightTransform = DGL::Scale (LightTransform, LightScale ); + } +} + using DGL::GetBufferParameterIV; @@ -409,6 +443,8 @@ sfn RAW_RenderLight(CoordSpace _projection, CoordSpace _viewport) DGL::BindVertexArray(LightVAO); RAW_RenderCube(); + + DGL::Basic_LampShader::Stop(); } @@ -448,7 +484,7 @@ sfn RAW_RenderLitCube(CoordSpace _projection, CoordSpace _viewport) Vector3 lightColor = LightColor.Vector(); - DGL::PhongShader::SetupRender(screenspaceTransform, LitCubeTransform, CubeColor, LightPosition, lightColor); + //DGL::PhongShader::SetupRender(screenspaceTransform, LitCubeTransform, CubeColor, LightPosition, lightColor); DGL::BindVertexArray(LitCubeVAO); @@ -459,7 +495,7 @@ sfn RAW_RenderLitCube(CoordSpace _projection, CoordSpace _viewport) namespace ProperCube { - Model model("cube.obj"); + Model model("Cube.obj"); Vector3 position = Vector3(0.0f); @@ -469,20 +505,33 @@ namespace ProperCube sfn Rotate(gFloat _delta) { - transform = DGL::Rotate(transform, 3.5f * _delta, Vector3(0, 1, 0)); + //transform = DGL::Rotate(transform, 1.5f * _delta, Vector3(0, 1, 0)); } - sfn Render(Ref(CoordSpace) _projection, Ref(CoordSpace) _viewport) + sfn Render(Ref(CoordSpace) _projection, Ref(CoordSpace) _viewport, Ref(Vector3) _cameraPosition) { CoordSpace screenspaceTransform = _projection * _viewport * transform; Vector3 lightColor = LightColor.Vector(); - //DGL::PhongShader::SetupRender(screenspaceTransform, transform, color, LightPosition, lightColor); + DGL::PhongShader::SetupRender + ( + _projection , + _viewport , + transform , + color , + LightPosition , + lightColor , + _cameraPosition + ); - DGL::Basic_LightingShader::SetupRender(screenspaceTransform, color, lightColor); + //DGL::Basic_LightingShader::Use(screenspaceTransform, color, lightColor); model.Render(); + + DGL::Basic_LightingShader::Stop(); + + DGL::PhongShader::Stop(); } sfn Setup() @@ -496,9 +545,3 @@ namespace ProperCube //transform = DGL::Scale(transform, Vector3(0.01)); } } - - - - - -