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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
|
//-----------------------------------------------------------------------------
// Name: reflectioncaptureobject.cpp
// Developer: Wolfire Games LLC
// Description:
// License: Read below
//-----------------------------------------------------------------------------
//
// Copyright 2022 Wolfire Games LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
//-----------------------------------------------------------------------------
#include "reflectioncaptureobject.h"
#include <Graphics/camera.h>
#include <Graphics/shaders.h>
#include <Graphics/graphics.h>
#include <Graphics/sky.h>
#include <Graphics/models.h>
#include <Timing/timingevent.h>
#include <Timing/intel_gl_perf.h>
#include <Internal/profiler.h>
#include <Internal/common.h>
#include <Game/EntityDescription.h>
#include <Main/scenegraph.h>
#include <Editors/map_editor.h>
#include <Utility/assert.h>
extern bool g_debug_runtime_disable_reflection_capture_object_draw;
bool ReflectionCaptureObject::Initialize() {
obj_file = "reflection_capture_object";
sp.ASAddIntCheckbox("Global", false);
return true;
}
void ReflectionCaptureObject::Moved(Object::MoveType type) {
Object::Moved(type);
dirty = true;
}
void ReflectionCaptureObject::Dispose() {
Object::Dispose();
}
ReflectionCaptureObject::ReflectionCaptureObject() {
box_.dims = vec3(2.0f);
}
void ReflectionCaptureObject::Draw() {
if (g_debug_runtime_disable_reflection_capture_object_draw) {
return;
}
if(scenegraph_->map_editor->IsTypeEnabled(_reflection_capture_object) &&
cube_map_ref.valid() &&
!Graphics::Instance()->media_mode() &&
scenegraph_->map_editor->state_ != MapEditor::kInGame &&
ActiveCameras::Instance()->Get()->GetFlags() == Camera::kEditorCamera)
{
PROFILER_GPU_ZONE(g_profiler_ctx, "ReflectionCaptureObject::Draw");
Shaders* shaders = Shaders::Instance();
Graphics* graphics = Graphics::Instance();
GLState gl_state;
gl_state.blend = false;
gl_state.cull_face = true;
gl_state.depth_test = true;
gl_state.depth_write = true;
graphics->setGLState(gl_state);
int shader_id = shaders->returnProgram("reflectioncapture");
shaders->setProgram(shader_id);
Camera* camera = ActiveCameras::Get();
shaders->SetUniformVec3("cam_pos", camera->GetPos());
shaders->SetUniformMat4("model_mat", GetTransform());
shaders->SetUniformMat4("view_mat", camera->GetViewMatrix());
shaders->SetUniformMat4("proj_mat", camera->GetProjMatrix());
Textures::Instance()->bindTexture(cube_map_ref);
int vert_attrib_id = shaders->returnShaderAttrib("vertex", shader_id);
Model* probe_model = &Models::Instance()->GetModel(scenegraph_->light_probe_collection.probe_model_id);
if(!probe_model->vbo_loaded){
probe_model->createVBO();
}
probe_model->VBO_vertices.Bind();
probe_model->VBO_faces.Bind();
graphics->EnableVertexAttribArray(vert_attrib_id);
glVertexAttribPointer(vert_attrib_id, 3, GL_FLOAT, false, 3 * sizeof(GL_FLOAT), 0);
graphics->DrawElements(GL_TRIANGLES, (unsigned int) probe_model->faces.size(), GL_UNSIGNED_INT, 0);
graphics->ResetVertexAttribArrays();
}
}
ReflectionCaptureObject::~ReflectionCaptureObject() {
}
void ReflectionCaptureObject::GetDisplayName(char* buf, int buf_size) {
if( GetName().empty() ) {
FormatString(buf, buf_size, "%d: Reflection Capture", GetID());
} else {
FormatString(buf, buf_size, "%s: Reflection Capture", GetName().c_str());
}
}
void ReflectionCaptureObject::GetDesc(EntityDescription &desc) const {
Object::GetDesc(desc);
const size_t data_size = kLightProbeNumCoeffs * sizeof(float);
std::vector<char> data(data_size);
memcpy(&data[0], &avg_color, data_size);
desc.AddData(EDF_GI_COEFFICIENTS, data);
}
bool ReflectionCaptureObject::SetFromDesc( const EntityDescription& desc ) {
bool ret = Object::SetFromDesc(desc);
if( ret ) {
for(unsigned i=0; i<desc.fields.size(); ++i){
const EntityDescriptionField& field = desc.fields[i];
switch(field.type){
case EDF_GI_COEFFICIENTS: {
memcpy(avg_color, &field.data[0], kLightProbeNumCoeffs * sizeof(float));
break;}
}
}
}
return ret;
}
|