Correction shader + autres choses

This commit is contained in:
Marc-Eric Martel 2021-10-25 10:50:08 -04:00
parent 781c2776b7
commit fbf2e8858e
10 changed files with 99 additions and 46 deletions

View File

@ -64,27 +64,27 @@
<ConfigurationType>Application</ConfigurationType> <ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries> <UseDebugLibraries>true</UseDebugLibraries>
<CharacterSet>Unicode</CharacterSet> <CharacterSet>Unicode</CharacterSet>
<PlatformToolset>v142</PlatformToolset> <PlatformToolset>ClangCL</PlatformToolset>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType> <ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries> <UseDebugLibraries>true</UseDebugLibraries>
<CharacterSet>Unicode</CharacterSet> <CharacterSet>Unicode</CharacterSet>
<PlatformToolset>v142</PlatformToolset> <PlatformToolset>ClangCL</PlatformToolset>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType> <ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries> <UseDebugLibraries>false</UseDebugLibraries>
<WholeProgramOptimization>true</WholeProgramOptimization> <WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet> <CharacterSet>Unicode</CharacterSet>
<PlatformToolset>v142</PlatformToolset> <PlatformToolset>ClangCL</PlatformToolset>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType> <ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries> <UseDebugLibraries>false</UseDebugLibraries>
<WholeProgramOptimization>true</WholeProgramOptimization> <WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet> <CharacterSet>Unicode</CharacterSet>
<PlatformToolset>v142</PlatformToolset> <PlatformToolset>ClangCL</PlatformToolset>
</PropertyGroup> </PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" /> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings"> <ImportGroup Label="ExtensionSettings">
@ -168,7 +168,7 @@
<GenerateDebugInformation>true</GenerateDebugInformation> <GenerateDebugInformation>true</GenerateDebugInformation>
<EnableCOMDATFolding>true</EnableCOMDATFolding> <EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences> <OptimizeReferences>true</OptimizeReferences>
<AdditionalDependencies>irrKlang.lib;sfml-main.lib;sfml-system.lib;sfml-window.lib;sfml-graphics.lib;GlU32.Lib;OpenGL32.Lib;DevIL.lib;ILU.lib;ILUT.lib;%(AdditionalDependencies);winmm.lib;mmsystem.lib</AdditionalDependencies> <AdditionalDependencies>irrKlang.lib;sfml-main.lib;sfml-system.lib;sfml-window.lib;sfml-graphics.lib;GlU32.Lib;OpenGL32.Lib;DevIL.lib;ILU.lib;ILUT.lib;glew32.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link> </Link>
</ItemDefinitionGroup> </ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
@ -187,7 +187,7 @@
<GenerateDebugInformation>true</GenerateDebugInformation> <GenerateDebugInformation>true</GenerateDebugInformation>
<EnableCOMDATFolding>true</EnableCOMDATFolding> <EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences> <OptimizeReferences>true</OptimizeReferences>
<AdditionalDependencies>irrKlang.lib;sfml-main.lib;sfml-system.lib;sfml-window.lib;sfml-graphics.lib;GlU32.Lib;OpenGL32.Lib;DevIL.lib;ILU.lib;ILUT.lib;%(AdditionalDependencies);winmm.lib;mmsystem.lib</AdditionalDependencies> <AdditionalDependencies>irrKlang.lib;sfml-main.lib;sfml-system.lib;sfml-window.lib;sfml-graphics.lib;GlU32.Lib;OpenGL32.Lib;DevIL.lib;ILU.lib;ILUT.lib;glew32.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link> </Link>
</ItemDefinitionGroup> </ItemDefinitionGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />

View File

@ -1,14 +1,47 @@
#include "audio.h" #include "audio.h"
Audio::Audio() { m_WavEngine = irrklang::createIrrKlangDevice(); } irrklang::vec3df Audio::convertVector(Vector3f& vec) const { return irrklang::vec3df(vec.x, vec.y, vec.z); };
Audio::~Audio() { m_WavEngine->drop(); } Audio::Audio() {
m_engine = irrklang::createIrrKlangDevice();
bool Audio::GetState() const { return m_state; } m_engine->setDopplerEffectParameters(1);
m_engine->setRolloffFactor(1);
void Audio::SetState(bool state) { m_engine->setDefault3DSoundMinDistance(1);
if (state) m_engine->setDefault3DSoundMaxDistance(1000);
m_WavEngine->play2D(AUDIO_PATH "music01.wav", true);
else m_WavEngine->stopAllSounds();
m_state = state;
} }
Audio::Audio(const char * music) {
m_engine = irrklang::createIrrKlangDevice();
m_engine->setDopplerEffectParameters(1);
m_engine->setRolloffFactor(1);
m_engine->setDefault3DSoundMinDistance(1);
m_engine->setDefault3DSoundMaxDistance(1000);
m_music = m_engine->play2D(music, true, true, true, irrklang::ESM_STREAMING);
}
Audio::~Audio() {
m_music->drop();
m_engine->drop();
}
void Audio::Update3DAudio(Vector3f& pos, Vector3f& dir, Vector3f& speed) {
m_engine->setListenerPosition(convertVector(pos),
convertVector(dir),
convertVector(speed));
}
void Audio::Create3DAudioObj(irrklang::ISound* sound, const char* name, Vector3f& pos, Vector3f& speed, float volume = 1) {
sound = m_engine->play3D(name, convertVector(pos), true, false, true, irrklang::ESM_NO_STREAMING, true);
sound->setVelocity(convertVector(speed));
sound->setVolume(volume);
}
void Audio::Render3DAudioObj(irrklang::ISound* sound, Vector3f& pos, Vector3f& speed, float volume = 1) {
sound->setPosition(convertVector(pos));
sound->setVelocity(convertVector(speed));
sound->setVolume(volume);
}
void Audio::ToggleMusicState() { m_music->setIsPaused(!m_music->getIsPaused()); }
void Audio::PauseEngine() { m_engine->setAllSoundsPaused(); }

View File

@ -2,21 +2,31 @@
#define AUDIO_H__ #define AUDIO_H__
#include <irrKlang.h> #include <irrKlang.h>
#include <ik_ISoundSource.h>
#include "define.h" #include "define.h"
#include "vector3.h"
class Audio { class Audio {
private: private:
irrklang::ISoundEngine* m_WavEngine; irrklang::ISoundEngine* m_engine;
bool m_state = false; irrklang::ISound* m_music;
irrklang::vec3df convertVector(Vector3f& vec) const;
public: public:
Audio(); Audio();
Audio(const char* music);
~Audio(); ~Audio();
bool GetState() const; void Update3DAudio(Vector3f& pos, Vector3f& dir, Vector3f& speed);
void SetState(bool state); void Create3DAudioObj(irrklang::ISound* sound, const char* name, Vector3f& pos, Vector3f& speed, float volume);
void Render3DAudioObj(irrklang::ISound* sound, Vector3f& pos, Vector3f& speed, float volume);
void ToggleMusicState();
void PauseEngine();
}; };
#endif // AUDIO_H__ #endif // AUDIO_H__

View File

@ -56,25 +56,25 @@ void Chunk::AddBlockToMesh(VertexBuffer::VertexData* vd, int& count, BlockType b
vd[count++] = VertexBuffer::VertexData(x + .5f, y - .5f, z - .5f, 1.f, 1.f, 1.f, 1.f, 0.f); vd[count++] = VertexBuffer::VertexData(x + .5f, y - .5f, z - .5f, 1.f, 1.f, 1.f, 1.f, 0.f);
vd[count++] = VertexBuffer::VertexData(x - .5f, y - .5f, z - .5f, 1.f, 1.f, 1.f, 0.f, 0.f); vd[count++] = VertexBuffer::VertexData(x - .5f, y - .5f, z - .5f, 1.f, 1.f, 1.f, 0.f, 0.f);
vd[count++] = VertexBuffer::VertexData(x - .5f, y + .5f, z + .5f, 1.f, 1.f, 1.f, 0.f, 1.f); vd[count++] = VertexBuffer::VertexData(x - .5f, y + .5f, z + .5f, .9f, .9f, .9f, 0.f, 1.f);
vd[count++] = VertexBuffer::VertexData(x - .5f, y + .5f, z - .5f, 1.f, 1.f, 1.f, 1.f, 1.f); vd[count++] = VertexBuffer::VertexData(x - .5f, y + .5f, z - .5f, .9f, .9f, .9f, 1.f, 1.f);
vd[count++] = VertexBuffer::VertexData(x - .5f, y - .5f, z - .5f, 1.f, 1.f, 1.f, 1.f, 0.f); vd[count++] = VertexBuffer::VertexData(x - .5f, y - .5f, z - .5f, .9f, .9f, .9f, 1.f, 0.f);
vd[count++] = VertexBuffer::VertexData(x - .5f, y - .5f, z + .5f, 1.f, 1.f, 1.f, 0.f, 0.f); vd[count++] = VertexBuffer::VertexData(x - .5f, y - .5f, z + .5f, .9f, .9f, .9f, 0.f, 0.f);
vd[count++] = VertexBuffer::VertexData(x + .5f, y - .5f, z - .5f, 1.f, 1.f, 1.f, 0.f, 0.f); vd[count++] = VertexBuffer::VertexData(x + .5f, y - .5f, z - .5f, .9f, .9f, .9f, 0.f, 0.f);
vd[count++] = VertexBuffer::VertexData(x + .5f, y + .5f, z - .5f, 1.f, 1.f, 1.f, 0.f, 1.f); vd[count++] = VertexBuffer::VertexData(x + .5f, y + .5f, z - .5f, .9f, .9f, .9f, 0.f, 1.f);
vd[count++] = VertexBuffer::VertexData(x + .5f, y + .5f, z + .5f, 1.f, 1.f, 1.f, 1.f, 1.f); vd[count++] = VertexBuffer::VertexData(x + .5f, y + .5f, z + .5f, .9f, .9f, .9f, 1.f, 1.f);
vd[count++] = VertexBuffer::VertexData(x + .5f, y - .5f, z + .5f, 1.f, 1.f, 1.f, 1.f, 0.f); vd[count++] = VertexBuffer::VertexData(x + .5f, y - .5f, z + .5f, .9f, .9f, .9f, 1.f, 0.f);
vd[count++] = VertexBuffer::VertexData(x - .5f, y + .5f, z - .5f, 1.f, 1.f, 1.f, 0.f, 0.f); vd[count++] = VertexBuffer::VertexData(x - .5f, y + .5f, z - .5f, .8f, .8f, .8f, 0.f, 0.f);
vd[count++] = VertexBuffer::VertexData(x - .5f, y + .5f, z + .5f, 1.f, 1.f, 1.f, 0.f, 1.f); vd[count++] = VertexBuffer::VertexData(x - .5f, y + .5f, z + .5f, .8f, .8f, .8f, 0.f, 1.f);
vd[count++] = VertexBuffer::VertexData(x + .5f, y + .5f, z + .5f, 1.f, 1.f, 1.f, 1.f, 1.f); vd[count++] = VertexBuffer::VertexData(x + .5f, y + .5f, z + .5f, .8f, .8f, .8f, 1.f, 1.f);
vd[count++] = VertexBuffer::VertexData(x + .5f, y + .5f, z - .5f, 1.f, 1.f, 1.f, 1.f, 0.f); vd[count++] = VertexBuffer::VertexData(x + .5f, y + .5f, z - .5f, .8f, .8f, .8f, 1.f, 0.f);
vd[count++] = VertexBuffer::VertexData(x - .5f, y - .5f, z + .5f, 1.f, 1.f, 1.f, 0.f, 0.f); vd[count++] = VertexBuffer::VertexData(x - .5f, y - .5f, z + .5f, .8f, .8f, .8f, 0.f, 0.f);
vd[count++] = VertexBuffer::VertexData(x - .5f, y - .5f, z - .5f, 1.f, 1.f, 1.f, 0.f, 1.f); vd[count++] = VertexBuffer::VertexData(x - .5f, y - .5f, z - .5f, .8f, .8f, .8f, 0.f, 1.f);
vd[count++] = VertexBuffer::VertexData(x + .5f, y - .5f, z - .5f, 1.f, 1.f, 1.f, 1.f, 1.f); vd[count++] = VertexBuffer::VertexData(x + .5f, y - .5f, z - .5f, .8f, .8f, .8f, 1.f, 1.f);
vd[count++] = VertexBuffer::VertexData(x + .5f, y - .5f, z + .5f, 1.f, 1.f, 1.f, 1.f, 0.f); vd[count++] = VertexBuffer::VertexData(x + .5f, y - .5f, z + .5f, .8f, .8f, .8f, 1.f, 0.f);
} }
void Chunk::Render() const { m_vertexBuffer.Render(); } void Chunk::Render() const { m_vertexBuffer.Render(); }

View File

@ -33,7 +33,7 @@ void Engine::Init()
// Light // Light
GLfloat light0Pos[4] = { 0.0f, CHUNK_SIZE_Y, 0.0f, 1.0f }; GLfloat light0Pos[4] = { 0.0f, CHUNK_SIZE_Y, 0.0f, 1.0f };
GLfloat light0Amb[4] = { 0.9f, 0.9f, 0.9f, 1.f }; GLfloat light0Amb[4] = { 0.2f, 0.2f, 0.2f, 1.f };
GLfloat light0Diff[4] = { 1.f, 1.f, 1.f, 1.f }; GLfloat light0Diff[4] = { 1.f, 1.f, 1.f, 1.f };
GLfloat light0Spec[4] = { 0.2f, 0.2f, 0.2f, 1.0f }; GLfloat light0Spec[4] = { 0.2f, 0.2f, 0.2f, 1.0f };
@ -47,7 +47,7 @@ void Engine::Init()
m_skybox.Init(0.00013f); m_skybox.Init(0.00013f);
// Objet de musique! // Objet de musique!
m_music.SetState(true); m_audio.ToggleMusicState();
// Init testChunk // Init testChunk
for (int x = 0; x < CHUNK_SIZE_X; ++x) { for (int x = 0; x < CHUNK_SIZE_X; ++x) {
@ -106,12 +106,13 @@ void Engine::Render(float elapsedTime)
m_player.ApplyTransformation(all); m_player.ApplyTransformation(all);
m_player.ApplyTransformation(skybox, false); // Version d'ApplyTransformation qui ne tient compte que de la rotation m_player.ApplyTransformation(skybox, false); // Version d'ApplyTransformation qui ne tient compte que de la rotation
// (donc l'objet ne bouge pas relativement au joueur, ce qui est pratique pour une skybox!). // (donc l'objet ne bouge pas relativement au joueur, ce qui est pratique pour une skybox!).
glDisable(GL_LIGHT0);
m_skybox.Render(skybox); m_skybox.Render(skybox);
// Plancher // Plancher
// Les vertex doivent etre affiches dans le sens anti-horaire (CCW) // Les vertex doivent etre affiches dans le sens anti-horaire (CCW)
all.Use(); all.Use();
glEnable(GL_LIGHT0);
m_shader01.Use(); m_shader01.Use();
m_textureFloor.Bind(); m_textureFloor.Bind();
float nbRep = 10.f; float nbRep = 10.f;
@ -142,7 +143,7 @@ void Engine::Render(float elapsedTime)
m_testChunk.Update(); m_testChunk.Update();
m_testChunk.Render(); m_testChunk.Render();
//Shader::Disable(); m_shader01.Disable();
} }
@ -204,7 +205,7 @@ void Engine::KeyReleaseEvent(unsigned char key)
{ {
switch (key) { switch (key) {
case 12: case 12:
m_music.SetState(!m_music.GetState()); m_audio.ToggleMusicState();
break; break;
case 24: // Y case 24: // Y
m_wireframe = !m_wireframe; m_wireframe = !m_wireframe;

View File

@ -42,7 +42,7 @@ private:
Skybox m_skybox; Skybox m_skybox;
Shader m_shader01; Shader m_shader01;
Chunk m_testChunk; Chunk m_testChunk;
Audio m_music; Audio m_audio = Audio(AUDIO_PATH "music01.wav");
Player m_player = Player(Vector3f(0, 0, 0)); Player m_player = Player(Vector3f(0, 0, 0));

View File

@ -7,7 +7,6 @@ void main()
texel = texture2D(tex,gl_TexCoord[0].st); texel = texture2D(tex,gl_TexCoord[0].st);
texel *= light; texel *= light;
texel.a *= gl_Position.z;
gl_FragColor = texel; gl_FragColor = texel;
} }

View File

@ -70,8 +70,8 @@ void Player::Move(bool front, bool back, bool left, bool right, bool jump, bool
} }
} }
if (dbljump < 1 && ( left || right || front || back) || if ((dbljump < 1 && ( left || right || front || back)) ||
dash && !(left || right || front || back)) (dash && !(left || right || front || back)) )
{ {
yrotrad = (m_rotY / 57.2957795056f); // 180/Pi = 57.295... yrotrad = (m_rotY / 57.2957795056f); // 180/Pi = 57.295...
xrotrad = (m_rotX / 57.2957795056f); xrotrad = (m_rotX / 57.2957795056f);
@ -139,3 +139,9 @@ void Player::ApplyTransformation(Transformation& transformation, bool rel) const
transformation.ApplyRotation(-m_rotY, 0, 1, 0); transformation.ApplyRotation(-m_rotY, 0, 1, 0);
if (rel) transformation.ApplyTranslation(-m_position); if (rel) transformation.ApplyTranslation(-m_position);
} }
Vector3f Player::GetPosition() const { return m_position; }
Vector3f Player::GetDirection(bool velocity = false) const {
return Vector3f(); // Temporaire.
}

View File

@ -12,6 +12,9 @@ public:
void Move(bool front, bool back, bool left, bool right, bool jump, bool dash, float elapsedTime); void Move(bool front, bool back, bool left, bool right, bool jump, bool dash, float elapsedTime);
void ApplyTransformation(Transformation& transformation, bool rel = true) const; void ApplyTransformation(Transformation& transformation, bool rel = true) const;
Vector3f GetPosition() const;
Vector3f GetDirection(bool velocity) const;
private: private:
Vector3f m_position; Vector3f m_position;
float m_rotX = 0; float m_rotX = 0;

View File

@ -48,6 +48,7 @@ void Skybox::Render(Transformation tran) const {
m_texture.Bind(); m_texture.Bind();
m_shader.Use(); m_shader.Use();
m_vertexBuffer.Render(); m_vertexBuffer.Render();
m_shader.Disable();
glEnable(GL_DEPTH_TEST); glEnable(GL_DEPTH_TEST);
} }