Skip to content

Commit

Permalink
Particles properly update the shadow maps, closes #8815
Browse files Browse the repository at this point in the history
  • Loading branch information
reduz committed Jun 17, 2017
1 parent 5fc3a99 commit e11fae0
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 0 deletions.
19 changes: 19 additions & 0 deletions drivers/gles3/rasterizer_storage_gles3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5258,6 +5258,23 @@ void RasterizerStorageGLES3::particles_set_emission_transform(RID p_particles, c
particles->emission_transform = p_transform;
}

int RasterizerStorageGLES3::particles_get_draw_passes(RID p_particles) const {

const Particles *particles = particles_owner.getornull(p_particles);
ERR_FAIL_COND_V(!particles, 0);

return particles->draw_passes.size();
}

RID RasterizerStorageGLES3::particles_get_draw_pass_mesh(RID p_particles, int p_pass) const {

const Particles *particles = particles_owner.getornull(p_particles);
ERR_FAIL_COND_V(!particles, RID());
ERR_FAIL_INDEX_V(p_pass, particles->draw_passes.size(), RID());

return particles->draw_passes[p_pass];
}

void RasterizerStorageGLES3::_particles_process(Particles *particles, float p_delta) {

float new_phase = Math::fmod((float)particles->phase + (p_delta / particles->lifetime) * particles->speed_scale, (float)1.0);
Expand Down Expand Up @@ -5452,6 +5469,8 @@ void RasterizerStorageGLES3::update_particles() {

particles->particle_valid_histories[0] = true;
}

particles->instance_change_notify(); //make sure shadows are updated
}

glDisable(GL_RASTERIZER_DISCARD);
Expand Down
3 changes: 3 additions & 0 deletions drivers/gles3/rasterizer_storage_gles3.h
Original file line number Diff line number Diff line change
Expand Up @@ -1149,6 +1149,9 @@ class RasterizerStorageGLES3 : public RasterizerStorage {
virtual void particles_set_emission_transform(RID p_particles, const Transform &p_transform);
void _particles_process(Particles *p_particles, float p_delta);

virtual int particles_get_draw_passes(RID p_particles) const;
virtual RID particles_get_draw_pass_mesh(RID p_particles, int p_pass) const;

/* INSTANCE */

virtual void instance_add_skeleton(RID p_skeleton, RasterizerScene::InstanceBase *p_instance);
Expand Down
3 changes: 3 additions & 0 deletions servers/visual/rasterizer.h
Original file line number Diff line number Diff line change
Expand Up @@ -465,6 +465,9 @@ class RasterizerStorage {

virtual void particles_set_emission_transform(RID p_particles, const Transform &p_transform) = 0;

virtual int particles_get_draw_passes(RID p_particles) const = 0;
virtual RID particles_get_draw_pass_mesh(RID p_particles, int p_pass) const = 0;

/* RENDER TARGET */

enum RenderTargetFlags {
Expand Down
30 changes: 30 additions & 0 deletions servers/visual/visual_server_scene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3323,6 +3323,36 @@ void VisualServerScene::_update_dirty_instance(Instance *p_instance) {
} else {
can_cast_shadows = false;
}
} else if (p_instance->base_type == VS::INSTANCE_PARTICLES) {

bool cast_shadows = false;

int dp = VSG::storage->particles_get_draw_passes(p_instance->base);

for (int i = 0; i < dp; i++) {

RID mesh = VSG::storage->particles_get_draw_pass_mesh(p_instance->base, i);

int sc = VSG::storage->mesh_get_surface_count(mesh);
for (int j = 0; j < sc; j++) {

RID mat = VSG::storage->mesh_surface_get_material(mesh, j);

if (!mat.is_valid()) {
cast_shadows = true;
break;
}

if (VSG::storage->material_casts_shadows(mat)) {
cast_shadows = true;
break;
}
}
}

if (!cast_shadows) {
can_cast_shadows = false;
}
}
}

Expand Down

0 comments on commit e11fae0

Please sign in to comment.