diff --git a/Debug/astria.exe b/Debug/astria.exe index fd7846e..93ab773 100644 Binary files a/Debug/astria.exe and b/Debug/astria.exe differ diff --git a/Debug/astria.ilk b/Debug/astria.ilk index 199d620..e14b56f 100644 Binary files a/Debug/astria.ilk and b/Debug/astria.ilk differ diff --git a/Debug/astria.pdb b/Debug/astria.pdb index e4b834b..fd9baa1 100644 Binary files a/Debug/astria.pdb and b/Debug/astria.pdb differ diff --git a/Debug/credits.txt b/Debug/credits.txt index c3ce60a..3caa8ea 100644 --- a/Debug/credits.txt +++ b/Debug/credits.txt @@ -8,6 +8,7 @@ SplashScreen - Perilous Ice Shape by tobylewin Skybox - from www.custommapmakers.org/skyboxes.php Models - tf3dm.com - www.turbosquid.com -Font - After shok by eightface - - Gunplay by Typodermic Fonts +Font - After shok by eightface + - Gunplay by Typodermic Fonts + - Ethnocentric by Typodermic Fonts Music - Self Esteem Fund from Portal diff --git a/Debug/help.txt b/Debug/help.txt index cea23fe..d9be24e 100644 --- a/Debug/help.txt +++ b/Debug/help.txt @@ -2,7 +2,8 @@ WASD - Movement Mouse - Look MouseWheel - Zoom In/Out Hold Shift - Toggle Sprint -Q - Toggle Wireframe Mode F - Toggle Fog (to see the beautiful skybox) G - Toggle Gravity (also collision with map) +N - Toggle Normal Map +M - Pause/Resume Music & Sound Effects Escape - Pause \ No newline at end of file diff --git a/Debug/params.ini b/Debug/params.ini index 2dd622b..bacc079 100644 --- a/Debug/params.ini +++ b/Debug/params.ini @@ -1,5 +1,5 @@ WindowName Desolation -VersionNumber 0.2.3 +VersionNumber 0.2.3a ResolutionWidth 1024 ResolutionHeight 768 IconImage gfx/img/dota2sf_icon.png diff --git a/Debug/shaders/instancing.vert b/Debug/shaders/instancing.vert index 9d939e8..27a79b9 100644 --- a/Debug/shaders/instancing.vert +++ b/Debug/shaders/instancing.vert @@ -1,9 +1,19 @@ #version 330 -layout(location = 0) in vec3 inPosition; -layout(location = 1) in vec2 inCoords; -layout(location = 2) in vec3 inNormal; -layout(location = 3) in mat4 inModelMatrix; +layout (location = 0) in vec3 inPosition; +layout (location = 1) in vec2 inCoords; +layout (location = 2) in vec3 inNormal; +layout (location = 3) in vec3 inTangent; +layout (location = 4) in vec3 inBitangent; +layout (location = 5) in mat4 inModelMatrix; + +struct DirectionalLight +{ + vec3 vColor; + vec3 vDirection; + float fAmbient; + float fBrightness; +}; uniform struct Matrices { @@ -15,6 +25,11 @@ smooth out vec3 vNormal; smooth out vec2 vTexCoord; smooth out vec3 vWorldPos; +out vec3 vLightDir_tangentspace; + +uniform DirectionalLight sunLight; +uniform bool bEnableNormalMap; + void main() { mat4 mMVP = matrices.mProjection * matrices.mView * inModelMatrix; diff --git a/Debug/shaders/main_shader.frag b/Debug/shaders/main_shader.frag index 52a13e6..30afd76 100644 --- a/Debug/shaders/main_shader.frag +++ b/Debug/shaders/main_shader.frag @@ -1,16 +1,9 @@ #version 330 -#include - -smooth in vec2 vTexCoord; -smooth in vec3 vNormal; -smooth in vec4 vEyeSpacePos; -smooth in vec3 vWorldPos; -out vec4 outputColor; - struct Material { sampler2D diffuse; + sampler2D normal; sampler2D specular; }; @@ -54,6 +47,16 @@ uniform FogParameters fogParams; uniform int bSkybox; uniform int bFog; +uniform bool bEnableNormalMap; + +smooth in vec2 vTexCoord; +smooth in vec3 vNormal; +smooth in vec4 vEyeSpacePos; +smooth in vec3 vWorldPos; +in vec3 vLightDir_tangentspace; +in vec3 vEyeDir_tangentspace; + +out vec4 outputColor; void main() { @@ -69,20 +72,29 @@ void main() return; } - vec3 vNormalized = normalize(vNormal); + vec3 vNormal_extended = normalize(vNormal); + vec3 vLightDir = sunLight.vDirection; + vec3 vEyeDirection = vEyePosition - vWorldPos; + + if(bEnableNormalMap) + { + vNormal_extended = normalize(texture2D(mat.normal, vTexCoord).rgb*2.0-1.0); + vLightDir = normalize(vLightDir_tangentspace); + vEyeDirection = vEyeDir_tangentspace; + } //Diffuse light - float fDiffuseIntensity = clamp(dot(vNormal, -sunLight.vDirection), 0.0, 1.0); - vec3 vDiffuseColor = pow(sunLight.fBrightness,2) * sunLight.vColor * fDiffuseIntensity * vec3(texture2D(mat.diffuse, vTexCoord)); + float fDiffuseIntensity = clamp(dot(vNormal_extended, -vLightDir), 0.0, 1.0); + vec3 vDiffuseColor = sunLight.fBrightness * sunLight.vColor * fDiffuseIntensity * vec3(texture2D(mat.diffuse, vTexCoord)); //Ambient vec3 vAmbientColor = sunLight.vColor * sunLight.fAmbient * vec3(texture2D(mat.diffuse, vTexCoord)); - //Specular - vec3 vReflected = normalize(reflect(sunLight.vDirection, vNormalized)); - vec3 vView = normalize(vEyePosition - vWorldPos); + //Specular + vec3 vReflected = reflect(vLightDir, vNormal_extended); + vec3 vView = normalize(vEyeDirection); float fSpecularIntensity = clamp(dot(vReflected, vView), 0, 1); - vec3 vSpecularColor = 0.6 * sunLight.vColor * fSpecularIntensity * vec3(texture2D(mat.specular, vTexCoord)); + vec3 vSpecularColor = sunLight.fBrightness * 0.6 * sunLight.vColor * fSpecularIntensity * vec3(texture2D(mat.specular, vTexCoord)); outputColor = vec4(vAmbientColor + vDiffuseColor + vSpecularColor, 1.0f); diff --git a/Debug/shaders/main_shader.vert b/Debug/shaders/main_shader.vert index f451f9b..89bfaff 100644 --- a/Debug/shaders/main_shader.vert +++ b/Debug/shaders/main_shader.vert @@ -8,9 +8,20 @@ uniform struct Matrices mat4 mNormal; } matrices; +struct DirectionalLight +{ + vec3 vColor; + vec3 vDirection; + float fAmbient; + float fBrightness; +}; + layout (location = 0) in vec3 inPosition; layout (location = 1) in vec2 inCoord; layout (location = 2) in vec3 inNormal; +layout (location = 3) in vec3 inTangent; +layout (location = 4) in vec3 inBitangent; + smooth out vec3 vNormal; smooth out vec2 vTexCoord; @@ -18,16 +29,44 @@ smooth out vec3 vWorldPos; smooth out vec4 vEyeSpacePos; +out vec3 vEyeDir_tangentspace; +out vec3 vLightDir_tangentspace; + +uniform vec3 vEyePosition; +uniform DirectionalLight sunLight; +uniform bool bEnableNormalMap; + void main() { - mat4 mMV = matrices.mView*matrices.mModel; //Matrix multiplication is from left to right + mat4 mMV = matrices.mView*matrices.mModel; mat4 mMVP = matrices.mProjection*matrices.mView*matrices.mModel; vTexCoord = inCoord; - vEyeSpacePos = mMV*vec4(inPosition, 1.0); + vEyeSpacePos = mMV * vec4(inPosition, 1.0); gl_Position = mMVP*vec4(inPosition, 1.0); vNormal = (matrices.mNormal*vec4(inNormal, 1.0)).xyz; vWorldPos = (matrices.mModel*vec4(inPosition, 1.0)).xyz; + + //Eye space calculations + vec3 vLightDir_eyespace = (mMV * vec4(-sunLight.vDirection, 1.0f)).xyz; + vec3 vEyeDir_eyespace = vec3(0,0,0) - (vEyeSpacePos).xyz; + + if(bEnableNormalMap) + { + mat3 mMV3x3 = mat3(mMV); + + vec3 vNormal_eyespace = mMV3x3 * inNormal; + vec3 vTangent_eyespace = mMV3x3 * inTangent; + vec3 vBitangent_eyespace = mMV3x3 * inBitangent; + + mat3 mTBN = transpose(mat3(vTangent_eyespace, vBitangent_eyespace, vNormal_eyespace)); + vLightDir_tangentspace = mTBN * vLightDir_eyespace; + vEyeDir_tangentspace = mTBN * vEyeDir_eyespace; + } + else + { + vLightDir_tangentspace = vec3(0,0,0); + } } \ No newline at end of file diff --git a/Release/astria.exe b/Release/astria.exe deleted file mode 100644 index 74a7e6f..0000000 Binary files a/Release/astria.exe and /dev/null differ diff --git a/Release/astria.pdb b/Release/astria.pdb index 82bf34e..2d9da41 100644 Binary files a/Release/astria.pdb and b/Release/astria.pdb differ diff --git a/Release/credits.txt b/Release/credits.txt index c3ce60a..3caa8ea 100644 --- a/Release/credits.txt +++ b/Release/credits.txt @@ -8,6 +8,7 @@ SplashScreen - Perilous Ice Shape by tobylewin Skybox - from www.custommapmakers.org/skyboxes.php Models - tf3dm.com - www.turbosquid.com -Font - After shok by eightface - - Gunplay by Typodermic Fonts +Font - After shok by eightface + - Gunplay by Typodermic Fonts + - Ethnocentric by Typodermic Fonts Music - Self Esteem Fund from Portal diff --git a/Release/gfx/Thumbs.db b/Release/gfx/Thumbs.db index c7e460d..1d208be 100644 Binary files a/Release/gfx/Thumbs.db and b/Release/gfx/Thumbs.db differ diff --git a/Release/gfx/barrel/Thumbs.db b/Release/gfx/barrel/Thumbs.db index 517f2fc..fc539f0 100644 Binary files a/Release/gfx/barrel/Thumbs.db and b/Release/gfx/barrel/Thumbs.db differ diff --git a/Release/gfx/coffee_tree/Thumbs.db b/Release/gfx/coffee_tree/Thumbs.db index f2973d7..d84d568 100644 Binary files a/Release/gfx/coffee_tree/Thumbs.db and b/Release/gfx/coffee_tree/Thumbs.db differ diff --git a/Release/gfx/img/Thumbs.db b/Release/gfx/img/Thumbs.db index 5f12eca..389bf22 100644 Binary files a/Release/gfx/img/Thumbs.db and b/Release/gfx/img/Thumbs.db differ diff --git a/Release/gfx/nanosuit/Thumbs.db b/Release/gfx/nanosuit/Thumbs.db index 9fc1d37..e079ae4 100644 Binary files a/Release/gfx/nanosuit/Thumbs.db and b/Release/gfx/nanosuit/Thumbs.db differ diff --git a/Release/help.txt b/Release/help.txt index d041692..d9be24e 100644 --- a/Release/help.txt +++ b/Release/help.txt @@ -4,4 +4,6 @@ MouseWheel - Zoom In/Out Hold Shift - Toggle Sprint F - Toggle Fog (to see the beautiful skybox) G - Toggle Gravity (also collision with map) +N - Toggle Normal Map +M - Pause/Resume Music & Sound Effects Escape - Pause \ No newline at end of file diff --git a/Release/params.ini b/Release/params.ini index 2dd622b..bacc079 100644 --- a/Release/params.ini +++ b/Release/params.ini @@ -1,5 +1,5 @@ WindowName Desolation -VersionNumber 0.2.3 +VersionNumber 0.2.3a ResolutionWidth 1024 ResolutionHeight 768 IconImage gfx/img/dota2sf_icon.png diff --git a/Release/shaders/main_shader.frag b/Release/shaders/main_shader.frag index 8606fe8..30afd76 100644 --- a/Release/shaders/main_shader.frag +++ b/Release/shaders/main_shader.frag @@ -74,27 +74,28 @@ void main() vec3 vNormal_extended = normalize(vNormal); vec3 vLightDir = sunLight.vDirection; + vec3 vEyeDirection = vEyePosition - vWorldPos; if(bEnableNormalMap) { vNormal_extended = normalize(texture2D(mat.normal, vTexCoord).rgb*2.0-1.0); - vLightDir = vLightDir_tangentspace; + vLightDir = normalize(vLightDir_tangentspace); + vEyeDirection = vEyeDir_tangentspace; } //Diffuse light float fDiffuseIntensity = clamp(dot(vNormal_extended, -vLightDir), 0.0, 1.0); - vec3 vDiffuseColor = pow(sunLight.fBrightness,2) * sunLight.vColor * fDiffuseIntensity * vec3(texture2D(mat.diffuse, vTexCoord)); - //vDiffuseColor = vec3(0,0,0); + vec3 vDiffuseColor = sunLight.fBrightness * sunLight.vColor * fDiffuseIntensity * vec3(texture2D(mat.diffuse, vTexCoord)); //Ambient vec3 vAmbientColor = sunLight.vColor * sunLight.fAmbient * vec3(texture2D(mat.diffuse, vTexCoord)); - //Specular - vec3 vReflected = (reflect(sunLight.vDirection, vNormal)); //Not using normal map yet - vec3 vView = normalize(vEyePosition - vWorldPos); + //Specular + vec3 vReflected = reflect(vLightDir, vNormal_extended); + vec3 vView = normalize(vEyeDirection); float fSpecularIntensity = clamp(dot(vReflected, vView), 0, 1); - vec3 vSpecularColor = 0.6 * sunLight.vColor * fSpecularIntensity * vec3(texture2D(mat.specular, vTexCoord)); - + vec3 vSpecularColor = sunLight.fBrightness * 0.6 * sunLight.vColor * fSpecularIntensity * vec3(texture2D(mat.specular, vTexCoord)); + outputColor = vec4(vAmbientColor + vDiffuseColor + vSpecularColor, 1.0f); if (bFog == 1) diff --git a/Release/shaders/main_shader.vert b/Release/shaders/main_shader.vert index 5c04479..89bfaff 100644 --- a/Release/shaders/main_shader.vert +++ b/Release/shaders/main_shader.vert @@ -32,36 +32,41 @@ smooth out vec4 vEyeSpacePos; out vec3 vEyeDir_tangentspace; out vec3 vLightDir_tangentspace; +uniform vec3 vEyePosition; uniform DirectionalLight sunLight; uniform bool bEnableNormalMap; void main() { - mat4 mMV = matrices.mView*matrices.mModel; //Matrix multiplication is from left to right + mat4 mMV = matrices.mView*matrices.mModel; mat4 mMVP = matrices.mProjection*matrices.mView*matrices.mModel; vTexCoord = inCoord; - vEyeSpacePos = mMV*vec4(inPosition, 1.0); + vEyeSpacePos = mMV * vec4(inPosition, 1.0); gl_Position = mMVP*vec4(inPosition, 1.0); vNormal = (matrices.mNormal*vec4(inNormal, 1.0)).xyz; vWorldPos = (matrices.mModel*vec4(inPosition, 1.0)).xyz; - vec3 vEyeDir_eyespace = vec3(0,0,0) - vEyeSpacePos.xyz; + //Eye space calculations + vec3 vLightDir_eyespace = (mMV * vec4(-sunLight.vDirection, 1.0f)).xyz; + vec3 vEyeDir_eyespace = vec3(0,0,0) - (vEyeSpacePos).xyz; if(bEnableNormalMap) { mat3 mMV3x3 = mat3(mMV); - vec3 vNormal_eyespace = mMV3x3 * normalize(vNormal); + vec3 vNormal_eyespace = mMV3x3 * inNormal; vec3 vTangent_eyespace = mMV3x3 * inTangent; vec3 vBitangent_eyespace = mMV3x3 * inBitangent; mat3 mTBN = transpose(mat3(vTangent_eyespace, vBitangent_eyespace, vNormal_eyespace)); - vLightDir_tangentspace = normalize(mTBN * sunLight.vDirection); - vEyeDir_tangentspace = normalize(mTBN * vEyeDir_eyespace); + vLightDir_tangentspace = mTBN * vLightDir_eyespace; + vEyeDir_tangentspace = mTBN * vEyeDir_eyespace; } else + { vLightDir_tangentspace = vec3(0,0,0); + } } \ No newline at end of file diff --git a/astria.v12.suo b/astria.v12.suo index b56f74f..c864ec0 100644 Binary files a/astria.v12.suo and b/astria.v12.suo differ diff --git a/astria/AppStateMain.cpp b/astria/AppStateMain.cpp index c7b1077..2d5c5ab 100644 --- a/astria/AppStateMain.cpp +++ b/astria/AppStateMain.cpp @@ -26,6 +26,7 @@ void CAppStateMain::OnActivate() MouseSpeed = 0.0015f; GravityEnabled = false; FogEnabled = 1; + NormalMapEnabled = true; CLoadingScreen::OnActivate(&Loaded); Loaded = OnLoad(); if (!Loaded) CMain::GetInstance()->Running = false; @@ -33,7 +34,7 @@ void CAppStateMain::OnActivate() } //Resume all sound effects for when we return from pause - CSoundEffect::ResumeAll(); + if(!SfxPaused) SoundFire.Resume(); //Hide mouse cursor if (SDL_ShowCursor(SDL_DISABLE) < 0) @@ -57,7 +58,7 @@ void CAppStateMain::OnDeactivate() SDL_FreeSurface(Surf_Tmp); //Pause all sound effects - CSoundEffect::PauseAll(); + SoundFire.Pause(); SDL_ShowCursor(SDL_ENABLE); } @@ -210,7 +211,7 @@ void CAppStateMain::OnRender() newPos.y = Map.GetHeight(newPos); ModelMatrix = glm::translate(glm::mat4(1.0), newPos); ProgramMain.SetModelAndNormalMatrix("matrices.mModel", "matrices.mNormal", ModelMatrix); - ProgramMain.SetUniform("bEnableNormalMap", true); + ProgramMain.SetUniform("bEnableNormalMap", NormalMapEnabled); models[0].Render(); newPos = glm::vec3(64, 0, 193); @@ -219,10 +220,11 @@ void CAppStateMain::OnRender() ModelMatrix = glm::scale(ModelMatrix, glm::vec3(5.0)); ModelMatrix = glm::rotate(ModelMatrix, -90.0f, glm::vec3(1, 0, 0)); ProgramMain.SetModelAndNormalMatrix("matrices.mModel", "matrices.mNormal", ModelMatrix); - ProgramMain.SetUniform("bEnableNormalMap", models[1].NormalMap()); + ProgramMain.SetUniform("bEnableNormalMap", NormalMapEnabled); models[1].Render(); //Render instanced models + CModel::BindVAO(); ProgramInstancing.Use(); ProgramInstancing.SetUniform("matrices.mProjection", ProjectionMatrix); ProgramInstancing.SetUniform("matrices.mView", ViewMatrix); @@ -280,7 +282,8 @@ void CAppStateMain::OnRender() FontEthnocentric.PrintFormatted(25, 25, 18, "Shao Kun Deng | Project ASTRIA v.%s", CParams::VersionNumber); ProgramFont.SetUniform("vColor", glm::vec4(0.4, 0.4, 0.4, 1.0f)); FontGunplay.PrintFormatted(20, height - 30, 18, "FPS: %d", CFPS::FPSControl.GetFPS()); - FontGunplay.Print(HelpText, 20, height - 50, 18); + FontGunplay.PrintFormatted(20, height - 50, 18, "Normal map: %s", NormalMapEnabled ? "Enabled" : "Disabled"); + FontGunplay.Print(HelpText, 20, height - 70, 18); SDL_GL_SwapWindow(CMain::GetInstance()->GetWindow()); } @@ -451,6 +454,7 @@ int CAppStateMain::OnLoad() HorizontalAngle = 0.5f; VerticalAngle = -0.1f; + MusicPaused = SfxPaused = false; MusicMain.Load("sound/PortalSelfEsteemFund.mp3"); MusicMain.Play(); @@ -516,12 +520,24 @@ void CAppStateMain::OnKeyDown(SDL_Keycode sym, Uint16 mod, SDL_Scancode scancode break; case SDLK_f: + //Toggle fog FogEnabled = 1 - FogEnabled; break; case SDLK_g: //Toggle gravity GravityEnabled = !GravityEnabled; break; + case SDLK_m: + //Toggle music + if (MusicPaused) { MusicMain.Resume(); MusicPaused = false; } + else { MusicMain.Pause(); MusicPaused = true; } + if (SfxPaused) { SoundFire.Resume(); SfxPaused = false; } + else { SoundFire.Pause(); SfxPaused = true; } + break; + case SDLK_n: + //Toggle normal map + NormalMapEnabled = !NormalMapEnabled; + break; } } diff --git a/astria/AppStateMain.h b/astria/AppStateMain.h index 5d04c5e..d2abaf6 100644 --- a/astria/AppStateMain.h +++ b/astria/AppStateMain.h @@ -108,6 +108,7 @@ class CAppStateMain : public CAppState bool GravityEnabled; int FogEnabled; + bool NormalMapEnabled; //Control parameters float Speed; //Speed of movements @@ -116,6 +117,7 @@ class CAppStateMain : public CAppState //Music and sound effects CMusic MusicMain; CSoundEffect SoundFire; + bool MusicPaused, SfxPaused; //Font Text_GL FontGunplay; diff --git a/astria/Common.h b/astria/Common.h index 90e1de6..af06e5a 100644 --- a/astria/Common.h +++ b/astria/Common.h @@ -21,6 +21,8 @@ #include #include +#define NDEBUG + extern std::string HelpText; extern std::string CreditsText; diff --git a/astria/Model.cpp b/astria/Model.cpp index e2e8463..659651a 100644 --- a/astria/Model.cpp +++ b/astria/Model.cpp @@ -310,20 +310,18 @@ void CInstancedModel::UploadMatrices(int count, glm::mat4* model) glBindVertexArray(VAO); - vboMatrixData.AddData(model, count*sizeof(glm::mat4)); - vboMatrixData.Bind(); vboMatrixData.UploadGPU(GL_STATIC_DRAW); - glEnableVertexAttribArray(3); + glEnableVertexAttribArray(5); glVertexAttribPointer(5, 4, GL_FLOAT, GL_FALSE, 4 * sizeof(glm::vec4), (GLvoid*)0); - glEnableVertexAttribArray(4); + glEnableVertexAttribArray(6); glVertexAttribPointer(6, 4, GL_FLOAT, GL_FALSE, 4 * sizeof(glm::vec4), (GLvoid*)(sizeof(glm::vec4))); - glEnableVertexAttribArray(5); + glEnableVertexAttribArray(7); glVertexAttribPointer(7, 4, GL_FLOAT, GL_FALSE, 4 * sizeof(glm::vec4), (GLvoid*)(2 * sizeof(glm::vec4))); - glEnableVertexAttribArray(6); + glEnableVertexAttribArray(8); glVertexAttribPointer(8, 4, GL_FLOAT, GL_FALSE, 4 * sizeof(glm::vec4), (GLvoid*)(3 * sizeof(glm::vec4))); glVertexAttribDivisor(5, 1); diff --git a/astria/PxMain.cpp b/astria/PxMain.cpp new file mode 100644 index 0000000..6389497 --- /dev/null +++ b/astria/PxMain.cpp @@ -0,0 +1,89 @@ +#include "PxMain.h" + +PxDefaultAllocator CPhysx::gDefaultAllocatorCallback; +PxDefaultErrorCallback CPhysx::gDefaultErrorCallback; +PxSimulationFilterShader CPhysx::gDefaultFilterShader; + +CPhysx::CPhysx() +{ + mFoundation = NULL; + gDefaultFilterShader = PxDefaultSimulationFilterShader; + + //Initialize settings + mRecordMemoryAllocations = true; + mNumThreads = 1; +} + +CPhysx::~CPhysx() +{ + +} + +bool CPhysx::OnInitialize() +{ + //Title of all error and warning window in this method + const std::string LOG_TAG = "PhysX OnInitialize Error"; + + //Create the foundation + mFoundation = PxCreateFoundation(PX_PHYSICS_VERSION, gDefaultAllocatorCallback, gDefaultErrorCallback); + if (!mFoundation) + { + Error(LOG_TAG, "PxCreateFoundation failed!"); + return false; + } + + //Create a PxPhysics object with no profile zone manager + mPhysics = PxCreatePhysics(PX_PHYSICS_VERSION, *mFoundation, PxTolerancesScale(), mRecordMemoryAllocations); + + //Initialize the cooking library + mCooking = PxCreateCooking(PX_PHYSICS_VERSION, *mFoundation, PxCookingParams(PxTolerancesScale())); + + //Initialize extensions + if (!PxInitExtensions(*mPhysics)) + { + Error(LOG_TAG, "PxInitExtensions failed!"); + return false; + } + + //Initialize scene + mSceneDescriptor = new PxSceneDesc(mPhysics->getTolerancesScale()); + mSceneDescriptor->gravity = PxVec3(0.0f, -9.81f, 0.0f); + // ===>customize mSceneDescriptor here<=== + + if (!mSceneDescriptor->cpuDispatcher) + { + mCpuDispatcher = PxDefaultCpuDispatcherCreate(mNumThreads); + if (!mCpuDispatcher) + { + Error(LOG_TAG, "PxDefaultCpuDispatcherCreate failed!"); + return false; + } + mSceneDescriptor->cpuDispatcher = mCpuDispatcher; + } + if (!mSceneDescriptor->filterShader) + { + mSceneDescriptor->filterShader = gDefaultFilterShader; + } +#ifdef PX_WINDOWS + //Set gpu dispatcher for CUDA-accelerated features + //if (!mSceneDescriptor->gpuDispatcher && mCudaContextManager) + //{ + // mSceneDescriptor->gpuDispatcher = mCudaContextManager->getGpuDispatcher(); + //} +#endif + + mScene = mPhysics->createScene(*mSceneDescriptor); + if (!mScene) + { + Error(LOG_TAG, "createScene failed!"); + return false; + } + + return true; +} + +void CPhysx::OnShutdown() +{ + mPhysics->release(); + mFoundation->release(); +} \ No newline at end of file diff --git a/astria/PxMain.h b/astria/PxMain.h new file mode 100644 index 0000000..49c8213 --- /dev/null +++ b/astria/PxMain.h @@ -0,0 +1,56 @@ +#ifndef _PX_MAIN_H_ +#define _PX_MAIN_H_ + +#include "Common.h" +#include "utils.h" + +#include +#include +#include +#include +#include +#include +#include +#include + +#pragma comment(lib, "PhysX3_x86.lib") +#pragma comment(lib, "PhysX3Common_x86.lib") +#pragma comment(lib, "PhysX3Extensions.lib") +#pragma comment(lib, "PhysX3Cooking_x86.lib") +#pragma comment(lib, "PxTask.lib") + +using namespace physx; + +class CPhysx +{ +public: + CPhysx(); + ~CPhysx(); + + bool OnInitialize(); + void OnStep(); + void OnRender(); + + void OnShutdown(); + +private: + //basic objects + PxFoundation* mFoundation; + static PxDefaultAllocator gDefaultAllocatorCallback; + static PxDefaultErrorCallback gDefaultErrorCallback; + PxPhysics* mPhysics; + PxCooking* mCooking; + + //Scene + PxScene* mScene; + PxSceneDesc* mSceneDescriptor; + static PxSimulationFilterShader gDefaultFilterShader; + PxDefaultCpuDispatcher* mCpuDispatcher; + + //settings + bool mRecordMemoryAllocations; + int mNumThreads; +}; + + +#endif \ No newline at end of file diff --git a/astria/Release/AppStateIntro.obj b/astria/Release/AppStateIntro.obj index 200def7..3f3324d 100644 Binary files a/astria/Release/AppStateIntro.obj and b/astria/Release/AppStateIntro.obj differ diff --git a/astria/Release/AppStateMain.obj b/astria/Release/AppStateMain.obj index 03a52e1..4c03117 100644 Binary files a/astria/Release/AppStateMain.obj and b/astria/Release/AppStateMain.obj differ diff --git a/astria/Release/AppStateManager.obj b/astria/Release/AppStateManager.obj index 9fd5998..11f1321 100644 Binary files a/astria/Release/AppStateManager.obj and b/astria/Release/AppStateManager.obj differ diff --git a/astria/Release/AppStatePause.obj b/astria/Release/AppStatePause.obj index c1b3c81..84905b2 100644 Binary files a/astria/Release/AppStatePause.obj and b/astria/Release/AppStatePause.obj differ diff --git a/astria/Release/Event.obj b/astria/Release/Event.obj index 6ac4524..caeeb58 100644 Binary files a/astria/Release/Event.obj and b/astria/Release/Event.obj differ diff --git a/astria/Release/FPS.obj b/astria/Release/FPS.obj index 4f26f62..78362ee 100644 Binary files a/astria/Release/FPS.obj and b/astria/Release/FPS.obj differ diff --git a/astria/Release/FileManager.obj b/astria/Release/FileManager.obj index 906b01b..9efafa4 100644 Binary files a/astria/Release/FileManager.obj and b/astria/Release/FileManager.obj differ diff --git a/astria/Release/Fog.obj b/astria/Release/Fog.obj index 0aac49c..c779bf0 100644 Binary files a/astria/Release/Fog.obj and b/astria/Release/Fog.obj differ diff --git a/astria/Release/Font.obj b/astria/Release/Font.obj index b5e8fde..024d291 100644 Binary files a/astria/Release/Font.obj and b/astria/Release/Font.obj differ diff --git a/astria/Release/HeightMap.obj b/astria/Release/HeightMap.obj index 604865a..031e66c 100644 Binary files a/astria/Release/HeightMap.obj and b/astria/Release/HeightMap.obj differ diff --git a/astria/Release/Light.obj b/astria/Release/Light.obj index 9eb6265..1a1b3ba 100644 Binary files a/astria/Release/Light.obj and b/astria/Release/Light.obj differ diff --git a/astria/Release/LoadingScreen.obj b/astria/Release/LoadingScreen.obj index 6ab79f7..ec9b8fe 100644 Binary files a/astria/Release/LoadingScreen.obj and b/astria/Release/LoadingScreen.obj differ diff --git a/astria/Release/Main.obj b/astria/Release/Main.obj index 0bb849d..ba5c8bd 100644 Binary files a/astria/Release/Main.obj and b/astria/Release/Main.obj differ diff --git a/astria/Release/Model.obj b/astria/Release/Model.obj index ff2c7f9..76abddf 100644 Binary files a/astria/Release/Model.obj and b/astria/Release/Model.obj differ diff --git a/astria/Release/Params.obj b/astria/Release/Params.obj index 4f11966..c10fa59 100644 Binary files a/astria/Release/Params.obj and b/astria/Release/Params.obj differ diff --git a/astria/Release/ParticleSystem.obj b/astria/Release/ParticleSystem.obj index b4ba785..1e708b8 100644 Binary files a/astria/Release/ParticleSystem.obj and b/astria/Release/ParticleSystem.obj differ diff --git a/astria/Release/PxMain.obj b/astria/Release/PxMain.obj new file mode 100644 index 0000000..c22fc07 Binary files /dev/null and b/astria/Release/PxMain.obj differ diff --git a/astria/Release/Shader.obj b/astria/Release/Shader.obj index 5fe2321..1a3ceef 100644 Binary files a/astria/Release/Shader.obj and b/astria/Release/Shader.obj differ diff --git a/astria/Release/Skybox.obj b/astria/Release/Skybox.obj index 78d11f7..6fca263 100644 Binary files a/astria/Release/Skybox.obj and b/astria/Release/Skybox.obj differ diff --git a/astria/Release/Sound.obj b/astria/Release/Sound.obj index aa37e75..406bd68 100644 Binary files a/astria/Release/Sound.obj and b/astria/Release/Sound.obj differ diff --git a/astria/Release/Stringify.obj b/astria/Release/Stringify.obj index 144a581..8b719dd 100644 Binary files a/astria/Release/Stringify.obj and b/astria/Release/Stringify.obj differ diff --git a/astria/Release/Texture.obj b/astria/Release/Texture.obj index b48ccba..dbd3e32 100644 Binary files a/astria/Release/Texture.obj and b/astria/Release/Texture.obj differ diff --git a/astria/Release/TextureBank_SDL.obj b/astria/Release/TextureBank_SDL.obj index 8f3e4b2..653f5db 100644 Binary files a/astria/Release/TextureBank_SDL.obj and b/astria/Release/TextureBank_SDL.obj differ diff --git a/astria/Release/Texture_SDL.obj b/astria/Release/Texture_SDL.obj index 6c48d1d..3021675 100644 Binary files a/astria/Release/Texture_SDL.obj and b/astria/Release/Texture_SDL.obj differ diff --git a/astria/Release/VBO.obj b/astria/Release/VBO.obj index 86146a8..6dedd36 100644 Binary files a/astria/Release/VBO.obj and b/astria/Release/VBO.obj differ diff --git a/astria/Release/Water.obj b/astria/Release/Water.obj index 74fee20..94a8d09 100644 Binary files a/astria/Release/Water.obj and b/astria/Release/Water.obj differ diff --git a/astria/Release/astria.log b/astria/Release/astria.log index 0431c16..68ee09a 100644 --- a/astria/Release/astria.log +++ b/astria/Release/astria.log @@ -1,18 +1,7 @@ -Build started 2/27/2015 3:21:29 AM. +Build started 3/8/2015 5:42:31 PM. 1>Project "C:\Users\kvp_\astria\astria\astria.vcxproj" on node 2 (Build target(s)). - 1>ClCompile: - C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\bin\CL.exe /c /IC:\Users\kvp_\Documents\LocalSDK\include\freetype /Zi /nologo /W3 /WX- /sdl /O2 /Oi /Oy- /GL /D _CRT_NONSTDC_NO_DEPRECATE /D _CRT_SECURE_NO_DEPRECATE /D _MBCS /Gm- /EHsc /MD /GS /Gy /fp:precise /Zc:wchar_t /Zc:forScope /Fo"Release\\" /Fd"Release\vc120.pdb" /Gd /TP /analyze- /errorReport:prompt Model.cpp - Model.cpp - 1>Model.cpp(65): warning C4018: '<' : signed/unsigned mismatch - 1>Model.cpp(115): warning C4018: '<' : signed/unsigned mismatch - 1>Model.cpp(123): warning C4018: '<' : signed/unsigned mismatch - 1>Model.cpp(144): warning C4018: '<' : signed/unsigned mismatch - 1>Model.cpp(152): warning C4018: '<' : signed/unsigned mismatch - 1>Model.cpp(174): warning C4018: '<' : signed/unsigned mismatch - 1>Model.cpp(182): warning C4018: '<' : signed/unsigned mismatch - 1>Model.cpp(204): warning C4018: '<' : signed/unsigned mismatch - Link: - C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\bin\link.exe /ERRORREPORT:PROMPT /OUT:"C:\Users\kvp_\astria\Release\astria.exe" /NOLOGO SDL2.lib SDL2main.lib SDL2_image.lib SDL2_ttf.lib SDL2_mixer.lib opengl32.lib glu32.lib glew32.lib assimp.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /MANIFEST /MANIFESTUAC:"level='asInvoker' uiAccess='false'" /manifest:embed /DEBUG /PDB:"C:\Users\kvp_\astria\Release\astria.pdb" /SUBSYSTEM:WINDOWS /OPT:REF /OPT:ICF /LTCG /TLBID:1 /DYNAMICBASE /NXCOMPAT /IMPLIB:"C:\Users\kvp_\astria\Release\astria.lib" /MACHINE:X86 /SAFESEH Release\Fog.obj + 1>Link: + C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\bin\link.exe /ERRORREPORT:PROMPT /OUT:"C:\Users\kvp_\astria\Release\astria.exe" /NOLOGO /LIBPATH:C:\Users\kvp_\Documents\LocalSDK\physx332\Lib\vc11win32 SDL2.lib SDL2main.lib SDL2_image.lib SDL2_ttf.lib SDL2_mixer.lib opengl32.lib glu32.lib glew32.lib assimp.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /MANIFEST /MANIFESTUAC:"level='asInvoker' uiAccess='false'" /manifest:embed /DEBUG /PDB:"C:\Users\kvp_\astria\Release\astria.pdb" /SUBSYSTEM:WINDOWS /OPT:REF /OPT:ICF /LTCG /TLBID:1 /DYNAMICBASE /NXCOMPAT /IMPLIB:"C:\Users\kvp_\astria\Release\astria.lib" /MACHINE:X86 /SAFESEH /NODEFAULTLIB:libcmt.lib Release\Fog.obj Release\Font.obj Release\LoadingScreen.obj Release\AppStateMain.obj @@ -28,6 +17,7 @@ Release\Light.obj Release\Model.obj Release\ParticleSystem.obj + Release\PxMain.obj Release\Shader.obj Release\Skybox.obj Release\Sound.obj @@ -37,11 +27,29 @@ Release\Texture_SDL.obj Release\VBO.obj Release\Water.obj - Generating code - Finished generating code - astria.vcxproj -> C:\Users\kvp_\astria\Release\astria.exe - 1>Done Building Project "C:\Users\kvp_\astria\astria\astria.vcxproj" (Build target(s)). + 1>PhysX3Extensions.lib(ExtExtensions.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MT_StaticRelease' doesn't match value 'MD_DynamicRelease' in Fog.obj + 1>PhysX3Extensions.lib(ExtDefaultSimulationFilterShader.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MT_StaticRelease' doesn't match value 'MD_DynamicRelease' in Fog.obj + 1>PhysX3Extensions.lib(ExtDefaultErrorCallback.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MT_StaticRelease' doesn't match value 'MD_DynamicRelease' in Fog.obj + 1>PhysX3Extensions.lib(ExtDefaultCpuDispatcher.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MT_StaticRelease' doesn't match value 'MD_DynamicRelease' in Fog.obj + 1>PhysX3Extensions.lib(ExtDistanceJoint.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MT_StaticRelease' doesn't match value 'MD_DynamicRelease' in Fog.obj + 1>PhysX3Extensions.lib(ExtD6Joint.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MT_StaticRelease' doesn't match value 'MD_DynamicRelease' in Fog.obj + 1>PhysX3Extensions.lib(ExtFixedJoint.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MT_StaticRelease' doesn't match value 'MD_DynamicRelease' in Fog.obj + 1>PhysX3Extensions.lib(ExtPrismaticJoint.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MT_StaticRelease' doesn't match value 'MD_DynamicRelease' in Fog.obj + 1>PhysX3Extensions.lib(ExtRevoluteJoint.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MT_StaticRelease' doesn't match value 'MD_DynamicRelease' in Fog.obj + 1>PhysX3Extensions.lib(ExtSphericalJoint.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MT_StaticRelease' doesn't match value 'MD_DynamicRelease' in Fog.obj + 1>PhysX3Extensions.lib(SnRepXCoreSerializer.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MT_StaticRelease' doesn't match value 'MD_DynamicRelease' in Fog.obj + 1>PhysX3Extensions.lib(SnJointRepXSerializer.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MT_StaticRelease' doesn't match value 'MD_DynamicRelease' in Fog.obj + 1>PhysX3Extensions.lib(ExtCpuWorkerThread.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MT_StaticRelease' doesn't match value 'MD_DynamicRelease' in Fog.obj + 1>PhysX3Extensions.lib(ExtDistanceJointSolverPrep.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MT_StaticRelease' doesn't match value 'MD_DynamicRelease' in Fog.obj + 1>PhysX3Extensions.lib(ExtJoint.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MT_StaticRelease' doesn't match value 'MD_DynamicRelease' in Fog.obj + 1>PhysX3Extensions.lib(ExtD6JointSolverPrep.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MT_StaticRelease' doesn't match value 'MD_DynamicRelease' in Fog.obj + 1>PhysX3Extensions.lib(ExtFixedJointSolverPrep.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MT_StaticRelease' doesn't match value 'MD_DynamicRelease' in Fog.obj + 1>PhysX3Extensions.lib(ExtPrismaticJointSolverPrep.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MT_StaticRelease' doesn't match value 'MD_DynamicRelease' in Fog.obj + 1>PhysX3Extensions.lib(ExtRevoluteJointSolverPrep.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MT_StaticRelease' doesn't match value 'MD_DynamicRelease' in Fog.obj + 1>PhysX3Extensions.lib(ExtSphericalJointSolverPrep.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MT_StaticRelease' doesn't match value 'MD_DynamicRelease' in Fog.obj + 1>C:\Users\kvp_\astria\Release\astria.exe : fatal error LNK1319: 20 mismatches detected + 1>Done Building Project "C:\Users\kvp_\astria\astria\astria.vcxproj" (Build target(s)) -- FAILED. -Build succeeded. +Build FAILED. -Time Elapsed 00:00:05.30 +Time Elapsed 00:00:03.70 diff --git a/astria/Release/astria.tlog/CL.read.1.tlog b/astria/Release/astria.tlog/CL.read.1.tlog index c4c321b..287cec1 100644 Binary files a/astria/Release/astria.tlog/CL.read.1.tlog and b/astria/Release/astria.tlog/CL.read.1.tlog differ diff --git a/astria/Release/astria.tlog/CL.write.1.tlog b/astria/Release/astria.tlog/CL.write.1.tlog index 8f15e72..203111d 100644 Binary files a/astria/Release/astria.tlog/CL.write.1.tlog and b/astria/Release/astria.tlog/CL.write.1.tlog differ diff --git a/astria/Release/astria.tlog/cl.command.1.tlog b/astria/Release/astria.tlog/cl.command.1.tlog index c48593c..e73dcaa 100644 Binary files a/astria/Release/astria.tlog/cl.command.1.tlog and b/astria/Release/astria.tlog/cl.command.1.tlog differ diff --git a/astria/Release/astria.tlog/link.command.1.tlog b/astria/Release/astria.tlog/link.command.1.tlog index de79065..77139fe 100644 Binary files a/astria/Release/astria.tlog/link.command.1.tlog and b/astria/Release/astria.tlog/link.command.1.tlog differ diff --git a/astria/Release/astria.tlog/link.read.1.tlog b/astria/Release/astria.tlog/link.read.1.tlog index 57c98b0..cb8d3d6 100644 Binary files a/astria/Release/astria.tlog/link.read.1.tlog and b/astria/Release/astria.tlog/link.read.1.tlog differ diff --git a/astria/Release/astria.tlog/unsuccessfulbuild b/astria/Release/astria.tlog/unsuccessfulbuild new file mode 100644 index 0000000..e69de29 diff --git a/astria/Release/vc120.pdb b/astria/Release/vc120.pdb index 68748a1..7e85040 100644 Binary files a/astria/Release/vc120.pdb and b/astria/Release/vc120.pdb differ diff --git a/astria/Sound.cpp b/astria/Sound.cpp index 8405bb2..7a38c52 100644 --- a/astria/Sound.cpp +++ b/astria/Sound.cpp @@ -80,6 +80,16 @@ void CMusic::Resume() } } +bool CMusic::IsPlaying() +{ + return Mix_PlayingMusic(); +} + +bool CMusic::IsPaused() +{ + return Mix_PausedMusic(); +} + //================================================================================== CSoundEffect::CSoundEffect() @@ -126,12 +136,22 @@ void CSoundEffect::SetPositionEffect(int angle, int dist) Mix_SetPosition(Channel, angle, dist); } -void CSoundEffect::PauseAll() +void CSoundEffect::Pause() +{ + Mix_Pause(Channel); +} + +void CSoundEffect::Resume() +{ + Mix_Resume(Channel); +} + +bool CSoundEffect::IsPlaying() { - Mix_Pause(-1); + return Mix_Playing(Channel); } -void CSoundEffect::ResumeAll() +bool CSoundEffect::IsPaused() { - Mix_Resume(-1); + return Mix_Paused(Channel); } \ No newline at end of file diff --git a/astria/Sound.h b/astria/Sound.h index 4938af8..971a1c2 100644 --- a/astria/Sound.h +++ b/astria/Sound.h @@ -24,6 +24,9 @@ class CMusic static void Pause(); static void Resume(); + + static bool IsPlaying(); + static bool IsPaused(); private: Mix_Music* Music; }; @@ -44,8 +47,10 @@ class CSoundEffect //angle 0 = front, 90 = right void SetPositionEffect(int angle, int dist); - static void PauseAll(); - static void ResumeAll(); + void Pause(); + void Resume(); + bool IsPlaying(); + bool IsPaused(); private: Mix_Chunk* Sound; int Channel; diff --git a/astria/astria.vcxproj b/astria/astria.vcxproj index a942ce3..d2ea681 100644 --- a/astria/astria.vcxproj +++ b/astria/astria.vcxproj @@ -52,7 +52,10 @@ - + + $(IncludePath) + $(LibraryPath) + Level3 @@ -60,12 +63,13 @@ true _CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) MultiThreadedDLL - C:\Users\kvp_\Documents\LocalSDK\include\freetype;%(AdditionalIncludeDirectories) + C:\Users\kvp_\Documents\LocalSDK\include\physx332;C:\Users\kvp_\Documents\LocalSDK\include\freetype;%(AdditionalIncludeDirectories) true SDL2.lib;SDL2main.lib;SDL2_image.lib;SDL2_ttf.lib;SDL2_mixer.lib;opengl32.lib;glu32.lib;glew32.lib;assimp.lib;%(AdditionalDependencies) Console + C:\Users\kvp_\Documents\LocalSDK\physx332\Lib\vc11win32;%(AdditionalLibraryDirectories) @@ -77,7 +81,7 @@ true _CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_DEPRECATE;%(PreprocessorDefinitions) false - C:\Users\kvp_\Documents\LocalSDK\include\freetype;%(AdditionalIncludeDirectories) + C:\Users\kvp_\Documents\LocalSDK\physx332\Include;C:\Users\kvp_\Documents\LocalSDK\include\freetype;%(AdditionalIncludeDirectories) true @@ -85,6 +89,8 @@ true Windows SDL2.lib;SDL2main.lib;SDL2_image.lib;SDL2_ttf.lib;SDL2_mixer.lib;opengl32.lib;glu32.lib;glew32.lib;assimp.lib;%(AdditionalDependencies) + C:\Users\kvp_\Documents\LocalSDK\physx332\Lib\vc11win32;%(AdditionalLibraryDirectories) + /NODEFAULTLIB:libcmt.lib %(AdditionalOptions) true diff --git a/astria/astria.vcxproj.filters b/astria/astria.vcxproj.filters index ccab4f5..83af5c4 100644 --- a/astria/astria.vcxproj.filters +++ b/astria/astria.vcxproj.filters @@ -34,6 +34,12 @@ {05fae406-b96f-4462-bbbb-c06746f2a7ad} + + {311b3d06-419e-4873-a895-8611ec9e0fa5} + + + {014cc848-c44b-4160-871e-b46fbe2e6eee} + diff --git a/astria/credits.txt b/astria/credits.txt index c3ce60a..3caa8ea 100644 --- a/astria/credits.txt +++ b/astria/credits.txt @@ -8,6 +8,7 @@ SplashScreen - Perilous Ice Shape by tobylewin Skybox - from www.custommapmakers.org/skyboxes.php Models - tf3dm.com - www.turbosquid.com -Font - After shok by eightface - - Gunplay by Typodermic Fonts +Font - After shok by eightface + - Gunplay by Typodermic Fonts + - Ethnocentric by Typodermic Fonts Music - Self Esteem Fund from Portal diff --git a/astria/help.txt b/astria/help.txt index cea23fe..d9be24e 100644 --- a/astria/help.txt +++ b/astria/help.txt @@ -2,7 +2,8 @@ WASD - Movement Mouse - Look MouseWheel - Zoom In/Out Hold Shift - Toggle Sprint -Q - Toggle Wireframe Mode F - Toggle Fog (to see the beautiful skybox) G - Toggle Gravity (also collision with map) +N - Toggle Normal Map +M - Pause/Resume Music & Sound Effects Escape - Pause \ No newline at end of file diff --git a/astria/params.ini b/astria/params.ini index 2dd622b..bacc079 100644 --- a/astria/params.ini +++ b/astria/params.ini @@ -1,5 +1,5 @@ WindowName Desolation -VersionNumber 0.2.3 +VersionNumber 0.2.3a ResolutionWidth 1024 ResolutionHeight 768 IconImage gfx/img/dota2sf_icon.png diff --git a/astria/shaders/instancing.vert b/astria/shaders/instancing.vert index 4ca8489..27a79b9 100644 --- a/astria/shaders/instancing.vert +++ b/astria/shaders/instancing.vert @@ -1,9 +1,19 @@ #version 330 -layout(location = 0) in vec3 inPosition; -layout(location = 1) in vec2 inCoords; -layout(location = 2) in vec3 inNormal; -layout(location = 5) in mat4 inModelMatrix; +layout (location = 0) in vec3 inPosition; +layout (location = 1) in vec2 inCoords; +layout (location = 2) in vec3 inNormal; +layout (location = 3) in vec3 inTangent; +layout (location = 4) in vec3 inBitangent; +layout (location = 5) in mat4 inModelMatrix; + +struct DirectionalLight +{ + vec3 vColor; + vec3 vDirection; + float fAmbient; + float fBrightness; +}; uniform struct Matrices { @@ -15,6 +25,11 @@ smooth out vec3 vNormal; smooth out vec2 vTexCoord; smooth out vec3 vWorldPos; +out vec3 vLightDir_tangentspace; + +uniform DirectionalLight sunLight; +uniform bool bEnableNormalMap; + void main() { mat4 mMVP = matrices.mProjection * matrices.mView * inModelMatrix; diff --git a/astria/shaders/main_shader.frag b/astria/shaders/main_shader.frag index 52a13e6..30afd76 100644 --- a/astria/shaders/main_shader.frag +++ b/astria/shaders/main_shader.frag @@ -1,16 +1,9 @@ #version 330 -#include - -smooth in vec2 vTexCoord; -smooth in vec3 vNormal; -smooth in vec4 vEyeSpacePos; -smooth in vec3 vWorldPos; -out vec4 outputColor; - struct Material { sampler2D diffuse; + sampler2D normal; sampler2D specular; }; @@ -54,6 +47,16 @@ uniform FogParameters fogParams; uniform int bSkybox; uniform int bFog; +uniform bool bEnableNormalMap; + +smooth in vec2 vTexCoord; +smooth in vec3 vNormal; +smooth in vec4 vEyeSpacePos; +smooth in vec3 vWorldPos; +in vec3 vLightDir_tangentspace; +in vec3 vEyeDir_tangentspace; + +out vec4 outputColor; void main() { @@ -69,20 +72,29 @@ void main() return; } - vec3 vNormalized = normalize(vNormal); + vec3 vNormal_extended = normalize(vNormal); + vec3 vLightDir = sunLight.vDirection; + vec3 vEyeDirection = vEyePosition - vWorldPos; + + if(bEnableNormalMap) + { + vNormal_extended = normalize(texture2D(mat.normal, vTexCoord).rgb*2.0-1.0); + vLightDir = normalize(vLightDir_tangentspace); + vEyeDirection = vEyeDir_tangentspace; + } //Diffuse light - float fDiffuseIntensity = clamp(dot(vNormal, -sunLight.vDirection), 0.0, 1.0); - vec3 vDiffuseColor = pow(sunLight.fBrightness,2) * sunLight.vColor * fDiffuseIntensity * vec3(texture2D(mat.diffuse, vTexCoord)); + float fDiffuseIntensity = clamp(dot(vNormal_extended, -vLightDir), 0.0, 1.0); + vec3 vDiffuseColor = sunLight.fBrightness * sunLight.vColor * fDiffuseIntensity * vec3(texture2D(mat.diffuse, vTexCoord)); //Ambient vec3 vAmbientColor = sunLight.vColor * sunLight.fAmbient * vec3(texture2D(mat.diffuse, vTexCoord)); - //Specular - vec3 vReflected = normalize(reflect(sunLight.vDirection, vNormalized)); - vec3 vView = normalize(vEyePosition - vWorldPos); + //Specular + vec3 vReflected = reflect(vLightDir, vNormal_extended); + vec3 vView = normalize(vEyeDirection); float fSpecularIntensity = clamp(dot(vReflected, vView), 0, 1); - vec3 vSpecularColor = 0.6 * sunLight.vColor * fSpecularIntensity * vec3(texture2D(mat.specular, vTexCoord)); + vec3 vSpecularColor = sunLight.fBrightness * 0.6 * sunLight.vColor * fSpecularIntensity * vec3(texture2D(mat.specular, vTexCoord)); outputColor = vec4(vAmbientColor + vDiffuseColor + vSpecularColor, 1.0f); diff --git a/astria/shaders/main_shader.vert b/astria/shaders/main_shader.vert index f451f9b..89bfaff 100644 --- a/astria/shaders/main_shader.vert +++ b/astria/shaders/main_shader.vert @@ -8,9 +8,20 @@ uniform struct Matrices mat4 mNormal; } matrices; +struct DirectionalLight +{ + vec3 vColor; + vec3 vDirection; + float fAmbient; + float fBrightness; +}; + layout (location = 0) in vec3 inPosition; layout (location = 1) in vec2 inCoord; layout (location = 2) in vec3 inNormal; +layout (location = 3) in vec3 inTangent; +layout (location = 4) in vec3 inBitangent; + smooth out vec3 vNormal; smooth out vec2 vTexCoord; @@ -18,16 +29,44 @@ smooth out vec3 vWorldPos; smooth out vec4 vEyeSpacePos; +out vec3 vEyeDir_tangentspace; +out vec3 vLightDir_tangentspace; + +uniform vec3 vEyePosition; +uniform DirectionalLight sunLight; +uniform bool bEnableNormalMap; + void main() { - mat4 mMV = matrices.mView*matrices.mModel; //Matrix multiplication is from left to right + mat4 mMV = matrices.mView*matrices.mModel; mat4 mMVP = matrices.mProjection*matrices.mView*matrices.mModel; vTexCoord = inCoord; - vEyeSpacePos = mMV*vec4(inPosition, 1.0); + vEyeSpacePos = mMV * vec4(inPosition, 1.0); gl_Position = mMVP*vec4(inPosition, 1.0); vNormal = (matrices.mNormal*vec4(inNormal, 1.0)).xyz; vWorldPos = (matrices.mModel*vec4(inPosition, 1.0)).xyz; + + //Eye space calculations + vec3 vLightDir_eyespace = (mMV * vec4(-sunLight.vDirection, 1.0f)).xyz; + vec3 vEyeDir_eyespace = vec3(0,0,0) - (vEyeSpacePos).xyz; + + if(bEnableNormalMap) + { + mat3 mMV3x3 = mat3(mMV); + + vec3 vNormal_eyespace = mMV3x3 * inNormal; + vec3 vTangent_eyespace = mMV3x3 * inTangent; + vec3 vBitangent_eyespace = mMV3x3 * inBitangent; + + mat3 mTBN = transpose(mat3(vTangent_eyespace, vBitangent_eyespace, vNormal_eyespace)); + vLightDir_tangentspace = mTBN * vLightDir_eyespace; + vEyeDir_tangentspace = mTBN * vEyeDir_eyespace; + } + else + { + vLightDir_tangentspace = vec3(0,0,0); + } } \ No newline at end of file diff --git a/changelog.txt b/changelog.txt index b24ad27..a4d5139 100644 --- a/changelog.txt +++ b/changelog.txt @@ -1,3 +1,8 @@ +- 0.2.3a + - Added Normal Mapping to specular lighting + - Added Music/Sound effect pause/resume + - Fixed minor instancing bug + - 0.2.3 - Added Normal Mapping (quite laggy and only diffuse textures use it for now)