|
@ -44,8 +44,8 @@ INT WINAPI WinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _ |
|
|
RECT rect; |
|
|
RECT rect; |
|
|
rect.left = 0; |
|
|
rect.left = 0; |
|
|
rect.top = 0; |
|
|
rect.top = 0; |
|
|
rect.right = 800; |
|
|
|
|
|
rect.bottom = 600; |
|
|
|
|
|
|
|
|
rect.right = 1280; |
|
|
|
|
|
rect.bottom = 720; |
|
|
AdjustWindowRect(&rect, WS_OVERLAPPEDWINDOW, FALSE); |
|
|
AdjustWindowRect(&rect, WS_OVERLAPPEDWINDOW, FALSE); |
|
|
|
|
|
|
|
|
HWND hwnd = CreateWindowEx(NULL, "OpenGL", "RenderWindow", WS_OVERLAPPEDWINDOW, 100, 100, rect.right - rect.left, rect.bottom - rect.top, NULL, NULL, hInstance, NULL); |
|
|
HWND hwnd = CreateWindowEx(NULL, "OpenGL", "RenderWindow", WS_OVERLAPPEDWINDOW, 100, 100, rect.right - rect.left, rect.bottom - rect.top, NULL, NULL, hInstance, NULL); |
|
@ -81,92 +81,36 @@ INT WINAPI WinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _ |
|
|
originalProgram.DetectAttribute("texcoord"); |
|
|
originalProgram.DetectAttribute("texcoord"); |
|
|
originalProgram.DetectUniform("U_MainTexture"); |
|
|
originalProgram.DetectUniform("U_MainTexture"); |
|
|
|
|
|
|
|
|
//init depth render program
|
|
|
|
|
|
GPUProgram depthRenderProgram; |
|
|
|
|
|
depthRenderProgram.AttachShader(GL_VERTEX_SHADER, "res/shader/fullscreenquad.vs"); |
|
|
|
|
|
depthRenderProgram.AttachShader(GL_FRAGMENT_SHADER, "res/shader/depthrender.fs"); |
|
|
|
|
|
depthRenderProgram.Link(); |
|
|
|
|
|
depthRenderProgram.DetectAttribute("pos"); |
|
|
|
|
|
depthRenderProgram.DetectAttribute("texcoord"); |
|
|
|
|
|
depthRenderProgram.DetectUniform("U_MainTexture"); |
|
|
|
|
|
|
|
|
|
|
|
//init hdr program
|
|
|
|
|
|
GPUProgram hdrProgram; |
|
|
|
|
|
hdrProgram.AttachShader(GL_VERTEX_SHADER, "res/shader/fullscreenquad.vs"); |
|
|
|
|
|
hdrProgram.AttachShader(GL_FRAGMENT_SHADER, "res/shader/hdrrender.fs"); |
|
|
|
|
|
hdrProgram.Link(); |
|
|
|
|
|
hdrProgram.DetectAttribute("pos"); |
|
|
|
|
|
hdrProgram.DetectAttribute("texcoord"); |
|
|
|
|
|
hdrProgram.DetectUniform("U_MainTexture"); |
|
|
|
|
|
|
|
|
|
|
|
//高斯模糊
|
|
|
|
|
|
GPUProgram gaussianProgram; |
|
|
|
|
|
gaussianProgram.AttachShader(GL_VERTEX_SHADER, "res/shader/fullscreenquad.vs"); |
|
|
|
|
|
gaussianProgram.AttachShader(GL_FRAGMENT_SHADER, "res/shader/fullscreenquad_gaussian.fs"); |
|
|
|
|
|
gaussianProgram.Link(); |
|
|
|
|
|
gaussianProgram.DetectAttribute("pos"); |
|
|
|
|
|
gaussianProgram.DetectAttribute("texcoord"); |
|
|
|
|
|
gaussianProgram.DetectUniform("U_MainTexture"); |
|
|
|
|
|
|
|
|
|
|
|
//combine program
|
|
|
|
|
|
GPUProgram combineProgram; |
|
|
|
|
|
combineProgram.AttachShader(GL_VERTEX_SHADER, "res/shader/fullscreenquad.vs"); |
|
|
|
|
|
combineProgram.AttachShader(GL_FRAGMENT_SHADER, "res/shader/combine.fs"); |
|
|
|
|
|
combineProgram.Link(); |
|
|
|
|
|
combineProgram.DetectAttribute("pos"); |
|
|
|
|
|
combineProgram.DetectAttribute("texcoord"); |
|
|
|
|
|
combineProgram.DetectUniform("U_MainTexture"); |
|
|
|
|
|
combineProgram.DetectUniform("U_HDRTexture"); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//init light source program
|
|
|
|
|
|
GPUProgram lightSourceProgram; |
|
|
|
|
|
lightSourceProgram.AttachShader(GL_VERTEX_SHADER, "res/shader/lightSource.vs"); |
|
|
|
|
|
lightSourceProgram.AttachShader(GL_FRAGMENT_SHADER, "res/shader/lightSource.fs"); |
|
|
|
|
|
lightSourceProgram.Link(); |
|
|
|
|
|
lightSourceProgram.DetectAttribute("pos"); |
|
|
|
|
|
lightSourceProgram.DetectUniform("M"); |
|
|
|
|
|
lightSourceProgram.DetectUniform("V"); |
|
|
|
|
|
lightSourceProgram.DetectUniform("P"); |
|
|
|
|
|
|
|
|
|
|
|
//init depth program
|
|
|
|
|
|
GPUProgram depthProgram; |
|
|
|
|
|
depthProgram.AttachShader(GL_VERTEX_SHADER, "res/shader/sample_depth_buffer.vs"); |
|
|
|
|
|
depthProgram.AttachShader(GL_FRAGMENT_SHADER, "res/shader/sample_depth_buffer.fs"); |
|
|
|
|
|
depthProgram.Link(); |
|
|
|
|
|
depthProgram.DetectAttribute("pos"); |
|
|
|
|
|
depthProgram.DetectUniform("M"); |
|
|
|
|
|
depthProgram.DetectUniform("V"); |
|
|
|
|
|
depthProgram.DetectUniform("P"); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//init gpu program
|
|
|
|
|
|
GPUProgram gpuProgram; |
|
|
|
|
|
gpuProgram.AttachShader(GL_VERTEX_SHADER, "res/shader/test.vs"); |
|
|
|
|
|
gpuProgram.AttachShader(GL_FRAGMENT_SHADER, "res/shader/hdr.fs"); |
|
|
|
|
|
gpuProgram.Link(); |
|
|
|
|
|
|
|
|
|
|
|
gpuProgram.DetectAttribute("pos"); |
|
|
|
|
|
gpuProgram.DetectAttribute("texcoord"); |
|
|
|
|
|
gpuProgram.DetectAttribute("normal"); |
|
|
|
|
|
gpuProgram.DetectUniform("M"); |
|
|
|
|
|
gpuProgram.DetectUniform("V"); |
|
|
|
|
|
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_EyePos"); |
|
|
|
|
|
gpuProgram.DetectUniform("U_LightProjection"); |
|
|
|
|
|
gpuProgram.DetectUniform("U_LightViewMatrix"); |
|
|
|
|
|
gpuProgram.DetectUniform("U_ShadowMap"); |
|
|
|
|
|
|
|
|
//init projector program
|
|
|
|
|
|
GPUProgram sampleProgram; |
|
|
|
|
|
sampleProgram.AttachShader(GL_VERTEX_SHADER, "res/shader/sample.vs"); |
|
|
|
|
|
sampleProgram.AttachShader(GL_FRAGMENT_SHADER, "res/shader/sample.fs"); |
|
|
|
|
|
sampleProgram.Link(); |
|
|
|
|
|
|
|
|
|
|
|
sampleProgram.DetectAttribute("pos"); |
|
|
|
|
|
sampleProgram.DetectAttribute("texcoord"); |
|
|
|
|
|
sampleProgram.DetectUniform("M"); |
|
|
|
|
|
sampleProgram.DetectUniform("V"); |
|
|
|
|
|
sampleProgram.DetectUniform("P"); |
|
|
|
|
|
sampleProgram.DetectUniform("U_MainTexture"); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//init projective texture program
|
|
|
|
|
|
GPUProgram projectedTextureProgram; |
|
|
|
|
|
projectedTextureProgram.AttachShader(GL_VERTEX_SHADER, "res/shader/projector.vs"); |
|
|
|
|
|
projectedTextureProgram.AttachShader(GL_FRAGMENT_SHADER, "res/shader/projector.fs"); |
|
|
|
|
|
projectedTextureProgram.Link(); |
|
|
|
|
|
|
|
|
|
|
|
projectedTextureProgram.DetectAttribute("pos"); |
|
|
|
|
|
projectedTextureProgram.DetectAttribute("texcoord"); |
|
|
|
|
|
projectedTextureProgram.DetectUniform("M"); |
|
|
|
|
|
projectedTextureProgram.DetectUniform("V"); |
|
|
|
|
|
projectedTextureProgram.DetectUniform("P"); |
|
|
|
|
|
projectedTextureProgram.DetectUniform("U_ShadowMap"); |
|
|
|
|
|
projectedTextureProgram.DetectUniform("U_MainTexture"); |
|
|
|
|
|
projectedTextureProgram.DetectUniform("U_ProjectiveTexture"); |
|
|
|
|
|
projectedTextureProgram.DetectUniform("U_ProjectorMatrix"); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//init 3d model
|
|
|
//init 3d model
|
|
|
ObjModel obj, quad, sphere; |
|
|
ObjModel obj, quad, sphere; |
|
@ -181,61 +125,36 @@ 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[] = { 1.0f,1.0f,1.0f,1.0f }; |
|
|
|
|
|
float diffuseMaterial[] = { 0.8f, 0.8f, 0.8f, 1.0f }; |
|
|
|
|
|
float lightPos[] = { 1.0f, 3.0f, -0.8f,1.0f }; |
|
|
|
|
|
float diffuseIntensity = 2.0f; |
|
|
|
|
|
|
|
|
|
|
|
float spotLightDirection[] = { 0.0f, -1.0f, 0.0f, 32.0f };//把最后一位改成......
|
|
|
|
|
|
float spotLightCutoff = 20.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 }; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
glm::mat4 model = glm::translate<float>(6.0f, 0.0f, -6.0f) * glm::rotate(-30.0f, 1.0f, 1.0f, 1.0f); |
|
|
|
|
|
|
|
|
glm::mat4 model = glm::translate<float>(1.0f, 0.0f, 0.0f) * glm::rotate(-60.0f, 1.0f, 1.0f, 1.0f); |
|
|
|
|
|
glm::mat4 normalMatrix = glm::inverseTranspose(model); |
|
|
|
|
|
|
|
|
glm::mat4 quadModel = glm::translate<float>(6.0f, -1.5f, -6.0f) * glm::rotate(-90.0f, 1.0f, 0.0f, 0.0f) * glm::scale(10.0f, 10.0f, 10.0f); |
|
|
|
|
|
|
|
|
glm::mat4 quadModel = glm::translate<float>(0.0f, -1.5f, 0.0f) * glm::rotate(-90.0f, 1.0f, 0.0f, 0.0f) * glm::scale(8.0f, 8.0f, 8.0f); |
|
|
|
|
|
glm::mat4 quadNormalMatrix = glm::inverseTranspose(quadModel); |
|
|
|
|
|
|
|
|
glm::mat4 sphereModel = glm::translate<float>(0.0f, 0.0f, 0.0f) * glm::scale(0.3f, 0.3f, 0.3f); |
|
|
|
|
|
|
|
|
glm::mat4 sphereModel = glm::translate<float>(lightPos[0], lightPos[1], lightPos[2]) * glm::scale(0.3f, 0.3f, 0.3f); |
|
|
|
|
|
glm::mat4 sphereNormalMatrix = glm::inverseTranspose(sphereModel); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
glm::mat4 viewMatrix = glm::lookAt(glm::vec3(0.5f, 1.9f, -8.0f), glm::vec3(0.0f, 0.0f, -1.0f), glm::vec3(0.0f, 1.0f, 0.0f)); |
|
|
|
|
|
|
|
|
glm::mat4 viewMatrix = glm::lookAt(glm::vec3(10.0f, 3.0f, 0.0f), glm::vec3(6.0f, -1.0f, -6.0f), glm::vec3(0.0f, 1.0f, 0.0f)); |
|
|
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); |
|
|
|
|
|
|
|
|
glm::mat4 lightMatrix = glm::lookAt(glm::vec3(lightPos[0], lightPos[1], lightPos[2]), glm::vec3(1.0f, 0.0f, 0.0f), glm::vec3(0.0f, 0.0f, -1.0f)); |
|
|
|
|
|
glm::mat4 lightprojectionMatrix = glm::perspective(90.0f, (float)viewportWidth / (float)viewportHeight, 0.1f, 1000.0f);;//glm::ortho(-5.0f, 5.0f, -5.0f, 5.0f, 0.1f, 15.0f);
|
|
|
|
|
|
|
|
|
glm::mat4 projectorMatrix = glm::translate<float>(0.5f, 0.5f, 0.5f)*glm::scale(0.5f, 0.5f, 0.5f) * projectionMatrix * viewMatrix; |
|
|
|
|
|
|
|
|
//初始化fsq
|
|
|
//初始化fsq
|
|
|
FullScreenQuad fsq; |
|
|
FullScreenQuad fsq; |
|
|
fsq.Init(); |
|
|
fsq.Init(); |
|
|
|
|
|
|
|
|
//初始化FBO
|
|
|
//初始化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(); |
|
|
|
|
|
|
|
|
|
|
|
FBO HDRfbo; |
|
|
|
|
|
HDRfbo.AttachColorBuffer("color", GL_COLOR_ATTACHMENT0, GL_RGBA, viewportWidth, viewportHeight); |
|
|
|
|
|
HDRfbo.AttachColorBuffer("hdrcolor", GL_COLOR_ATTACHMENT1, GL_RGBA16F, viewportWidth, viewportHeight); |
|
|
|
|
|
HDRfbo.AttachDepthBuffer("depth", viewportWidth, viewportHeight); |
|
|
|
|
|
HDRfbo.Finish(); |
|
|
|
|
|
|
|
|
|
|
|
FBO depthfbo; |
|
|
|
|
|
depthfbo.AttachColorBuffer("color", GL_COLOR_ATTACHMENT0, GL_RGB, viewportWidth, viewportHeight); |
|
|
|
|
|
depthfbo.AttachDepthBuffer("depth", viewportWidth, viewportHeight); |
|
|
|
|
|
depthfbo.Finish(); |
|
|
|
|
|
|
|
|
FBO originalFbo; |
|
|
|
|
|
originalFbo.AttachColorBuffer("color", GL_COLOR_ATTACHMENT0, GL_RGBA, viewportWidth, viewportHeight); |
|
|
|
|
|
originalFbo.AttachDepthBuffer("depth", viewportWidth, viewportHeight); |
|
|
|
|
|
originalFbo.Finish(); |
|
|
|
|
|
|
|
|
|
|
|
FBO projectiveTextureFbo; |
|
|
|
|
|
projectiveTextureFbo.AttachColorBuffer("color", GL_COLOR_ATTACHMENT0, GL_RGBA, viewportWidth, viewportHeight); |
|
|
|
|
|
projectiveTextureFbo.AttachDepthBuffer("depth", viewportWidth, viewportHeight); |
|
|
|
|
|
projectiveTextureFbo.Finish(); |
|
|
|
|
|
|
|
|
|
|
|
GLuint mainTexture = SOIL_load_OGL_texture("res/image/stone.bmp", 0, 0, SOIL_FLAG_POWER_OF_TWO); |
|
|
|
|
|
GLuint projectiveTexture = SOIL_load_OGL_texture("res/image/grass.png", 0, 0, SOIL_FLAG_POWER_OF_TWO | SOIL_FLAG_INVERT_Y); |
|
|
|
|
|
|
|
|
ShowWindow(hwnd, SW_SHOW); |
|
|
ShowWindow(hwnd, SW_SHOW); |
|
|
UpdateWindow(hwnd); |
|
|
UpdateWindow(hwnd); |
|
@ -243,102 +162,49 @@ INT WINAPI WinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _ |
|
|
glClearColor(0.0f, 0.0f, 0.0f, 1.0f); |
|
|
glClearColor(0.0f, 0.0f, 0.0f, 1.0f); |
|
|
glEnable(GL_DEPTH_TEST); |
|
|
glEnable(GL_DEPTH_TEST); |
|
|
|
|
|
|
|
|
depthfbo.Bind(); |
|
|
|
|
|
glUseProgram(depthProgram.mProgram); |
|
|
|
|
|
|
|
|
originalFbo.Bind(); |
|
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); |
|
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); |
|
|
glUniformMatrix4fv(depthProgram.GetLocation("M"), 1, GL_FALSE, glm::value_ptr(model)); |
|
|
|
|
|
glUniformMatrix4fv(depthProgram.GetLocation("V"), 1, GL_FALSE, glm::value_ptr(lightMatrix)); |
|
|
|
|
|
glUniformMatrix4fv(depthProgram.GetLocation("P"), 1, GL_FALSE, glm::value_ptr(lightprojectionMatrix)); |
|
|
|
|
|
obj.Bind(depthProgram.GetLocation("pos"), depthProgram.GetLocation("texcoord"), depthProgram.GetLocation("normal")); |
|
|
|
|
|
obj.Draw(); |
|
|
|
|
|
|
|
|
glUseProgram(sampleProgram.mProgram); |
|
|
|
|
|
glUniformMatrix4fv(sampleProgram.GetLocation("P"), 1, GL_FALSE, glm::value_ptr(projectionMatrix)); |
|
|
|
|
|
glUniformMatrix4fv(sampleProgram.GetLocation("V"), 1, GL_FALSE, glm::value_ptr(viewMatrix)); |
|
|
|
|
|
glUniformMatrix4fv(sampleProgram.GetLocation("M"), 1, GL_FALSE, glm::value_ptr(model)); |
|
|
|
|
|
|
|
|
glUniformMatrix4fv(depthProgram.GetLocation("M"), 1, GL_FALSE, glm::value_ptr(quadModel)); |
|
|
|
|
|
quad.Bind(depthProgram.GetLocation("pos"), depthProgram.GetLocation("texcoord"), depthProgram.GetLocation("normal")); |
|
|
|
|
|
quad.Draw(); |
|
|
|
|
|
|
|
|
|
|
|
glUseProgram(0); |
|
|
|
|
|
depthfbo.Unbind(); |
|
|
|
|
|
|
|
|
glBindTexture(GL_TEXTURE_2D, mainTexture); |
|
|
|
|
|
glUniform1i(sampleProgram.GetLocation("U_MainTexture"), 0); |
|
|
|
|
|
|
|
|
HDRfbo.Bind(); |
|
|
|
|
|
glUseProgram(gpuProgram.mProgram); |
|
|
|
|
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); |
|
|
|
|
|
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_LightDirection"), 1, spotLightDirection); |
|
|
|
|
|
glUniform4fv(gpuProgram.GetLocation("U_SpecularLightColor"), 1, specularLightColor); |
|
|
|
|
|
glUniform4fv(gpuProgram.GetLocation("U_SpecularMaterial"), 1, specularMaterial); |
|
|
|
|
|
glUniform4fv(gpuProgram.GetLocation("U_LightPos"), 1, lightPos); |
|
|
|
|
|
glUniform3fv(gpuProgram.GetLocation("U_EyePos"), 1, eyePos); |
|
|
|
|
|
glUniform1f(gpuProgram.GetLocation("U_Cutoff"), spotLightCutoff); |
|
|
|
|
|
glUniformMatrix4fv(gpuProgram.GetLocation("M"), 1, GL_FALSE, glm::value_ptr(model)); |
|
|
|
|
|
glUniformMatrix4fv(gpuProgram.GetLocation("V"), 1, GL_FALSE, glm::value_ptr(viewMatrix)); |
|
|
|
|
|
glUniformMatrix4fv(gpuProgram.GetLocation("P"), 1, GL_FALSE, glm::value_ptr(projectionMatrix)); |
|
|
|
|
|
glUniformMatrix4fv(gpuProgram.GetLocation("NM"), 1, GL_FALSE, glm::value_ptr(normalMatrix)); |
|
|
|
|
|
glUniformMatrix4fv(gpuProgram.GetLocation("U_LightProjection"), 1, GL_FALSE, glm::value_ptr(lightprojectionMatrix)); |
|
|
|
|
|
glUniformMatrix4fv(gpuProgram.GetLocation("U_LightViewMatrix"), 1, GL_FALSE, glm::value_ptr(lightMatrix)); |
|
|
|
|
|
glBindTexture(GL_TEXTURE_2D, depthfbo.GetBuffer("depth")); |
|
|
|
|
|
glUniform1i(gaussianProgram.GetLocation("U_ShadowMap"), 0); |
|
|
|
|
|
|
|
|
|
|
|
obj.Bind(gpuProgram.GetLocation("pos"), gpuProgram.GetLocation("texcoord"), gpuProgram.GetLocation("normal")); |
|
|
|
|
|
|
|
|
obj.Bind(sampleProgram.GetLocation("pos"), sampleProgram.GetLocation("texcoord"), sampleProgram.GetLocation("normal")); |
|
|
obj.Draw(); |
|
|
obj.Draw(); |
|
|
|
|
|
|
|
|
glUniformMatrix4fv(gpuProgram.GetLocation("M"), 1, GL_FALSE, glm::value_ptr(quadModel)); |
|
|
|
|
|
glUniformMatrix4fv(gpuProgram.GetLocation("NM"), 1, GL_FALSE, glm::value_ptr(quadNormalMatrix)); |
|
|
|
|
|
quad.Bind(gpuProgram.GetLocation("pos"), gpuProgram.GetLocation("texcoord"), gpuProgram.GetLocation("normal")); |
|
|
|
|
|
|
|
|
glUniformMatrix4fv(sampleProgram.GetLocation("M"), 1, GL_FALSE, glm::value_ptr(quadModel)); |
|
|
|
|
|
quad.Bind(sampleProgram.GetLocation("pos"), sampleProgram.GetLocation("texcoord"), sampleProgram.GetLocation("normal")); |
|
|
quad.Draw(); |
|
|
quad.Draw(); |
|
|
|
|
|
originalFbo.Unbind(); |
|
|
|
|
|
|
|
|
|
|
|
projectiveTextureFbo.Bind(); |
|
|
|
|
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); |
|
|
|
|
|
glUseProgram(projectedTextureProgram.mProgram); |
|
|
|
|
|
glUniformMatrix4fv(projectedTextureProgram.GetLocation("P"), 1, GL_FALSE, glm::value_ptr(projectionMatrix)); |
|
|
|
|
|
glUniformMatrix4fv(projectedTextureProgram.GetLocation("V"), 1, GL_FALSE, glm::value_ptr(viewMatrix)); |
|
|
|
|
|
glUniformMatrix4fv(projectedTextureProgram.GetLocation("M"), 1, GL_FALSE, glm::value_ptr(model)); |
|
|
|
|
|
|
|
|
glUseProgram(lightSourceProgram.mProgram); |
|
|
|
|
|
glUniformMatrix4fv(lightSourceProgram.GetLocation("M"), 1, GL_FALSE, glm::value_ptr(sphereModel)); |
|
|
|
|
|
glUniformMatrix4fv(lightSourceProgram.GetLocation("V"), 1, GL_FALSE, glm::value_ptr(viewMatrix)); |
|
|
|
|
|
glUniformMatrix4fv(lightSourceProgram.GetLocation("P"), 1, GL_FALSE, glm::value_ptr(projectionMatrix)); |
|
|
|
|
|
sphere.Bind(lightSourceProgram.GetLocation("pos"), lightSourceProgram.GetLocation("texcoord"), lightSourceProgram.GetLocation("normal")); |
|
|
|
|
|
sphere.Draw(); |
|
|
|
|
|
|
|
|
|
|
|
glUseProgram(0); |
|
|
|
|
|
HDRfbo.Unbind(); |
|
|
|
|
|
|
|
|
glUniformMatrix4fv(projectedTextureProgram.GetLocation("U_ProjectorMatrix"), 1, GL_FALSE, glm::value_ptr(projectorMatrix)); |
|
|
|
|
|
|
|
|
/* blur start */ |
|
|
|
|
|
fbo[0].Bind(); |
|
|
|
|
|
glUseProgram(gaussianProgram.mProgram); |
|
|
|
|
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); |
|
|
|
|
|
glActiveTexture(GL_TEXTURE0); |
|
|
glActiveTexture(GL_TEXTURE0); |
|
|
glBindTexture(GL_TEXTURE_2D, HDRfbo.GetBuffer("hdrcolor")); |
|
|
|
|
|
glUniform1i(gaussianProgram.GetLocation("U_MainTexture"), 0); |
|
|
|
|
|
fsq.Draw(gaussianProgram.GetLocation("pos"), gaussianProgram.GetLocation("texcoord")); |
|
|
|
|
|
fbo[0].Unbind(); |
|
|
|
|
|
|
|
|
glBindTexture(GL_TEXTURE_2D, mainTexture); |
|
|
|
|
|
glUniform1i(projectedTextureProgram.GetLocation("U_MainTexture"), 0); |
|
|
|
|
|
|
|
|
fbo[1].Bind(); |
|
|
|
|
|
glUseProgram(gaussianProgram.mProgram); |
|
|
|
|
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); |
|
|
|
|
|
glActiveTexture(GL_TEXTURE0); |
|
|
|
|
|
glBindTexture(GL_TEXTURE_2D, fbo[0].GetBuffer("color")); |
|
|
|
|
|
glUniform1i(gaussianProgram.GetLocation("U_MainTexture"), 0); |
|
|
|
|
|
fsq.Draw(gaussianProgram.GetLocation("pos"), gaussianProgram.GetLocation("texcoord")); |
|
|
|
|
|
fbo[1].Unbind(); |
|
|
|
|
|
|
|
|
glActiveTexture(GL_TEXTURE1); |
|
|
|
|
|
glBindTexture(GL_TEXTURE_2D, projectiveTexture); |
|
|
|
|
|
glUniform1i(projectedTextureProgram.GetLocation("U_ProjectiveTexture"), 1); |
|
|
|
|
|
|
|
|
fbo[0].Bind(); |
|
|
|
|
|
glUseProgram(gaussianProgram.mProgram); |
|
|
|
|
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); |
|
|
|
|
|
glActiveTexture(GL_TEXTURE0); |
|
|
|
|
|
glBindTexture(GL_TEXTURE_2D, fbo[1].GetBuffer("color")); |
|
|
|
|
|
glUniform1i(gaussianProgram.GetLocation("U_MainTexture"), 0); |
|
|
|
|
|
fsq.Draw(gaussianProgram.GetLocation("pos"), gaussianProgram.GetLocation("texcoord")); |
|
|
|
|
|
fbo[0].Unbind(); |
|
|
|
|
|
|
|
|
obj.Bind(projectedTextureProgram.GetLocation("pos"), projectedTextureProgram.GetLocation("texcoord"), projectedTextureProgram.GetLocation("normal")); |
|
|
|
|
|
obj.Draw(); |
|
|
|
|
|
|
|
|
fbo[1].Bind(); |
|
|
|
|
|
glUseProgram(gaussianProgram.mProgram); |
|
|
|
|
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); |
|
|
|
|
|
glActiveTexture(GL_TEXTURE0); |
|
|
|
|
|
glBindTexture(GL_TEXTURE_2D, fbo[0].GetBuffer("color")); |
|
|
|
|
|
glUniform1i(gaussianProgram.GetLocation("U_MainTexture"), 0); |
|
|
|
|
|
fsq.Draw(gaussianProgram.GetLocation("pos"), gaussianProgram.GetLocation("texcoord")); |
|
|
|
|
|
fbo[1].Unbind(); |
|
|
|
|
|
/* blur end */ |
|
|
|
|
|
|
|
|
glUniformMatrix4fv(projectedTextureProgram.GetLocation("M"), 1, GL_FALSE, glm::value_ptr(quadModel)); |
|
|
|
|
|
quad.Bind(projectedTextureProgram.GetLocation("pos"), projectedTextureProgram.GetLocation("texcoord"), projectedTextureProgram.GetLocation("normal")); |
|
|
|
|
|
quad.Draw(); |
|
|
|
|
|
|
|
|
|
|
|
projectiveTextureFbo.Unbind(); |
|
|
|
|
|
|
|
|
MSG msg; |
|
|
MSG msg; |
|
|
while (true) |
|
|
while (true) |
|
@ -353,32 +219,20 @@ INT WINAPI WinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _ |
|
|
DispatchMessage(&msg); |
|
|
DispatchMessage(&msg); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
glClearColor(0.1f, 0.4f, 0.7f, 1.0f); |
|
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); |
|
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); |
|
|
glActiveTexture(GL_TEXTURE0); |
|
|
|
|
|
|
|
|
|
|
|
glUseProgram(originalProgram.mProgram); |
|
|
glUseProgram(originalProgram.mProgram); |
|
|
glBindTexture(GL_TEXTURE_2D, HDRfbo.GetBuffer("color")); |
|
|
|
|
|
|
|
|
glActiveTexture(GL_TEXTURE0); |
|
|
|
|
|
glBindTexture(GL_TEXTURE_2D, originalFbo.GetBuffer("color")); |
|
|
glUniform1i(originalProgram.GetLocation("U_MainTexture"), 0); |
|
|
glUniform1i(originalProgram.GetLocation("U_MainTexture"), 0); |
|
|
fsq.DrawToLeftTop(originalProgram.GetLocation("pos"), originalProgram.GetLocation("texcoord")); |
|
|
fsq.DrawToLeftTop(originalProgram.GetLocation("pos"), originalProgram.GetLocation("texcoord")); |
|
|
|
|
|
|
|
|
glUseProgram(depthRenderProgram.mProgram); |
|
|
|
|
|
glBindTexture(GL_TEXTURE_2D, depthfbo.GetBuffer("depth")); |
|
|
|
|
|
glUniform1i(depthRenderProgram.GetLocation("U_MainTexture"), 0); |
|
|
|
|
|
fsq.DrawToRightTop(depthRenderProgram.GetLocation("pos"), depthRenderProgram.GetLocation("texcoord")); |
|
|
|
|
|
|
|
|
|
|
|
glUseProgram(gaussianProgram.mProgram); |
|
|
|
|
|
glBindTexture(GL_TEXTURE_2D, fbo[1].GetBuffer("color")); |
|
|
|
|
|
glUniform1i(gaussianProgram.GetLocation("U_MainTexture"), 0); |
|
|
|
|
|
fsq.DrawToLeftBottom(gaussianProgram.GetLocation("pos"), gaussianProgram.GetLocation("texcoord")); |
|
|
|
|
|
|
|
|
|
|
|
glUseProgram(combineProgram.mProgram); |
|
|
|
|
|
|
|
|
glUseProgram(originalProgram.mProgram); |
|
|
glActiveTexture(GL_TEXTURE0); |
|
|
glActiveTexture(GL_TEXTURE0); |
|
|
glBindTexture(GL_TEXTURE_2D, HDRfbo.GetBuffer("color")); |
|
|
|
|
|
glUniform1i(combineProgram.GetLocation("U_MainTexture"), 0); |
|
|
|
|
|
glActiveTexture(GL_TEXTURE1); |
|
|
|
|
|
glBindTexture(GL_TEXTURE_2D, fbo[1].GetBuffer("color")); |
|
|
|
|
|
glUniform1i(combineProgram.GetLocation("U_HDRTexture"), 1); |
|
|
|
|
|
fsq.DrawToRightBottom(combineProgram.GetLocation("pos"), combineProgram.GetLocation("texcoord")); |
|
|
|
|
|
|
|
|
glBindTexture(GL_TEXTURE_2D, projectiveTextureFbo.GetBuffer("color")); |
|
|
|
|
|
glUniform1i(originalProgram.GetLocation("U_MainTexture"), 0); |
|
|
|
|
|
fsq.DrawToRightTop(originalProgram.GetLocation("pos"), originalProgram.GetLocation("texcoord")); |
|
|
|
|
|
|
|
|
glFlush(); |
|
|
glFlush(); |
|
|
SwapBuffers(dc); |
|
|
SwapBuffers(dc); |
|
|