diff options
author | Alexander Romanov <a.romanov@blend4web.com> | 2015-07-14 19:48:54 +0300 |
---|---|---|
committer | Antony Riakiotakis <kalast@gmail.com> | 2015-07-14 19:52:29 +0300 |
commit | 38940662e540743a6a8da287390a02a9f3f76f6d (patch) | |
tree | f29f438c5365e2ea2699853ef9510ee676273dc7 /source/blender/gpu/intern | |
parent | 107e34407d0ae4120cc7a12fdb208986a0b47d8e (diff) |
Particle Info node support for GLSL mode and the internal render.
With this patch "Particle Info" node from Cycles works in GLSL and BI
Alexander (Blend4Web Team)
Reviewers: psy-fi
Note: moved particle info to object render instance instead of
shadeinput during review - Antony.
Differential Revision: https://developer.blender.org/D1313
Diffstat (limited to 'source/blender/gpu/intern')
-rw-r--r-- | source/blender/gpu/intern/gpu_codegen.c | 8 | ||||
-rw-r--r-- | source/blender/gpu/intern/gpu_draw.c | 54 | ||||
-rw-r--r-- | source/blender/gpu/intern/gpu_material.c | 28 |
3 files changed, 88 insertions, 2 deletions
diff --git a/source/blender/gpu/intern/gpu_codegen.c b/source/blender/gpu/intern/gpu_codegen.c index 944011879b5..335342c7123 100644 --- a/source/blender/gpu/intern/gpu_codegen.c +++ b/source/blender/gpu/intern/gpu_codegen.c @@ -387,6 +387,14 @@ const char *GPU_builtin_name(GPUBuiltin builtin) return "unfobautobumpscale"; else if (builtin == GPU_CAMERA_TEXCO_FACTORS) return "unfcameratexfactors"; + else if (builtin == GPU_PARTICLE_SCALAR_PROPS) + return "unfparticlescalarprops"; + else if (builtin == GPU_PARTICLE_LOCATION) + return "unfparticleco"; + else if (builtin == GPU_PARTICLE_VELOCITY) + return "unfparticlevel"; + else if (builtin == GPU_PARTICLE_ANG_VELOCITY) + return "unfparticleangvel"; else return ""; } diff --git a/source/blender/gpu/intern/gpu_draw.c b/source/blender/gpu/intern/gpu_draw.c index f7060779676..a925d44ecf8 100644 --- a/source/blender/gpu/intern/gpu_draw.c +++ b/source/blender/gpu/intern/gpu_draw.c @@ -56,6 +56,7 @@ #include "DNA_scene_types.h" #include "DNA_smoke_types.h" #include "DNA_view3d_types.h" +#include "DNA_particle_types.h" #include "MEM_guardedalloc.h" @@ -1411,6 +1412,7 @@ static struct GPUMaterialState { Material *gmatbuf_fixed[FIXEDMAT]; Material *gboundmat; Object *gob; + DupliObject *dob; Scene *gscene; int glay; bool gscenelock; @@ -1493,11 +1495,22 @@ static Material *gpu_active_node_material(Material *ma) return ma; } +void GPU_begin_dupli_object(DupliObject *dob) +{ + GMS.dob = dob; +} + +void GPU_end_dupli_object(void) +{ + GMS.dob = NULL; +} + void GPU_begin_object_materials(View3D *v3d, RegionView3D *rv3d, Scene *scene, Object *ob, bool glsl, bool *do_alpha_after) { Material *ma; GPUMaterial *gpumat; GPUBlendMode alphablend; + DupliObject *dob; int a; const bool gamma = BKE_scene_check_color_management_enabled(scene); const bool new_shading_nodes = BKE_scene_use_new_shading_nodes(scene); @@ -1510,7 +1523,10 @@ void GPU_begin_object_materials(View3D *v3d, RegionView3D *rv3d, Scene *scene, O #endif /* initialize state */ + /* DupliObject must be restored */ + dob = GMS.dob; memset(&GMS, 0, sizeof(GMS)); + GMS.dob = dob; GMS.lastmatnr = -1; GMS.lastretval = -1; GMS.lastalphablend = GPU_BLEND_SOLID; @@ -1618,6 +1634,36 @@ void GPU_begin_object_materials(View3D *v3d, RegionView3D *rv3d, Scene *scene, O GPU_disable_material(); } +int GPU_get_particle_info(GPUParticleInfo *pi) +{ + ParticleData *p; + DupliObject *dob = GMS.dob; + int ind; + if(dob->particle_system) { + if(dob->persistent_id[0] < dob->particle_system->totpart) + ind = dob->persistent_id[0]; + else { + ind = dob->particle_system->child[dob->persistent_id[0] - dob->particle_system->totpart].parent; + } + if (ind >= 0) { + p = &dob->particle_system->particles[ind]; + + pi->scalprops[0] = ind; + pi->scalprops[1] = GMS.gscene->r.cfra - p->time; + pi->scalprops[2] = p->lifetime; + pi->scalprops[3] = p->size; + + copy_v3_v3(pi->location, p->state.co); + copy_v3_v3(pi->velocity, p->state.vel); + copy_v3_v3(pi->angular_velocity, p->state.ave); + return 1; + } + else return 0; + } + else + return 0; +} + int GPU_enable_material(int nr, void *attribs) { GPUVertexAttribs *gattribs = attribs; @@ -1680,14 +1726,20 @@ int GPU_enable_material(int nr, void *attribs) if (gattribs && GMS.gmatbuf[nr]) { /* bind glsl material and get attributes */ Material *mat = GMS.gmatbuf[nr]; + GPUParticleInfo partile_info; + float auto_bump_scale; gpumat = GPU_material_from_blender(GMS.gscene, mat); GPU_material_vertex_attributes(gpumat, gattribs); + + if (GMS.dob) + GPU_get_particle_info(&partile_info); + GPU_material_bind(gpumat, GMS.gob->lay, GMS.glay, 1.0, !(GMS.gob->mode & OB_MODE_TEXTURE_PAINT), GMS.gviewmat, GMS.gviewinv, GMS.gviewcamtexcofac, GMS.gscenelock); auto_bump_scale = GMS.gob->derivedFinal != NULL ? GMS.gob->derivedFinal->auto_bump_scale : 1.0f; - GPU_material_bind_uniforms(gpumat, GMS.gob->obmat, GMS.gob->col, auto_bump_scale); + GPU_material_bind_uniforms(gpumat, GMS.gob->obmat, GMS.gob->col, auto_bump_scale, &partile_info); GMS.gboundmat = mat; /* for glsl use alpha blend mode, unless it's set to solid and diff --git a/source/blender/gpu/intern/gpu_material.c b/source/blender/gpu/intern/gpu_material.c index bd17fb0b1aa..5db516daa26 100644 --- a/source/blender/gpu/intern/gpu_material.c +++ b/source/blender/gpu/intern/gpu_material.c @@ -112,6 +112,11 @@ struct GPUMaterial { int obcolloc, obautobumpscaleloc; int cameratexcofacloc; + int partscalarpropsloc; + int partcoloc; + int partvel; + int partangvel; + ListBase lamps; bool bound; }; @@ -241,6 +246,14 @@ static int GPU_material_construct_end(GPUMaterial *material, const char *passnam material->obautobumpscaleloc = GPU_shader_get_uniform(shader, GPU_builtin_name(GPU_AUTO_BUMPSCALE)); if (material->builtins & GPU_CAMERA_TEXCO_FACTORS) material->cameratexcofacloc = GPU_shader_get_uniform(shader, GPU_builtin_name(GPU_CAMERA_TEXCO_FACTORS)); + if (material->builtins & GPU_PARTICLE_SCALAR_PROPS) + material->partscalarpropsloc = GPU_shader_get_uniform(shader, GPU_builtin_name(GPU_PARTICLE_SCALAR_PROPS)); + if (material->builtins & GPU_PARTICLE_LOCATION) + material->partcoloc = GPU_shader_get_uniform(shader, GPU_builtin_name(GPU_PARTICLE_LOCATION)); + if (material->builtins & GPU_PARTICLE_VELOCITY) + material->partvel = GPU_shader_get_uniform(shader, GPU_builtin_name(GPU_PARTICLE_VELOCITY)); + if (material->builtins & GPU_PARTICLE_ANG_VELOCITY) + material->partangvel = GPU_shader_get_uniform(shader, GPU_builtin_name(GPU_PARTICLE_ANG_VELOCITY)); return 1; } @@ -367,7 +380,7 @@ void GPU_material_bind(GPUMaterial *material, int oblay, int viewlay, double tim } } -void GPU_material_bind_uniforms(GPUMaterial *material, float obmat[4][4], float obcol[4], float autobumpscale) +void GPU_material_bind_uniforms(GPUMaterial *material, float obmat[4][4], float obcol[4], float autobumpscale, GPUParticleInfo* pi) { if (material->pass) { GPUShader *shader = GPU_pass_shader(material->pass); @@ -389,6 +402,19 @@ void GPU_material_bind_uniforms(GPUMaterial *material, float obmat[4][4], float if (material->builtins & GPU_AUTO_BUMPSCALE) { GPU_shader_uniform_vector(shader, material->obautobumpscaleloc, 1, 1, &autobumpscale); } + if (material->builtins & GPU_PARTICLE_SCALAR_PROPS) { + GPU_shader_uniform_vector(shader, material->partscalarpropsloc, 4, 1, pi->scalprops); + } + if (material->builtins & GPU_PARTICLE_LOCATION) { + GPU_shader_uniform_vector(shader, material->partcoloc, 3, 1, pi->location); + } + if (material->builtins & GPU_PARTICLE_VELOCITY) { + GPU_shader_uniform_vector(shader, material->partvel, 3, 1, pi->velocity); + } + if (material->builtins & GPU_PARTICLE_ANG_VELOCITY) { + GPU_shader_uniform_vector(shader, material->partangvel, 3, 1, pi->angular_velocity); + } + } } |