[Bf-blender-cvs] [8884930] cycles-ptex-12: Add Ptex shader node
Nicholas Bishop
noreply at git.blender.org
Mon Jan 26 02:05:01 CET 2015
Commit: 8884930a77805859f2b991a8c0e4920785c572da
Author: Nicholas Bishop
Date: Tue Jan 20 18:42:02 2015 +0100
Branches: cycles-ptex-12
https://developer.blender.org/rB8884930a77805859f2b991a8c0e4920785c572da
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_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_material.c
M source/blender/gpu/shaders/gpu_shader_material.glsl
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 039af94..96b6647 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 870b463..30db8fd 100644
--- a/source/blender/editors/space_node/drawnode.c
+++ b/source/blender/editors/space_node/drawnode.c
@@ -888,6 +888,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);
@@ -1132,6 +1136,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_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 56a753f..6d5fe6d 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,12 @@
#include "BLI_sys_types.h" // for intptr_t support
+#include "BKE_customdata.h"
+#include "BKE_DerivedMesh.h"
+#include "BKE_image.h"
+#include "IMB_imbuf_types.h"
+#include "IMB_imbuf.h"
+
#include "gpu_codegen.h"
#include <string.h>
@@ -359,7 +366,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 +438,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 +790,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 +798,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,17 +819,51 @@ 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;
ListBase *inputs = &pass->inputs;
+ DerivedMesh *dm = (ob && ob->derivedFinal) ? ob->derivedFinal : NULL;
+
if (!shader)
return;
GPU_shader_bind(shader);
+ // TODO
+ for (input=inputs->first; input; input=input->next) {
+ if (input->ptex != 0) {
+ ImBuf *imbuf = NULL;
+
+ MTessFacePtex *ptex = CustomData_get_layer(&dm->faceData,
+ CD_TESSFACE_PTEX);
+
+ if (ptex) {
+ imbuf = ptex[0].imbuf;
+ }
+
+ input->tex = 0;
+ if (input->ptex == 1 && imbuf) {
+ char err[256];
+ IMB_float_from_rect(imbuf);
+ input->tex = GPU_texture_create_2D(imbuf->x,
+ imbuf->y,
+ (float*)imbuf->rect_float,
+ err);
+ }
+ else if (input->ptex == 2 && imbuf) {
+ input->tex =
+ GPU_texture_create_1D_float(imbuf->num_ptex_coords,
+ (float*)imbuf->ptex_coords,
+ NULL);
+ }
+ }
+ }
+
/* now bind the textures */
for (input=inputs->first; input; input=input->next) {
if (input->ima)
@@ -844,7 +890,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 +908,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 +1038,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->attribtype) {
/* vertex attribute */
input->type = type;
@@ -1194,6 +1248,16 @@ GPUNodeLink *GPU_image(Image *ima, ImageUser *iuser, bool is_data)
return link;
}
+// TODO
+GPUNodeLink *GPU_ptex(int ptex)
+{
+ GPUNodeLink *link = GPU_node_link_create();
+
+ link->ptex = ptex;
+
+ return link;
+}
+
GPUNodeLink *GPU_image_preview(PreviewImage *prv)
{
GPUNodeLink *link = GPU_node_link_create();
diff --git a/source/blender/gpu/intern/gpu_codegen.h b/source/blender/gpu/intern/gpu_codegen.h
index 346b143..95035dc 100644
--- a/source/blender/gpu/intern/gpu_codegen.h
+++
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list