Commit: a6aaaad9795e80af05e8281030107c32c6a1366b Author: Alexander Romanov Date: Sat Jan 23 15:27:36 2016 +0300 Branches: master https://developer.blender.org/rBa6aaaad9795e80af05e8281030107c32c6a1366b
Vector Transform node support for GLSL mode and the internal renderer The Vector Transform node is a useful node which is present in the Cycles renderer. {F144283} This patch implements the Vector Transform node for GLSL mode and the internal renderer. Example: {F273060} Alexander (Blend4Web Team) Reviewers: brecht, campbellbarton, sergey Reviewed By: campbellbarton, sergey Subscribers: psy-fi, duarteframos, RobM, lightbwk, sergey, AlexKowel, valentin_b4w, Evgeny_Rodygin, yurikovelenov Projects: #bf_blender:_next Differential Revision: https://developer.blender.org/D909 =================================================================== M release/scripts/startup/nodeitems_builtins.py M source/blender/editors/render/render_internal.c M source/blender/gpu/GPU_material.h M source/blender/gpu/intern/gpu_codegen.c M source/blender/gpu/intern/gpu_draw.c M source/blender/gpu/intern/gpu_material.c M source/blender/gpu/shaders/gpu_shader_material.glsl M source/blender/nodes/shader/nodes/node_shader_vectTransform.c M source/blender/python/intern/gpu.c M source/blender/render/extern/include/RE_pipeline.h M source/blender/render/extern/include/RE_shader_ext.h M source/blender/render/intern/include/render_types.h M source/blender/render/intern/include/renderdatabase.h M source/blender/render/intern/source/renderdatabase.c M source/blender/render/intern/source/shadeoutput.c M source/blenderplayer/bad_level_call_stubs/stubs.c M source/gameengine/Ketsji/BL_BlenderShader.cpp =================================================================== diff --git a/release/scripts/startup/nodeitems_builtins.py b/release/scripts/startup/nodeitems_builtins.py index c3def14..7af10aa 100644 --- a/release/scripts/startup/nodeitems_builtins.py +++ b/release/scripts/startup/nodeitems_builtins.py @@ -159,6 +159,7 @@ shader_node_categories = [ NodeItem("ShaderNodeNormal"), NodeItem("ShaderNodeMapping"), NodeItem("ShaderNodeVectorCurve"), + NodeItem("ShaderNodeVectorTransform"), ]), ShaderOldNodeCategory("SH_CONVERTOR", "Converter", items=[ NodeItem("ShaderNodeValToRGB"), diff --git a/source/blender/editors/render/render_internal.c b/source/blender/editors/render/render_internal.c index 143003c..eb8ea01 100644 --- a/source/blender/editors/render/render_internal.c +++ b/source/blender/editors/render/render_internal.c @@ -1188,6 +1188,7 @@ static void render_view3d_startjob(void *customdata, short *stop, short *do_upda char name[32]; int update_flag; bool use_border; + int ob_inst_update_flag = 0; update_flag = rp->engine->job_update_flag; rp->engine->job_update_flag = 0; @@ -1299,6 +1300,13 @@ static void render_view3d_startjob(void *customdata, short *stop, short *do_upda /* OK, can we enter render code? */ if (rstats->convertdone) { bool first_time = true; + + if (update_flag & PR_UPDATE_VIEW) { + ob_inst_update_flag |= RE_OBJECT_INSTANCES_UPDATE_VIEW; + } + + RE_updateRenderInstances(re, ob_inst_update_flag); + for (;;) { if (first_time == false) { if (restore) diff --git a/source/blender/gpu/GPU_material.h b/source/blender/gpu/GPU_material.h index 25788c2..65cdf83 100644 --- a/source/blender/gpu/GPU_material.h +++ b/source/blender/gpu/GPU_material.h @@ -95,6 +95,8 @@ typedef enum GPUBuiltin { GPU_PARTICLE_LOCATION = (1 << 10), GPU_PARTICLE_VELOCITY = (1 << 11), GPU_PARTICLE_ANG_VELOCITY = (1 << 12), + GPU_LOC_TO_VIEW_MATRIX = (1 << 13), + GPU_INVERSE_LOC_TO_VIEW_MATRIX = (1 << 14), } GPUBuiltin; typedef enum GPUOpenGLBuiltin { @@ -148,6 +150,8 @@ typedef enum GPUDynamicType { GPU_DYNAMIC_OBJECT_IMAT = 4 | GPU_DYNAMIC_GROUP_OBJECT, GPU_DYNAMIC_OBJECT_COLOR = 5 | GPU_DYNAMIC_GROUP_OBJECT, GPU_DYNAMIC_OBJECT_AUTOBUMPSCALE = 6 | GPU_DYNAMIC_GROUP_OBJECT, + GPU_DYNAMIC_OBJECT_LOCTOVIEWMAT = 7 | GPU_DYNAMIC_GROUP_OBJECT, + GPU_DYNAMIC_OBJECT_LOCTOVIEWIMAT = 8 | GPU_DYNAMIC_GROUP_OBJECT, GPU_DYNAMIC_LAMP_DYNVEC = 1 | GPU_DYNAMIC_GROUP_LAMP, GPU_DYNAMIC_LAMP_DYNCO = 2 | GPU_DYNAMIC_GROUP_LAMP, @@ -218,7 +222,7 @@ void GPU_material_bind( GPUMaterial *material, int oblay, int viewlay, double time, int mipmap, float viewmat[4][4], float viewinv[4][4], float cameraborder[4], bool scenelock); void GPU_material_bind_uniforms( - GPUMaterial *material, float obmat[4][4], float obcol[4], + GPUMaterial *material, float obmat[4][4], float viewmat[4][4], float obcol[4], float autobumpscale, GPUParticleInfo *pi); void GPU_material_unbind(GPUMaterial *material); bool GPU_material_bound(GPUMaterial *material); diff --git a/source/blender/gpu/intern/gpu_codegen.c b/source/blender/gpu/intern/gpu_codegen.c index 857b339..fb46b16 100644 --- a/source/blender/gpu/intern/gpu_codegen.c +++ b/source/blender/gpu/intern/gpu_codegen.c @@ -381,6 +381,10 @@ const char *GPU_builtin_name(GPUBuiltin builtin) return "unfinvviewmat"; else if (builtin == GPU_INVERSE_OBJECT_MATRIX) return "unfinvobmat"; + else if (builtin == GPU_LOC_TO_VIEW_MATRIX) + return "unflocaltoviewmat"; + else if (builtin == GPU_INVERSE_LOC_TO_VIEW_MATRIX) + return "unfinvlocaltoviewmat"; else if (builtin == GPU_VIEW_POSITION) return "varposition"; else if (builtin == GPU_VIEW_NORMAL) diff --git a/source/blender/gpu/intern/gpu_draw.c b/source/blender/gpu/intern/gpu_draw.c index 95c019b..a7f802a 100644 --- a/source/blender/gpu/intern/gpu_draw.c +++ b/source/blender/gpu/intern/gpu_draw.c @@ -1763,7 +1763,7 @@ int GPU_object_material_bind(int nr, void *attribs) 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, &partile_info); + GPU_material_bind_uniforms(gpumat, GMS.gob->obmat, GMS.gviewmat, 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 29e49ca..7cb2fc0 100644 --- a/source/blender/gpu/intern/gpu_material.c +++ b/source/blender/gpu/intern/gpu_material.c @@ -112,6 +112,7 @@ struct GPUMaterial { /* for passing uniforms */ int viewmatloc, invviewmatloc; int obmatloc, invobmatloc; + int localtoviewmatloc, invlocaltoviewmatloc; int obcolloc, obautobumpscaleloc; int cameratexcofacloc; @@ -242,6 +243,10 @@ static int GPU_material_construct_end(GPUMaterial *material, const char *passnam material->obmatloc = GPU_shader_get_uniform(shader, GPU_builtin_name(GPU_OBJECT_MATRIX)); if (material->builtins & GPU_INVERSE_OBJECT_MATRIX) material->invobmatloc = GPU_shader_get_uniform(shader, GPU_builtin_name(GPU_INVERSE_OBJECT_MATRIX)); + if (material->builtins & GPU_LOC_TO_VIEW_MATRIX) + material->localtoviewmatloc = GPU_shader_get_uniform(shader, GPU_builtin_name(GPU_LOC_TO_VIEW_MATRIX)); + if (material->builtins & GPU_INVERSE_LOC_TO_VIEW_MATRIX) + material->invlocaltoviewmatloc = GPU_shader_get_uniform(shader, GPU_builtin_name(GPU_INVERSE_LOC_TO_VIEW_MATRIX)); if (material->builtins & GPU_OBCOLOR) material->obcolloc = GPU_shader_get_uniform(shader, GPU_builtin_name(GPU_OBCOLOR)); if (material->builtins & GPU_AUTO_BUMPSCALE) @@ -384,12 +389,14 @@ void GPU_material_bind( } void GPU_material_bind_uniforms( - GPUMaterial *material, float obmat[4][4], float obcol[4], + GPUMaterial *material, float obmat[4][4], float viewmat[4][4], float obcol[4], float autobumpscale, GPUParticleInfo *pi) { if (material->pass) { GPUShader *shader = GPU_pass_shader(material->pass); float invmat[4][4], col[4]; + float localtoviewmat[4][4]; + float invlocaltoviewmat[4][4]; /* handle per object builtins */ if (material->builtins & GPU_OBJECT_MATRIX) { @@ -399,6 +406,19 @@ void GPU_material_bind_uniforms( invert_m4_m4(invmat, obmat); GPU_shader_uniform_vector(shader, material->invobmatloc, 16, 1, (float *)invmat); } + if (material->builtins & GPU_LOC_TO_VIEW_MATRIX) { + if (viewmat) { + mul_m4_m4m4(localtoviewmat, viewmat, obmat); + GPU_shader_uniform_vector(shader, material->localtoviewmatloc, 16, 1, (float *)localtoviewmat); + } + } + if (material->builtins & GPU_INVERSE_LOC_TO_VIEW_MATRIX) { + if (viewmat) { + mul_m4_m4m4(localtoviewmat, viewmat, obmat); + invert_m4_m4(invlocaltoviewmat, localtoviewmat); + GPU_shader_uniform_vector(shader, material->invlocaltoviewmatloc, 16, 1, (float*)invlocaltoviewmat); + } + } if (material->builtins & GPU_OBCOLOR) { copy_v4_v4(col, obcol); CLAMP(col[3], 0.0f, 1.0f); @@ -2352,6 +2372,8 @@ GPUShaderExport *GPU_shader_export(struct Scene *scene, struct Material *ma) { GPU_INVERSE_VIEW_MATRIX, GPU_DYNAMIC_OBJECT_VIEWIMAT, GPU_DATA_16F }, { GPU_OBJECT_MATRIX, GPU_DYNAMIC_OBJECT_MAT, GPU_DATA_16F }, { GPU_INVERSE_OBJECT_MATRIX, GPU_DYNAMIC_OBJECT_IMAT, GPU_DATA_16F }, + { GPU_LOC_TO_VIEW_MATRIX, GPU_DYNAMIC_OBJECT_LOCTOVIEWMAT, GPU_DATA_16F }, + { GPU_INVERSE_LOC_TO_VIEW_MATRIX, GPU_DYNAMIC_OBJECT_LOCTOVIEWIMAT, GPU_DATA_16F }, { GPU_OBCOLOR, GPU_DYNAMIC_OBJECT_COLOR, GPU_DATA_4F }, { GPU_AUTO_BUMPSCALE, GPU_DYNAMIC_OBJECT_AUTOBUMPSCALE, GPU_DATA_1F }, { 0 } diff --git a/source/blender/gpu/shaders/gpu_shader_material.glsl b/source/blender/gpu/shaders/gpu_shader_material.glsl index dfb1af0..e707201 100644 --- a/source/blender/gpu/shaders/gpu_shader_material.glsl +++ b/source/blender/gpu/shaders/gpu_shader_material.glsl @@ -166,6 +166,21 @@ void particle_info(vec4 sprops, vec3 loc, vec3 vel, vec3 avel, out float index, angular_velocity = avel; } +void vect_normalize(vec3 vin, out vec3 vout) +{ + vout = normalize(vin); +} + +void direction_transform_m4v3(vec3 vin, mat4 mat, out vec3 vout) +{ + vout = (mat*vec4(vin, 0.0)).xyz; +} + +void point_transform_m4v3(vec3 vin, mat4 mat, out vec3 vout) +{ + vout = (mat*vec4(vin, 1.0)).xyz; +} + void mapping(vec3 vec, mat4 mat, vec3 minvec, vec3 maxvec, float domin, float domax, out vec3 outvec) { outvec = (mat * vec4(vec, 1.0)).xyz; diff --git a/source/blender/nodes/shader/nodes/node_shader_vectTransform.c b/source/blender/nodes/shader/nodes/node_shader_vectTransform.c index 4cab9d3..5b6d213 100644 --- a/source/blender/nodes/shader/nodes/node_shader_vectTransform.c +++ b/source/blender/nodes/shader/nodes/node_shader_vectTransform.c @@ -52,15 +52,146 @@ static void node_shader_init_vect_transform(bNodeTree *UNUSED(ntree), bNode *nod node->storage = vect; } +static const float (* const get_matrix_from_to(ShaderCallData *scd, short from, short to))[4] +{ + switch (from) { + case SHD_VECT_TRANSFORM_SPACE_OBJECT: + switch (to) { + case SHD_VECT_TRANSFORM_SPACE_OBJECT: + return NULL; + case SHD_VECT_TRANSFORM_SPACE_WORLD: + return RE_object_instance_get_matrix(scd->shi->obi, RE_OBJECT_INSTANCE_MATRIX_OB); + case SHD_VECT_TRANSFORM_SPACE_CAMERA: + return RE_object_instance_get_matrix(scd->shi->obi, RE_OBJECT_INSTANCE_MATRIX_LOCALTOVIEW); + } + break; + case SHD_VECT_TRANSFORM_SPACE_WORLD: + switch (to) { + case SHD_VECT_TRANSFORM_SPACE_WORLD: + return NULL; + case SHD_VECT_TRANSFORM_SPACE_CAMERA: + return RE_render_current_get_matrix(RE_VIEW_MATRIX); + case SHD_VECT_TRANSFORM_SPACE_OBJECT: + return RE_object_instance_get_matrix(scd->shi->obi, RE_OBJECT_INSTANCE_MATRIX_OBINV); + } + break; + case SHD_VECT_TRANSFORM_SPACE_CAMERA: + switch (to) { + case SHD_VECT_TRANSFORM_SPACE_CAMERA: + return NULL; + case SHD_VECT_TRANSFORM_SPACE_WORLD: + return RE_render_current_get_matrix(RE_V @@ Diff output truncated at 10240 characters. @@ _______________________________________________ Bf-blender-cvs mailing list Bf-blender-cvs@blender.org http://lists.blender.org/mailman/listinfo/bf-blender-cvs