From ac296727dee6aad1b2a48a93c665339681c2113d Mon Sep 17 00:00:00 2001 From: Vladislav Khorev Date: Tue, 30 Oct 2018 02:03:42 +0500 Subject: [PATCH] Finalizing render --- assets/ices.json | 12 ++--- assets/test_simplelight.fragment | 7 +++ assets/test_simplelight.vertex | 3 +- jni/main_code.cpp | 75 ++++++++++++++++++++++--------- jni/main_code.h | 1 - windows/Template/Template.vcxproj | 4 +- 6 files changed, 71 insertions(+), 31 deletions(-) diff --git a/assets/ices.json b/assets/ices.json index d457894..a420c65 100644 --- a/assets/ices.json +++ b/assets/ices.json @@ -1,42 +1,42 @@ { "ices": [ { - "position": [ -20, 0, -50 ], + "position": [ -20, 0.8, -50 ], "scale": 1, "angle": 0, "type": 1, "texture": 1 }, { - "position": [ 30, 0, 30 ], + "position": [ 30, 0.7, 30 ], "scale": 0.3, "angle": 0, "type": 2, "texture": 2 }, { - "position": [ -10, 0, 50 ], + "position": [ -10, 0.7, 50 ], "scale": 0.1, "angle": 0, "type": 3, "texture": 3 }, { - "position": [ 0, 0, 50 ], + "position": [ 0, 0.7, 50 ], "scale": 0.1, "angle": 0, "type": 4, "texture": 1 }, { - "position": [ 30, 0, 30 ], + "position": [ 30, 0.7, 30 ], "scale": 0.2, "angle": 0, "type": 5, "texture": 2 }, { - "position": [ 50, 0, -50 ], + "position": [ 50, 0.7, -50 ], "scale": 2, "angle": 0, "type": 6, diff --git a/assets/test_simplelight.fragment b/assets/test_simplelight.fragment index c07e463..398d02b 100644 --- a/assets/test_simplelight.fragment +++ b/assets/test_simplelight.fragment @@ -5,6 +5,7 @@ uniform sampler2D NormalMap; uniform vec3 LightDirection; uniform float TimeOfDayCoef1; uniform float TimeOfDayCoef2; +uniform float invCoef; uniform vec3 TimeOfDayColor; varying vec2 texCoord; @@ -24,4 +25,10 @@ void main() //gl_FragColor = vec4(((texture2D(Texture, texCoord).rgb + vec3(0.0, 0.1, 0.2)) * (0.4)), 1.0); gl_FragColor = vec4(((texture2D(Texture, texCoord).rgb + TimeOfDayColor) * (cosf * TimeOfDayCoef1 + TimeOfDayCoef2)), 1.0); + + if (posVec.y < 0.0) + { + discard; + //gl_FragColor = vec4(0.0, 0.0, 0.0, 0.0); + } } diff --git a/assets/test_simplelight.vertex b/assets/test_simplelight.vertex index 225dba6..8b4d05a 100644 --- a/assets/test_simplelight.vertex +++ b/assets/test_simplelight.vertex @@ -4,6 +4,7 @@ attribute vec3 Tangent; attribute vec3 Binormal; attribute vec2 vTexCoord; +uniform mat4 ModelViewMatrix; uniform mat4 ProjectionMatrix; uniform vec3 CamPos; @@ -29,5 +30,5 @@ void main() normVec = Normal; - posVec = vPosition; + posVec = vPosition.xyz; } \ No newline at end of file diff --git a/jni/main_code.cpp b/jni/main_code.cpp index 6ccea0b..63c0a29 100755 --- a/jni/main_code.cpp +++ b/jni/main_code.cpp @@ -20,8 +20,8 @@ extern bool SnowPref; extern float lastOffsetX; #ifdef TARGET_WIN32 -int TimeOfDayPref = 0; -bool SnowPref = false; +int TimeOfDayPref = 0; +bool SnowPref = true; #else extern int TimeOfDayPref; @@ -94,7 +94,14 @@ void TAndroidApplication::LoadModels() Vector3f size = objData.models[0].maxCorner - objData.models[0].minCorner; float radius = myMax(size[0], myMax(size[1], size[2])) / 2; - mountainTransformation = Affine3f(Scaling(cameraDistance / radius * 0.25f)).matrix(); + SE::MoveDataTriangleList(mountain.second.Data, Vector3f(0, -10.0, 0)); + + mountain.second.RefreshBuffer(); + + + mountainTransformation = Affine3f(Scaling(cameraDistance / radius * 0.5f)).matrix(); + //mountainTransformation = Affine3f(Translation3f(0, -size[1] * 0.02f, 0)).matrix() * mountainTransformation; + //mountainTransformation = Affine3f(Translation3f(0, -size[1] / 20 * cameraDistance / radius * 0.25f, 0)).matrix() * mountainTransformation; //Matrix3f rotation(Quaternionf(0, 1 * sin(pi / 8 + pi / 2), 0, 1 * cos(pi / 8 + pi / 2)).toRotationMatrix()); //mountainTransformation = Affine3f(rotation).matrix() * mountainTransformation; @@ -104,6 +111,13 @@ void TAndroidApplication::LoadModels() { objData = loadObjFile("ice/ice" + std::to_string(i) + ".obj", ""); ices[i - 1] = ObjDataToRenderPairs(objData)[0][0].second; + + + + //SE::MoveDataTriangleList(ices[i - 1].Data, Vector3f(0, 0.1f, 0)); + + ices[i - 1].RefreshBuffer(); + } size = objData.models[0].maxCorner - objData.models[0].minCorner; @@ -130,7 +144,9 @@ void TAndroidApplication::LoadModels() iceParams.push_back(params); Matrix4f iceTransformation = Affine3f(Translation3f(centerShift)).matrix(); - iceTransformation = Affine3f(Scaling(cameraDistance / radius * 0.1f * scale)).matrix() * iceTransformation; + //iceTransformation = Affine3f(Scaling(cameraDistance / radius * 0.1f * scale)).matrix() * iceTransformation; + + //Matrix3f rotation(Quaternionf(0, cos(angle*pi / 360.f), 0, sin(angle*pi / 360.f)).toRotationMatrix()); //iceTransformation = Affine3f(rotation).matrix() * iceTransformation; iceTransformation = Affine3f(Translation3f(position)).matrix() * iceTransformation; @@ -155,7 +171,6 @@ void TAndroidApplication::DrawSceneWithoutWater(bool inv) Renderer->PushProjectionMatrix(1,1); Renderer->LoadIdentity(); - //Renderer->PushSpecialMatrix(Matrix4f::Identity()); if (inv) { @@ -169,13 +184,13 @@ void TAndroidApplication::DrawSceneWithoutWater(bool inv) { glBindTexture(GL_TEXTURE_2D, ResourceManager->TexList["sky.png"]); } - Renderer->DrawRect(Vector2f(0.0f, 0.56f), Vector2f(1.f, 0.f), Vector2f(0.5f + SkyTexShift, 0.f), Vector2f(1.f + SkyTexShift, 1.f)); + Renderer->DrawRect(Vector2f(0.0f, 0.55f), Vector2f(1.f, 0.f), Vector2f(0.5f + SkyTexShift, 0.f), Vector2f(1.f + SkyTexShift, 1.f)); if (TimeOfDayPref == 1) { glClear(GL_DEPTH_BUFFER_BIT); glBindTexture(GL_TEXTURE_2D, ResourceManager->TexList["final_cloud.png"]); - Renderer->DrawRect(Vector2f(0.0f, 0.56f), Vector2f(4.f, 0.f), Vector2f(0.0f + SkyTexShift + CloudTimer, 0.f), Vector2f(1.f + SkyTexShift + CloudTimer, 0.5f)); + Renderer->DrawRect(Vector2f(0.0f, 0.55f), Vector2f(4.f, 0.f), Vector2f(0.0f + SkyTexShift + CloudTimer, 0.f), Vector2f(1.f + SkyTexShift + CloudTimer, 0.5f)); } } else @@ -188,13 +203,13 @@ void TAndroidApplication::DrawSceneWithoutWater(bool inv) { glBindTexture(GL_TEXTURE_2D, ResourceManager->TexList["sky.png"]); } - Renderer->DrawRect(Vector2f(0.0f, 0.54f), Vector2f(1.f, 1.f), Vector2f(0.5f + SkyTexShift, 0.f), Vector2f(1.f + SkyTexShift, 1.f)); + Renderer->DrawRect(Vector2f(0.0f, 0.55f), Vector2f(1.f, 1.f), Vector2f(0.5f + SkyTexShift, 0.f), Vector2f(1.f + SkyTexShift, 1.f)); if (TimeOfDayPref == 1) { glClear(GL_DEPTH_BUFFER_BIT); glBindTexture(GL_TEXTURE_2D, ResourceManager->TexList["final_cloud.png"]); - Renderer->DrawRect(Vector2f(0.0f, 0.54f), Vector2f(4.f, 1.f), Vector2f(0.0f + SkyTexShift + CloudTimer, 0.f), Vector2f(1.f + SkyTexShift + CloudTimer, 0.5f)); + Renderer->DrawRect(Vector2f(0.0f, 0.55f), Vector2f(4.f, 1.f), Vector2f(0.0f + SkyTexShift + CloudTimer, 0.f), Vector2f(1.f + SkyTexShift + CloudTimer, 0.5f)); } } @@ -226,14 +241,30 @@ void TAndroidApplication::DrawSceneWithoutWater(bool inv) if (inv) { - //Renderer->PushMatrix(); - Renderer->TranslateMatrix(Vector3f(0,0.1f,0)); + Renderer->TranslateMatrix(Vector3f(0, 0.0f, 0)); Renderer->ScaleMatrix(Vector3f(1, -1, 1)); } + else + { + Renderer->TranslateMatrix(Vector3f(0, 0.0f, 0)); + } + + Renderer->PushShader("SimplelightShader"); RenderUniform3fv("LightDirection", Vector3f(1, 1, 1).data()); + + if (inv) + { + RenderUniform1f("invCoef", -1.0f); + RenderUniform1f("extraSpace", 2.0f); + } + else + { + RenderUniform1f("invCoef", 1.0f); + RenderUniform1f("extraSpace", 0.0f); + } Vector3f dayColor = Vector3f(0,0,0); @@ -322,8 +353,8 @@ void TAndroidApplication::DrawSnow() void TAndroidApplication::DrawAllScene(bool toScreen) { - glClearColor(1.f, 0.f, 1.f, 1.0f); - //glClearColor(1.f, 1.f, 1.f, 1.0f); + //glClearColor(1.f, 0.f, 1.f, 1.0f); + glClearColor(0.9f, 0.9f, 1.f, 1.0f); glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT); Renderer->PushMatrix(); @@ -332,6 +363,8 @@ void TAndroidApplication::DrawAllScene(bool toScreen) Renderer->PushShader("ClipShader"); + + Renderer->SwitchToFrameBuffer("WaterFrame"); Renderer->SetGLCamView(); Renderer->ScaleMatrix(Vector3f(1, -1, 1)); @@ -353,7 +386,7 @@ void TAndroidApplication::DrawAllScene(bool toScreen) } Renderer->SetGLCamView(); - + Renderer->PushShader("NormShader"); RenderUniform1f("Time", WaterTimer); if (Renderer->GetScreenWidth() < 600) @@ -369,18 +402,19 @@ void TAndroidApplication::DrawAllScene(bool toScreen) glActiveTexture(GL_TEXTURE1); // THIS IS A COLOR MAP (UNIFORM IS SETTED BY ENGINE IN Renderer->PushShader() -> SetUnifroms()) if (toScreen) { - Renderer->SetFullScreenViewport(); + Renderer->SetFullScreenViewport(); } else { Renderer->SetFrameViewport("ScreenshotFrame"); } - Renderer->DrawFramePartScreen("WaterFrame", Vector2f(0, 0), Vector2f(1.f, 0.54f)); + Renderer->DrawFramePartScreen("WaterFrame", Vector2f(0, 0), Vector2f(1.f, 0.55f)); glActiveTexture(GL_TEXTURE0); // return back Renderer->PopShader(); + glClear(GL_DEPTH_BUFFER_BIT); @@ -393,10 +427,10 @@ void TAndroidApplication::DrawAllScene(bool toScreen) glBindTexture(GL_TEXTURE_2D, ResourceManager->TexList["snow.png"]); - //if (SnowPref) - //{ - // DrawSnow(); - //} + if (SnowPref) + { + DrawSnow(); + } Renderer->PopShader(); @@ -454,7 +488,6 @@ void TAndroidApplication::InnerInit() boost::get(Renderer->Camera).MovePhi(pi / 360.f * 5); mCamera.MovePhi(pi / 360.f * 5); - if (Renderer->GetScreenWidth() > Renderer->GetScreenHeight()) { diff --git a/jni/main_code.h b/jni/main_code.h index da6b5d6..899195b 100755 --- a/jni/main_code.h +++ b/jni/main_code.h @@ -24,7 +24,6 @@ #include "boost/shared_ptr.hpp" #include "boost/thread/thread.hpp" #include "boost/asio.hpp" -#include "boost/signal.hpp" #include "boost/assign.hpp" #include "boost/variant.hpp" #include "boost/function.hpp" diff --git a/windows/Template/Template.vcxproj b/windows/Template/Template.vcxproj index 0adb993..3d75e5a 100644 --- a/windows/Template/Template.vcxproj +++ b/windows/Template/Template.vcxproj @@ -96,7 +96,7 @@ - ../../jni/;../../../boost_1_67_0;../../../eigen-3.3.4;../../../tes-engine;../../../libs/jpeg-9;../../../libs/jpeg-9/vc10;../../../libs/lpng1510;%(AdditionalIncludeDirectories) + ../../jni/;../../../boost_1_67_0;../../../eigen;../../../tes-engine;../../../libs/jpeg-9;../../../libs/jpeg-9/vc10;../../../libs/lpng1510;%(AdditionalIncludeDirectories) Sync TARGET_WIN32;DEBUG;_WIN32_WINNT=0x0600;EIGEN_DONT_ALIGN_STATICALLY;%(PreprocessorDefinitions) Level3 @@ -114,7 +114,7 @@ - ../../jni/;../../../boost_1_67_0;../../../eigen-3.3.4;../../../tes-engine;../../../libs/jpeg-9;../../../libs/jpeg-9/vc10;../../../libs/lpng1510;%(AdditionalIncludeDirectories) + ../../jni/;../../../boost_1_67_0;../../../eigen;../../../tes-engine;../../../libs/jpeg-9;../../../libs/jpeg-9/vc10;../../../libs/lpng1510;%(AdditionalIncludeDirectories) Async TARGET_WIN32;NDEBUG;_WIN32_WINNT=0x0501;%(PreprocessorDefinitions)