|
|
@ -99,6 +99,15 @@ INT WINAPI WinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _ |
|
|
|
dilationProgram.DetectAttribute("texcoord"); |
|
|
|
dilationProgram.DetectUniform("U_MainTexture"); |
|
|
|
|
|
|
|
//init dilation program
|
|
|
|
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"); |
|
|
|
|
|
|
|
//init gpu program
|
|
|
|
GPUProgram gpuProgram; |
|
|
|
gpuProgram.AttachShader(GL_VERTEX_SHADER, "res/shader/test.vs"); |
|
|
@ -112,11 +121,21 @@ INT WINAPI WinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _ |
|
|
|
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"); |
|
|
|
|
|
|
|
//init 3d model
|
|
|
|
ObjModel obj; |
|
|
|
obj.Init("res/model/Sphere.obj"); |
|
|
|
obj.Init("res/model/Cube.obj"); |
|
|
|
|
|
|
|
float identity[] = { |
|
|
|
1.0f,0,0,0, |
|
|
@ -125,11 +144,24 @@ INT WINAPI WinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _ |
|
|
|
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[] = { 0.1f,3.0f, -2.2f,1.0f }; |
|
|
|
float diffuseIntensity = 4.0f; |
|
|
|
|
|
|
|
float spotLightDirection[] = { 0.0f, -1.0f, 0.0f, 128.0f };//°Ñ×îºóһλ¸Ä³É......
|
|
|
|
float spotLightCutoff = 15.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>(0.0f, 0.0f, -4.0f); |
|
|
|
glm::mat4 viewMatrix = glm::lookAt(glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3(0.0f, 0.0f, -2.0f), glm::vec3(0.0f, 1.0f, 0.0f)); |
|
|
|
glm::mat4 model = glm::translate<float>(0.0f, 0.0f, -2.5f) * glm::rotate(-60.0f, 1.0f, 1.0f, 1.0f); |
|
|
|
glm::mat4 viewMatrix = glm::lookAt(glm::vec3(0.0f, 0.0f, 0.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 normalMatrix = glm::inverseTranspose(model); |
|
|
|
|
|
|
@ -168,11 +200,22 @@ INT WINAPI WinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _ |
|
|
|
|
|
|
|
fbo.Bind(); |
|
|
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); |
|
|
|
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_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(); |
|
|
|
fbo.Unbind(); |
|
|
@ -198,6 +241,9 @@ INT WINAPI WinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _ |
|
|
|
glUseProgram(dilationProgram.mProgram); |
|
|
|
fsq.DrawToLeftBottom(dilationProgram.GetLocation("pos"), dilationProgram.GetLocation("texcoord")); |
|
|
|
|
|
|
|
glUseProgram(gaussianProgram.mProgram); |
|
|
|
fsq.DrawToRightBottom(gaussianProgram.GetLocation("pos"), gaussianProgram.GetLocation("texcoord")); |
|
|
|
|
|
|
|
SwapBuffers(dc); |
|
|
|
} |
|
|
|
return 0; |