diff --git a/Template/gameMap.cpp b/Template/gameMap.cpp index 15559e5..a90abac 100644 --- a/Template/gameMap.cpp +++ b/Template/gameMap.cpp @@ -169,11 +169,8 @@ TSimpleLandClass* TGameMap::GetLand() void TGameMap::DrawVBO() { - Renderer->PushShader("Simple3D"); - Land->DrawVBO(); - Renderer->PopShader(); - //Land->DrawImmediate(); + Land->DrawVBO(); for (TLiteModelArr::iterator i = StaticModelArr.begin(); i != StaticModelArr.end(); ++i) { //i->DrawImmediate(); diff --git a/Template/log.txt b/Template/log.txt index bf536ec..4ca7e02 100644 --- a/Template/log.txt +++ b/Template/log.txt @@ -1,102 +1,109 @@ -2024-Jun-06 15:57:24: Log started -2024-Jun-06 15:57:25: OpenGL Window created -2024-Jun-06 15:57:25: Script manager ready -2024-Jun-06 15:57:25: Render::OpenGL glVersion = 4.6.0 - Build 31.0.101.4887 -2024-Jun-06 15:57:25: Render::OpenGL glVersion above 2.0 ok -2024-Jun-06 15:57:25: Render::OpenGL GL_ARB_framebuffer_object supported ok -2024-Jun-06 15:57:25: Render::OpenGL GL_ARB_uniform_buffer_object supported ok -2024-Jun-06 15:57:25: Prepare to add shader GUI -2024-Jun-06 15:57:25: ResourceManager::ShaderManager::Shader WARNING: 0:1: '' : #version directive missing +2024-Jun-08 20:53:34: Log started +2024-Jun-08 20:53:34: OpenGL Window created +2024-Jun-08 20:53:34: Script manager ready +2024-Jun-08 20:53:34: Render::OpenGL glVersion = 4.6.0 - Build 31.0.101.4887 +2024-Jun-08 20:53:34: Render::OpenGL glVersion above 2.0 ok +2024-Jun-08 20:53:34: Render::OpenGL GL_ARB_framebuffer_object supported ok +2024-Jun-08 20:53:34: Render::OpenGL GL_ARB_uniform_buffer_object supported ok +2024-Jun-08 20:53:34: Prepare to add shader GUI +2024-Jun-08 20:53:34: ResourceManager::ShaderManager::Shader WARNING: 0:1: '' : #version directive missing -2024-Jun-06 15:57:25: ResourceManager::ShaderManager::Shader WARNING: 0:1: '' : #version directive missing +2024-Jun-08 20:53:34: ResourceManager::ShaderManager::Shader WARNING: 0:1: '' : #version directive missing -2024-Jun-06 15:57:25: Shader program is - 3 -2024-Jun-06 15:57:25: ResourceManager::ShaderManager::Shader -2024-Jun-06 15:57:25: ResourceManager::ShaderManager shader loaded: GUI -2024-Jun-06 15:57:25: Prepare to add shader Parallax -2024-Jun-06 15:57:25: ResourceManager::ShaderManager::Shader WARNING: 0:1: '' : #version directive missing +2024-Jun-08 20:53:34: Shader program is - 3 +2024-Jun-08 20:53:34: ResourceManager::ShaderManager::Shader +2024-Jun-08 20:53:34: ResourceManager::ShaderManager shader loaded: GUI +2024-Jun-08 20:53:34: Prepare to add shader Parallax +2024-Jun-08 20:53:34: ResourceManager::ShaderManager::Shader WARNING: 0:1: '' : #version directive missing -2024-Jun-06 15:57:25: ResourceManager::ShaderManager::Shader WARNING: 0:1: '' : #version directive missing +2024-Jun-08 20:53:34: ResourceManager::ShaderManager::Shader WARNING: 0:1: '' : #version directive missing WARNING: 0:27: 'assign' : implicit type conversion allowed from GLSL 1.20 WARNING: 0:27: 'assign' : implicit type conversion allowed from GLSL 1.20 WARNING: 0:27: 'assign' : implicit type conversion allowed -2024-Jun-06 15:57:25: Shader program is - 6 -2024-Jun-06 15:57:25: ResourceManager::ShaderManager::Shader -2024-Jun-06 15:57:25: ResourceManager::ShaderManager shader loaded: Parallax -2024-Jun-06 15:57:25: Prepare to add shader Directlight -2024-Jun-06 15:57:25: ResourceManager::ShaderManager::Shader WARNING: 0:1: '' : #version directive missing +2024-Jun-08 20:53:34: Shader program is - 6 +2024-Jun-08 20:53:34: ResourceManager::ShaderManager::Shader +2024-Jun-08 20:53:34: ResourceManager::ShaderManager shader loaded: Parallax +2024-Jun-08 20:53:34: Prepare to add shader Directlight +2024-Jun-08 20:53:34: ResourceManager::ShaderManager::Shader WARNING: 0:1: '' : #version directive missing -2024-Jun-06 15:57:25: ResourceManager::ShaderManager::Shader WARNING: 0:1: '' : #version directive missing +2024-Jun-08 20:53:34: ResourceManager::ShaderManager::Shader WARNING: 0:1: '' : #version directive missing -2024-Jun-06 15:57:25: Shader program is - 9 -2024-Jun-06 15:57:25: ResourceManager::ShaderManager::Shader -2024-Jun-06 15:57:25: ResourceManager::ShaderManager shader loaded: Directlight -2024-Jun-06 15:57:25: Prepare to add shader Env -2024-Jun-06 15:57:25: ResourceManager::ShaderManager::Shader WARNING: 0:1: '' : #version directive missing +2024-Jun-08 20:53:34: Shader program is - 9 +2024-Jun-08 20:53:34: ResourceManager::ShaderManager::Shader +2024-Jun-08 20:53:34: ResourceManager::ShaderManager shader loaded: Directlight +2024-Jun-08 20:53:34: Prepare to add shader Env +2024-Jun-08 20:53:34: ResourceManager::ShaderManager::Shader WARNING: 0:1: '' : #version directive missing -2024-Jun-06 15:57:25: ResourceManager::ShaderManager::Shader WARNING: 0:1: '' : #version directive missing +2024-Jun-08 20:53:34: ResourceManager::ShaderManager::Shader WARNING: 0:1: '' : #version directive missing -2024-Jun-06 15:57:25: Shader program is - 12 -2024-Jun-06 15:57:25: ResourceManager::ShaderManager::Shader -2024-Jun-06 15:57:25: ResourceManager::ShaderManager shader loaded: Env -2024-Jun-06 15:57:25: Prepare to add shader Water -2024-Jun-06 15:57:25: ResourceManager::ShaderManager::Shader WARNING: 0:1: '' : #version directive missing +2024-Jun-08 20:53:34: Shader program is - 12 +2024-Jun-08 20:53:34: ResourceManager::ShaderManager::Shader +2024-Jun-08 20:53:34: ResourceManager::ShaderManager shader loaded: Env +2024-Jun-08 20:53:34: Prepare to add shader Water +2024-Jun-08 20:53:34: ResourceManager::ShaderManager::Shader WARNING: 0:1: '' : #version directive missing -2024-Jun-06 15:57:25: ResourceManager::ShaderManager::Shader WARNING: 0:1: '' : #version directive missing +2024-Jun-08 20:53:34: ResourceManager::ShaderManager::Shader WARNING: 0:1: '' : #version directive missing WARNING: 0:20: 'assign' : implicit type conversion allowed from GLSL 1.20 -2024-Jun-06 15:57:25: Shader program is - 15 -2024-Jun-06 15:57:25: ResourceManager::ShaderManager::Shader -2024-Jun-06 15:57:25: ResourceManager::ShaderManager shader loaded: Water -2024-Jun-06 15:57:25: Prepare to add shader Frame -2024-Jun-06 15:57:25: ResourceManager::ShaderManager::Shader WARNING: 0:1: '' : #version directive missing +2024-Jun-08 20:53:34: Shader program is - 15 +2024-Jun-08 20:53:34: ResourceManager::ShaderManager::Shader +2024-Jun-08 20:53:34: ResourceManager::ShaderManager shader loaded: Water +2024-Jun-08 20:53:34: Prepare to add shader Frame +2024-Jun-08 20:53:34: ResourceManager::ShaderManager::Shader WARNING: 0:1: '' : #version directive missing -2024-Jun-06 15:57:25: ResourceManager::ShaderManager::Shader WARNING: 0:1: '' : #version directive missing +2024-Jun-08 20:53:34: ResourceManager::ShaderManager::Shader WARNING: 0:1: '' : #version directive missing -2024-Jun-06 15:57:25: Shader program is - 18 -2024-Jun-06 15:57:25: ResourceManager::ShaderManager::Shader -2024-Jun-06 15:57:25: ResourceManager::ShaderManager shader loaded: Frame -2024-Jun-06 15:57:25: Prepare to add shader Lightview -2024-Jun-06 15:57:25: ResourceManager::ShaderManager::Shader WARNING: 0:5: '' : #version directive missing +2024-Jun-08 20:53:34: Shader program is - 18 +2024-Jun-08 20:53:34: ResourceManager::ShaderManager::Shader +2024-Jun-08 20:53:34: ResourceManager::ShaderManager shader loaded: Frame +2024-Jun-08 20:53:34: Prepare to add shader Lightview +2024-Jun-08 20:53:34: ResourceManager::ShaderManager::Shader WARNING: 0:5: '' : #version directive missing -2024-Jun-06 15:57:25: ResourceManager::ShaderManager::Shader WARNING: 0:1: '' : #version directive missing +2024-Jun-08 20:53:34: ResourceManager::ShaderManager::Shader WARNING: 0:1: '' : #version directive missing -2024-Jun-06 15:57:25: Shader program is - 21 -2024-Jun-06 15:57:25: ResourceManager::ShaderManager::Shader -2024-Jun-06 15:57:25: ResourceManager::ShaderManager shader loaded: Lightview -2024-Jun-06 15:57:25: Prepare to add shader Simple3D -2024-Jun-06 15:57:25: ResourceManager::ShaderManager::Shader WARNING: 0:1: '' : #version directive missing +2024-Jun-08 20:53:34: Shader program is - 21 +2024-Jun-08 20:53:34: ResourceManager::ShaderManager::Shader +2024-Jun-08 20:53:34: ResourceManager::ShaderManager shader loaded: Lightview +2024-Jun-08 20:53:34: Prepare to add shader Simple3D +2024-Jun-08 20:53:34: ResourceManager::ShaderManager::Shader WARNING: 0:1: '' : #version directive missing -2024-Jun-06 15:57:25: ResourceManager::ShaderManager::Shader WARNING: 0:1: '' : #version directive missing +2024-Jun-08 20:53:34: ResourceManager::ShaderManager::Shader WARNING: 0:1: '' : #version directive missing -2024-Jun-06 15:57:25: Shader program is - 24 -2024-Jun-06 15:57:25: ResourceManager::ShaderManager::Shader -2024-Jun-06 15:57:25: ResourceManager::ShaderManager shader loaded: Simple3D -2024-Jun-06 15:57:25: ResourceManager::TexList Texture added: bt_box_yellow.bmp with id = 1 -2024-Jun-06 15:57:25: ResourceManager::TexList Texture added: bt_box_norm.bmp32 with id = 2 -2024-Jun-06 15:57:25: Lite model added successfully: models/bt_box_yellow.lm1 -2024-Jun-06 15:57:25: ResourceManager::TexList Texture added: bt_cone.bmp with id = 3 -2024-Jun-06 15:57:25: Lite model added successfully: models/bt_cone.lm1 -2024-Jun-06 15:57:25: Lite model added successfully: models/girl.lm1 -2024-Jun-06 15:57:25: Lite model added successfully: models/bonemodel.lm1 -2024-Jun-06 15:57:26: ResourceManager::TexList Texture added: out.bmp with id = 4 -2024-Jun-06 15:57:26: FrameManager:: frame buffer added: Skybox -2024-Jun-06 15:57:26: ResourceManager::TexList Texture added: normalmap.bmp with id = 6 -2024-Jun-06 15:57:26: FrameManager:: frame buffer added: ScreenBlur -2024-Jun-06 15:57:26: FrameManager:: frame buffer added: ShadowBufferGlobal -2024-Jun-06 15:57:26: FrameManager:: frame buffer added: ShadowBufferLocal +2024-Jun-08 20:53:34: Shader program is - 24 +2024-Jun-08 20:53:34: ResourceManager::ShaderManager::Shader +2024-Jun-08 20:53:34: ResourceManager::ShaderManager shader loaded: Simple3D +2024-Jun-08 20:53:34: ResourceManager::TexList Texture added: bt_box_yellow.bmp with id = 1 +2024-Jun-08 20:53:34: ResourceManager::TexList Texture added: bt_box_norm.bmp32 with id = 2 +2024-Jun-08 20:53:34: Lite model added successfully: models/bt_box_yellow.lm1 +2024-Jun-08 20:53:34: ResourceManager::TexList Texture added: bt_cone.bmp with id = 3 +2024-Jun-08 20:53:34: Lite model added successfully: models/bt_cone.lm1 +2024-Jun-08 20:53:34: Lite model added successfully: models/girl.lm1 +2024-Jun-08 20:53:34: Lite model added successfully: models/bonemodel.lm1 +2024-Jun-08 20:53:35: ResourceManager::TexList Texture added: out.bmp with id = 4 +2024-Jun-08 20:53:35: FrameManager:: frame buffer added: Skybox +2024-Jun-08 20:53:35: ResourceManager::TexList Texture added: normalmap.bmp with id = 6 +2024-Jun-08 20:53:35: Going to add texture: C:\Work\OldProjects\ho3\resources\../resources/posx.bmp +2024-Jun-08 20:53:35: Going to add texture: C:\Work\OldProjects\ho3\resources\../resources/negx.bmp +2024-Jun-08 20:53:35: Going to add texture: C:\Work\OldProjects\ho3\resources\../resources/posy.bmp +2024-Jun-08 20:53:35: Going to add texture: C:\Work\OldProjects\ho3\resources\../resources/negy.bmp +2024-Jun-08 20:53:35: Going to add texture: C:\Work\OldProjects\ho3\resources\../resources/posz.bmp +2024-Jun-08 20:53:35: Going to add texture: C:\Work\OldProjects\ho3\resources\../resources/negz.bmp +2024-Jun-08 20:53:35: ResourceManager::TexList texture added succesfuly: posx.bmp +2024-Jun-08 20:53:35: FrameManager:: frame buffer added: ScreenBlur +2024-Jun-08 20:53:35: FrameManager:: frame buffer added: ShadowBufferGlobal +2024-Jun-08 20:53:35: FrameManager:: frame buffer added: ShadowBufferLocal diff --git a/Template/main.cpp b/Template/main.cpp index 03539f9..65fbca6 100644 --- a/Template/main.cpp +++ b/Template/main.cpp @@ -10,6 +10,7 @@ cardinal CONST_CUBEMAP_UPDATE_INTERVAL = 5000; void TMyApplication::DrawToCubemap() { + Renderer->PushPerspectiveProjectionMatrix(pi/2, 1.0, 1, 1000); Renderer->PushShader("Directlight"); Renderer->SwitchToCubemapBuffer("Skybox",0); @@ -39,6 +40,8 @@ void TMyApplication::DrawToCubemap() Renderer->SwitchToScreen(); Renderer->PopShader(); + + Renderer->PopProjectionMatrix(); } void TMyApplication::DrawToShadowMap() @@ -86,11 +89,33 @@ void TMyApplication::DrawWaterSurface() Renderer->PopShader(); } +void TMyApplication::DrawCubemap() +{ + Renderer->PushShader("Env"); + Renderer->SetGLCamAngleView(); + //Renderer->LoadIdentity(); + RenderUniformMatrix3fv(CONST_STRING_MODELROTATEMATRIX_UNIFORM, false, (float*)IdentityMatrix.m); + RenderUniform3fv(CONST_STRING_MODELTRANSLATEVECTOR_UNIFORM, (float*)ZeroVec3.v); + + glBindTexture(GL_TEXTURE_CUBE_MAP, ResourceManager->FrameManager.GetFrameTexture("Skybox")); + //glBindTexture(GL_TEXTURE_CUBE_MAP, cubemapTexture); + + EnableVertexAttribArray("vPosition"); + + DrawVertexDataStruct(cubemapVertexDataStruct); + + DisableVertexAttribArray("vPosition"); + + Renderer->PopShader(); +} + //What to do on init void TMyApplication::InnerInit() { ResourceManager->PathToResources = "C:\\Work\\OldProjects\\ho3\\resources\\"; + glDisable(GL_CULL_FACE); + ResourceManager->ShaderManager.AddShader("GUI", "shaders/gui_transparent.vertex", "shaders/gui_transparent.fragment"); ResourceManager->ShaderManager.AddShader("Parallax", "shaders/directlight_parallax_shadow.vertex", "shaders/directlight_parallax_shadow.fragment"); @@ -136,6 +161,13 @@ void TMyApplication::InnerInit() ResourceManager->TexList.AddTexture("../resources/normalmap.bmp"); + std::array cubemapTextureStr = { + "../resources/posx.bmp", "../resources/negx.bmp", "../resources/posy.bmp", "../resources/negy.bmp", "../resources/posz.bmp", "../resources/negz.bmp" + }; + + cubemapTexture = ResourceManager->TexList.AddCubemapTexture(cubemapTextureStr); + //."posx.bmp","negx.bmp","posy.bmp","negy.bmp","posz.bmp","negz.bmp" + ResourceManager->FrameManager.AddFrameRenderBuffer("ScreenBlur", 512, 512); ResourceManager->FrameManager.AddDepthBuffer("ShadowBufferGlobal", 512, 512); @@ -151,9 +183,119 @@ void TMyApplication::InnerInit() glClearColor(0.2f, 0.5f, 1.0f, 1.0f); //Renderer->SetShadowClampValue(0.3f); - Renderer->SetShadowClampValue(0.0f); - + //Renderer->SetShadowClampValue(0.0f); + Renderer->SetFogBeginDistance(15.f); + Renderer->SetFogEndDistance(30.f); + + + // +x + cubemapVertexDataStruct.PositionData.push_back({ 10.0f, -10.0f, -10.0f }); + cubemapVertexDataStruct.PositionData.push_back({ 10.0f, 10.0f, -10.0f }); + cubemapVertexDataStruct.PositionData.push_back({ 10.0f, 10.0f, 10.0f }); + + cubemapVertexDataStruct.PositionData.push_back({ 10.0f, -10.0f, -10.0f }); + cubemapVertexDataStruct.PositionData.push_back({ 10.0f, 10.0f, 10.0f }); + cubemapVertexDataStruct.PositionData.push_back({ 10.0f, -10.0f, 10.0f }); + + // -x + cubemapVertexDataStruct.PositionData.push_back({ -10.0f, -10.0f, -10.0f }); + cubemapVertexDataStruct.PositionData.push_back({ -10.0f, 10.0f, -10.0f }); + cubemapVertexDataStruct.PositionData.push_back({ -10.0f, 10.0f, 10.0f }); + + cubemapVertexDataStruct.PositionData.push_back({ -10.0f, -10.0f, -10.0f }); + cubemapVertexDataStruct.PositionData.push_back({ -10.0f, 10.0f, 10.0f }); + cubemapVertexDataStruct.PositionData.push_back({ -10.0f, -10.0f, 10.0f }); + + + // +y + cubemapVertexDataStruct.PositionData.push_back({ -10.0f, 10.0f, -10.0f }); + cubemapVertexDataStruct.PositionData.push_back({ 10.0f, 10.0f, -10.0f }); + cubemapVertexDataStruct.PositionData.push_back({ 10.0f, 10.0f, 10.0f }); + + cubemapVertexDataStruct.PositionData.push_back({ -10.0f, 10.0f, -10.0f }); + cubemapVertexDataStruct.PositionData.push_back({ 10.0f, 10.0f, 10.0f }); + cubemapVertexDataStruct.PositionData.push_back({ -10.0f, 10.0f, 10.0f }); + + + // -y + cubemapVertexDataStruct.PositionData.push_back({ -10.0f, -10.0f, -10.0f }); + cubemapVertexDataStruct.PositionData.push_back({ 10.0f, -10.0f, -10.0f }); + cubemapVertexDataStruct.PositionData.push_back({ 10.0f, -10.0f, 10.0f }); + + cubemapVertexDataStruct.PositionData.push_back({ -10.0f, -10.0f, -10.0f }); + cubemapVertexDataStruct.PositionData.push_back({ 10.0f, -10.0f, 10.0f }); + cubemapVertexDataStruct.PositionData.push_back({ -10.0f, -10.0f, 10.0f }); + + + // +z + cubemapVertexDataStruct.PositionData.push_back({ -10.0f, -10.0f, 10.0f }); + cubemapVertexDataStruct.PositionData.push_back({ 10.0f, -10.0f, 10.0f }); + cubemapVertexDataStruct.PositionData.push_back({ 10.0f, 10.0f, 10.0f }); + + cubemapVertexDataStruct.PositionData.push_back({ -10.0f, -10.0f, 10.0f }); + cubemapVertexDataStruct.PositionData.push_back({ 10.0f, 10.0f, 10.0f }); + cubemapVertexDataStruct.PositionData.push_back({ -10.0f, 10.0f, 10.0f }); + // -z + cubemapVertexDataStruct.PositionData.push_back({ -10.0f, -10.0f, -10.0f }); + cubemapVertexDataStruct.PositionData.push_back({ 10.0f, -10.0f, -10.0f }); + cubemapVertexDataStruct.PositionData.push_back({ 10.0f, 10.0f, -10.0f }); + + cubemapVertexDataStruct.PositionData.push_back({ -10.0f, -10.0f, -10.0f }); + cubemapVertexDataStruct.PositionData.push_back({ 10.0f, 10.0f, -10.0f }); + cubemapVertexDataStruct.PositionData.push_back({ -10.0f, 10.0f, -10.0f }); + + + cubemapVertexDataStruct.TexCoordData.push_back({ 0.0, 0.0 }); + cubemapVertexDataStruct.TexCoordData.push_back({ 0.0, 0.0 }); + cubemapVertexDataStruct.TexCoordData.push_back({ 0.0, 0.0 }); + + cubemapVertexDataStruct.TexCoordData.push_back({ 0.0, 0.0 }); + cubemapVertexDataStruct.TexCoordData.push_back({ 0.0, 0.0 }); + cubemapVertexDataStruct.TexCoordData.push_back({ 0.0, 0.0 }); + + cubemapVertexDataStruct.TexCoordData.push_back({ 0.0, 0.0 }); + cubemapVertexDataStruct.TexCoordData.push_back({ 0.0, 0.0 }); + cubemapVertexDataStruct.TexCoordData.push_back({ 0.0, 0.0 }); + + cubemapVertexDataStruct.TexCoordData.push_back({ 0.0, 0.0 }); + cubemapVertexDataStruct.TexCoordData.push_back({ 0.0, 0.0 }); + cubemapVertexDataStruct.TexCoordData.push_back({ 0.0, 0.0 }); + + cubemapVertexDataStruct.TexCoordData.push_back({ 0.0, 0.0 }); + cubemapVertexDataStruct.TexCoordData.push_back({ 0.0, 0.0 }); + cubemapVertexDataStruct.TexCoordData.push_back({ 0.0, 0.0 }); + + cubemapVertexDataStruct.TexCoordData.push_back({ 0.0, 0.0 }); + cubemapVertexDataStruct.TexCoordData.push_back({ 0.0, 0.0 }); + cubemapVertexDataStruct.TexCoordData.push_back({ 0.0, 0.0 }); + + cubemapVertexDataStruct.TexCoordData.push_back({ 0.0, 0.0 }); + cubemapVertexDataStruct.TexCoordData.push_back({ 0.0, 0.0 }); + cubemapVertexDataStruct.TexCoordData.push_back({ 0.0, 0.0 }); + + cubemapVertexDataStruct.TexCoordData.push_back({ 0.0, 0.0 }); + cubemapVertexDataStruct.TexCoordData.push_back({ 0.0, 0.0 }); + cubemapVertexDataStruct.TexCoordData.push_back({ 0.0, 0.0 }); + + cubemapVertexDataStruct.TexCoordData.push_back({ 0.0, 0.0 }); + cubemapVertexDataStruct.TexCoordData.push_back({ 0.0, 0.0 }); + cubemapVertexDataStruct.TexCoordData.push_back({ 0.0, 0.0 }); + + cubemapVertexDataStruct.TexCoordData.push_back({ 0.0, 0.0 }); + cubemapVertexDataStruct.TexCoordData.push_back({ 0.0, 0.0 }); + cubemapVertexDataStruct.TexCoordData.push_back({ 0.0, 0.0 }); + + cubemapVertexDataStruct.TexCoordData.push_back({ 0.0, 0.0 }); + cubemapVertexDataStruct.TexCoordData.push_back({ 0.0, 0.0 }); + cubemapVertexDataStruct.TexCoordData.push_back({ 0.0, 0.0 }); + + cubemapVertexDataStruct.TexCoordData.push_back({ 0.0, 0.0 }); + cubemapVertexDataStruct.TexCoordData.push_back({ 0.0, 0.0 }); + cubemapVertexDataStruct.TexCoordData.push_back({ 0.0, 0.0 }); + + + cubemapVertexDataStruct.RefreshVBO(); } @@ -168,12 +310,64 @@ void TMyApplication::InnerDeinit() void TMyApplication::InnerDraw() { Renderer->SwitchToScreen(); - glClearColor(0.0f, 1.0f, 0.0f, 1.0f); + glClearColor(0.2f, 0.55f, 1.0f, 1.0f); glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT); - Renderer->PushShader("GUI"); + + Renderer->PushShader("Directlight"); + + DrawToCubemap(); + + //Renderer->SwitchToCubemapBuffer("Skybox", 0); + //Renderer->SetGlPosXView(); + //DrawSceneWithoutWater(); + if (view == 6) + { + DrawCubemap(); + } + else + { + + Renderer->PushPerspectiveProjectionMatrix(pi / 2, 1.0, 1, 1000); + if (view == 0) + { + Renderer->SetGlNegZView(); + } + else if (view == 1) + { + Renderer->SetGlNegYView(); + } + else if (view == 2) + { + Renderer->SetGlPosXView(); + } + else if (view == 3) + { + Renderer->SetGlNegXView(); + } + else if (view == 4) + { + Renderer->SetGlPosZView(); + } + else if (view == 5) + { + Renderer->SetGlPosYView(); + } + DrawSceneWithoutWater(); + Renderer->PopProjectionMatrix(); + } + + //DrawCubemap(); + + Renderer->PopShader(); + + + /* + Renderer->PushShader("Directlight"); DrawSceneWithoutWater(); Renderer->PopShader(); + */ + //DrawToCubemap(); /* DrawToCubemap(); @@ -270,6 +464,11 @@ void TMyApplication::OnMouseDown(TMouseState& mouseState) if (mouseState.LeftButtonPressed) { MouseLeftButtonPressed = true; + view += 1; + if (view == 7) + { + view = 0; + } } } diff --git a/Template/main.h b/Template/main.h index d460324..dd716b8 100644 --- a/Template/main.h +++ b/Template/main.h @@ -26,6 +26,8 @@ class TMyApplication : public SE::TApplication int MouseX0, MouseY0; //Mouse pos caught on right button click + int view = 0; + float WaterTimer; void DrawSceneWithoutWater(); @@ -36,6 +38,11 @@ class TMyApplication : public SE::TApplication void DrawWaterSurface(); + void DrawCubemap(); + + cardinal cubemapTexture; + VertexDataStruct cubemapVertexDataStruct; + public: //Constructor diff --git a/resources/negx.bmp b/resources/negx.bmp new file mode 100644 index 0000000..6caee8c Binary files /dev/null and b/resources/negx.bmp differ diff --git a/resources/negy.bmp b/resources/negy.bmp new file mode 100644 index 0000000..768513b Binary files /dev/null and b/resources/negy.bmp differ diff --git a/resources/negz.bmp b/resources/negz.bmp new file mode 100644 index 0000000..af0d397 Binary files /dev/null and b/resources/negz.bmp differ diff --git a/resources/posx.bmp b/resources/posx.bmp new file mode 100644 index 0000000..6bd5a2c Binary files /dev/null and b/resources/posx.bmp differ diff --git a/resources/posy.bmp b/resources/posy.bmp new file mode 100644 index 0000000..65716c7 Binary files /dev/null and b/resources/posy.bmp differ diff --git a/resources/posz.bmp b/resources/posz.bmp new file mode 100644 index 0000000..8958d8d Binary files /dev/null and b/resources/posz.bmp differ diff --git a/resources/shaders/directlight — копия.fragment b/resources/shaders/directlight — копия.fragment new file mode 100644 index 0000000..df1f186 --- /dev/null +++ b/resources/shaders/directlight — копия.fragment @@ -0,0 +1,36 @@ +uniform sampler2D Texture; +uniform sampler2D NormalMap; +uniform int NormalMapExists; +uniform float FogBeginDistance; +uniform float FogEndDistance; +uniform vec4 FogColor; + +varying vec2 texCoord; +varying vec3 camVec; +varying vec3 lightVec; +varying vec3 vertexPos; + + +void main() +{ + vec3 lVec = lightVec; + vec3 cVec = normalize(camVec); + + //go-go-go + vec3 TexRGB = texture2D(Texture, texCoord.xy).xyz; + + vec3 norm = vec3(0.0,0.0,1.0); + + float shineFactor = 15.0 * pow(max(dot(cVec, norm),0.0),gl_FrontMaterial.shininess) / (129.0 - gl_FrontMaterial.shininess); + + float light_coef = 1.0; + + vec4 ambient = gl_LightSource[0].ambient; + vec4 diffuse = gl_FrontMaterial.diffuse * gl_LightSource[0].diffuse * min( max(dot(lVec,norm),0.0), light_coef); + vec4 specular = gl_LightSource[0].specular * min(shineFactor, light_coef); + + float fogFactor = min(max(max(abs(vertexPos.x)-FogBeginDistance, abs(vertexPos.z)-FogBeginDistance),0.0)/(FogEndDistance - FogBeginDistance),1.0); + + gl_FragColor = mix(vec4(TexRGB,1.0)*ambient+(vec4(TexRGB,1.0)*diffuse+specular), FogColor, fogFactor); + +} \ No newline at end of file diff --git a/resources/shaders/directlight — копия.vertex b/resources/shaders/directlight — копия.vertex new file mode 100644 index 0000000..0d00766 --- /dev/null +++ b/resources/shaders/directlight — копия.vertex @@ -0,0 +1,35 @@ +uniform vec3 CamPos; +uniform mat3 ModelRotateMatrix; +uniform vec3 ModelTranslateVector; + +attribute vec3 Tangent; +attribute vec3 Binormal; + +varying vec2 texCoord; +varying vec3 camVec; +varying vec3 lightVec; +varying vec3 vertexPos; + +void main() +{ + vec4 realVertexPos = vec4(ModelRotateMatrix * gl_Vertex.xyz + ModelTranslateVector, 1.0); + gl_Position = gl_ModelViewProjectionMatrix * realVertexPos; + + texCoord = gl_MultiTexCoord0.st; + + vec3 lVec = normalize(gl_LightSource[0].position.xyz); + vec3 cVec = (CamPos - gl_Vertex.xyz); + + vertexPos = gl_Vertex.xyz; + + mat3 rot; + rot[0] = normalize(Tangent); + rot[1] = normalize(Binormal); + rot[2] = normalize(gl_Normal.xyz); + + rot = ModelRotateMatrix * rot; + + lightVec = lVec * rot; + camVec = cVec * rot; + +} \ No newline at end of file diff --git a/resources/shaders/directlight.fragment b/resources/shaders/directlight.fragment index df1f186..bd6617c 100644 --- a/resources/shaders/directlight.fragment +++ b/resources/shaders/directlight.fragment @@ -1,36 +1,23 @@ uniform sampler2D Texture; -uniform sampler2D NormalMap; -uniform int NormalMapExists; uniform float FogBeginDistance; uniform float FogEndDistance; -uniform vec4 FogColor; varying vec2 texCoord; -varying vec3 camVec; -varying vec3 lightVec; varying vec3 vertexPos; void main() { - vec3 lVec = lightVec; - vec3 cVec = normalize(camVec); + vec4 texColor = texture2D(Texture,texCoord).rgba; - //go-go-go - vec3 TexRGB = texture2D(Texture, texCoord.xy).xyz; + vec4 fogColor = vec4(0.25, 0.55, 1.0, 1.0); - vec3 norm = vec3(0.0,0.0,1.0); + float fogDistCoef = (vertexPos.z - FogBeginDistance) / (FogEndDistance - FogBeginDistance); - float shineFactor = 15.0 * pow(max(dot(cVec, norm),0.0),gl_FrontMaterial.shininess) / (129.0 - gl_FrontMaterial.shininess); + fogDistCoef = clamp(fogDistCoef, 0.0, 1.0); - float light_coef = 1.0; - - vec4 ambient = gl_LightSource[0].ambient; - vec4 diffuse = gl_FrontMaterial.diffuse * gl_LightSource[0].diffuse * min( max(dot(lVec,norm),0.0), light_coef); - vec4 specular = gl_LightSource[0].specular * min(shineFactor, light_coef); - - float fogFactor = min(max(max(abs(vertexPos.x)-FogBeginDistance, abs(vertexPos.z)-FogBeginDistance),0.0)/(FogEndDistance - FogBeginDistance),1.0); + vec4 resultColor = mix(texColor, fogColor, fogDistCoef); - gl_FragColor = mix(vec4(TexRGB,1.0)*ambient+(vec4(TexRGB,1.0)*diffuse+specular), FogColor, fogFactor); + gl_FragColor = vec4(resultColor.rgb, 1.0); } \ No newline at end of file diff --git a/resources/shaders/directlight.vertex b/resources/shaders/directlight.vertex index 0d00766..4b2e55d 100644 --- a/resources/shaders/directlight.vertex +++ b/resources/shaders/directlight.vertex @@ -1,35 +1,46 @@ -uniform vec3 CamPos; +attribute vec3 vPosition; +attribute vec2 vTexCoord; + +uniform mat4 ProjectionMatrix; uniform mat3 ModelRotateMatrix; uniform vec3 ModelTranslateVector; -attribute vec3 Tangent; -attribute vec3 Binormal; - varying vec2 texCoord; -varying vec3 camVec; -varying vec3 lightVec; varying vec3 vertexPos; void main() { - vec4 realVertexPos = vec4(ModelRotateMatrix * gl_Vertex.xyz + ModelTranslateVector, 1.0); - gl_Position = gl_ModelViewProjectionMatrix * realVertexPos; + vec4 realVertexPos = vec4(ModelRotateMatrix * vPosition.xyz + ModelTranslateVector, 1.0); + gl_Position = ProjectionMatrix * realVertexPos; + vertexPos = gl_Position.xyz; - texCoord = gl_MultiTexCoord0.st; + texCoord = vTexCoord.st; + //vertexPos = vPosition.xyz; + + //vec3 cVec = (CamPos - vPosition.xyz); + + /* vec3 lVec = normalize(gl_LightSource[0].position.xyz); - vec3 cVec = (CamPos - gl_Vertex.xyz); + vec3 cVec = (CamPos - vPosition.xyz); - vertexPos = gl_Vertex.xyz; - - mat3 rot; - rot[0] = normalize(Tangent); - rot[1] = normalize(Binormal); - rot[2] = normalize(gl_Normal.xyz); - - rot = ModelRotateMatrix * rot; + vertexPos = vPosition.xyz; - lightVec = lVec * rot; - camVec = cVec * rot; - + vec3 normal = normalize(gl_NormalMatrix * gl_Normal); + + // Используем производные для вычисления тангентного и бинормального вектора + vec3 dp1 = dFdx(vPosition.xyz); + vec3 dp2 = dFdy(vPosition.xyz); + vec2 duv1 = dFdx(vTexCoord.st); + vec2 duv2 = dFdy(vTexCoord.st); + + vec3 tangent = normalize(dp1 * duv2.y - dp2 * duv1.y); + vec3 binormal = normalize(dp2 * duv1.x - dp1 * duv2.x); + + // Создаем матрицу тангенциального пространства + mat3 tbnMatrix = mat3(tangent, binormal, normal); + tbnMatrix = ModelRotateMatrix * tbnMatrix; + + lightVec = lVec * tbnMatrix; + camVec = cVec * tbnMatrix;*/ } \ No newline at end of file diff --git a/resources/shaders/env.fragment b/resources/shaders/env.fragment index 13b5a62..96dfd4a 100644 --- a/resources/shaders/env.fragment +++ b/resources/shaders/env.fragment @@ -3,6 +3,7 @@ uniform samplerCube Env; varying vec3 dir; void main(){ - gl_FragColor = textureCube(Env, dir); + gl_FragColor = textureCube(Env, normalize(dir)); + //gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0); } \ No newline at end of file diff --git a/resources/shaders/env.vertex b/resources/shaders/env.vertex index fc565c8..d4a4d03 100644 --- a/resources/shaders/env.vertex +++ b/resources/shaders/env.vertex @@ -1,7 +1,14 @@ +attribute vec3 vPosition; + +uniform mat4 ProjectionMatrix; +uniform mat3 ModelRotateMatrix; +uniform vec3 ModelTranslateVector; + varying vec3 dir; void main(){ - gl_Position = ftransform(); + vec4 realVertexPos = vec4(ModelRotateMatrix * vPosition.xyz + ModelTranslateVector, 1.0); + gl_Position = ProjectionMatrix * realVertexPos; - dir = gl_Vertex.xyz; + dir = -vPosition; } \ No newline at end of file