Browse Source

点光源阴影渲染

master
blobt 4 years ago
parent
commit
717dd81598
  1. 20
      main.cpp
  2. 2
      res/shader/depthrender.fs
  3. 2
      res/shader/hdr.fs

20
main.cpp

@ -185,8 +185,8 @@ INT WINAPI WinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _
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.0f,1.0f, 0.0f,0.0f };
float diffuseIntensity = 1.0f;
float lightPos[] = { 1.0f, 3.0f, -0.8f,1.0f };
float diffuseIntensity = 2.0f;
float spotLightDirection[] = { 0.0f, -1.0f, 0.0f, 128.0f };//°Ñ×îºóһλ¸Ä³É......
float spotLightCutoff = 0.0f;
@ -197,21 +197,21 @@ 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.0f) * glm::rotate(-60.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>(0.0f, -1.5f, -2.0f) * glm::rotate(-90.0f, 1.0f, 0.0f, 0.0f) * glm::scale(8.0f, 8.0f, 8.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.1f, 3.0f, -2.2f) * 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(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 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 projectionMatrix = glm::perspective(50.0f, (float)viewportWidth / (float)viewportHeight, 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);
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);
//³õʼ»¯fsq
FullScreenQuad fsq;
@ -240,7 +240,7 @@ INT WINAPI WinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _
ShowWindow(hwnd, SW_SHOW);
UpdateWindow(hwnd);
glClearColor(0.1f, 0.1f, 0.1f, 1.0f);
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
glEnable(GL_DEPTH_TEST);
depthfbo.Bind();

2
res/shader/depthrender.fs

@ -6,6 +6,6 @@ uniform sampler2D U_MainTexture;
void main()
{
float depthValue=texture2D(U_MainTexture,V_Texcoord).r;
depthValue = pow(depthValue, 2);
depthValue = pow(depthValue, 32);
gl_FragColor=vec4(vec3(depthValue),1.0);
}

2
res/shader/hdr.fs

@ -28,7 +28,7 @@ float CalculateShadow(){
for(int y = -1; y < 1; ++y){
for(int x = -1; x < 1; ++x){
float pcfDepth = texture2D(U_ShadowMap, fragPos.xy + texelSize * vec2(x,y)).r;
shadow += (currentDepth-0.05) > pcfDepth ? 1.0 : 0.0;
shadow += (currentDepth-0.001) > pcfDepth ? 1.0 : 0.0;
}
}
shadow/=9.0;

Loading…
Cancel
Save