~ubuntu-branches/ubuntu/gutsy/blender/gutsy-security

« back to all changes in this revision

Viewing changes to source/blender/render/intern/source/zbuf.c

  • Committer: Bazaar Package Importer
  • Author(s): Florian Ernst
  • Date: 2007-05-17 11:47:59 UTC
  • mfrom: (1.2.6 upstream)
  • Revision ID: james.westby@ubuntu.com-20070517114759-yp4ybrnhp2u7pk66
Tags: 2.44-1
* New upstream release.
* Drop debian/patches/01_64bits_stupidity, not needed anymore: as of this
  version blender is 64 bits safe again. Adjust README.Debian accordingly.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/**
2
 
 * $Id: zbuf.c,v 1.79 2007/01/21 10:04:50 ton Exp $
 
2
 * $Id: zbuf.c,v 1.84 2007/05/03 21:37:52 blendix Exp $
3
3
 *
4
4
 * ***** BEGIN GPL LICENSE BLOCK *****
5
5
 *
51
51
#include "DNA_meshdata_types.h"
52
52
 
53
53
#include "BKE_global.h"
 
54
#include "BKE_material.h"
54
55
#include "BKE_utildefines.h"
55
56
 
56
57
#include "radio_types.h"
67
68
#include "rendercore.h"
68
69
#include "shadbuf.h"
69
70
#include "shading.h"
 
71
#include "sss.h"
70
72
 
71
73
/* own includes */
72
74
#include "zbuf.h"
1740
1742
                zspan.zofsx= -pa->disprect.xmin;
1741
1743
                zspan.zofsy= -pa->disprect.ymin;
1742
1744
        }
1743
 
        /* to centre the sample position */
 
1745
        /* to center the sample position */
1744
1746
        zspan.zofsx -= 0.5f;
1745
1747
        zspan.zofsy -= 0.5f;
1746
1748
        
1877
1879
        zspan.zofsy= -0.5f;
1878
1880
        
1879
1881
        /* the buffers */
1880
 
        zspan.rectz= vw->rectz;
1881
 
        zspan.rectp= vw->rect;
 
1882
        zspan.rectz= (int *)vw->rectz;
 
1883
        zspan.rectp= (int *)vw->rect;
1882
1884
        fillrect(zspan.rectz, vw->rectx, vw->recty, 0x7FFFFFFF);
1883
1885
        fillrect(zspan.rectp, vw->rectx, vw->recty, 0xFFFFFF);
1884
1886
        
2012
2014
        zbuf_free_span(&zspan);
2013
2015
}
2014
2016
 
 
2017
static void zbuffill_sss(ZSpan *zspan, int zvlnr, float *v1, float *v2, float *v3, float *v4)
 
2018
{
 
2019
        double zxd, zyd, zy0, z;
 
2020
        float x0, y0, x1, y1, x2, y2, z0, z1, z2, xx1, *span1, *span2;
 
2021
        int x, y, sn1, sn2, rectx= zspan->rectx, my0, my2;
 
2022
        
 
2023
        /* init */
 
2024
        zbuf_init_span(zspan);
 
2025
        
 
2026
        /* set spans */
 
2027
        zbuf_add_to_span(zspan, v1, v2);
 
2028
        zbuf_add_to_span(zspan, v2, v3);
 
2029
        if(v4) {
 
2030
                zbuf_add_to_span(zspan, v3, v4);
 
2031
                zbuf_add_to_span(zspan, v4, v1);
 
2032
        }
 
2033
        else 
 
2034
                zbuf_add_to_span(zspan, v3, v1);
 
2035
        
 
2036
        /* clipped */
 
2037
        if(zspan->minp2==NULL || zspan->maxp2==NULL) return;
 
2038
        
 
2039
        if(zspan->miny1 < zspan->miny2) my0= zspan->miny2; else my0= zspan->miny1;
 
2040
        if(zspan->maxy1 > zspan->maxy2) my2= zspan->maxy2; else my2= zspan->maxy1;
 
2041
        
 
2042
        if(my2<my0) return;
 
2043
        
 
2044
        /* ZBUF DX DY, in floats still */
 
2045
        x1= v1[0]- v2[0];
 
2046
        x2= v2[0]- v3[0];
 
2047
        y1= v1[1]- v2[1];
 
2048
        y2= v2[1]- v3[1];
 
2049
        z1= v1[2]- v2[2];
 
2050
        z2= v2[2]- v3[2];
 
2051
        
 
2052
        x0= y1*z2-z1*y2;
 
2053
        y0= z1*x2-x1*z2;
 
2054
        z0= x1*y2-y1*x2;
 
2055
        
 
2056
        if(z0==0.0f) return;
 
2057
        
 
2058
        xx1= (x0*v1[0] + y0*v1[1])/z0 + v1[2];
 
2059
        zxd= -(double)x0/(double)z0;
 
2060
        zyd= -(double)y0/(double)z0;
 
2061
        zy0= ((double)my2)*zyd + (double)xx1;
 
2062
        
 
2063
        /* correct span */
 
2064
        sn1= (my0 + my2)/2;
 
2065
        if(zspan->span1[sn1] < zspan->span2[sn1]) {
 
2066
                span1= zspan->span1+my2;
 
2067
                span2= zspan->span2+my2;
 
2068
        }
 
2069
        else {
 
2070
                span1= zspan->span2+my2;
 
2071
                span2= zspan->span1+my2;
 
2072
        }
 
2073
        
 
2074
        for(y=my2; y>=my0; y--, span1--, span2--) {
 
2075
                sn1= floor(*span1);
 
2076
                sn2= floor(*span2);
 
2077
                sn1++; 
 
2078
                
 
2079
                if(sn2>=rectx) sn2= rectx-1;
 
2080
                if(sn1<0) sn1= 0;
 
2081
                
 
2082
                z= (double)sn1*zxd + zy0;
 
2083
                
 
2084
                for(x= sn1; x<=sn2; x++, z+=zxd)
 
2085
                        zspan->sss_func(zspan->sss_handle, zvlnr, x, y, z);
 
2086
                
 
2087
                zy0 -= zyd;
 
2088
        }
 
2089
}
 
2090
 
 
2091
void zbuffer_sss(RenderPart *pa, unsigned int lay, void *handle, void (*func)(void *, int, int, int, int))
 
2092
{
 
2093
        ZSpan zspan;
 
2094
        VlakRen *vlr= NULL;
 
2095
        VertRen *v1, *v2, *v3, *v4;
 
2096
        Material *ma=0, *sss_ma= R.sss_mat;
 
2097
        short nofill=0, env=0, wire=0;
 
2098
        char *clipflag= pa->clipflag;
 
2099
        int v, zvlnr;
 
2100
        
 
2101
        zbuf_alloc_span(&zspan, pa->rectx, pa->recty);
 
2102
 
 
2103
        zspan.sss_handle= handle;
 
2104
        zspan.sss_func= func;
 
2105
        
 
2106
        /* needed for transform from hoco to zbuffer co */
 
2107
        zspan.zmulx=  ((float)R.winx)/2.0;
 
2108
        zspan.zmuly=  ((float)R.winy)/2.0;
 
2109
        
 
2110
        /* -0.5f to center the sample position */
 
2111
        zspan.zofsx= -pa->disprect.xmin - 0.5f;
 
2112
        zspan.zofsy= -pa->disprect.ymin - 0.5f;
 
2113
        
 
2114
        /* filling methods */
 
2115
        zspan.zbuffunc= zbuffill_sss;
 
2116
 
 
2117
        /* fill front and back zbuffer */
 
2118
        if(pa->rectz) {
 
2119
                fillrect(pa->rectp, pa->rectx, pa->recty, 0); 
 
2120
                fillrect(pa->rectz, pa->rectx, pa->recty, 0x7FFFFFFF);
 
2121
        }
 
2122
        if(pa->rectbackz) {
 
2123
                fillrect(pa->rectbackp, pa->rectx, pa->recty, 0); 
 
2124
                fillrect(pa->rectbackz, pa->rectx, pa->recty, -0x7FFFFFFF);
 
2125
        }
 
2126
 
 
2127
        for(v=0; v<R.totvlak; v++) {
 
2128
                if((v & 255)==0) vlr= R.vlaknodes[v>>8].vlak;
 
2129
                else vlr++;
 
2130
                
 
2131
                if((vlr->flag & R_VISIBLE) && material_in_material(vlr->mat, sss_ma)) {
 
2132
                        /* three cases, visible for render, only z values and nothing */
 
2133
                        if(vlr->lay & lay) {
 
2134
                                if(vlr->mat!=ma) {
 
2135
                                        ma= vlr->mat;
 
2136
                                        nofill= ma->mode & MA_ONLYCAST;
 
2137
                                        env= (ma->mode & MA_ENV);
 
2138
                                        wire= (ma->mode & MA_WIRE);
 
2139
                                }
 
2140
                        }
 
2141
                        else {
 
2142
                                nofill= 1;
 
2143
                                ma= NULL;       /* otherwise nofill can hang */
 
2144
                        }
 
2145
                        
 
2146
                        if(nofill==0 && wire==0 && env==0) {
 
2147
                                unsigned short partclip;
 
2148
                                
 
2149
                                v1= vlr->v1;
 
2150
                                v2= vlr->v2;
 
2151
                                v3= vlr->v3;
 
2152
                                v4= vlr->v4;
 
2153
                                
 
2154
                                /* partclipping doesn't need viewplane clipping */
 
2155
                                partclip= clipflag[v1->index] & clipflag[v2->index] & clipflag[v3->index];
 
2156
                                if(v4)
 
2157
                                        partclip &= clipflag[v4->index];
 
2158
                                
 
2159
 
 
2160
                                if(partclip==0) {
 
2161
                                        zvlnr= v+1;
 
2162
                                        zbufclip(&zspan, zvlnr, v1->ho, v2->ho, v3->ho, v1->clip, v2->clip, v3->clip);
 
2163
                                        if(v4) {
 
2164
                                                zvlnr+= RE_QUAD_OFFS;
 
2165
                                                zbufclip(&zspan, zvlnr, v1->ho, v3->ho, v4->ho, v1->clip, v3->clip, v4->clip);
 
2166
                                        }
 
2167
                                }
 
2168
                        }
 
2169
                }
 
2170
        }
 
2171
        
 
2172
        zbuf_free_span(&zspan);
 
2173
}
 
2174
 
2015
2175
/* ******************** VECBLUR ACCUM BUF ************************* */
2016
2176
 
2017
2177
typedef struct DrawBufPixel {
2579
2739
                        zspan.zofsx= -pa->disprect.xmin;
2580
2740
                        zspan.zofsy= -pa->disprect.ymin;
2581
2741
                }
2582
 
                /* to centre the sample position */
 
2742
                /* to center the sample position */
2583
2743
                zspan.zofsx -= 0.5f;
2584
2744
                zspan.zofsy -= 0.5f;
2585
2745
                
2699
2859
        }
2700
2860
}
2701
2861
 
 
2862
static void add_transp_obindex(RenderLayer *rl, int offset, int facenr)
 
2863
{
 
2864
        VlakRen *vlr= RE_findOrAddVlak(&R, (facenr-1) & RE_QUAD_MASK);
 
2865
        if(vlr && vlr->ob) {
 
2866
                RenderPass *rpass;
 
2867
                
 
2868
                for(rpass= rl->passes.first; rpass; rpass= rpass->next) {
 
2869
                        if(rpass->passtype == SCE_PASS_INDEXOB) {
 
2870
                                float *fp= rpass->rect + offset;
 
2871
                                *fp= (float)vlr->ob->index;
 
2872
                                break;
 
2873
                        }
 
2874
                }
 
2875
        }
 
2876
}
 
2877
 
2702
2878
/* ONLY OSA! merge all shaderesult samples to one */
2703
2879
/* target should have been cleared */
2704
2880
static void merge_transp_passes(RenderLayer *rl, ShadeResult *shr)
2977
3153
        
2978
3154
        fp= RE_RenderLayerGetPass(rl, SCE_PASS_VECTOR);
2979
3155
        if(fp==NULL) return;
2980
 
        col= rl->rectf+3;
 
3156
        col= rl->acolrect+3;
2981
3157
        
2982
3158
        for(a= 4*pa->rectx*pa->recty -4; a>=0; a-=4) {
2983
3159
                if(col[a]==0.0f) {
3110
3286
                                        qsort(zrow, totface, sizeof(int)*3, vergzvlak);
3111
3287
                                }
3112
3288
                                
 
3289
                                /* zbuffer and index pass for transparent, no AA or filters */
3113
3290
                                if(addzbuf)
3114
3291
                                        if(pa->rectz[od]>zrow[totface-1][0])
3115
3292
                                                pa->rectz[od]= zrow[totface-1][0];
3116
3293
                                
 
3294
                                if(addpassflag & SCE_PASS_INDEXOB)
 
3295
                                        add_transp_obindex(rl, od, zrow[totface-1][1]);
 
3296
                                
 
3297
                                
3117
3298
                                if(R.osa==0) {
3118
3299
                                        while(totface>0) {
3119
3300
                                                totface--;
3130
3311
                                                add_transp_speed(rl, od, ssamp.shr[0].winspeed, pass[3], rdrect);
3131
3312
                                }
3132
3313
                                else {
3133
 
                                        short filled, *sp= ztramask+od;
 
3314
                                        short filled, *sp= (short *)(ztramask+od);
3134
3315
                                        
3135
3316
                                        /* for each mask-sample we alpha-under colors. then in end it's added using filter */
3136
3317
                                        memset(samp_shr, 0, sizeof(ShadeResult)*R.osa);