MCPcopy Create free account
hub / github.com/WolfireGames/overgrowth / DrawGPUParticleField

Function DrawGPUParticleField

Source/Graphics/particles.cpp:94–285  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

92TextureAssetRef smoke_texture;
93
94void DrawGPUParticleField(SceneGraph* scenegraph, const char* type) {
95 if (g_debug_runtime_disable_gpu_particle_field_draw) {
96 return;
97 }
98
99 static bool initialized = false;
100
101 if (initialized == false) {
102 smoke_texture = Engine::Instance()->GetAssetManager()->LoadSync<TextureAsset>("Data/Textures/smoke.tga");
103 initialized = true;
104 }
105
106 Graphics* graphics = Graphics::Instance();
107 Shaders* shaders = Shaders::Instance();
108 Camera* cam = ActiveCameras::Get();
109 Textures* textures = Textures::Instance();
110 mat4 proj_view_matrix = cam->GetProjMatrix() * cam->GetViewMatrix();
111 CHECK_GL_ERROR();
112
113 GLState gl_state;
114 gl_state.blend = true;
115 gl_state.depth_test = true;
116 gl_state.depth_write = false;
117 gl_state.cull_face = false;
118 graphics->setGLState(gl_state);
119 graphics->setAdditiveBlend(false);
120 glDisable(GL_SAMPLE_ALPHA_TO_COVERAGE);
121
122 int shader_id;
123 {
124 // Get shader id with flags
125 char shader_name[ParticleType::kMaxNameLen];
126 if (g_particle_field_simple) {
127 FormatString(shader_name, ParticleType::kMaxNameLen, "envobject #GPU_PARTICLE_FIELD #GPU_PARTICLE_FIELD_SIMPLE %s %s", type, global_shader_suffix);
128 } else {
129 FormatString(shader_name, ParticleType::kMaxNameLen, "envobject #GPU_PARTICLE_FIELD %s %s", type, global_shader_suffix);
130 }
131 shader_id = shaders->returnProgram(shader_name);
132 }
133 shaders->setProgram(shader_id);
134 shaders->SetUniformMat4("mvp", proj_view_matrix);
135 shaders->SetUniformMat4("projection_matrix", cam->GetProjMatrix());
136 shaders->SetUniformMat4("view_matrix", cam->GetViewMatrix());
137 shaders->SetUniformFloat("time", game_timer.GetRenderTime());
138 if (Engine::Instance()->paused) {
139 shaders->SetUniformFloat("time_scale", 0.05f);
140 } else {
141 shaders->SetUniformFloat("time_scale", game_timer.time_scale);
142 }
143
144 shaders->SetUniformFloat("haze_mult", scenegraph->haze_mult);
145
146 textures->bindTexture(smoke_texture->GetTextureRef());
147
148 { // Bind shadow matrices to shader
149 std::vector<mat4> shadow_matrix;
150 shadow_matrix.resize(4);
151 for (int i = 0; i < 4; ++i) {

Callers 1

DrawMethod · 0.85

Calls 15

FormatStringFunction · 0.85
GetAssetManagerMethod · 0.80
GetProjMatrixMethod · 0.80
GetViewMatrixMethod · 0.80
setGLStateMethod · 0.80
setAdditiveBlendMethod · 0.80
returnProgramMethod · 0.80
setProgramMethod · 0.80
SetUniformMat4Method · 0.80
GetRenderTimeMethod · 0.80
bindTextureMethod · 0.80
GetTextureRefMethod · 0.80

Tested by

no test coverage detected