Revision: 15725
          
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=15725
Author:   joeedh
Date:     2008-07-24 02:44:12 +0200 (Thu, 24 Jul 2008)

Log Message:
-----------
strands work again

Modified Paths:
--------------
    branches/soc-2007-joeedh/source/blender/makesdna/DNA_material_types.h
    branches/soc-2007-joeedh/source/blender/makesdna/DNA_texture_types.h
    branches/soc-2007-joeedh/source/blender/render/intern/source/dsm.c
    branches/soc-2007-joeedh/source/blender/render/intern/source/texture.c
    branches/soc-2007-joeedh/source/blender/src/buttons_shading.c

Modified: branches/soc-2007-joeedh/source/blender/makesdna/DNA_material_types.h
===================================================================
--- branches/soc-2007-joeedh/source/blender/makesdna/DNA_material_types.h       
2008-07-23 22:23:28 UTC (rev 15724)
+++ branches/soc-2007-joeedh/source/blender/makesdna/DNA_material_types.h       
2008-07-24 00:44:12 UTC (rev 15725)
@@ -281,6 +281,10 @@
 #define MAP_DISPLACE   4096
 #define MAP_WARP               8192
 #define MAP_LAYER              16384
+/*interval mapping displacement, similar
+  to relief mapping, steeped parallax maps,
+  occlusion parallax maps, etc.*/
+#define MAP_IDISP              (16384*2)
 
 /* mapto for halo */
 //#define MAP_HA_COL           1

Modified: branches/soc-2007-joeedh/source/blender/makesdna/DNA_texture_types.h
===================================================================
--- branches/soc-2007-joeedh/source/blender/makesdna/DNA_texture_types.h        
2008-07-23 22:23:28 UTC (rev 15724)
+++ branches/soc-2007-joeedh/source/blender/makesdna/DNA_texture_types.h        
2008-07-24 00:44:12 UTC (rev 15725)
@@ -194,6 +194,11 @@
 
 /* **************** TEX ********************* */
 
+/*turn this on to enable a root-finding texture displacement
+  method, similar to e.g. steeped parallax maps, relief mapping,
+  occlusion parallax maps, iterative parallax maps, etc.*/
+//#define INTERVAL_MAPPING
+
 /* type */
 #define TEX_CLOUDS             1
 #define TEX_WOOD               2

Modified: branches/soc-2007-joeedh/source/blender/render/intern/source/dsm.c
===================================================================
--- branches/soc-2007-joeedh/source/blender/render/intern/source/dsm.c  
2008-07-23 22:23:28 UTC (rev 15724)
+++ branches/soc-2007-joeedh/source/blender/render/intern/source/dsm.c  
2008-07-24 00:44:12 UTC (rev 15725)
@@ -204,9 +204,11 @@
 {
        VlakRen *vlak;
        VertRen *vert;
+       StrandRen *strand= NULL;
+       StrandVert *svert;
        ObjectRen *obr;
        float imat[3][3], mat[3][3], viewinv[4][4];
-       int i, j;
+       int i, j, a;
        
        if (mode == 0) {
                Mat4SwapMat4((float*)newview, (float*)oldview);
@@ -225,6 +227,19 @@
                        MTC_Mat3MulVecfl(imat, vert->n);
                        MTC_Mat3MulVecfl(mat, vert->n);
                }
+               
+               /*do strands*/
+               for (j=0; j<obr->totstrand; j++) {
+                       if((j & 255)==0) strand= obr->strandnodes[j>>8].strand;
+                       else strand++;  
+                       
+                       svert= strand->vert;
+                       for (a=0; a < strand->totvert; a++, svert++) {
+                               MTC_Mat4MulVecfl(viewinv, svert->co);
+                               MTC_Mat4MulVecfl(newview, svert->co);
+                       }
+                       
+               }
 
                for (j=0; j<obr->totvlak; j++) {
                        vlak = RE_findOrAddVlak(obr, j);
@@ -512,6 +527,8 @@
                                        done += 1;
                                }
                        }
+
+                       printf("done: %d, lastdone: %d\n", done, lastdone);
                        if (done != lastdone) {
                                printf("bleh!\n");
                                sprintf(rendertitle, "Shadow tiles %d out of %d 
completed", done, dbuf->tilex*dbuf->tiley);

Modified: branches/soc-2007-joeedh/source/blender/render/intern/source/texture.c
===================================================================
--- branches/soc-2007-joeedh/source/blender/render/intern/source/texture.c      
2008-07-23 22:23:28 UTC (rev 15724)
+++ branches/soc-2007-joeedh/source/blender/render/intern/source/texture.c      
2008-07-24 00:44:12 UTC (rev 15725)
@@ -1451,7 +1451,235 @@
        return in;
 }
 
+/*clips ray where ray[axis] == pos */
+static void VecClipLine3f(float *v1, float *v2, int axis, float pos)
+{
+       float vec[3], t;
 
+       vec[0] = v2[0] - v1[0];
+       vec[1] = v2[1] - v1[1];
+       vec[2] = v2[2] - v1[2];
+       
+       if (vec[axis] == 0.0f) {
+               printf("bad value for VecClipLine3f!\n");
+               return;
+       }
+
+       t = (pos-v1[axis])/vec[axis];
+       v2[0] = v1[0] + vec[0]*t;
+       v2[1] = v1[1] + vec[1]*t;
+       v2[2] = v1[2] + vec[2]*t;
+}
+
+#ifdef INTERVAL_MAPPING
+static void do_interval_mapping(MTex *mtex, float *co, ShadeInput *oshi,
+                                                           float *orayvec1, 
float *warp, int steps1, 
+                                                               int steps2, 
float *no, float *dxt, float *dyt, float *tno)
+{
+       ShadeInput shi = *oshi;
+       TexResult texres= {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0, NULL}, texres2= 
{0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0, NULL};
+       TexResult midres= {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0, NULL};
+       Tex *tex = mtex->tex;
+       float rco[4], irco[3], lastirco[3], rayvec[3], orayvec[3], eco[3];
+       float mat[4][4], imat[4][4], vec[3] = {0};
+       float istep = 1.0 / steps1;
+       float co1[3], co2[3], mid[3], omid[3], oz, oz2, oz3;
+       int i, lasti = 0, rgbnor, rgbnor2, midrgbnor;
+       float tco1[3], tco2[3], invwin[4][4];
+       float negview[3], dfac = 1.0 - mtex->dispfac;
+
+       memset(mat, 0, sizeof(float)*4*4);
+       
+       VECCOPY(orayvec, orayvec1);
+
+       /*algorithm in a nutshell:
+         build a matrix to project to normalspace.
+         rotate ray vec into normalspace.
+         this gives us the height of the ray for free.
+         regularly sample the texture within this space.*/
+
+       /*in theory, the singularity issues with this
+         stupid approach shouldn't matter.  I hope.*/
+       //origin is initial point
+
+       /*origin should be 1 unit along the normal below the origin
+         coordinates*/
+       VECCOPY(mat[3], co);
+       VecSubf(mat[3], mat[3], no);
+       mat[3][3] = 1.0;
+
+       VECCOPY(mat[2], no);
+
+       //align x to x axis
+       mat[0][0] = 1.0;
+       Crossf(mat[1], mat[0], mat[2]);
+       Crossf(mat[0], mat[1], mat[2]);
+       Normalize(mat[0]);
+       Normalize(mat[1]);
+       Normalize(mat[2]);
+
+       Mat4Invert(imat, mat);
+
+#if 0
+       //this is like basic parallax mapping,
+       //though I'm not sure it's working correctly.
+       //basically, you just offset the texture coord
+       //by the view vector.
+
+       VECCOPY(negview, orayvec1);
+       //VecMulf(negview, -1);
+       Normalize(negview);
+
+       rgbnor= multitex(tex, co, dxt, dyt, shi.osatex, &texres);
+       VecMulf(negview, texres.tin*mtex->dispfac);
+       VecAddf(rco, co, negview);
+
+       Mat4MulVecfl(imat, rco);
+       rco[2] = 1.0;
+       Mat4MulVecfl(mat, rco);
+       
+       VecSubf(rco, rco, co);
+
+       VECCOPY(warp, rco);
+       return;
+#else
+       //yay! we have a matrix.  blah.
+       VECCOPY(rayvec, orayvec);
+
+       VECCOPY(rco, co);
+       
+       //rotate to planar face space
+       Mat4MulVecfl(imat, rco);
+       Mat4MulVecfl(imat, rayvec);
+
+       /*intersect ray with face*/
+       VecAddf(eco, rco, rayvec);
+       VecClipLine3f(rco, eco, 2, 0.0);
+       VecSubf(rayvec, eco, rco);
+       VecMulf(rayvec, istep);
+
+       VECCOPY(orayvec, rayvec);
+       Mat4MulVecfl(mat, orayvec);
+
+       if (G.rt == 2) printf("rco[2]: %f\n", rco[2]);
+       
+       VECCOPY(lastirco, co);
+
+       /*first step: find interval bounds*/
+       for (i=0; i<steps1; i++) {
+               oz = rco[2];
+               rco[2] = 1.0;
+               VECCOPY(irco, rco);
+
+               Mat4MulVecfl(mat, irco);
+               rgbnor= multitex(tex, irco, dxt, dyt, shi.osatex, &texres);
+               texres.tin = dfac + (1.0 - dfac) * texres.tin;
+               rco[2] = oz;
+               
+               /*restore irco to its pure, non-snapped-to-face form,
+                 as it's used outside the loop.*/
+               VECCOPY(irco, rco);
+               Mat4MulVecfl(mat, irco);
+
+               if (rco[2] <= texres.tin || rco[2] < 0) {
+                       break;
+               }               
+
+               VECCOPY(lastirco, irco);
+               VecAddf(rco, rco, rayvec);
+       }
+
+       if (G.rt == 2) printf("rco[2] post first loop: %f, tin: %f\n\n", 
rco[2], texres.tin);
+       
+       VECCOPY(co1, irco);
+       VECCOPY(co2, lastirco);
+       //VECCOPY(co1, co);
+       //VECCOPY(co2, eco);
+
+       if (G.rt == 2) {
+               VECCOPY(tco1, co1);
+               VECCOPY(tco2, co2);
+               Mat4MulVecfl(imat, tco1);
+               Mat4MulVecfl(imat, tco2);
+               printf("minz: %f, maxz: %f\n", tco1[2], tco2[2]);
+               printf("texres.tin: %f\n\n", texres.tin);
+       }
+
+       /*binary search for now*/
+       for (i=0; i<steps2; i++) {
+               VecAddf(omid, co1, co2);
+               VecMulf(omid, 0.5f);
+
+               VECCOPY(mid, omid);
+               Mat4MulVecfl(imat, mid);
+               mid[2] = 1.0;
+               Mat4MulVecfl(mat, mid);
+
+               VECCOPY(tco1, co1);
+               VECCOPY(tco2, co2);
+
+               Mat4MulVecfl(imat, tco1);
+               Mat4MulVecfl(imat, tco2);
+               tco1[2] = 1.0f;
+               tco2[2] = 1.0f;
+               Mat4MulVecfl(mat, tco2);
+               Mat4MulVecfl(mat, tco2);
+               
+               rgbnor = multitex(tex, tco1, dxt, dyt, shi.osatex, &texres);
+               texres.tin = dfac + (1.0 - dfac) * texres.tin;
+
+               rgbnor2= multitex(tex, tco2, dxt, dyt, shi.osatex, &texres2);
+               texres2.tin = dfac + (1.0 - dfac) * texres2.tin;
+
+               midrgbnor= multitex(tex, mid, dxt, dyt, shi.osatex, &midres);
+               midres.tin = dfac + (1.0 - dfac) * midres.tin;
+               
+               Mat4MulVecfl(imat, mid);
+               if (mid[2] < midres.tin) {
+                       VECCOPY(co1, omid);
+               } else {
+                       VECCOPY(co2, omid);
+               }
+       }
+       
+       VECCOPY(mid, omid);
+       Mat4MulVecfl(imat, mid);
+       if (G.rt == 2) {
+               printf("mid: %f %f %f\n", mid[0], mid[1], mid[2]);
+               printf("tin: %f\n", midres.tin);
+       }
+
+       mid[2] = 1.0;
+       Mat4MulVecfl(mat, mid);
+
+       VecSubf(vec, mid, co);
+       //VecMulf(vec, mtex->dispfac);
+       VECCOPY(warp, vec);
+       if (midres.nor) {
+               float nor[3], dot;
+
+               if(shi.mat->mode & MA_TANGENT_V) {
+                       shi.tang[0]+= tex->norfac*midres.nor[0];
+                       shi.tang[1]+= tex->norfac*midres.nor[1];
+                       shi.tang[2]+= tex->norfac*midres.nor[2];
+               }
+
+               /* prevent bump to become negative normal */
+               nor[0]= tex->norfac*midres.nor[0];
+               nor[1]= tex->norfac*midres.nor[1];
+               nor[2]= tex->norfac*midres.nor[2];
+               
+               dot= 0.5f + 0.5f*INPR(nor, shi.vn);
+               
+               nor[0]= shi.vn[0] + dot*nor[0];
+               nor[1]= shi.vn[1] + dot*nor[1];
+               nor[2]= shi.vn[2] + dot*nor[2];         
+               VECCOPY(tno, nor);
+       }
+#endif
+}
+#endif
+
 void do_material_tex(ShadeInput *shi)
 {
        MTex *mtex;
@@ -1460,11 +1688,15 @@
        float *co = NULL, *dx = NULL, *dy = NULL;
        float fact, facm, factt, facmm, stencilTin=1.0;
        float texvec[3], dxt[3], dyt[3], tempvec[3], norvec[3], 
warpvec[3]={0.0f, 0.0f, 0.0f}, Tnor=1.0;
+       /*displacement warp vector, used by interval (relief) mapping*/
+       float dispwarpvec[3] = {0.0, 0.0, 0.0}, dispwarpnor[3];
        int tex_nr, rgbnor= 0, warpdone=0;
 
        if (R.r.scemode & R_NO_TEX) return;
        /* here: test flag if there's a tex (todo) */
        
+       VECCOPY(dispwarpnor, shi->vn);
+
        for(tex_nr=0; tex_nr<MAX_MTEX; tex_nr++) {
                
                /* separate tex switching */
@@ -1671,6 +1903,15 @@
                                }
                        }
 
+#ifdef INTERVAL_MAPPING
+                       if ((mtex->mapto & MAP_IDISP)) {
+                               float ray[3];
+                               VECCOPY(ray, shi->view);
+                               do_interval_mapping(mtex, texvec, shi, ray, 
dispwarpvec, G.rt+5, 10, shi->facenor, dxt, dyt, dispwarpnor);
+                       }
+#endif
+
+                       VecAddf(texvec, texvec, dispwarpvec);
                        rgbnor= multitex(tex, texvec, dxt, dyt, shi->osatex, 
&texres);
 
                        /* texture output */
@@ -1857,12 +2098,13 @@
                                                nor[1]= 
Tnor*tex->norfac*texres.nor[1];
                                                nor[2]= 
Tnor*tex->norfac*texres.nor[2];
                                                
-                                               dot= 0.5f + 0.5f*INPR(nor, 
shi->vn);
+                                               dot= 0.5f + 0.5f*INPR(nor, 
dispwarpnor);
                                                
-                                               shi->vn[0]+= dot*nor[0];
-                                               shi->vn[1]+= dot*nor[1];
-                                               shi->vn[2]+= dot*nor[2];
-                                       }                                       
+                                               dispwarpnor[0]+= dot*nor[0];
+                                               dispwarpnor[1]+= dot*nor[1];
+                                               dispwarpnor[2]+= dot*nor[2];
+                                       }
+                                       VECCOPY(shi->vn, dispwarpnor);
                                        Normalize(shi->vn);
                                        
                                        /* this makes sure the bump is passed 
on to the next texture */


@@ Diff output truncated at 10240 characters. @@

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to