|
@ -81,6 +81,15 @@ 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
|
|
|
//init hdr program
|
|
|
GPUProgram hdrProgram; |
|
|
GPUProgram hdrProgram; |
|
|
hdrProgram.AttachShader(GL_VERTEX_SHADER, "res/shader/fullscreenquad.vs"); |
|
|
hdrProgram.AttachShader(GL_VERTEX_SHADER, "res/shader/fullscreenquad.vs"); |
|
@ -120,6 +129,16 @@ INT WINAPI WinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _ |
|
|
lightSourceProgram.DetectUniform("V"); |
|
|
lightSourceProgram.DetectUniform("V"); |
|
|
lightSourceProgram.DetectUniform("P"); |
|
|
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
|
|
|
//init gpu program
|
|
|
GPUProgram gpuProgram; |
|
|
GPUProgram gpuProgram; |
|
@ -188,6 +207,8 @@ INT WINAPI WinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _ |
|
|
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 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 projectionMatrix = glm::perspective(50.0f, 800.0f / 600.0f, 0.1f, 1000.0f); |
|
|
glm::mat4 projectionMatrix = glm::perspective(50.0f, 800.0f / 600.0f, 0.1f, 1000.0f); |
|
|
|
|
|
|
|
|
|
|
|
glm::mat4 lightMatrix = glm::lookAt(glm::vec3(0.0f, 10.0f, 0.0f), glm::vec3(0.0f, 0.0f, -2.0f), glm::vec3(0.0f, 0.0f, -1.0f)); |
|
|
|
|
|
glm::mat4 lightprojectionMatrix = glm::ortho(-5.0f, 5.0f, -5.0f, 5.0f, 0.1f, 15.0f); |
|
|
|
|
|
|
|
|
//³õʼ»¯fsq
|
|
|
//³õʼ»¯fsq
|
|
|
FullScreenQuad fsq; |
|
|
FullScreenQuad fsq; |
|
@ -208,10 +229,34 @@ INT WINAPI WinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _ |
|
|
HDRfbo.AttachDepthBuffer("depth", viewportWidth, viewportHeight); |
|
|
HDRfbo.AttachDepthBuffer("depth", viewportWidth, viewportHeight); |
|
|
HDRfbo.Finish(); |
|
|
HDRfbo.Finish(); |
|
|
|
|
|
|
|
|
|
|
|
FBO depthfbo; |
|
|
|
|
|
depthfbo.AttachColorBuffer("color", GL_COLOR_ATTACHMENT0, GL_RGB, viewportWidth, viewportHeight); |
|
|
|
|
|
depthfbo.AttachDepthBuffer("depth", viewportWidth, viewportHeight); |
|
|
|
|
|
depthfbo.Finish(); |
|
|
|
|
|
|
|
|
ShowWindow(hwnd, SW_SHOW); |
|
|
ShowWindow(hwnd, SW_SHOW); |
|
|
UpdateWindow(hwnd); |
|
|
UpdateWindow(hwnd); |
|
|
|
|
|
|
|
|
glClearColor(0.0f, 0.0f, 0.0f, 1.0f); |
|
|
|
|
|
|
|
|
glClearColor(0.1f, 0.1f, 0.1f, 1.0f); |
|
|
|
|
|
glEnable(GL_DEPTH_TEST); |
|
|
|
|
|
|
|
|
|
|
|
depthfbo.Bind(); |
|
|
|
|
|
glUseProgram(depthProgram.mProgram); |
|
|
|
|
|
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(); |
|
|
|
|
|
|
|
|
|
|
|
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(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
MSG msg; |
|
|
MSG msg; |
|
|
while (true) |
|
|
while (true) |
|
|
{ |
|
|
{ |
|
@ -224,7 +269,6 @@ INT WINAPI WinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _ |
|
|
TranslateMessage(&msg); |
|
|
TranslateMessage(&msg); |
|
|
DispatchMessage(&msg); |
|
|
DispatchMessage(&msg); |
|
|
} |
|
|
} |
|
|
glEnable(GL_DEPTH_TEST); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
HDRfbo.Bind(); |
|
|
HDRfbo.Bind(); |
|
@ -311,10 +355,10 @@ INT WINAPI WinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _ |
|
|
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(hdrProgram.mProgram); |
|
|
|
|
|
glBindTexture(GL_TEXTURE_2D, HDRfbo.GetBuffer("hdrcolor")); |
|
|
|
|
|
glUniform1i(hdrProgram.GetLocation("U_MainTexture"), 0); |
|
|
|
|
|
fsq.DrawToRightTop(hdrProgram.GetLocation("pos"), hdrProgram.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); |
|
|
glUseProgram(gaussianProgram.mProgram); |
|
|
glBindTexture(GL_TEXTURE_2D, fbo[1].GetBuffer("color")); |
|
|
glBindTexture(GL_TEXTURE_2D, fbo[1].GetBuffer("color")); |
|
|