[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [15217] branches/apricot/source: Apricot Branch: GLSL
Brecht Van Lommel
brechtvanlommel at pandora.be
Fri Jun 13 23:24:59 CEST 2008
Revision: 15217
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=15217
Author: blendix
Date: 2008-06-13 23:24:21 +0200 (Fri, 13 Jun 2008)
Log Message:
-----------
Apricot Branch: GLSL
====================
* Added support for lamps and shaders. All material diffuse and
specular shaders are supported, for lamps especially area light
support is not there yet.
* Added support for these GLSL shaders in the game engine, though
it is incomplete and somewhat of a hack. Specifically all the
variables are completely static, which means moving lights, or
animating material properties will not work.
* Enabling GLSL shaders is now different. They work in textured
drawmode, and can be enabled in the Game menu with the option
"Blender GLSL Materials"
Known issues:
* The GLSL shaders don't always update correct on light changes.
* The game player appears to crash with these GLSL shaders, while
regular blender works fine.
Modified Paths:
--------------
branches/apricot/source/blender/blenkernel/BKE_colortools.h
branches/apricot/source/blender/blenkernel/BKE_global.h
branches/apricot/source/blender/blenkernel/BKE_node.h
branches/apricot/source/blender/blenkernel/intern/DerivedMesh.c
branches/apricot/source/blender/blenkernel/intern/colortools.c
branches/apricot/source/blender/blenkernel/intern/node.c
branches/apricot/source/blender/gpu/GPU_extensions.h
branches/apricot/source/blender/gpu/GPU_material.h
branches/apricot/source/blender/gpu/intern/gpu_codegen.c
branches/apricot/source/blender/gpu/intern/gpu_codegen.h
branches/apricot/source/blender/gpu/intern/gpu_extensions.c
branches/apricot/source/blender/gpu/intern/gpu_material.c
branches/apricot/source/blender/gpu/intern/material_shaders.glsl
branches/apricot/source/blender/gpu/intern/material_shaders.glsl.c
branches/apricot/source/blender/gpu/intern/material_vertex_shader.glsl.c
branches/apricot/source/blender/makesdna/DNA_userdef_types.h
branches/apricot/source/blender/nodes/intern/SHD_nodes/SHD_curves.c
branches/apricot/source/blender/src/drawobject.c
branches/apricot/source/blender/src/header_info.c
branches/apricot/source/blender/src/previewrender.c
branches/apricot/source/blender/src/space.c
branches/apricot/source/gameengine/BlenderRoutines/BL_KetsjiEmbedStart.cpp
branches/apricot/source/gameengine/BlenderRoutines/SConscript
branches/apricot/source/gameengine/Converter/BL_BlenderDataConversion.cpp
branches/apricot/source/gameengine/Converter/KX_BlenderSceneConverter.cpp
branches/apricot/source/gameengine/Converter/KX_BlenderSceneConverter.h
branches/apricot/source/gameengine/Converter/SConscript
branches/apricot/source/gameengine/GamePlayer/common/SConscript
branches/apricot/source/gameengine/GamePlayer/ghost/GPG_Application.cpp
branches/apricot/source/gameengine/GamePlayer/ghost/GPG_Application.h
branches/apricot/source/gameengine/GamePlayer/ghost/SConscript
branches/apricot/source/gameengine/Ketsji/BL_Material.cpp
branches/apricot/source/gameengine/Ketsji/BL_Material.h
branches/apricot/source/gameengine/Ketsji/CMakeLists.txt
branches/apricot/source/gameengine/Ketsji/KX_BlenderMaterial.cpp
branches/apricot/source/gameengine/Ketsji/KX_BlenderMaterial.h
branches/apricot/source/gameengine/Ketsji/KX_GameObject.cpp
branches/apricot/source/gameengine/Ketsji/KX_ISceneConverter.h
branches/apricot/source/gameengine/Ketsji/Makefile
branches/apricot/source/gameengine/Ketsji/SConscript
branches/apricot/source/gameengine/Rasterizer/RAS_CameraData.h
branches/apricot/source/gameengine/Rasterizer/RAS_MaterialBucket.cpp
branches/apricot/source/gameengine/Rasterizer/SConscript
Added Paths:
-----------
branches/apricot/source/gameengine/Ketsji/BL_BlenderShader.cpp
branches/apricot/source/gameengine/Ketsji/BL_BlenderShader.h
Modified: branches/apricot/source/blender/blenkernel/BKE_colortools.h
===================================================================
--- branches/apricot/source/blender/blenkernel/BKE_colortools.h 2008-06-13 21:07:46 UTC (rev 15216)
+++ branches/apricot/source/blender/blenkernel/BKE_colortools.h 2008-06-13 21:24:21 UTC (rev 15217)
@@ -57,6 +57,7 @@
void curvemapping_premultiply(struct CurveMapping *cumap, int restore);
int curvemapping_RGBA_does_something(struct CurveMapping *cumap);
void curvemapping_initialize(struct CurveMapping *cumap);
+void curvemapping_table_RGBA(struct CurveMapping *cumap, float **array, int *size);
#endif
Modified: branches/apricot/source/blender/blenkernel/BKE_global.h
===================================================================
--- branches/apricot/source/blender/blenkernel/BKE_global.h 2008-06-13 21:07:46 UTC (rev 15216)
+++ branches/apricot/source/blender/blenkernel/BKE_global.h 2008-06-13 21:24:21 UTC (rev 15217)
@@ -220,6 +220,7 @@
#define G_FILE_GAME_MAT (1 << 12)
#define G_FILE_DIAPLAY_LISTS (1 << 13)
#define G_FILE_SHOW_PHYSICS (1 << 14)
+#define G_FILE_GAME_MAT_GLSL (1 << 15)
/* G.windowstate */
#define G_WINDOWSTATE_USERDEF 0
Modified: branches/apricot/source/blender/blenkernel/BKE_node.h
===================================================================
--- branches/apricot/source/blender/blenkernel/BKE_node.h 2008-06-13 21:07:46 UTC (rev 15216)
+++ branches/apricot/source/blender/blenkernel/BKE_node.h 2008-06-13 21:24:21 UTC (rev 15217)
@@ -258,7 +258,7 @@
extern void (*node_shader_lamp_loop)(struct ShadeInput *, struct ShadeResult *);
void set_node_shader_lamp_loop(void (*lamp_loop_func)(struct ShadeInput *, struct ShadeResult *));
-struct GPUMaterial *ntreeShaderCreateGPU(struct bNodeTree *tree);
+void ntreeGPUMaterialNodes(struct bNodeTree *ntree, struct GPUMaterial *mat);
/* ************** COMPOSITE NODES *************** */
Modified: branches/apricot/source/blender/blenkernel/intern/DerivedMesh.c
===================================================================
--- branches/apricot/source/blender/blenkernel/intern/DerivedMesh.c 2008-06-13 21:07:46 UTC (rev 15216)
+++ branches/apricot/source/blender/blenkernel/intern/DerivedMesh.c 2008-06-13 21:24:21 UTC (rev 15217)
@@ -3119,11 +3119,11 @@
if (mf->v4) {
v4= &mvert[mf->v4];
- CalcNormFloat4(v1->co, v2->co, v3->co, v4->co, fno);
+ CalcNormFloat4(v4->co, v3->co, v2->co, v1->co, fno);
}
else {
v4= NULL;
- CalcNormFloat(v1->co, v2->co, v3->co, fno);
+ CalcNormFloat(v3->co, v2->co, v1->co, fno);
}
if(mtface) {
Modified: branches/apricot/source/blender/blenkernel/intern/colortools.c
===================================================================
--- branches/apricot/source/blender/blenkernel/intern/colortools.c 2008-06-13 21:07:46 UTC (rev 15216)
+++ branches/apricot/source/blender/blenkernel/intern/colortools.c 2008-06-13 21:24:21 UTC (rev 15217)
@@ -730,3 +730,24 @@
curvemap_make_table(cumap->cm+a, &cumap->clipr);
}
}
+
+void curvemapping_table_RGBA(CurveMapping *cumap, float **array, int *size)
+{
+ int a;
+
+ *size = CM_TABLE+1;
+ *array = MEM_callocN(sizeof(float)*(*size)*4, "CurveMapping");
+ curvemapping_initialize(cumap);
+
+ for(a=0; a<*size; a++) {
+ if(cumap->cm[0].table)
+ (*array)[a*4+0]= cumap->cm[0].table[a].y;
+ if(cumap->cm[1].table)
+ (*array)[a*4+1]= cumap->cm[1].table[a].y;
+ if(cumap->cm[2].table)
+ (*array)[a*4+2]= cumap->cm[2].table[a].y;
+ if(cumap->cm[3].table)
+ (*array)[a*4+3]= cumap->cm[3].table[a].y;
+ }
+}
+
Modified: branches/apricot/source/blender/blenkernel/intern/node.c
===================================================================
--- branches/apricot/source/blender/blenkernel/intern/node.c 2008-06-13 21:07:46 UTC (rev 15216)
+++ branches/apricot/source/blender/blenkernel/intern/node.c 2008-06-13 21:24:21 UTC (rev 15217)
@@ -2393,20 +2393,18 @@
ns[i]->data= gs[i].link;
}
-GPUMaterial *ntreeShaderCreateGPU(bNodeTree *ntree)
+void ntreeGPUMaterialNodes(bNodeTree *ntree, GPUMaterial *mat)
{
bNode *node;
bNodeStack *stack;
bNodeStack *nsin[MAX_SOCKET]; /* arbitrary... watch this */
bNodeStack *nsout[MAX_SOCKET]; /* arbitrary... watch this */
GPUNodeStack gpuin[MAX_SOCKET+1], gpuout[MAX_SOCKET+1];
- GPUMaterial *mat;
if((ntree->init & NTREE_EXEC_INIT)==0)
ntreeBeginExecTree(ntree);
stack= ntree->stack;
- mat= GPU_material_construct_begin();
for(node= ntree->nodes.first; node; node= node->next) {
if(node->typeinfo->gpufunc) {
@@ -2419,14 +2417,7 @@
/* groups not supported yet .. */
}
- if(!GPU_material_construct_end(mat)) {
- GPU_material_free(mat);
- mat= NULL;
- }
-
ntreeEndExecTree(ntree);
-
- return mat;
}
/* **************** call to switch lamploop for material node ************ */
Modified: branches/apricot/source/blender/gpu/GPU_extensions.h
===================================================================
--- branches/apricot/source/blender/gpu/GPU_extensions.h 2008-06-13 21:07:46 UTC (rev 15216)
+++ branches/apricot/source/blender/gpu/GPU_extensions.h 2008-06-13 21:24:21 UTC (rev 15217)
@@ -33,6 +33,10 @@
#ifndef GPU_EXTENSIONS_H
#define GPU_EXTENSIONS_H
+#ifdef __cplusplus
+extern "C" {
+#endif
+
/* GPU extensions support */
struct Image;
@@ -50,7 +54,7 @@
void GPU_extensions_init(void); /* call this before running any of the functions below */
void GPU_extensions_exit(void);
int GPU_extensions_minimum_support(void);
-void GPU_print_error(char *str);
+int GPU_print_error(char *str);
/* GPU Texture
- always returns unsigned char RGBA textures
@@ -136,5 +140,9 @@
int totlayer;
} GPUVertexAttribs;
+#ifdef __cplusplus
+}
#endif
+#endif
+
Modified: branches/apricot/source/blender/gpu/GPU_material.h
===================================================================
--- branches/apricot/source/blender/gpu/GPU_material.h 2008-06-13 21:07:46 UTC (rev 15216)
+++ branches/apricot/source/blender/gpu/GPU_material.h 2008-06-13 21:24:21 UTC (rev 15217)
@@ -33,6 +33,10 @@
#ifndef __GPU_MATERIAL__
#define __GPU_MATERIAL__
+#ifdef __cplusplus
+extern "C" {
+#endif
+
struct Image;
struct ImageUser;
struct Material;
@@ -47,7 +51,7 @@
typedef struct GPUNodeLink GPUNodeLink;
typedef struct GPUMaterial GPUMaterial;
-/* Nodes */
+/* Functions to create GPU Materials nodes */
typedef enum GPUType {
GPU_NONE = 0,
@@ -72,6 +76,7 @@
GPUNodeLink *GPU_attribute(int type, char *name);
GPUNodeLink *GPU_uniform(float *num);
+GPUNodeLink *GPU_dynamic_uniform(float *num);
GPUNodeLink *GPU_image(struct Image *ima, struct ImageUser *iuser);
GPUNodeLink *GPU_texture(int size, float *pixels);
GPUNodeLink *GPU_socket(GPUNodeStack *sock);
@@ -79,23 +84,27 @@
GPUNode *GPU_link(GPUMaterial *mat, char *name, ...);
GPUNode *GPU_stack_link(GPUMaterial *mat, char *name, GPUNodeStack *in, GPUNodeStack *out, ...);
-/* Material */
-
-GPUMaterial *GPU_material_construct_begin();
void GPU_material_output_link(GPUMaterial *material, GPUNodeLink *link);
void GPU_material_enable_alpha(GPUMaterial *material);
-GPUNodeLink *GPU_blender_material(GPUMaterial *mat, struct Material *ma);
-int GPU_material_construct_end(GPUMaterial *material);
+/* High level functions to create and use GPU materials */
+
+#define GPU_PROFILE_GAME 0
+#define GPU_PROFILE_DERIVEDMESH 1
+
+GPUMaterial *GPU_material_from_blender(struct Material *ma, int profile);
void GPU_material_free(GPUMaterial *material);
-void GPU_material_bind(struct Object *ob, GPUMaterial *material);
+void GPU_material_bind(GPUMaterial *material);
+void GPU_material_bind_uniforms(GPUMaterial *material, float obmat[][4], float viewmat[][4]);
void GPU_material_unbind(GPUMaterial *material);
void GPU_material_vertex_attributes(GPUMaterial *material,
struct GPUVertexAttribs *attrib);
-GPUMaterial *GPU_material_from_blender(struct Material *ma);
+#ifdef __cplusplus
+}
+#endif
#endif /*__GPU_MATERIAL__*/
Modified: branches/apricot/source/blender/gpu/intern/gpu_codegen.c
===================================================================
--- branches/apricot/source/blender/gpu/intern/gpu_codegen.c 2008-06-13 21:07:46 UTC (rev 15216)
+++ branches/apricot/source/blender/gpu/intern/gpu_codegen.c 2008-06-13 21:24:21 UTC (rev 15217)
@@ -34,6 +34,7 @@
#include "MEM_guardedalloc.h"
+#include "DNA_customdata_types.h"
#include "DNA_image_types.h"
#include "DNA_listBase.h"
@@ -97,6 +98,8 @@
void *ptr1, *ptr2;
+ int dynamic;
+
int type;
int users;
@@ -129,6 +132,7 @@
int textarget; /* GL_TEXTURE_* */
float vec[16]; /* vector data */
+ float *dynamicvec; /* vector data in case it is dynamic */
GPUNodeLink *link;
GPUTexture *tex; /* input texture, only set at runtime */
struct Image *ima; /* image */
@@ -333,6 +337,26 @@
}
}
+static void codegen_convert_datatype_texco(DynStr *ds, int to, char *tmp, int id)
+{
+ char name[1024];
+
+ snprintf(name, sizeof(name), "%s%d", tmp, id);
+
+ if (to == GPU_FLOAT) {
+ BLI_dynstr_printf(ds, "%s.x", name);
+ }
+ else if (to == GPU_VEC2) {
+ BLI_dynstr_printf(ds, "%s.xy", name);
+ }
+ else if (to == GPU_VEC3) {
+ BLI_dynstr_printf(ds, "%s.xyz", name);
+ }
+ else if (to == GPU_VEC4) {
+ BLI_dynstr_append(ds, name);
+ }
+}
+
static int codegen_input_has_texture(GPUInput *input)
{
if (input->link)
@@ -500,10 +524,10 @@
}
else if (input->samp == GPU_TEX_PIXEL) {
if (input->link && input->link->source)
- codegen_convert_datatype(ds, input->link->source->type /* was GPU_VEC4 */, input->type,
+ codegen_convert_datatype(ds, input->link->source->type, input->type,
"tmp", input->link->source->id);
else
- codegen_convert_datatype(ds, input->link->source->type /* was GPU_VEC4 */, input->type,
+ codegen_convert_datatype(ds, input->link->source->type, input->type,
"tex", input->texid);
}
else if ((input->samp == GPU_VEC_UNIFORM) ||
@@ -549,12 +573,12 @@
code = BLI_dynstr_get_cstring(ds);
BLI_dynstr_free(ds);
- if(G.f & G_DEBUG) printf("%s\n", code);
+ //if(G.f & G_DEBUG) printf("%s\n", code);
return code;
}
-static char *code_generate_vertex(ListBase *nodes)
+static char *code_generate_vertex(ListBase *nodes, int profile)
{
DynStr *ds = BLI_dynstr_new();
GPUNode *node;
@@ -564,8 +588,9 @@
for (node=nodes->first; node; node=node->next) {
for (input=node->inputs.first; input; input=input->next) {
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list