|
@ -72,19 +72,11 @@ INT WINAPI WinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _ |
|
|
|
|
|
|
|
|
glewInit(); |
|
|
glewInit(); |
|
|
|
|
|
|
|
|
//init fsqgpu program
|
|
|
|
|
|
GPUProgram fsqProgram; |
|
|
|
|
|
fsqProgram.AttachShader(GL_VERTEX_SHADER, "res/shader/fullscreenquad.vs"); |
|
|
|
|
|
fsqProgram.AttachShader(GL_FRAGMENT_SHADER, "res/shader/fullscreenquad.fs"); |
|
|
|
|
|
fsqProgram.Link(); |
|
|
|
|
|
fsqProgram.DetectAttribute("pos"); |
|
|
|
|
|
fsqProgram.DetectAttribute("texcoord"); |
|
|
|
|
|
fsqProgram.DetectUniform("U_MainTexture"); |
|
|
|
|
|
|
|
|
|
|
|
//gpu program
|
|
|
//gpu program
|
|
|
GPUProgram gpuProgram; |
|
|
GPUProgram gpuProgram; |
|
|
gpuProgram.AttachShader(GL_VERTEX_SHADER, "res/shader/forg.vs"); |
|
|
|
|
|
gpuProgram.AttachShader(GL_FRAGMENT_SHADER, "res/shader/forg.fs"); |
|
|
|
|
|
|
|
|
gpuProgram.AttachShader(GL_VERTEX_SHADER, "res/shader/skybox.vs"); |
|
|
|
|
|
gpuProgram.AttachShader(GL_FRAGMENT_SHADER, "res/shader/skybox.fs"); |
|
|
gpuProgram.Link(); |
|
|
gpuProgram.Link(); |
|
|
|
|
|
|
|
|
gpuProgram.DetectAttribute("pos"); |
|
|
gpuProgram.DetectAttribute("pos"); |
|
@ -93,23 +85,6 @@ INT WINAPI WinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _ |
|
|
gpuProgram.DetectUniform("M"); |
|
|
gpuProgram.DetectUniform("M"); |
|
|
gpuProgram.DetectUniform("V"); |
|
|
gpuProgram.DetectUniform("V"); |
|
|
gpuProgram.DetectUniform("P"); |
|
|
gpuProgram.DetectUniform("P"); |
|
|
gpuProgram.DetectUniform("NM"); |
|
|
|
|
|
gpuProgram.DetectUniform("U_AmbientLightColor"); |
|
|
|
|
|
gpuProgram.DetectUniform("U_AmbientMaterial"); |
|
|
|
|
|
gpuProgram.DetectUniform("U_DiffuseLightColor"); |
|
|
|
|
|
gpuProgram.DetectUniform("U_DiffuseMaterial"); |
|
|
|
|
|
gpuProgram.DetectUniform("U_DiffuseIntensity"); |
|
|
|
|
|
gpuProgram.DetectUniform("U_LightPos"); |
|
|
|
|
|
gpuProgram.DetectUniform("U_LightDirection"); |
|
|
|
|
|
gpuProgram.DetectUniform("U_Cutoff"); |
|
|
|
|
|
gpuProgram.DetectUniform("U_SpecularLightColor"); |
|
|
|
|
|
gpuProgram.DetectUniform("U_SpecularMaterial"); |
|
|
|
|
|
|
|
|
|
|
|
gpuProgram.DetectUniform("U_FogStart"); |
|
|
|
|
|
gpuProgram.DetectUniform("U_FogEnd"); |
|
|
|
|
|
gpuProgram.DetectUniform("U_FogColor"); |
|
|
|
|
|
gpuProgram.DetectUniform("U_FogDensity"); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//init 3d model
|
|
|
//init 3d model
|
|
@ -123,47 +98,20 @@ INT WINAPI WinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _ |
|
|
0,0,0,1.0f |
|
|
0,0,0,1.0f |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
float ambientLightColor[] = { 0.4f,0.4f,0.4f,1.0f }; |
|
|
|
|
|
float ambientMaterial[] = { 0.2f,0.2f,0.2f,1.0f }; |
|
|
|
|
|
float diffuseLightColor[] = { 0.1f,0.4f,0.7f,1.0f }; |
|
|
|
|
|
float diffuseMaterial[] = { 0.6f, 0.6f, 0.6f, 1.0f }; |
|
|
|
|
|
float lightPos[] = { 1.0f,1.0f,0.0f,0.0f }; |
|
|
|
|
|
float diffuseIntensity = 1.0f; |
|
|
|
|
|
|
|
|
|
|
|
float spotLightDirection[] = { 0.0f, -1.0f, 0.0f, 628.0f }; |
|
|
|
|
|
float spotLightCutoff = 5.0f; |
|
|
|
|
|
float specularLightColor[] = { 1.0f,1.0f,1.0f,1.0f }; |
|
|
|
|
|
float specularMaterial[] = { 1.0f,1.0f,1.0f,1.0f }; |
|
|
|
|
|
float eyePos[] = { 0.0f,0.0f,0.0f }; |
|
|
|
|
|
|
|
|
|
|
|
float fogStart = 2.0f; |
|
|
|
|
|
float fogEnd = 23.0f; |
|
|
|
|
|
float fogColor[] = { 0.6f, 0.6f, 0.6f, 1.0f }; |
|
|
|
|
|
float fogDensity = 0.11; |
|
|
|
|
|
|
|
|
|
|
|
glm::mat4 cubeModelMatrix = glm::translate<float>(-2.2f, 0.0f, -4.0f) * glm::rotate(-30.0f, 1.0f, 1.0f, 1.0f); |
|
|
|
|
|
glm::mat4 cubeNormalMatrix = glm::inverseTranspose(cubeModelMatrix); |
|
|
|
|
|
|
|
|
|
|
|
glm::mat4 cubeModelMatrix2 = glm::translate<float>(-2.0f, 0.0f, -12.0f) * glm::rotate(-30.0f, 1.0f, 1.0f, 1.0f); |
|
|
|
|
|
glm::mat4 cubeNormalMatrix2 = glm::inverseTranspose(cubeModelMatrix); |
|
|
|
|
|
|
|
|
|
|
|
glm::mat4 cubeModelMatrix3 = glm::translate<float>(-0.4f, 0.0f, -20.0f) * glm::rotate(-30.0f, 1.0f, 1.0f, 1.0f); |
|
|
|
|
|
glm::mat4 cubeNormalMatrix3 = glm::inverseTranspose(cubeModelMatrix); |
|
|
|
|
|
//glm::mat4 viewMatrix = glm::lookAt(glm::vec3(1.0f, 0.5f, -10.0f), glm::vec3(0.0f, 0.0f, -1.0f), glm::vec3(0.0f, 1.0f, 0.0f));
|
|
|
|
|
|
|
|
|
glm::mat4 cubeModelMatrix; |
|
|
glm::mat4 projectionMatrix = glm::perspective(50.0f, (float)viewportWidth / (float)viewportHeight, 0.1f, 1000.0f); |
|
|
glm::mat4 projectionMatrix = glm::perspective(50.0f, (float)viewportWidth / (float)viewportHeight, 0.1f, 1000.0f); |
|
|
|
|
|
|
|
|
//³õʼ»¯fsq
|
|
|
|
|
|
FullScreenQuad fsq; |
|
|
|
|
|
fsq.Init(); |
|
|
|
|
|
|
|
|
GLuint mainTexture = SOIL_load_OGL_cubemap( |
|
|
|
|
|
"res/image/right.bmp", |
|
|
|
|
|
"res/image/left.bmp", |
|
|
|
|
|
"res/image/top.bmp", |
|
|
|
|
|
"res/image/bottom.bmp", |
|
|
|
|
|
"res/image/back.bmp", |
|
|
|
|
|
"res/image/front.bmp", |
|
|
|
|
|
0, 0, SOIL_FLAG_POWER_OF_TWO |
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
//³õʼ»¯2¸öfbo
|
|
|
|
|
|
FBO fbo[2]; |
|
|
|
|
|
fbo[0].AttachColorBuffer("color", GL_COLOR_ATTACHMENT0, GL_RGBA, viewportWidth, viewportHeight); |
|
|
|
|
|
fbo[0].AttachDepthBuffer("depth", viewportWidth, viewportHeight); |
|
|
|
|
|
fbo[0].Finish(); |
|
|
|
|
|
fbo[1].AttachColorBuffer("color", GL_COLOR_ATTACHMENT0, GL_RGBA, viewportWidth, viewportHeight); |
|
|
|
|
|
fbo[1].AttachDepthBuffer("depth", viewportWidth, viewportHeight); |
|
|
|
|
|
fbo[1].Finish(); |
|
|
|
|
|
|
|
|
|
|
|
ShowWindow(hwnd, SW_SHOW); |
|
|
ShowWindow(hwnd, SW_SHOW); |
|
|
UpdateWindow(hwnd); |
|
|
UpdateWindow(hwnd); |
|
@ -181,85 +129,19 @@ INT WINAPI WinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _ |
|
|
TranslateMessage(&msg); |
|
|
TranslateMessage(&msg); |
|
|
DispatchMessage(&msg); |
|
|
DispatchMessage(&msg); |
|
|
} |
|
|
} |
|
|
glEnable(GL_DEPTH_TEST); |
|
|
|
|
|
|
|
|
glDisable(GL_DEPTH_TEST); |
|
|
|
|
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); |
|
|
glUseProgram(gpuProgram.mProgram); |
|
|
glUseProgram(gpuProgram.mProgram); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
glUniformMatrix4fv(gpuProgram.GetLocation("V"), 1, GL_FALSE, identity); |
|
|
glUniformMatrix4fv(gpuProgram.GetLocation("V"), 1, GL_FALSE, identity); |
|
|
glUniformMatrix4fv(gpuProgram.GetLocation("P"), 1, GL_FALSE, glm::value_ptr(projectionMatrix)); |
|
|
glUniformMatrix4fv(gpuProgram.GetLocation("P"), 1, GL_FALSE, glm::value_ptr(projectionMatrix)); |
|
|
|
|
|
|
|
|
glUniform4fv(gpuProgram.GetLocation("U_AmbientLightColor"), 1, ambientLightColor); |
|
|
|
|
|
glUniform4fv(gpuProgram.GetLocation("U_AmbientMaterial"), 1, ambientMaterial); |
|
|
|
|
|
glUniform4fv(gpuProgram.GetLocation("U_DiffuseLightColor"), 1, diffuseLightColor); |
|
|
|
|
|
glUniform4fv(gpuProgram.GetLocation("U_DiffuseMaterial"), 1, diffuseMaterial); |
|
|
|
|
|
glUniform1f(gpuProgram.GetLocation("U_DiffuseIntensity"), diffuseIntensity); |
|
|
|
|
|
glUniform4fv(gpuProgram.GetLocation("U_LightPos"), 1, lightPos); |
|
|
|
|
|
glUniform4fv(gpuProgram.GetLocation("U_LightDirection"), 1, spotLightDirection); |
|
|
|
|
|
glUniform1f(gpuProgram.GetLocation("U_Cutoff"), spotLightCutoff); |
|
|
|
|
|
glUniform4fv(gpuProgram.GetLocation("U_SpecularLightColor"), 1, specularLightColor); |
|
|
|
|
|
glUniform4fv(gpuProgram.GetLocation("U_SpecularMaterial"), 1, specularMaterial); |
|
|
|
|
|
glUniform3fv(gpuProgram.GetLocation("U_EyePos"), 1, eyePos); |
|
|
|
|
|
glUniform1f(gpuProgram.GetLocation("U_FogStart"), fogStart); |
|
|
|
|
|
glUniform1f(gpuProgram.GetLocation("U_FogEnd"), fogEnd); |
|
|
|
|
|
glUniform4fv(gpuProgram.GetLocation("U_FogColor"), 1, fogColor); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fbo[0].Bind(); |
|
|
|
|
|
fogDensity = 0.11; |
|
|
|
|
|
glUniform1f(gpuProgram.GetLocation("U_FogDensity"), fogDensity); |
|
|
|
|
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); |
|
|
|
|
|
glUniformMatrix4fv(gpuProgram.GetLocation("M"), 1, GL_FALSE, glm::value_ptr(cubeModelMatrix)); |
|
|
|
|
|
glUniformMatrix4fv(gpuProgram.GetLocation("NM"), 1, GL_FALSE, glm::value_ptr(cubeNormalMatrix)); |
|
|
|
|
|
cube.Bind(gpuProgram.GetLocation("pos"), gpuProgram.GetLocation("texcoord"), gpuProgram.GetLocation("normal")); |
|
|
|
|
|
cube.Draw(); |
|
|
|
|
|
glUniformMatrix4fv(gpuProgram.GetLocation("M"), 1, GL_FALSE, glm::value_ptr(cubeModelMatrix2)); |
|
|
|
|
|
glUniformMatrix4fv(gpuProgram.GetLocation("NM"), 1, GL_FALSE, glm::value_ptr(cubeNormalMatrix2)); |
|
|
|
|
|
cube.Bind(gpuProgram.GetLocation("pos"), gpuProgram.GetLocation("texcoord"), gpuProgram.GetLocation("normal")); |
|
|
|
|
|
cube.Draw(); |
|
|
|
|
|
glUniformMatrix4fv(gpuProgram.GetLocation("M"), 1, GL_FALSE, glm::value_ptr(cubeModelMatrix3)); |
|
|
|
|
|
glUniformMatrix4fv(gpuProgram.GetLocation("NM"), 1, GL_FALSE, glm::value_ptr(cubeNormalMatrix3)); |
|
|
|
|
|
cube.Bind(gpuProgram.GetLocation("pos"), gpuProgram.GetLocation("texcoord"), gpuProgram.GetLocation("normal")); |
|
|
|
|
|
cube.Draw(); |
|
|
|
|
|
fbo[0].Unbind(); |
|
|
|
|
|
|
|
|
|
|
|
fbo[1].Bind(); |
|
|
|
|
|
fogDensity = 0.31; |
|
|
|
|
|
glUniform1f(gpuProgram.GetLocation("U_FogDensity"), fogDensity); |
|
|
|
|
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); |
|
|
|
|
|
glUniformMatrix4fv(gpuProgram.GetLocation("M"), 1, GL_FALSE, glm::value_ptr(cubeModelMatrix)); |
|
|
glUniformMatrix4fv(gpuProgram.GetLocation("M"), 1, GL_FALSE, glm::value_ptr(cubeModelMatrix)); |
|
|
glUniformMatrix4fv(gpuProgram.GetLocation("NM"), 1, GL_FALSE, glm::value_ptr(cubeNormalMatrix)); |
|
|
|
|
|
cube.Bind(gpuProgram.GetLocation("pos"), gpuProgram.GetLocation("texcoord"), gpuProgram.GetLocation("normal")); |
|
|
|
|
|
cube.Draw(); |
|
|
|
|
|
glUniformMatrix4fv(gpuProgram.GetLocation("M"), 1, GL_FALSE, glm::value_ptr(cubeModelMatrix2)); |
|
|
|
|
|
glUniformMatrix4fv(gpuProgram.GetLocation("NM"), 1, GL_FALSE, glm::value_ptr(cubeNormalMatrix2)); |
|
|
|
|
|
cube.Bind(gpuProgram.GetLocation("pos"), gpuProgram.GetLocation("texcoord"), gpuProgram.GetLocation("normal")); |
|
|
|
|
|
cube.Draw(); |
|
|
|
|
|
glUniformMatrix4fv(gpuProgram.GetLocation("M"), 1, GL_FALSE, glm::value_ptr(cubeModelMatrix3)); |
|
|
|
|
|
glUniformMatrix4fv(gpuProgram.GetLocation("NM"), 1, GL_FALSE, glm::value_ptr(cubeNormalMatrix3)); |
|
|
|
|
|
|
|
|
glBindTexture(GL_TEXTURE_CUBE_MAP, mainTexture); |
|
|
|
|
|
glUniform1i(gpuProgram.GetLocation("U_MainTexture"), 0); |
|
|
cube.Bind(gpuProgram.GetLocation("pos"), gpuProgram.GetLocation("texcoord"), gpuProgram.GetLocation("normal")); |
|
|
cube.Bind(gpuProgram.GetLocation("pos"), gpuProgram.GetLocation("texcoord"), gpuProgram.GetLocation("normal")); |
|
|
cube.Draw(); |
|
|
cube.Draw(); |
|
|
fbo[1].Unbind(); |
|
|
|
|
|
glUseProgram(0); |
|
|
glUseProgram(0); |
|
|
|
|
|
glEnable(GL_DEPTH_TEST); |
|
|
glFlush(); |
|
|
glFlush(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
glClearColor(0.6f, 0.6f, 0.6f, 1.0f); |
|
|
|
|
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); |
|
|
|
|
|
glActiveTexture(GL_TEXTURE0); |
|
|
|
|
|
|
|
|
|
|
|
glUseProgram(fsqProgram.mProgram); |
|
|
|
|
|
glBindTexture(GL_TEXTURE_2D, fbo[0].GetBuffer("color")); |
|
|
|
|
|
glUniform1i(fsqProgram.GetLocation("U_MainTexture"), 0); |
|
|
|
|
|
fsq.DrawToLeftTop(fsqProgram.GetLocation("pos"), fsqProgram.GetLocation("texcoord")); |
|
|
|
|
|
|
|
|
|
|
|
glBindTexture(GL_TEXTURE_2D, fbo[1].GetBuffer("color")); |
|
|
|
|
|
glUniform1i(fsqProgram.GetLocation("U_MainTexture"), 0); |
|
|
|
|
|
fsq.DrawToRightTop(fsqProgram.GetLocation("pos"), fsqProgram.GetLocation("texcoord")); |
|
|
|
|
|
|
|
|
|
|
|
glUseProgram(0); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
SwapBuffers(dc); |
|
|
SwapBuffers(dc); |
|
|
} |
|
|
} |
|
|
return 0; |
|
|
return 0; |