Added scene related things
This commit is contained in:
@@ -0,0 +1,53 @@
|
||||
#include "light_node.h"
|
||||
|
||||
//#define GL_COMPARE_REF_TO_TEXTURE 0x884E
|
||||
|
||||
BEGIN_NAMESPACE
|
||||
|
||||
light_node::light_node(light_type type_) {
|
||||
type = scene_node_type::light;
|
||||
light_type_ = type_;
|
||||
|
||||
shadow_map_bias_matrix = glm::scale(glm::translate(glm::mat4(1.0f), glm::vec3(0.5f, 0.5f, 0.5f)),
|
||||
glm::vec3(0.5f, 0.5f, 0.5f));
|
||||
|
||||
int textures_to_generate = light_type_ == light_type::point ? 6 : 1;
|
||||
for (int i = 0; i < textures_to_generate; i++) {
|
||||
GLuint shadow_map_texture_id;
|
||||
|
||||
// setup the shadowmap texture
|
||||
glGenTextures(1, &shadow_map_texture_id);
|
||||
glBindTexture(GL_TEXTURE_2D, shadow_map_texture_id);
|
||||
|
||||
// set texture parameters
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
||||
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_REF_TO_TEXTURE);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL);
|
||||
// TODO: see if we need
|
||||
// glTexParameteri(GL_TEXTURE_2D, GL_DEPTH_TEXTURE_MODE, GL_INTENSITY);
|
||||
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT,
|
||||
shadow_map_width, shadow_map_width,
|
||||
0,
|
||||
GL_DEPTH_COMPONENT,
|
||||
GL_UNSIGNED_BYTE,
|
||||
nullptr);
|
||||
|
||||
shadow_map[i] = std::make_shared<texture>(shadow_map_texture_id, shadow_map_width, shadow_map_width);
|
||||
}
|
||||
}
|
||||
|
||||
void light_node::calculate_local_transform() {
|
||||
if (light_type_ == light_type::spot) {
|
||||
world_to_light_matrix[0] = glm::lookAt(position, spot_target, glm::vec3(0, 1, 0));
|
||||
light_projection_matrix[0] = glm::perspective(90.0f, 1.0f, 0.1f, 100.0f);
|
||||
glm::mat4 lightProjectionAndBiasMatrix = shadow_map_bias_matrix * light_projection_matrix[0];
|
||||
final_shadow_map_matrix[0] = lightProjectionAndBiasMatrix * world_to_light_matrix[0];
|
||||
}
|
||||
}
|
||||
|
||||
END_NAMESPACE
|
||||
Reference in New Issue
Block a user