-
Notifications
You must be signed in to change notification settings - Fork 0
/
ShadowMap.cpp
38 lines (31 loc) · 1.09 KB
/
ShadowMap.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
//
// Created by adamyuan on 4/23/18.
//
#include "ShadowMap.hpp"
#include "Config.hpp"
#include "Resources.hpp"
void ShadowMap::Initialize()
{
//depth shader
shadow_shader_.Initialize();
shadow_texture_.Initialize();
shadow_texture_.Load(mygl3::ImageInfo(kShadowWidth, kShadowHeight, 0, GL_DEPTH_COMPONENT24, 0, 0, nullptr), false);
shadow_texture_.SetSizeFilter(GL_LINEAR, GL_LINEAR);
shadow_texture_.SetWrapFilter(GL_CLAMP_TO_EDGE);
glTextureParameteri(shadow_texture_.Get(), GL_TEXTURE_COMPARE_MODE, GL_COMPARE_REF_TO_TEXTURE);
glTextureParameteri(shadow_texture_.Get(), GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL);
shadow_fbo_.Initialize();
shadow_fbo_.AttachTexture(shadow_texture_, GL_DEPTH_ATTACHMENT);
glNamedFramebufferDrawBuffer(shadow_fbo_.Get(), GL_NONE);
glNamedFramebufferReadBuffer(shadow_fbo_.Get(), GL_NONE);
}
void ShadowMap::Update()
{
mygl3::FrameBufferBinder binder(shadow_fbo_);
glCullFace(GL_BACK);
glViewport(0, 0, kShadowWidth, kShadowHeight);
glClear(GL_DEPTH_BUFFER_BIT);
shadow_shader_.SetULightMatrix(res::light_matrix);
shadow_shader_.Use();
res::sponza_model.Render();
}