|
|
@ -164,6 +164,9 @@ INT WINAPI WinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _ |
|
|
|
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 3d model
|
|
|
|
ObjModel obj, quad, sphere; |
|
|
@ -256,6 +259,86 @@ INT WINAPI WinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _ |
|
|
|
glUseProgram(0); |
|
|
|
depthfbo.Unbind(); |
|
|
|
|
|
|
|
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.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")); |
|
|
|
quad.Draw(); |
|
|
|
|
|
|
|
|
|
|
|
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(); |
|
|
|
|
|
|
|
/* blur start */ |
|
|
|
fbo[0].Bind(); |
|
|
|
glUseProgram(gaussianProgram.mProgram); |
|
|
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); |
|
|
|
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(); |
|
|
|
|
|
|
|
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(); |
|
|
|
|
|
|
|
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(); |
|
|
|
|
|
|
|
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 */ |
|
|
|
|
|
|
|
|
|
|
|
MSG msg; |
|
|
|
while (true) |
|
|
@ -270,83 +353,6 @@ INT WINAPI WinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _ |
|
|
|
DispatchMessage(&msg); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
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)); |
|
|
|
obj.Bind(gpuProgram.GetLocation("pos"), gpuProgram.GetLocation("texcoord"), gpuProgram.GetLocation("normal")); |
|
|
|
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")); |
|
|
|
quad.Draw(); |
|
|
|
|
|
|
|
|
|
|
|
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(); |
|
|
|
|
|
|
|
/* blur start */ |
|
|
|
fbo[0].Bind(); |
|
|
|
glUseProgram(gaussianProgram.mProgram); |
|
|
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); |
|
|
|
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(); |
|
|
|
|
|
|
|
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(); |
|
|
|
|
|
|
|
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(); |
|
|
|
|
|
|
|
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 */ |
|
|
|
|
|
|
|
glFlush(); |
|
|
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); |
|
|
|
glActiveTexture(GL_TEXTURE0); |
|
|
|
|
|
|
@ -374,6 +380,7 @@ INT WINAPI WinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _ |
|
|
|
glUniform1i(combineProgram.GetLocation("U_HDRTexture"), 1); |
|
|
|
fsq.DrawToRightBottom(combineProgram.GetLocation("pos"), combineProgram.GetLocation("texcoord")); |
|
|
|
|
|
|
|
glFlush(); |
|
|
|
SwapBuffers(dc); |
|
|
|
} |
|
|
|
return 0; |