|
|
@ -100,6 +100,18 @@ INT WINAPI WinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _ |
|
|
|
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 gpu program
|
|
|
|
GPUProgram gpuProgram; |
|
|
|
gpuProgram.AttachShader(GL_VERTEX_SHADER, "res/shader/test.vs"); |
|
|
@ -126,8 +138,10 @@ INT WINAPI WinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _ |
|
|
|
gpuProgram.DetectUniform("U_EyePos"); |
|
|
|
|
|
|
|
//init 3d model
|
|
|
|
ObjModel obj; |
|
|
|
ObjModel obj,quad,sphere; |
|
|
|
obj.Init("res/model/Cube.obj"); |
|
|
|
quad.Init("res/model/Quad.obj"); |
|
|
|
sphere.Init("res/model/Sphere.obj"); |
|
|
|
|
|
|
|
float identity[] = { |
|
|
|
1.0f,0,0,0, |
|
|
@ -141,10 +155,10 @@ INT WINAPI WinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _ |
|
|
|
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 diffuseIntensity = 3.0f; |
|
|
|
|
|
|
|
float spotLightDirection[] = { 0.0f, -1.0f, 0.0f, 128.0f };//°Ñ×îºóһλ¸Ä³É......
|
|
|
|
float spotLightCutoff = 15.0f; |
|
|
|
float spotLightCutoff = 0.0f; |
|
|
|
|
|
|
|
|
|
|
|
float specularLightColor[] = { 1.0f,1.0f,1.0f,1.0f }; |
|
|
@ -152,11 +166,20 @@ INT WINAPI WinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _ |
|
|
|
float eyePos[] = { 0.0f, 0.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 model = glm::translate<float>(0.0f, 0.0f, -2.0f) * glm::rotate(-60.0f, 1.0f, 1.0f, 1.0f); |
|
|
|
glm::mat4 normalMatrix = glm::inverseTranspose(model); |
|
|
|
|
|
|
|
glm::mat4 quadModel = glm::translate<float>(0.0f, 0.0f, -2.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.1f, 3.0f, -2.2f) * glm::scale(0.2f, 0.2f, 0.2f); |
|
|
|
glm::mat4 sphereNormalMatrix = glm::inverseTranspose(sphereModel); |
|
|
|
|
|
|
|
|
|
|
|
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); |
|
|
|
|
|
|
|
|
|
|
|
//³õʼ»¯fsq
|
|
|
|
FullScreenQuad fsq; |
|
|
|
fsq.Init(); |
|
|
@ -176,7 +199,7 @@ INT WINAPI WinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _ |
|
|
|
ShowWindow(hwnd, SW_SHOW); |
|
|
|
UpdateWindow(hwnd); |
|
|
|
|
|
|
|
glClearColor(0.0f, 0.0f, 0.0f, 1.0f); |
|
|
|
glClearColor(0.1f, 0.1f, 0.1f, 1.0f); |
|
|
|
MSG msg; |
|
|
|
while (true) |
|
|
|
{ |
|
|
@ -212,12 +235,25 @@ INT WINAPI WinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _ |
|
|
|
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(); |
|
|
|
|
|
|
|
glFlush(); |
|
|
|
|
|
|
|
glClearColor(0.0f, 0.0f, 0.0f, 1.0f); |
|
|
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); |
|
|
|
glActiveTexture(GL_TEXTURE0); |
|
|
|
|
|
|
|