[Bf-blender-cvs] [a02cdd0] cycles-ptex-19: Add Ptex shader node
Nicholas Bishop
noreply at git.blender.org
Wed Jan 28 19:40:29 CET 2015
Commit: a02cdd08c67bc38a3fe74f33f7dda220b784ae16
Author: Nicholas Bishop
Date: Tue Jan 20 18:42:02 2015 +0100
Branches: cycles-ptex-19
https://developer.blender.org/rBa02cdd08c67bc38a3fe74f33f7dda220b784ae16
Add Ptex shader node
===================================================================
M release/scripts/startup/nodeitems_builtins.py
M source/blender/blenkernel/BKE_node.h
M source/blender/blenkernel/intern/DerivedMesh.c
M source/blender/blenkernel/intern/node.c
M source/blender/editors/space_node/drawnode.c
M source/blender/editors/space_view3d/view3d_draw.c
M source/blender/gpu/GPU_extensions.h
M source/blender/gpu/GPU_material.h
M source/blender/gpu/intern/gpu_codegen.c
M source/blender/gpu/intern/gpu_codegen.h
M source/blender/gpu/intern/gpu_draw.c
M source/blender/gpu/intern/gpu_extensions.c
M source/blender/gpu/intern/gpu_material.c
M source/blender/gpu/shaders/gpu_shader_material.glsl
M source/blender/makesdna/DNA_image_types.h
M source/blender/makesdna/DNA_node_types.h
M source/blender/makesrna/RNA_access.h
M source/blender/makesrna/intern/rna_nodetree.c
M source/blender/nodes/CMakeLists.txt
M source/blender/nodes/NOD_shader.h
M source/blender/nodes/NOD_static_types.h
A source/blender/nodes/shader/nodes/node_shader_tex_ptex.c
===================================================================
diff --git a/release/scripts/startup/nodeitems_builtins.py b/release/scripts/startup/nodeitems_builtins.py
index 1590bd4..9ebfbd8 100644
--- a/release/scripts/startup/nodeitems_builtins.py
+++ b/release/scripts/startup/nodeitems_builtins.py
@@ -234,6 +234,7 @@ shader_node_categories = [
NodeItem("ShaderNodeTexMagic"),
NodeItem("ShaderNodeTexChecker"),
NodeItem("ShaderNodeTexBrick"),
+ NodeItem("ShaderNodeTexPtex"),
]),
ShaderNewNodeCategory("SH_NEW_OP_COLOR", "Color", items=[
NodeItem("ShaderNodeMixRGB"),
diff --git a/source/blender/blenkernel/BKE_node.h b/source/blender/blenkernel/BKE_node.h
index 573fa60..42b1753 100644
--- a/source/blender/blenkernel/BKE_node.h
+++ b/source/blender/blenkernel/BKE_node.h
@@ -755,6 +755,7 @@ struct ShadeResult;
#define SH_NODE_COMBXYZ 189
#define SH_NODE_OUTPUT_LINESTYLE 190
#define SH_NODE_UVALONGSTROKE 191
+#define SH_NODE_TEX_PTEX 192
/* custom defines options for Material node */
#define SH_NODE_MAT_DIFF 1
diff --git a/source/blender/blenkernel/intern/DerivedMesh.c b/source/blender/blenkernel/intern/DerivedMesh.c
index 849f871..e347f60 100644
--- a/source/blender/blenkernel/intern/DerivedMesh.c
+++ b/source/blender/blenkernel/intern/DerivedMesh.c
@@ -76,6 +76,9 @@ static DerivedMesh *navmesh_dm_createNavMeshForVisualization(DerivedMesh *dm);
#include "GPU_extensions.h"
#include "GPU_glew.h"
+#include "IMB_imbuf.h"
+#include "IMB_imbuf_types.h"
+
/* very slow! enable for testing only! */
//#define USE_MODIFIER_VALIDATE
diff --git a/source/blender/blenkernel/intern/node.c b/source/blender/blenkernel/intern/node.c
index f30e3b6..d8d13da 100644
--- a/source/blender/blenkernel/intern/node.c
+++ b/source/blender/blenkernel/intern/node.c
@@ -3568,6 +3568,7 @@ static void registerShaderNodes(void)
register_node_type_sh_tex_magic();
register_node_type_sh_tex_checker();
register_node_type_sh_tex_brick();
+ register_node_type_sh_tex_ptex();
}
static void registerTextureNodes(void)
diff --git a/source/blender/editors/space_node/drawnode.c b/source/blender/editors/space_node/drawnode.c
index f1dfa4f..d4ba1c5 100644
--- a/source/blender/editors/space_node/drawnode.c
+++ b/source/blender/editors/space_node/drawnode.c
@@ -889,6 +889,10 @@ static void node_shader_buts_uvalongstroke(uiLayout *layout, bContext *UNUSED(C)
uiItemR(layout, ptr, "use_tips", 0, NULL, 0);
}
+static void node_shader_buts_ptex(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
+{
+}
+
static void node_shader_buts_normal_map(uiLayout *layout, bContext *C, PointerRNA *ptr)
{
uiItemR(layout, ptr, "space", 0, "", 0);
@@ -1133,6 +1137,9 @@ static void node_shader_set_butfunc(bNodeType *ntype)
case SH_NODE_OUTPUT_LINESTYLE:
ntype->draw_buttons = node_buts_output_linestyle;
break;
+ case SH_NODE_TEX_PTEX:
+ ntype->draw_buttons = node_shader_buts_ptex;
+ break;
}
}
diff --git a/source/blender/editors/space_view3d/view3d_draw.c b/source/blender/editors/space_view3d/view3d_draw.c
index 88cabcc..3a35fa5 100644
--- a/source/blender/editors/space_view3d/view3d_draw.c
+++ b/source/blender/editors/space_view3d/view3d_draw.c
@@ -2830,7 +2830,7 @@ static void view3d_main_area_clear(Scene *scene, View3D *v3d, ARegion *ar, bool
GPUMaterial *gpumat = GPU_material_world(scene, scene->world);
/* calculate full shader for background */
- GPU_material_bind(gpumat, 1, 1, 1.0, false, rv3d->viewmat, rv3d->viewinv, (v3d->scenelock != 0));
+ GPU_material_bind(gpumat, 1, 1, 1.0, false, rv3d->viewmat, rv3d->viewinv, (v3d->scenelock != 0), NULL);
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_ALWAYS);
diff --git a/source/blender/gpu/GPU_extensions.h b/source/blender/gpu/GPU_extensions.h
index bb0cf2d..262399d 100644
--- a/source/blender/gpu/GPU_extensions.h
+++ b/source/blender/gpu/GPU_extensions.h
@@ -112,6 +112,9 @@ GPUTexture *GPU_texture_create_2D(int w, int h, float *pixels, char err_out[256]
GPUTexture *GPU_texture_create_3D(int w, int h, int depth, int channels, float *fpixels);
GPUTexture *GPU_texture_create_depth(int w, int h, char err_out[256]);
GPUTexture *GPU_texture_create_vsm_shadow_map(int size, char err_out[256]);
+ // TODO
+GPUTexture *GPU_ptex_texture_from_blender(struct Image *ima,
+ struct ImageUser *iuser);
GPUTexture *GPU_texture_from_blender(struct Image *ima,
struct ImageUser *iuser, bool is_data, double time, int mipmap);
GPUTexture *GPU_texture_from_preview(struct PreviewImage *prv, int mipmap);
diff --git a/source/blender/gpu/GPU_material.h b/source/blender/gpu/GPU_material.h
index a65a123..714b584 100644
--- a/source/blender/gpu/GPU_material.h
+++ b/source/blender/gpu/GPU_material.h
@@ -154,6 +154,7 @@ GPUNodeLink *GPU_attribute(CustomDataType type, const char *name);
GPUNodeLink *GPU_uniform(float *num);
GPUNodeLink *GPU_dynamic_uniform(float *num, GPUDynamicType dynamictype, void *data);
GPUNodeLink *GPU_image(struct Image *ima, struct ImageUser *iuser, bool is_data);
+GPUNodeLink *GPU_ptex(int ptex);
GPUNodeLink *GPU_image_preview(struct PreviewImage *prv);
GPUNodeLink *GPU_texture(int size, float *pixels);
GPUNodeLink *GPU_dynamic_texture(struct GPUTexture *tex, GPUDynamicType dynamictype, void *data);
@@ -177,7 +178,9 @@ void GPU_material_free(struct ListBase *gpumaterial);
void GPU_materials_free(void);
bool GPU_lamp_override_visible(GPULamp *lamp, struct SceneRenderLayer *srl, struct Material *ma);
-void GPU_material_bind(GPUMaterial *material, int oblay, int viewlay, double time, int mipmap, float viewmat[4][4], float viewinv[4][4], bool scenelock);
+void GPU_material_bind(GPUMaterial *material, int oblay, int viewlay, double time, int mipmap, float viewmat[4][4], float viewinv[4][4], bool scenelock,
+ // TODO
+ struct Object *ob);
void GPU_material_bind_uniforms(GPUMaterial *material, float obmat[4][4], float obcol[4], float autobumpscale);
void GPU_material_unbind(GPUMaterial *material);
int GPU_material_bound(GPUMaterial *material);
diff --git a/source/blender/gpu/intern/gpu_codegen.c b/source/blender/gpu/intern/gpu_codegen.c
index e77ea32..e35ed15 100644
--- a/source/blender/gpu/intern/gpu_codegen.c
+++ b/source/blender/gpu/intern/gpu_codegen.c
@@ -38,6 +38,7 @@
#include "DNA_customdata_types.h"
#include "DNA_image_types.h"
#include "DNA_material_types.h"
+#include "DNA_object_types.h"
#include "BLI_blenlib.h"
#include "BLI_utildefines.h"
@@ -49,6 +50,10 @@
#include "BLI_sys_types.h" // for intptr_t support
+#include "BKE_customdata.h"
+#include "BKE_DerivedMesh.h"
+#include "BKE_ptex.h"
+
#include "gpu_codegen.h"
#include <string.h>
@@ -359,7 +364,7 @@ static int codegen_input_has_texture(GPUInput *input)
{
if (input->link)
return 0;
- else if (input->ima || input->prv)
+ else if (input->ima || input->prv || input->ptex)
return 1;
else
return input->tex != NULL;
@@ -431,6 +436,11 @@ static void codegen_set_unique_ids(ListBase *nodes)
/* input is texture from buffer */
codegen_set_texid(bindhash, input, &texid, input->link);
}
+ else if (input->ptex) {
+ // TODO
+ input->texid = texid++;
+ input->bindtex = 1;
+ }
else if (input->ima) {
/* input is texture from image */
codegen_set_texid(bindhash, input, &texid, input->ima);
@@ -778,7 +788,7 @@ static void gpu_nodes_extract_dynamic_inputs(GPUPass *pass, ListBase *nodes)
continue;
}
- if (input->ima || input->tex || input->prv)
+ if (input->ima || input->tex || input->prv || input->ptex)
BLI_snprintf(input->shadername, sizeof(input->shadername), "samp%d", input->texid);
else
BLI_snprintf(input->shadername, sizeof(input->shadername), "unf%d", input->id);
@@ -786,7 +796,7 @@ static void gpu_nodes_extract_dynamic_inputs(GPUPass *pass, ListBase *nodes)
/* pass non-dynamic uniforms to opengl */
extract = 0;
- if (input->ima || input->tex || input->prv) {
+ if (input->ima || input->tex || input->prv || input->ptex) {
if (input->bindtex)
extract = 1;
}
@@ -807,7 +817,9 @@ static void gpu_nodes_extract_dynamic_inputs(GPUPass *pass, ListBase *nodes)
GPU_shader_unbind();
}
-void GPU_pass_bind(GPUPass *pass, double time, int mipmap)
+void GPU_pass_bind(GPUPass *pass, double time, int mipmap,
+ // TODO
+ Object *ob)
{
GPUInput *input;
GPUShader *shader = pass->shader;
@@ -818,6 +830,26 @@ void GPU_pass_bind(GPUPass *pass, double time, int mipmap)
GPU_shader_bind(shader);
+ // TODO: putting this here for now so that texture creation
+ // doesn't screw up bindings
+ for (input=inputs->first; input; input=input->next) {
+ if (input->ptex != 0) {
+ // TODO: will pass a layer index or name here
+ Image *image = BKE_ptex_mesh_image_get(ob);
+ input->tex = NULL;
+ if (image) {
+ if (input->ptex == 1) {
+ input->tex = GPU_texture_from_blender(image,
+ NULL, false,
+ time, false);
+ }
+ else if (input->ptex == 2) {
+ input->tex = GPU_ptex_texture_from_blender(image, NULL);
+ }
+ }
+ }
+ }
+
/* now bind the textures */
for (input=inputs->first; input; input=input->next) {
if (input->ima)
@@ -844,7 +876,7 @@ void GPU_pass_update_uniforms(GPUPass *pass)
/* pass dynamic inputs to opengl, others were removed */
for (input=inputs->first; input; input=input->next)
- if (!(input->ima || input->tex || input->prv))
+ if (!(input->ima || input->tex || input->prv || input->ptex))
GPU_shader_uniform_vector(shader, input->shaderloc, input->type, 1,
input->dynamicvec);
}
@@ -862,7 +894,7 @@ void GPU_pass_unbind(GPUPass *pass)
if (input->tex && input->bindtex)
GPU_texture_unbind(input->tex);
- if (input->ima || input->prv)
+ if (input->ima || input->prv || input->ptex)
input->tex = NULL;
}
@@ -992,6 +1024,14 @@ static void gpu_node_input_link(GPUNode *node, GPUNodeLink *link, const GPUType
input->textype = GPU_TEX2D;
MEM_freeN(link);
}
+ else if (link->ptex) {
+ input->type = GPU_VEC4;
+ input->source = GPU_SOURCE_TEX;
+ input->ptex = link->ptex;
+ input->textarget = GL_TEXTURE_2D;
+ input->textype = GPU_TEX2D;
+ MEM_freeN(link);
+ }
else if (link->a
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list