[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [15294] branches/apricot/source: Apricot Branch: GLSL
Brecht Van Lommel
brechtvanlommel at pandora.be
Sat Jun 21 12:33:13 CEST 2008
Revision: 15294
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=15294
Author: blendix
Date: 2008-06-21 12:33:12 +0200 (Sat, 21 Jun 2008)
Log Message:
-----------
Apricot Branch: GLSL
====================
* Added initial support for shadow buffers, works in the 3d view and the
game engine, but has known issues still:
* Shadow buffers are made again for each 3d viewport unnecessarily.
* No filtering.
* There was a bug with some shaders going black, but can't reproduce
it anymore?
* Added support for layer lamps, though they're still always computed
in the shader, this needs to be optimized.
* Added support for animating lamp position/rotation in the game engine.
* Fix issue with lamps giving negative light on the backside.
* Fix issue with specular + orthographic camera.
* Fix square spotlights.
* Potential workaround for a bug in the nvidia drivers with shader linking.
Modified Paths:
--------------
branches/apricot/source/blender/blenkernel/intern/object.c
branches/apricot/source/blender/blenloader/intern/readfile.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
branches/apricot/source/blender/gpu/intern/material_vertex_shader.glsl.c
branches/apricot/source/blender/include/BDR_drawobject.h
branches/apricot/source/blender/include/BSE_drawview.h
branches/apricot/source/blender/makesdna/DNA_object_types.h
branches/apricot/source/blender/nodes/intern/SHD_nodes/SHD_camera.c
branches/apricot/source/blender/nodes/intern/SHD_nodes/SHD_geom.c
branches/apricot/source/blender/src/buttons_shading.c
branches/apricot/source/blender/src/drawobject.c
branches/apricot/source/blender/src/drawview.c
branches/apricot/source/blender/src/previewrender.c
branches/apricot/source/blender/src/renderwin.c
branches/apricot/source/gameengine/Converter/BL_BlenderDataConversion.cpp
branches/apricot/source/gameengine/Ketsji/BL_BlenderShader.cpp
branches/apricot/source/gameengine/Ketsji/BL_BlenderShader.h
branches/apricot/source/gameengine/Ketsji/KX_BlenderMaterial.cpp
branches/apricot/source/gameengine/Ketsji/KX_KetsjiEngine.cpp
branches/apricot/source/gameengine/Ketsji/KX_KetsjiEngine.h
branches/apricot/source/gameengine/Ketsji/KX_Light.cpp
branches/apricot/source/gameengine/Ketsji/KX_Light.h
branches/apricot/source/gameengine/Ketsji/KX_Scene.cpp
branches/apricot/source/gameengine/Ketsji/KX_Scene.h
Modified: branches/apricot/source/blender/blenkernel/intern/object.c
===================================================================
--- branches/apricot/source/blender/blenkernel/intern/object.c 2008-06-20 21:36:15 UTC (rev 15293)
+++ branches/apricot/source/blender/blenkernel/intern/object.c 2008-06-21 10:33:12 UTC (rev 15294)
@@ -112,6 +112,8 @@
#include "BPY_extern.h"
+#include "GPU_material.h"
+
#include "blendef.h"
/* Local function protos */
@@ -268,6 +270,7 @@
}
if(ob->soft) sbFree(ob->soft);
if(ob->fluidsimSettings) fluidsimSettingsFree(ob->fluidsimSettings);
+ if(ob->gpulamp) GPU_lamp_free(ob->gpulamp);
}
static void unlink_object__unlinkModifierLinks(void *userData, Object *ob, Object **obpoin)
@@ -1215,6 +1218,7 @@
obn->vnode = NULL;
#endif
+ obn->gpulamp = NULL;
return obn;
}
Modified: branches/apricot/source/blender/blenloader/intern/readfile.c
===================================================================
--- branches/apricot/source/blender/blenloader/intern/readfile.c 2008-06-20 21:36:15 UTC (rev 15293)
+++ branches/apricot/source/blender/blenloader/intern/readfile.c 2008-06-21 10:33:12 UTC (rev 15294)
@@ -3368,6 +3368,7 @@
ob->bb= NULL;
ob->derivedDeform= NULL;
ob->derivedFinal= NULL;
+ ob->gpulamp= NULL;
}
/* ************ READ SCENE ***************** */
Modified: branches/apricot/source/blender/gpu/GPU_extensions.h
===================================================================
--- branches/apricot/source/blender/gpu/GPU_extensions.h 2008-06-20 21:36:15 UTC (rev 15293)
+++ branches/apricot/source/blender/gpu/GPU_extensions.h 2008-06-21 10:33:12 UTC (rev 15294)
@@ -72,6 +72,7 @@
GPUTexture *GPU_texture_create_1D(int w, float *pixels, int halffloat);
GPUTexture *GPU_texture_create_2D(int w, int h, float *pixels, int halffloat);
+GPUTexture *GPU_texture_create_depth(int w, int h);
GPUTexture *GPU_texture_from_blender(struct Image *ima, struct ImageUser *iuser);
void GPU_texture_free(GPUTexture *tex);
@@ -92,7 +93,6 @@
int GPU_texture_opengl_height(GPUTexture *tex);
void GPU_texture_coord_2f(GPUTexture *tex, float s, float t);
-#if 0
/* GPU Framebuffer
- this is a wrapper for an OpenGL framebuffer object (FBO). in practice
multiple FBO's may be created, to get around limitations on the number
@@ -108,7 +108,6 @@
void GPU_framebuffer_free(GPUFrameBuffer *fb);
void GPU_framebuffer_restore();
-#endif
/* GPU Shader
- only for fragment shaders now
Modified: branches/apricot/source/blender/gpu/GPU_material.h
===================================================================
--- branches/apricot/source/blender/gpu/GPU_material.h 2008-06-20 21:36:15 UTC (rev 15293)
+++ branches/apricot/source/blender/gpu/GPU_material.h 2008-06-21 10:33:12 UTC (rev 15294)
@@ -41,16 +41,21 @@
struct ImageUser;
struct Material;
struct Object;
+struct Lamp;
struct bNode;
+struct LinkNode;
struct GPUVertexAttribs;
struct GPUNode;
struct GPUNodeLink;
struct GPUNodeStack;
struct GPUMaterial;
+struct GPUTexture;
+struct GPULamp;
typedef struct GPUNode GPUNode;
typedef struct GPUNodeLink GPUNodeLink;
typedef struct GPUMaterial GPUMaterial;
+typedef struct GPULamp GPULamp;
/* Functions to create GPU Materials nodes */
@@ -64,9 +69,18 @@
GPU_MAT4 = 16,
GPU_TEX1D = 1001,
GPU_TEX2D = 1002,
- GPU_ATTRIB = 2001
+ GPU_ATTRIB = 3001
} GPUType;
+typedef enum GPUBuiltin {
+ GPU_VIEW_MATRIX = 1,
+ GPU_OBJECT_MATRIX = 2,
+ GPU_INVERSE_VIEW_MATRIX = 4,
+ GPU_INVERSE_OBJECT_MATRIX = 8,
+ GPU_VIEW_POSITION = 16,
+ GPU_VIEW_NORMAL = 32
+} GPUBuiltin;
+
typedef struct GPUNodeStack {
GPUType type;
char *name;
@@ -82,7 +96,9 @@
GPUNodeLink *GPU_dynamic_uniform(float *num);
GPUNodeLink *GPU_image(struct Image *ima, struct ImageUser *iuser);
GPUNodeLink *GPU_texture(int size, float *pixels);
+GPUNodeLink *GPU_dynamic_texture(struct GPUTexture *tex);
GPUNodeLink *GPU_socket(GPUNodeStack *sock);
+GPUNodeLink *GPU_builtin(GPUBuiltin builtin);
int GPU_link(GPUMaterial *mat, char *name, ...);
int GPU_stack_link(GPUMaterial *mat, char *name, GPUNodeStack *in, GPUNodeStack *out, ...);
@@ -92,13 +108,10 @@
/* 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);
+int GPU_material_from_blender(struct Material *ma);
void GPU_material_free(GPUMaterial *material);
-void GPU_material_bind(GPUMaterial *material);
+void GPU_material_bind(GPUMaterial *material, int lay);
void GPU_material_bind_uniforms(GPUMaterial *material, float obmat[][4], float viewmat[][4]);
void GPU_material_unbind(GPUMaterial *material);
@@ -122,6 +135,18 @@
void GPU_shadeinput_set(GPUMaterial *mat, struct Material *ma, GPUShadeInput *shi);
void GPU_shaderesult_set(GPUShadeInput *shi, GPUShadeResult *shr);
+/* Lamps */
+
+int GPU_lamp_from_blender(struct Object *ob, struct Lamp *la);
+void GPU_lamp_free(GPULamp *lamp);
+
+int GPU_lamp_has_shadow_buffer(GPULamp *lamp);
+void GPU_lamp_shadow_buffer_bind(GPULamp *lamp, float viewmat[][4], int *winsize, float winmat[][4]);
+void GPU_lamp_shadow_buffer_unbind(GPULamp *lamp);
+
+void GPU_lamp_update(GPULamp *lamp, float obmat[][4]);
+int GPU_lamp_shadow_layer(GPULamp *lamp);
+
#ifdef __cplusplus
}
#endif
Modified: branches/apricot/source/blender/gpu/intern/gpu_codegen.c
===================================================================
--- branches/apricot/source/blender/gpu/intern/gpu_codegen.c 2008-06-20 21:36:15 UTC (rev 15293)
+++ branches/apricot/source/blender/gpu/intern/gpu_codegen.c 2008-06-21 10:33:12 UTC (rev 15294)
@@ -68,11 +68,14 @@
/* structs and defines */
-#define GPU_VEC_UNIFORM 1
-#define GPU_TEX_PIXEL 2
-#define GPU_TEX_RAND 3
-#define GPU_ARR_UNIFORM 4
-#define GPU_S_ATTRIB 5
+typedef enum GPUDataSource {
+ GPU_SOURCE_VEC_UNIFORM,
+ GPU_SOURCE_ARRAY_UNIFORM,
+ GPU_SOURCE_BUILTIN,
+ GPU_SOURCE_TEX_PIXEL,
+ GPU_SOURCE_TEX,
+ GPU_SOURCE_ATTRIB
+} GPUDataSource;
static char* GPU_DATATYPE_STR[17] = {"", "float", "vec2", "vec3", "vec4",
0, 0, 0, 0, "mat3", 0, 0, 0, 0, 0, 0, "mat4"};
@@ -105,7 +108,11 @@
int type;
int users;
- struct GPUOutput *source;
+ GPUTexture *dynamictex;
+
+ GPUBuiltin builtin;
+
+ struct GPUOutput *output;
};
typedef struct GPUOutput {
@@ -124,7 +131,7 @@
int type; /* datatype */
int arraysize; /* number of elements in an array */
- int samp;
+ int source; /* data source */
int id; /* unique id as created by code generator */
int texid; /* number for multitexture */
@@ -137,11 +144,13 @@
float *dynamicvec; /* vector data in case it is dynamic */
GPUNodeLink *link;
GPUTexture *tex; /* input texture, only set at runtime */
+ int dynamictex; /* dynamic? */
struct Image *ima; /* image */
struct ImageUser *iuser;/* image user */
int attribtype; /* attribute type */
char attribname[32]; /* attribute name */
int attribfirst; /* this is the first one that is bound */
+ GPUBuiltin builtin; /* builtin uniform */
} GPUInput;
struct GPUPass {
@@ -411,26 +420,6 @@
}
}
-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)
@@ -441,6 +430,24 @@
return input->tex != 0;
}
+char *GPU_builtin_name(GPUBuiltin builtin)
+{
+ if(builtin == GPU_VIEW_MATRIX)
+ return "unfviewmat";
+ else if(builtin == GPU_OBJECT_MATRIX)
+ return "unfobmat";
+ else if(builtin == GPU_INVERSE_VIEW_MATRIX)
+ return "unfinvviewmat";
+ else if(builtin == GPU_INVERSE_OBJECT_MATRIX)
+ return "unfinvobmat";
+ else if(builtin == GPU_VIEW_POSITION)
+ return "varposition";
+ else if(builtin == GPU_VIEW_NORMAL)
+ return "varnormal";
+ else
+ return "";
+}
+
static void codegen_set_unique_ids(ListBase *nodes)
{
GHash *bindhash, *definehash;
@@ -461,7 +468,7 @@
/* set texid used for settings texture slot with multitexture */
if (codegen_input_has_texture(input) &&
- ((input->samp == GPU_TEX_RAND) || (input->samp == GPU_TEX_PIXEL))) {
+ ((input->source == GPU_SOURCE_TEX) || (input->source == GPU_SOURCE_TEX_PIXEL))) {
if (input->link) {
/* input is texture from buffer, assign only one texid per
buffer to avoid sampling the same texture twice */
@@ -492,7 +499,7 @@
}
/* make sure this pixel is defined exactly once */
- if (input->samp == GPU_TEX_PIXEL) {
+ if (input->source == GPU_SOURCE_TEX_PIXEL) {
if(input->ima) {
if (!BLI_ghash_haskey(definehash, input->ima)) {
input->definetex = 1;
@@ -522,27 +529,45 @@
{
GPUNode *node;
GPUInput *input;
+ char *name;
+ int builtins = 0;
/* print uniforms */
for (node=nodes->first; node; node=node->next) {
for (input=node->inputs.first; input; input=input->next) {
- if ((input->samp == GPU_TEX_RAND) || (input->samp == GPU_TEX_PIXEL)) {
+ if ((input->source == GPU_SOURCE_TEX) || (input->source == GPU_SOURCE_TEX_PIXEL)) {
/* create exactly one sampler for each texture */
if (codegen_input_has_texture(input) && input->bindtex)
BLI_dynstr_printf(ds, "uniform %s samp%d;\n",
(input->textarget == GL_TEXTURE_1D)? "sampler1D": "sampler2D",
input->texid);
}
- else if (input->samp == GPU_VEC_UNIFORM) {
+ else if(input->source == GPU_SOURCE_BUILTIN) {
+ /* only define each builting uniform/varying once */
+ if(!(builtins & input->builtin)) {
+ builtins |= input->builtin;
+ name = GPU_builtin_name(input->builtin);
+
+ if(gpu_str_prefix(name, "unf")) {
+ BLI_dynstr_printf(ds, "uniform %s %s;\n",
+ GPU_DATATYPE_STR[input->type], name);
+ }
+ else {
+ BLI_dynstr_printf(ds, "varying %s %s;\n",
+ GPU_DATATYPE_STR[input->type], name);
+ }
+ }
+ }
+ else if (input->source == GPU_SOURCE_VEC_UNIFORM) {
/* and create uniform vectors or matrices for all vectors */
BLI_dynstr_printf(ds, "uniform %s unf%d;\n",
GPU_DATATYPE_STR[input->type], input->id);
}
- else if (input->samp == GPU_ARR_UNIFORM) {
+ else if (input->source == GPU_SOURCE_ARRAY_UNIFORM) {
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list