[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [15625] branches/soc-2008-unclezeiv/source /blender/render/intern/source/lightcuts.c: Textured area lights: completed support to textures, now allowing multiple channels, stencil, offset/size, etc.
Davide Vercelli
davide.vercelli at gmail.com
Fri Jul 18 21:03:50 CEST 2008
Revision: 15625
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=15625
Author: unclezeiv
Date: 2008-07-18 21:03:50 +0200 (Fri, 18 Jul 2008)
Log Message:
-----------
Textured area lights: completed support to textures, now allowing multiple channels, stencil, offset/size, etc.
Modified Paths:
--------------
branches/soc-2008-unclezeiv/source/blender/render/intern/source/lightcuts.c
Modified: branches/soc-2008-unclezeiv/source/blender/render/intern/source/lightcuts.c
===================================================================
--- branches/soc-2008-unclezeiv/source/blender/render/intern/source/lightcuts.c 2008-07-18 17:57:34 UTC (rev 15624)
+++ branches/soc-2008-unclezeiv/source/blender/render/intern/source/lightcuts.c 2008-07-18 19:03:50 UTC (rev 15625)
@@ -43,6 +43,7 @@
#include "PIL_time.h"
#include "RE_pipeline.h"
#include "RE_raytrace.h"
+#include "RE_render_ext.h"
#include "blendef.h"
#include "pixelshading.h"
@@ -674,6 +675,98 @@
}
}
+/*
+ * TODO: this is similar to do_lamp_tex in texture.c, which in turn is similar
+ * to do_material_tex; maybe all three functions should share most of the code
+ * but there are many subtleties there.
+ */
+static void do_lamp_tex_eval(LampRen *la, float *texvec, int osatex, float *colf)
+{
+ MTex *mtex;
+ Tex *tex;
+ TexResult texres= {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0, NULL};
+ float fact, stencilTin=1.0;
+ int tex_nr, rgb= 0;
+ float dt[3]= {0.0, 0.0, 0.0};
+
+ tex_nr= 0;
+
+ for(; tex_nr<MAX_MTEX; tex_nr++) {
+ mtex= la->mtex[tex_nr];
+ if(mtex==NULL)
+ continue;
+
+ tex= mtex->tex;
+ if(tex==NULL)
+ continue;
+
+ texres.nor= NULL;
+
+ /* NOTE: of course we ignore projection */
+
+ /* size and offset */
+ texvec[0]= mtex->size[0]*(texvec[0] + mtex->ofs[0]);
+ texvec[1]= mtex->size[1]*(texvec[1] + mtex->ofs[1]);
+ texvec[2]= mtex->size[2]*(texvec[2] + mtex->ofs[2]);
+
+ /* TODO: do we need to support osa? e.g. for high res textures */
+
+ rgb= multitex_ext(tex, texvec, dt, dt, osatex, &texres);
+
+ /* texture output */
+ if(rgb && (mtex->texflag & MTEX_RGBTOINT)) {
+ texres.tin= (0.35*texres.tr+0.45*texres.tg+0.2*texres.tb);
+ rgb= 0;
+ }
+ if(mtex->texflag & MTEX_NEGATIVE) {
+ if(rgb) {
+ texres.tr= 1.0-texres.tr;
+ texres.tg= 1.0-texres.tg;
+ texres.tb= 1.0-texres.tb;
+ }
+ else texres.tin= 1.0-texres.tin;
+ }
+ if(mtex->texflag & MTEX_STENCIL) {
+ if(rgb) {
+ fact= texres.ta;
+ texres.ta*= stencilTin;
+ stencilTin*= fact;
+ }
+ else {
+ fact= texres.tin;
+ texres.tin*= stencilTin;
+ stencilTin*= fact;
+ }
+ }
+ else {
+ if(rgb) texres.ta*= stencilTin;
+ else texres.tin*= stencilTin;
+ }
+
+ /* mapping */
+ if(mtex->mapto & LAMAP_COL) {
+ float col[3];
+
+ if(rgb==0) {
+ texres.tr= mtex->r;
+ texres.tg= mtex->g;
+ texres.tb= mtex->b;
+ }
+ else if(mtex->mapto & MAP_ALPHA) {
+ texres.tin= stencilTin;
+ }
+ else texres.tin= texres.ta;
+
+ /* lamp colors were premultiplied with this */
+ col[0]= texres.tr*la->energy;
+ col[1]= texres.tg*la->energy;
+ col[2]= texres.tb*la->energy;
+
+ texture_rgb_blend(colf, col, colf, texres.tin, mtex->colfac, mtex->blendtype);
+ }
+ }
+}
+
static void convert_area_light(Render * re, LightcutsData *lcd, LampRen *orig)
{
GroupObject *gonew;
@@ -685,8 +778,8 @@
float stepx, stepy, texvec[2];
LampRen *lar;
float density;
- Tex *tex;
int use_texture= 0;
+ int tex_nr;
density= sqrtf(re->r.lightcuts_area_density);
@@ -709,10 +802,13 @@
return;
}
- /* XXX: add multichannel/stencil/etc. support */
- if (orig->mtex[0] && orig->mtex[0]->tex) {
- tex= orig->mtex[0]->tex;
- use_texture= 1;
+ if (!(re->r.scemode & R_NO_TEX)) {
+ for(tex_nr= 0; tex_nr<MAX_MTEX; tex_nr++) {
+ if(orig->mtex[tex_nr] && orig->mtex[tex_nr]->tex) {
+ use_texture= 1;
+ break;
+ }
+ }
}
for (x=0; x<smpx; x++) {
@@ -735,17 +831,12 @@
stepy= orig->area_sizey * (texvec[1] - 0.5f);
if (use_texture) {
- int ret;
- TexResult texres= {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0, NULL};
-
- /* NOTE: not using osatex */
+ /* TODO: NOTE: not using osatex */
texvec[0]= 1.0f - texvec[0]*2.0f;
texvec[1]= texvec[1]*2.0f - 1.0f;
- ret= multitex_ext(tex, texvec, NULL, NULL, 0, &texres);
- col[0]= texres.tr * orig->energy;
- col[1]= texres.tg * orig->energy;
- col[2]= texres.tb * orig->energy;
+ col[0]= col[1]= col[2]= 0.0f;
+ do_lamp_tex_eval(orig, texvec, 0, col);
}
else {
col[0]= orig->r;
More information about the Bf-blender-cvs
mailing list