Fixed shadows
This commit is contained in:
parent
0ffe8beef3
commit
9552610ca8
@ -41,14 +41,14 @@
|
|||||||
<None Include="shaders\shader_9_1.vert" />
|
<None Include="shaders\shader_9_1.vert" />
|
||||||
<None Include="shaders\shader_8_sun.frag" />
|
<None Include="shaders\shader_8_sun.frag" />
|
||||||
<None Include="shaders\shader_8_sun.vert" />
|
<None Include="shaders\shader_8_sun.vert" />
|
||||||
<None Include="shaders\test.frag" />
|
<None Include="shaders\shader_depth.frag" />
|
||||||
<None Include="shaders\test.vert" />
|
<None Include="shaders\shader_depth.vert" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<PropertyGroup Label="Globals">
|
<PropertyGroup Label="Globals">
|
||||||
<ProjectGuid>{5BACD057-4B83-4CB6-A367-40A10BCE2149}</ProjectGuid>
|
<ProjectGuid>{5BACD057-4B83-4CB6-A367-40A10BCE2149}</ProjectGuid>
|
||||||
<Keyword>Win32Proj</Keyword>
|
<Keyword>Win32Proj</Keyword>
|
||||||
<RootNamespace>grk-cw9</RootNamespace>
|
<RootNamespace>grk-cw9</RootNamespace>
|
||||||
<WindowsTargetPlatformVersion>10.0.19041.0</WindowsTargetPlatformVersion>
|
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
|
||||||
<ProjectName>grk-cw9</ProjectName>
|
<ProjectName>grk-cw9</ProjectName>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
||||||
|
@ -103,10 +103,10 @@
|
|||||||
<None Include="shaders\shader_9_1.vert">
|
<None Include="shaders\shader_9_1.vert">
|
||||||
<Filter>Shader Files</Filter>
|
<Filter>Shader Files</Filter>
|
||||||
</None>
|
</None>
|
||||||
<None Include="shaders\test.frag">
|
<None Include="shaders\shader_depth.frag">
|
||||||
<Filter>Shader Files</Filter>
|
<Filter>Shader Files</Filter>
|
||||||
</None>
|
</None>
|
||||||
<None Include="shaders\test.vert">
|
<None Include="shaders\shader_depth.vert">
|
||||||
<Filter>Shader Files</Filter>
|
<Filter>Shader Files</Filter>
|
||||||
</None>
|
</None>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
@ -4,9 +4,6 @@ float AMBIENT = 0.03;
|
|||||||
float PI = 3.14;
|
float PI = 3.14;
|
||||||
|
|
||||||
uniform sampler2D depthMap;
|
uniform sampler2D depthMap;
|
||||||
//uniform sampler2D depthMaplamp;
|
|
||||||
uniform sampler2D depthMapflash;
|
|
||||||
|
|
||||||
|
|
||||||
uniform vec3 cameraPos;
|
uniform vec3 cameraPos;
|
||||||
|
|
||||||
@ -38,11 +35,11 @@ in vec3 viewDirTS;
|
|||||||
in vec3 lightDirTS;
|
in vec3 lightDirTS;
|
||||||
in vec3 spotlightDirTS;
|
in vec3 spotlightDirTS;
|
||||||
in vec3 sunDirTS;
|
in vec3 sunDirTS;
|
||||||
in vec4 sunSpacePos;
|
|
||||||
in vec4 lampSpacePos;
|
|
||||||
in vec4 flashSpacePos;
|
|
||||||
|
|
||||||
in vec3 test;
|
in vec3 test;
|
||||||
|
|
||||||
|
in vec4 sunSpacePos;
|
||||||
|
|
||||||
float calculateShadow()
|
float calculateShadow()
|
||||||
{
|
{
|
||||||
vec4 lightSpacePosNormalized = (0.5*sunSpacePos / (sunSpacePos.w)) + 0.5;
|
vec4 lightSpacePosNormalized = (0.5*sunSpacePos / (sunSpacePos.w)) + 0.5;
|
||||||
@ -52,14 +49,6 @@ float calculateShadow()
|
|||||||
return (0.5*(diff)/abs(diff))+0.5;
|
return (0.5*(diff)/abs(diff))+0.5;
|
||||||
}
|
}
|
||||||
|
|
||||||
float calculateShadowOtherLigths(vec4 ligthSpacePos, sampler2D ligthDepthMap)
|
|
||||||
{
|
|
||||||
vec4 lightSpacePosNormalized = (0.5*ligthSpacePos / (ligthSpacePos.w)) + 0.5;
|
|
||||||
float closestDepth = texture2D(ligthDepthMap, lightSpacePosNormalized.xy).x;
|
|
||||||
float diff = (0.001+closestDepth) - lightSpacePosNormalized.z;//lightSpacePosNormalized.z;
|
|
||||||
|
|
||||||
return (0.5*(diff)/abs(diff))+0.5;
|
|
||||||
}
|
|
||||||
float DistributionGGX(vec3 normal, vec3 H, float roughness){
|
float DistributionGGX(vec3 normal, vec3 H, float roughness){
|
||||||
float a = roughness*roughness;
|
float a = roughness*roughness;
|
||||||
float a2 = a*a;
|
float a2 = a*a;
|
||||||
@ -145,13 +134,13 @@ void main()
|
|||||||
|
|
||||||
float angle_atenuation = clamp((dot(-normalize(spotlightPos-worldPos),spotlightConeDir)-0.5)*3,0,1);
|
float angle_atenuation = clamp((dot(-normalize(spotlightPos-worldPos),spotlightConeDir)-0.5)*3,0,1);
|
||||||
attenuatedlightColor = angle_atenuation*spotlightColor/pow(length(spotlightPos-worldPos),2);
|
attenuatedlightColor = angle_atenuation*spotlightColor/pow(length(spotlightPos-worldPos),2);
|
||||||
ilumination=ilumination+PBRLight(spotlightDir,attenuatedlightColor*calculateShadowOtherLigths(flashSpacePos, depthMapflash),normal,viewDir);
|
ilumination=ilumination+PBRLight(spotlightDir,attenuatedlightColor,normal,viewDir);
|
||||||
|
|
||||||
//sun
|
//sun
|
||||||
ilumination=ilumination+PBRLight(sunDir,sunColor*calculateShadow(),normal,viewDir);
|
ilumination=ilumination+PBRLight(sunDir,sunColor,normal,viewDir) * calculateShadow();
|
||||||
|
|
||||||
|
|
||||||
outColor = vec4(vec3(1.0) - exp(-ilumination*exposition),1);
|
outColor = vec4(vec3(1.0) - exp(-ilumination*exposition),1);
|
||||||
//outColor = (0.5*sunSpacePos / (sunSpacePos.w+0.0001)) + 0.5;
|
//outColor = vec4(roughness,metallic,0,1);
|
||||||
//outColor = vec4(test;
|
//outColor = vec4(test;
|
||||||
}
|
}
|
||||||
|
@ -8,6 +8,10 @@ layout(location = 4) in vec3 vertexBitangent;
|
|||||||
|
|
||||||
uniform mat4 transformation;
|
uniform mat4 transformation;
|
||||||
uniform mat4 modelMatrix;
|
uniform mat4 modelMatrix;
|
||||||
|
uniform mat4 LightVP;
|
||||||
|
|
||||||
|
out vec3 vecNormal;
|
||||||
|
out vec3 worldPos;
|
||||||
|
|
||||||
uniform vec3 lightPos;
|
uniform vec3 lightPos;
|
||||||
uniform vec3 spotlightPos;
|
uniform vec3 spotlightPos;
|
||||||
@ -18,17 +22,8 @@ out vec3 viewDirTS;
|
|||||||
out vec3 lightDirTS;
|
out vec3 lightDirTS;
|
||||||
out vec3 spotlightDirTS;
|
out vec3 spotlightDirTS;
|
||||||
out vec3 sunDirTS;
|
out vec3 sunDirTS;
|
||||||
out vec3 worldPos;
|
|
||||||
out vec3 vecNormal;
|
|
||||||
out vec4 sunSpacePos;
|
out vec4 sunSpacePos;
|
||||||
out vec4 lampSpacePos;
|
|
||||||
out vec4 flashSpacePos;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
uniform mat4 LightVP;
|
|
||||||
uniform mat4 LightVPlamp;
|
|
||||||
uniform mat4 LightVPflash;
|
|
||||||
|
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
@ -49,7 +44,4 @@ void main()
|
|||||||
sunDirTS = TBN*sunDir;
|
sunDirTS = TBN*sunDir;
|
||||||
|
|
||||||
sunSpacePos=LightVP*modelMatrix*vec4(vertexPosition,1);
|
sunSpacePos=LightVP*modelMatrix*vec4(vertexPosition,1);
|
||||||
lampSpacePos=LightVPlamp*modelMatrix*vec4(vertexPosition,1);
|
|
||||||
flashSpacePos=LightVPflash*modelMatrix*vec4(vertexPosition,1);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,8 @@ out vec4 FragColor;
|
|||||||
|
|
||||||
in vec2 tc;
|
in vec2 tc;
|
||||||
|
|
||||||
uniform sampler2D depthMap;
|
uniform sampler2D
|
||||||
|
;
|
||||||
|
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
|
240
src/ex_9_1.hpp
240
src/ex_9_1.hpp
@ -36,19 +36,15 @@ namespace models {
|
|||||||
Core::RenderContext testContext;
|
Core::RenderContext testContext;
|
||||||
}
|
}
|
||||||
|
|
||||||
GLuint depthMapFBOsun;
|
GLuint depthMapFBO;
|
||||||
GLuint depthMapFBOlamp;
|
GLuint depthMap;
|
||||||
GLuint depthMapFBOflash;
|
|
||||||
GLuint depthMapsun;
|
|
||||||
GLuint depthMaplamp;
|
|
||||||
GLuint depthMapflash;
|
|
||||||
|
|
||||||
GLuint program;
|
GLuint program;
|
||||||
GLuint programSun;
|
GLuint programSun;
|
||||||
GLuint programTest;
|
|
||||||
GLuint programTex;
|
GLuint programTex;
|
||||||
GLuint programDepth;
|
GLuint programDepth;
|
||||||
|
|
||||||
|
|
||||||
Core::Shader_Loader shaderLoader;
|
Core::Shader_Loader shaderLoader;
|
||||||
|
|
||||||
Core::RenderContext shipContext;
|
Core::RenderContext shipContext;
|
||||||
@ -79,11 +75,20 @@ glm::vec3 spotlightColor = glm::vec3(0.4, 0.4, 0.9)*3;
|
|||||||
float spotlightPhi = 3.14 / 4;
|
float spotlightPhi = 3.14 / 4;
|
||||||
|
|
||||||
|
|
||||||
glm::mat4 lightVPsun;
|
|
||||||
glm::mat4 lightVPlamp;
|
|
||||||
glm::mat4 lightVPflash;
|
|
||||||
|
|
||||||
|
float lastTime = -1.f;
|
||||||
|
float deltaTime = 0.f;
|
||||||
|
|
||||||
|
void updateDeltaTime(float time) {
|
||||||
|
if (lastTime < 0) {
|
||||||
|
lastTime = time;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
deltaTime = time - lastTime;
|
||||||
|
if (deltaTime > 0.1) deltaTime = 0.1;
|
||||||
|
lastTime = time;
|
||||||
|
}
|
||||||
glm::mat4 createCameraMatrix()
|
glm::mat4 createCameraMatrix()
|
||||||
{
|
{
|
||||||
glm::vec3 cameraSide = glm::normalize(glm::cross(cameraDir,glm::vec3(0.f,1.f,0.f)));
|
glm::vec3 cameraSide = glm::normalize(glm::cross(cameraDir,glm::vec3(0.f,1.f,0.f)));
|
||||||
@ -120,24 +125,6 @@ glm::mat4 createPerspectiveMatrix()
|
|||||||
|
|
||||||
return perspectiveMatrix;
|
return perspectiveMatrix;
|
||||||
}
|
}
|
||||||
glm::mat4 createPerspectiveMatrixC(float n, float f)
|
|
||||||
{
|
|
||||||
|
|
||||||
glm::mat4 perspectiveMatrix;
|
|
||||||
float a1 = glm::min(aspectRatio, 1.f);
|
|
||||||
float a2 = glm::min(1 / aspectRatio, 1.f);
|
|
||||||
perspectiveMatrix = glm::mat4({
|
|
||||||
1,0.,0.,0.,
|
|
||||||
0.,aspectRatio,0.,0.,
|
|
||||||
0.,0.,(f + n) / (n - f),2 * f * n / (n - f),
|
|
||||||
0.,0.,-1.,0.,
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
perspectiveMatrix = glm::transpose(perspectiveMatrix);
|
|
||||||
|
|
||||||
return perspectiveMatrix;
|
|
||||||
}
|
|
||||||
|
|
||||||
void drawObjectPBR(Core::RenderContext& context, glm::mat4 modelMatrix, glm::vec3 color, float roughness, float metallic) {
|
void drawObjectPBR(Core::RenderContext& context, glm::mat4 modelMatrix, glm::vec3 color, float roughness, float metallic) {
|
||||||
|
|
||||||
@ -166,47 +153,24 @@ void drawObjectPBR(Core::RenderContext& context, glm::mat4 modelMatrix, glm::vec
|
|||||||
glUniform3f(glGetUniformLocation(program, "spotlightColor"), spotlightColor.x, spotlightColor.y, spotlightColor.z);
|
glUniform3f(glGetUniformLocation(program, "spotlightColor"), spotlightColor.x, spotlightColor.y, spotlightColor.z);
|
||||||
glUniform1f(glGetUniformLocation(program, "spotlightPhi"), spotlightPhi);
|
glUniform1f(glGetUniformLocation(program, "spotlightPhi"), spotlightPhi);
|
||||||
|
|
||||||
|
glActiveTexture(GL_TEXTURE0);
|
||||||
|
glBindTexture(GL_TEXTURE_2D, depthMap);
|
||||||
|
|
||||||
glUniformMatrix4fv(glGetUniformLocation(program, "LightVP"), 1, GL_FALSE, (float*)&lightVPsun);
|
glm::mat4 lightVP = glm::ortho(-3.f, 2.3f, -1.3f, 3.f, -1.0f, 40.0f) * glm::lookAt(sunPos, sunPos - sunDir, glm::vec3(0, 1, 0));
|
||||||
//glUniformMatrix4fv(glGetUniformLocation(program, "LightVPlamp"), 1, GL_FALSE, (float*)&lightVPlamp);
|
glUniformMatrix4fv(glGetUniformLocation(program, "LightVP"), 1, GL_FALSE, (float*)&lightVP);
|
||||||
glUniformMatrix4fv(glGetUniformLocation(program, "LightVPflash"), 1, GL_FALSE, (float*)&lightVPflash);
|
|
||||||
|
|
||||||
|
|
||||||
//glUniform1i(glGetUniformLocation(program, "depthMap"), depthMap);
|
|
||||||
//glActiveTexture(GL_TEXTURE0);
|
|
||||||
//glBindTexture(GL_TEXTURE_2D, depthMap);
|
|
||||||
//void Core::SetActiveTexture(GLuint textureID, const char* shaderVariableName, GLuint programID, int textureUnit)
|
|
||||||
//{
|
|
||||||
//glUniform1i(glGetUniformLocation(programID, shaderVariableName), textureUnit);
|
|
||||||
//glActiveTexture(GL_TEXTURE0 + textureUnit);
|
|
||||||
//glBindTexture(GL_TEXTURE_2D, textureID);
|
|
||||||
//}
|
|
||||||
glUniform1i(glGetUniformLocation(program, "depthMapflash"), 1);
|
|
||||||
glActiveTexture(GL_TEXTURE0+1);
|
|
||||||
glBindTexture(GL_TEXTURE_2D, depthMapflash);
|
|
||||||
//glActiveTexture(GL_TEXTURE0 + 1);
|
|
||||||
//glBindTexture(GL_TEXTURE_2D, depthMaplamp);
|
|
||||||
glUniform1i(glGetUniformLocation(program, "depthMap"), 2);
|
|
||||||
glActiveTexture(GL_TEXTURE0 + 2);
|
|
||||||
glBindTexture(GL_TEXTURE_2D, depthMapsun);
|
|
||||||
|
|
||||||
Core::DrawContext(context);
|
Core::DrawContext(context);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void drawObjectDepth(Core::RenderContext& RenderContext, glm::mat4 viewProjection, glm::mat4 modelMatrix)
|
void drawObjectDepth(Core::RenderContext& RenderContext, glm::mat4 viewProjection, glm::mat4 modelMatrix)
|
||||||
{
|
{
|
||||||
|
|
||||||
glUniformMatrix4fv(glGetUniformLocation(programDepth, "viewProjectionMatrix"), 1, GL_FALSE, (float*)&viewProjection);
|
glUniformMatrix4fv(glGetUniformLocation(programDepth, "viewProjectionMatrix"), 1, GL_FALSE, (float*)&viewProjection);
|
||||||
glUniformMatrix4fv(glGetUniformLocation(programDepth, "modelMatrix"), 1, GL_FALSE, (float*)&modelMatrix);
|
glUniformMatrix4fv(glGetUniformLocation(programDepth, "modelMatrix"), 1, GL_FALSE, (float*)&modelMatrix);
|
||||||
Core::DrawContext(RenderContext);
|
Core::DrawContext(RenderContext);
|
||||||
}
|
}
|
||||||
void renderShadowapSun(GLuint depthMapFBO, glm::mat4 lightVP) {
|
|
||||||
float time = glfwGetTime();
|
|
||||||
glViewport(0, 0, SHADOW_WIDTH, SHADOW_HEIGHT);
|
|
||||||
//uzupelnij o renderowanie glebokosci do tekstury
|
|
||||||
glUseProgram(programDepth);
|
|
||||||
|
|
||||||
|
void renderShadowapSun() {
|
||||||
|
float time = glfwGetTime();
|
||||||
//ustawianie przestrzeni rysowania
|
//ustawianie przestrzeni rysowania
|
||||||
glViewport(0, 0, SHADOW_WIDTH, SHADOW_HEIGHT);
|
glViewport(0, 0, SHADOW_WIDTH, SHADOW_HEIGHT);
|
||||||
//bindowanie FBO
|
//bindowanie FBO
|
||||||
@ -216,37 +180,46 @@ void renderShadowapSun(GLuint depthMapFBO, glm::mat4 lightVP) {
|
|||||||
//ustawianie programu
|
//ustawianie programu
|
||||||
glUseProgram(programDepth);
|
glUseProgram(programDepth);
|
||||||
|
|
||||||
|
glm::mat4 lightVP = glm::ortho(-3.f, 2.3f, -1.3f, 3.f, -1.0f, 40.0f) * glm::lookAt(sunPos, sunPos - sunDir, glm::vec3(0, 1, 0));
|
||||||
drawObjectDepth(sphereContext, lightVP, glm::translate(pointlightPos) * glm::scale(glm::vec3(0.1)) * glm::eulerAngleY(time / 3) * glm::translate(glm::vec3(4.f, 0, 0)) * glm::scale(glm::vec3(0.3f)));
|
|
||||||
|
|
||||||
drawObjectDepth(sphereContext,
|
drawObjectDepth(sphereContext,
|
||||||
lightVP, glm::translate(pointlightPos) * glm::scale(glm::vec3(0.1)) * glm::eulerAngleY(time / 3) * glm::translate(glm::vec3(4.f, 0, 0)) * glm::eulerAngleY(time) * glm::translate(glm::vec3(1.f, 0, 0)) * glm::scale(glm::vec3(0.1f)));
|
lightVP,
|
||||||
|
glm::translate(pointlightPos) * glm::scale(glm::vec3(0.1)) * glm::eulerAngleY(time / 3) * glm::translate(glm::vec3(4.f, 0, 0)) * glm::scale(glm::vec3(0.3f)));
|
||||||
drawObjectDepth(models::bedContext, lightVP, glm::mat4());
|
drawObjectDepth(sphereContext,
|
||||||
drawObjectDepth(models::chairContext, lightVP, glm::mat4());
|
lightVP,
|
||||||
drawObjectDepth(models::deskContext, lightVP, glm::mat4());
|
glm::translate(pointlightPos) * glm::scale(glm::vec3(0.1)) * glm::eulerAngleY(time / 3) * glm::translate(glm::vec3(4.f, 0, 0)) * glm::eulerAngleY(time) * glm::translate(glm::vec3(1.f, 0, 0)) * glm::scale(glm::vec3(0.1f)));
|
||||||
drawObjectDepth(models::doorContext, lightVP, glm::mat4());
|
drawObjectDepth(models::bedContext,
|
||||||
drawObjectDepth(models::drawerContext, lightVP, glm::mat4());
|
lightVP,
|
||||||
drawObjectDepth(models::marbleBustContext, lightVP, glm::mat4());
|
glm::mat4());
|
||||||
drawObjectDepth(models::materaceContext, lightVP, glm::mat4());
|
drawObjectDepth(models::chairContext,
|
||||||
drawObjectDepth(models::pencilsContext, lightVP, glm::mat4());
|
lightVP,
|
||||||
drawObjectDepth(models::planeContext, lightVP, glm::mat4());
|
glm::mat4());
|
||||||
drawObjectDepth(models::roomContext, lightVP, glm::mat4());
|
drawObjectDepth(models::deskContext,
|
||||||
drawObjectDepth(models::windowContext, lightVP, glm::mat4());
|
lightVP,
|
||||||
|
glm::mat4());
|
||||||
glm::vec3 spaceshipSide = glm::normalize(glm::cross(spaceshipDir, glm::vec3(0.f, 1.f, 0.f)));
|
drawObjectDepth(models::doorContext,
|
||||||
glm::vec3 spaceshipUp = glm::normalize(glm::cross(spaceshipSide, spaceshipDir));
|
lightVP,
|
||||||
glm::mat4 specshipCameraRotrationMatrix = glm::mat4({
|
glm::mat4());
|
||||||
spaceshipSide.x,spaceshipSide.y,spaceshipSide.z,0,
|
drawObjectDepth(models::drawerContext,
|
||||||
spaceshipUp.x,spaceshipUp.y,spaceshipUp.z ,0,
|
lightVP,
|
||||||
-spaceshipDir.x,-spaceshipDir.y,-spaceshipDir.z,0,
|
glm::mat4());
|
||||||
0.,0.,0.,1.,
|
drawObjectDepth(models::marbleBustContext,
|
||||||
});
|
lightVP,
|
||||||
drawObjectDepth(shipContext, lightVP,
|
glm::mat4());
|
||||||
glm::translate(spaceshipPos)* specshipCameraRotrationMatrix* glm::eulerAngleY(glm::pi<float>())* glm::scale(glm::vec3(0.03f)));
|
drawObjectDepth(models::materaceContext,
|
||||||
|
lightVP,
|
||||||
|
glm::mat4());
|
||||||
|
drawObjectDepth(models::pencilsContext,
|
||||||
|
lightVP,
|
||||||
|
glm::mat4());
|
||||||
|
drawObjectDepth(models::planeContext,
|
||||||
|
lightVP,
|
||||||
|
glm::mat4());
|
||||||
|
drawObjectDepth(models::roomContext,
|
||||||
|
lightVP,
|
||||||
|
glm::mat4());
|
||||||
|
drawObjectDepth(models::windowContext,
|
||||||
|
lightVP,
|
||||||
|
glm::mat4());
|
||||||
|
|
||||||
|
|
||||||
glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
||||||
@ -258,14 +231,8 @@ void renderScene(GLFWwindow* window)
|
|||||||
glClearColor(0.4f, 0.4f, 0.8f, 1.0f);
|
glClearColor(0.4f, 0.4f, 0.8f, 1.0f);
|
||||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||||
float time = glfwGetTime();
|
float time = glfwGetTime();
|
||||||
|
updateDeltaTime(time);
|
||||||
lightVPsun = glm::ortho(-3.f, 2.3f, -1.3f, 3.f, -1.0f, 40.0f) * glm::lookAt(sunPos, sunPos - sunDir, glm::vec3(0, 1, 0));
|
renderShadowapSun();
|
||||||
lightVPlamp = createPerspectiveMatrixC(0.5, 30) * glm::lookAt(pointlightPos, glm::vec3(0, -1, 0), glm::vec3(0, 1, 0));
|
|
||||||
lightVPflash = createPerspectiveMatrixC(0.05, 20) * glm::lookAt(spotlightPos, spotlightConeDir, glm::vec3(0, 1, 0));
|
|
||||||
|
|
||||||
renderShadowapSun(depthMapFBOsun, lightVPsun);
|
|
||||||
renderShadowapSun(depthMapFBOlamp, lightVPlamp);
|
|
||||||
renderShadowapSun(depthMapFBOflash, lightVPflash);
|
|
||||||
|
|
||||||
//space lamp
|
//space lamp
|
||||||
glUseProgram(programSun);
|
glUseProgram(programSun);
|
||||||
@ -278,11 +245,17 @@ void renderScene(GLFWwindow* window)
|
|||||||
|
|
||||||
glUseProgram(program);
|
glUseProgram(program);
|
||||||
|
|
||||||
drawObjectPBR(sphereContext, glm::translate(pointlightPos) * glm::scale(glm::vec3(0.1)) * glm::eulerAngleY(time / 3) * glm::translate(glm::vec3(4.f, 0, 0)) * glm::scale(glm::vec3(0.3f)), glm::vec3(0.2, 0.7, 0.3), 0.3, 0.0);
|
drawObjectPBR(sphereContext,
|
||||||
|
glm::translate(pointlightPos) * glm::scale(glm::vec3(0.1)) * glm::eulerAngleY(time / 3) * glm::translate(glm::vec3(4.f, 0, 0)) * glm::scale(glm::vec3(0.3f))
|
||||||
|
,glm::vec3(0.2, 0.7, 0.3),
|
||||||
|
0.3,
|
||||||
|
0.0);
|
||||||
|
|
||||||
drawObjectPBR(sphereContext,
|
drawObjectPBR(sphereContext,
|
||||||
glm::translate(pointlightPos) * glm::scale(glm::vec3(0.1)) * glm::eulerAngleY(time / 3) * glm::translate(glm::vec3(4.f, 0, 0)) * glm::eulerAngleY(time) * glm::translate(glm::vec3(1.f, 0, 0)) * glm::scale(glm::vec3(0.1f)),
|
glm::translate(pointlightPos) * glm::scale(glm::vec3(0.1)) * glm::eulerAngleY(time / 3) * glm::translate(glm::vec3(4.f, 0, 0)) * glm::eulerAngleY(time) * glm::translate(glm::vec3(1.f, 0, 0)) * glm::scale(glm::vec3(0.1f)),
|
||||||
glm::vec3(0.5, 0.5, 0.5), 0.7, 0.0);
|
glm::vec3(0.5, 0.5, 0.5),
|
||||||
|
0.7,
|
||||||
|
0.0);
|
||||||
|
|
||||||
drawObjectPBR(models::bedContext, glm::mat4(), glm::vec3(0.03f, 0.03f, 0.03f), 0.2f, 0.0f);
|
drawObjectPBR(models::bedContext, glm::mat4(), glm::vec3(0.03f, 0.03f, 0.03f), 0.2f, 0.0f);
|
||||||
drawObjectPBR(models::chairContext, glm::mat4(), glm::vec3(0.195239f, 0.37728f, 0.8f), 0.4f, 0.0f);
|
drawObjectPBR(models::chairContext, glm::mat4(), glm::vec3(0.195239f, 0.37728f, 0.8f), 0.4f, 0.0f);
|
||||||
@ -319,15 +292,6 @@ void renderScene(GLFWwindow* window)
|
|||||||
spotlightPos = spaceshipPos + 0.2 * spaceshipDir;
|
spotlightPos = spaceshipPos + 0.2 * spaceshipDir;
|
||||||
spotlightConeDir = spaceshipDir;
|
spotlightConeDir = spaceshipDir;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
////test depth buffer
|
|
||||||
//glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
|
||||||
//glUseProgram(programTest);
|
|
||||||
//glActiveTexture(GL_TEXTURE0);
|
|
||||||
//glBindTexture(GL_TEXTURE_2D, depthMaplamp);
|
|
||||||
//Core::DrawContext(models::testContext);
|
|
||||||
|
|
||||||
glUseProgram(0);
|
glUseProgram(0);
|
||||||
glfwSwapBuffers(window);
|
glfwSwapBuffers(window);
|
||||||
}
|
}
|
||||||
@ -351,12 +315,11 @@ void loadModelToContext(std::string path, Core::RenderContext& context)
|
|||||||
context.initFromAssimpMesh(scene->mMeshes[0]);
|
context.initFromAssimpMesh(scene->mMeshes[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
void initDepthMap()
|
void initDepthMap() {
|
||||||
{
|
glGenFramebuffers(1, &depthMapFBO);
|
||||||
glGenFramebuffers(1, &depthMapFBOsun);
|
|
||||||
|
|
||||||
glGenTextures(1, &depthMapsun);
|
glGenTextures(1, &depthMap);
|
||||||
glBindTexture(GL_TEXTURE_2D, depthMapsun);
|
glBindTexture(GL_TEXTURE_2D, depthMap);
|
||||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT,
|
glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT,
|
||||||
SHADOW_WIDTH, SHADOW_HEIGHT, 0, GL_DEPTH_COMPONENT, GL_FLOAT, NULL);
|
SHADOW_WIDTH, SHADOW_HEIGHT, 0, GL_DEPTH_COMPONENT, GL_FLOAT, NULL);
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
||||||
@ -364,51 +327,14 @@ void initDepthMap()
|
|||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
|
||||||
|
|
||||||
glBindFramebuffer(GL_FRAMEBUFFER, depthMapFBOsun);
|
glBindFramebuffer(GL_FRAMEBUFFER, depthMapFBO);
|
||||||
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, depthMapsun, 0);
|
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, depthMap, 0);
|
||||||
glDrawBuffer(GL_NONE);
|
|
||||||
glReadBuffer(GL_NONE);
|
|
||||||
glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
glGenFramebuffers(1, &depthMapFBOlamp);
|
|
||||||
|
|
||||||
glGenTextures(1, &depthMaplamp);
|
|
||||||
glBindTexture(GL_TEXTURE_2D, depthMaplamp);
|
|
||||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT,
|
|
||||||
SHADOW_WIDTH, SHADOW_HEIGHT, 0, GL_DEPTH_COMPONENT, GL_FLOAT, NULL);
|
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
|
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
|
|
||||||
|
|
||||||
glBindFramebuffer(GL_FRAMEBUFFER, depthMapFBOlamp);
|
|
||||||
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, depthMaplamp, 0);
|
|
||||||
glDrawBuffer(GL_NONE);
|
|
||||||
glReadBuffer(GL_NONE);
|
|
||||||
glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
glGenFramebuffers(1, &depthMapFBOflash);
|
|
||||||
|
|
||||||
glGenTextures(1, &depthMapflash);
|
|
||||||
glBindTexture(GL_TEXTURE_2D, depthMapflash);
|
|
||||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT,
|
|
||||||
SHADOW_WIDTH, SHADOW_HEIGHT, 0, GL_DEPTH_COMPONENT, GL_FLOAT, NULL);
|
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
|
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
|
|
||||||
|
|
||||||
glBindFramebuffer(GL_FRAMEBUFFER, depthMapFBOflash);
|
|
||||||
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, depthMapflash, 0);
|
|
||||||
glDrawBuffer(GL_NONE);
|
glDrawBuffer(GL_NONE);
|
||||||
glReadBuffer(GL_NONE);
|
glReadBuffer(GL_NONE);
|
||||||
glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void init(GLFWwindow* window)
|
void init(GLFWwindow* window)
|
||||||
{
|
{
|
||||||
glfwSetFramebufferSizeCallback(window, framebuffer_size_callback);
|
glfwSetFramebufferSizeCallback(window, framebuffer_size_callback);
|
||||||
@ -416,9 +342,8 @@ void init(GLFWwindow* window)
|
|||||||
|
|
||||||
glEnable(GL_DEPTH_TEST);
|
glEnable(GL_DEPTH_TEST);
|
||||||
program = shaderLoader.CreateProgram("shaders/shader_9_1.vert", "shaders/shader_9_1.frag");
|
program = shaderLoader.CreateProgram("shaders/shader_9_1.vert", "shaders/shader_9_1.frag");
|
||||||
programTest = shaderLoader.CreateProgram("shaders/test.vert", "shaders/test.frag");
|
|
||||||
programSun = shaderLoader.CreateProgram("shaders/shader_8_sun.vert", "shaders/shader_8_sun.frag");
|
programSun = shaderLoader.CreateProgram("shaders/shader_8_sun.vert", "shaders/shader_8_sun.frag");
|
||||||
programDepth = shaderLoader.CreateProgram("shaders/programDepth.vert", "shaders/programDepth.frag");
|
programDepth = shaderLoader.CreateProgram("shaders/shader_depth.vert", "shaders/shader_depth.frag");
|
||||||
|
|
||||||
loadModelToContext("./models/sphere.obj", sphereContext);
|
loadModelToContext("./models/sphere.obj", sphereContext);
|
||||||
loadModelToContext("./models/spaceship.obj", shipContext);
|
loadModelToContext("./models/spaceship.obj", shipContext);
|
||||||
@ -437,7 +362,6 @@ void init(GLFWwindow* window)
|
|||||||
loadModelToContext("./models/spaceship.obj", models::spaceshipContext);
|
loadModelToContext("./models/spaceship.obj", models::spaceshipContext);
|
||||||
loadModelToContext("./models/sphere.obj", models::sphereContext);
|
loadModelToContext("./models/sphere.obj", models::sphereContext);
|
||||||
loadModelToContext("./models/window.obj", models::windowContext);
|
loadModelToContext("./models/window.obj", models::windowContext);
|
||||||
loadModelToContext("./models/test.obj", models::testContext);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -451,8 +375,8 @@ void processInput(GLFWwindow* window)
|
|||||||
{
|
{
|
||||||
glm::vec3 spaceshipSide = glm::normalize(glm::cross(spaceshipDir, glm::vec3(0.f,1.f,0.f)));
|
glm::vec3 spaceshipSide = glm::normalize(glm::cross(spaceshipDir, glm::vec3(0.f,1.f,0.f)));
|
||||||
glm::vec3 spaceshipUp = glm::vec3(0.f, 1.f, 0.f);
|
glm::vec3 spaceshipUp = glm::vec3(0.f, 1.f, 0.f);
|
||||||
float angleSpeed = 0.005f;
|
float angleSpeed = 0.05f * deltaTime * 60;
|
||||||
float moveSpeed = 0.005f;
|
float moveSpeed = 0.05f * deltaTime * 60;
|
||||||
if (glfwGetKey(window, GLFW_KEY_ESCAPE) == GLFW_PRESS) {
|
if (glfwGetKey(window, GLFW_KEY_ESCAPE) == GLFW_PRESS) {
|
||||||
glfwSetWindowShouldClose(window, true);
|
glfwSetWindowShouldClose(window, true);
|
||||||
}
|
}
|
||||||
@ -477,9 +401,9 @@ void processInput(GLFWwindow* window)
|
|||||||
cameraDir = spaceshipDir;
|
cameraDir = spaceshipDir;
|
||||||
|
|
||||||
if (glfwGetKey(window, GLFW_KEY_1) == GLFW_PRESS)
|
if (glfwGetKey(window, GLFW_KEY_1) == GLFW_PRESS)
|
||||||
exposition -= 0.005;
|
exposition -= 0.05;
|
||||||
if (glfwGetKey(window, GLFW_KEY_2) == GLFW_PRESS)
|
if (glfwGetKey(window, GLFW_KEY_2) == GLFW_PRESS)
|
||||||
exposition += 0.005;
|
exposition += 0.05;
|
||||||
|
|
||||||
if (glfwGetKey(window, GLFW_KEY_3) == GLFW_PRESS) {
|
if (glfwGetKey(window, GLFW_KEY_3) == GLFW_PRESS) {
|
||||||
printf("spaceshipPos = glm::vec3(%ff, %ff, %ff);\n", spaceshipPos.x, spaceshipPos.y, spaceshipPos.z);
|
printf("spaceshipPos = glm::vec3(%ff, %ff, %ff);\n", spaceshipPos.x, spaceshipPos.y, spaceshipPos.z);
|
||||||
|
Loading…
Reference in New Issue
Block a user