147
if( (tex->flag & TEX_CHECKER_ODD)==0) {
148
if((xs+ys) & 1);else return retval;
158
if ( (tex->flag & TEX_CHECKER_ODD)==0) {
159
if ((xs+ys) & 1);else return retval;
150
if( (tex->flag & TEX_CHECKER_EVEN)==0) {
151
if((xs+ys) & 1) return retval;
161
if ( (tex->flag & TEX_CHECKER_EVEN)==0) {
162
if ((xs+ys) & 1) return retval;
153
164
/* scale around center, (0.5, 0.5) */
154
if(tex->checkerdist<1.0) {
155
fx= (fx-0.5)/(1.0-tex->checkerdist) +0.5;
156
fy= (fy-0.5)/(1.0-tex->checkerdist) +0.5;
165
if (tex->checkerdist<1.0f) {
166
fx= (fx-0.5f)/(1.0f-tex->checkerdist) +0.5f;
167
fy= (fy-0.5f)/(1.0f-tex->checkerdist) +0.5f;
160
x = (int)(fx*ibuf->x);
161
y = (int)(fy*ibuf->y);
171
x= xi= (int)floorf(fx*ibuf->x);
172
y= yi= (int)floorf(fy*ibuf->y);
163
if(tex->extend == TEX_CLIPCUBE) {
164
if(x<0 || y<0 || x>=ibuf->x || y>=ibuf->y || texvec[2]<-1.0 || texvec[2]>1.0) {
174
if (tex->extend == TEX_CLIPCUBE) {
175
if (x<0 || y<0 || x>=ibuf->x || y>=ibuf->y || texvec[2]<-1.0f || texvec[2]>1.0f) {
168
else if( tex->extend==TEX_CLIP || tex->extend==TEX_CHECKER) {
169
if(x<0 || y<0 || x>=ibuf->x || y>=ibuf->y) {
179
else if ( tex->extend==TEX_CLIP || tex->extend==TEX_CHECKER) {
180
if (x<0 || y<0 || x>=ibuf->x || y>=ibuf->y) {
174
if(tex->extend==TEX_EXTEND) {
175
if(x>=ibuf->x) x = ibuf->x-1;
185
if (tex->extend==TEX_EXTEND) {
186
if (x>=ibuf->x) x = ibuf->x-1;
191
if (x<0) x+= ibuf->x;
182
if(tex->extend==TEX_EXTEND) {
183
if(y>=ibuf->y) y = ibuf->y-1;
193
if (tex->extend==TEX_EXTEND) {
194
if (y>=ibuf->y) y = ibuf->y-1;
199
if (y<0) y+= ibuf->y;
192
203
/* warning, no return before setting back! */
193
if( (R.flag & R_SEC_FIELD) && (ibuf->flags & IB_fields) ) {
204
if ( (R.flag & R_SEC_FIELD) && (ibuf->flags & IB_fields) ) {
194
205
ibuf->rect+= (ibuf->x*ibuf->y);
197
ibuf_get_color(&texres->tr, ibuf, x, y);
208
/* keep this before interpolation [#29761] */
209
if (tex->imaflag & TEX_USEALPHA) {
210
if ((tex->imaflag & TEX_CALCALPHA) == 0) {
211
texres->talpha = TRUE;
216
if (tex->imaflag & TEX_INTERPOL) {
217
float filterx, filtery;
218
filterx = (0.5f * tex->filtersize) / ibuf->x;
219
filtery = (0.5f * tex->filtersize) / ibuf->y;
221
/* important that this value is wrapped [#27782]
222
* this applies the modifications made by the checks above,
223
* back to the floating point values */
224
fx -= (float)(xi - x) / (float)ibuf->x;
225
fy -= (float)(yi - y) / (float)ibuf->y;
227
boxsample(ibuf, fx-filterx, fy-filtery, fx+filterx, fy+filtery, texres, (tex->extend==TEX_REPEAT), (tex->extend==TEX_EXTEND));
229
else { /* no filtering */
230
ibuf_get_color(&texres->tr, ibuf, x, y);
199
if( (R.flag & R_SEC_FIELD) && (ibuf->flags & IB_fields) ) {
233
if ( (R.flag & R_SEC_FIELD) && (ibuf->flags & IB_fields) ) {
200
234
ibuf->rect-= (ibuf->x*ibuf->y);
203
if(tex->imaflag & TEX_USEALPHA) {
204
if(tex->imaflag & TEX_CALCALPHA);
205
else texres->talpha= 1;
209
if(tex->imaflag & TEX_NORMALMAP) {
238
if (tex->imaflag & TEX_NORMALMAP) {
210
239
// qdn: normal from color
211
texres->nor[0] = 2.f*(texres->tr - 0.5f);
212
texres->nor[1] = 2.f*(0.5f - texres->tg);
240
// The invert of the red channel is to make
241
// the normal map compliant with the outside world.
242
// It needs to be done because in Blender
243
// the normal used in the renderer points inward. It is generated
244
// this way in calc_vertexnormals(). Should this ever change
245
// this negate must be removed.
246
texres->nor[0] = -2.f*(texres->tr - 0.5f);
247
texres->nor[1] = 2.f*(texres->tg - 0.5f);
213
248
texres->nor[2] = 2.f*(texres->tb - 0.5f);
216
251
/* bump: take three samples */
217
252
val1= texres->tr+texres->tg+texres->tb;
221
256
ibuf_get_color(col, ibuf, x+1, y);
222
257
val2= (col[0]+col[1]+col[2]);
228
263
ibuf_get_color(col, ibuf, x, y+1);
229
264
val3= (col[0]+col[1]+col[2]);
430
465
starty= (int)floor(rf->ymin);
431
466
endy= (int)floor(rf->ymax);
433
if(startx < 0) startx= 0;
434
if(starty < 0) starty= 0;
435
if(endx>=ibuf->x) endx= ibuf->x-1;
436
if(endy>=ibuf->y) endy= ibuf->y-1;
468
if (startx < 0) startx= 0;
469
if (starty < 0) starty= 0;
470
if (endx>=ibuf->x) endx= ibuf->x-1;
471
if (endy>=ibuf->y) endy= ibuf->y-1;
438
if(starty==endy && startx==endx) {
473
if (starty==endy && startx==endx) {
439
474
ibuf_get_color(&texres->tr, ibuf, startx, starty);
442
477
div= texres->tr= texres->tg= texres->tb= texres->ta= 0.0;
443
for(y=starty; y<=endy; y++) {
478
for (y=starty; y<=endy; y++) {
449
if(y==starty) muly= 1.0f-(rf->ymin - y);
450
if(y==endy) muly= (rf->ymax - y);
484
if (y==starty) muly= 1.0f-(rf->ymin - y);
485
if (y==endy) muly= (rf->ymax - y);
456
491
ibuf_get_color(col, ibuf, startx, y);
503
static void boxsample(ImBuf *ibuf, float minx, float miny, float maxx, float maxy, TexResult *texres, int imaprepeat, int imapextend, int intpol)
538
static void boxsample(ImBuf *ibuf, float minx, float miny, float maxx, float maxy, TexResult *texres, const short imaprepeat, const short imapextend)
505
540
/* Sample box, performs clip. minx etc are in range 0.0 - 1.0 .
506
* Enlarge with antialiased edges of pixels.
507
* If variable 'imaprepeat' has been set, the
508
* clipped-away parts are sampled as well.
510
/* note: actually minx etc isnt in the proper range... this due to filter size and offset vectors for bump */
541
* Enlarge with antialiased edges of pixels.
542
* If variable 'imaprepeat' has been set, the
543
* clipped-away parts are sampled as well.
545
/* note: actually minx etc isn't in the proper range... this due to filter size and offset vectors for bump */
546
/* note: talpha must be initialized */
547
/* note: even when 'imaprepeat' is set, this can only repeate once in any direction.
548
* the point which min/max is derived from is assumed to be wrapped */
512
550
rctf *rf, stack[8];
513
551
float opp, tot, alphaclip= 1.0;
517
rf->xmin= minx*(ibuf->x);
518
rf->xmax= maxx*(ibuf->x);
519
rf->ymin= miny*(ibuf->y);
520
rf->ymax= maxy*(ibuf->y);
555
rf->xmin = minx*(ibuf->x);
556
rf->xmax = maxx*(ibuf->x);
557
rf->ymin = miny*(ibuf->y);
558
rf->ymax = maxy*(ibuf->y);
522
560
texr.talpha= texres->talpha; /* is read by boxsample_clip */
525
563
CLAMP(rf->xmin, 0.0f, ibuf->x-1);
526
564
CLAMP(rf->xmax, 0.0f, ibuf->x-1);
529
567
clipx_rctf_swap(stack, &count, 0.0, (float)(ibuf->x));
531
569
alphaclip= clipx_rctf(rf, 0.0, (float)(ibuf->x));
571
if (alphaclip<=0.0f) {
534
572
texres->tr= texres->tb= texres->tg= texres->ta= 0.0;
540
578
CLAMP(rf->ymin, 0.0f, ibuf->y-1);
541
579
CLAMP(rf->ymax, 0.0f, ibuf->y-1);
544
582
clipy_rctf_swap(stack, &count, 0.0, (float)(ibuf->y));
546
584
alphaclip*= clipy_rctf(rf, 0.0, (float)(ibuf->y));
586
if (alphaclip<=0.0f) {
549
587
texres->tr= texres->tb= texres->tg= texres->ta= 0.0;
555
593
tot= texres->tr= texres->tb= texres->tg= texres->ta= 0.0;
557
595
boxsampleclip(ibuf, rf, &texr);
559
597
opp= square_rctf(rf);
963
static int imagewraposa_aniso(Tex *tex, Image *ima, ImBuf *ibuf, float *texvec, float *dxt, float *dyt, TexResult *texres)
1001
static void image_mipmap_test(Tex *tex, ImBuf *ibuf)
1003
if (tex->imaflag & TEX_MIPMAP) {
1004
if ((ibuf->flags & IB_fields) == 0) {
1006
if (ibuf->mipmap[0] && (ibuf->userflags & IB_MIPMAP_INVALID)) {
1007
BLI_lock_thread(LOCK_IMAGE);
1008
if (ibuf->userflags & IB_MIPMAP_INVALID) {
1009
IMB_remakemipmap(ibuf, tex->imaflag & TEX_GAUSS_MIP);
1010
ibuf->userflags &= ~IB_MIPMAP_INVALID;
1012
BLI_unlock_thread(LOCK_IMAGE);
1014
if (ibuf->mipmap[0] == NULL) {
1015
BLI_lock_thread(LOCK_IMAGE);
1016
if (ibuf->mipmap[0] == NULL)
1017
IMB_makemipmap(ibuf, tex->imaflag & TEX_GAUSS_MIP);
1018
BLI_unlock_thread(LOCK_IMAGE);
1025
static int imagewraposa_aniso(Tex *tex, Image *ima, ImBuf *ibuf, const float texvec[3], float dxt[3], float dyt[3], TexResult *texres)
966
1028
float fx, fy, minx, maxx, miny, maxy;
1374
1434
retval= texres->nor?3:1;
1376
1436
/* quick tests */
1377
if(ibuf==NULL && ima==NULL)
1437
if (ibuf==NULL && ima==NULL)
1381
1441
/* hack for icon render */
1382
if(ima->ibufs.first==NULL && (R.r.scemode & R_NO_IMAGE_LOAD))
1442
if (ima->ibufs.first==NULL && (R.r.scemode & R_NO_IMAGE_LOAD))
1385
1445
ibuf= BKE_image_get_ibuf(ima, &tex->iuser);
1447
ima->flag|= IMA_USED_FOR_RENDER;
1387
if(ibuf==NULL || (ibuf->rect==NULL && ibuf->rect_float==NULL))
1449
if (ibuf==NULL || (ibuf->rect==NULL && ibuf->rect_float==NULL))
1390
1452
/* mipmap test */
1391
if (tex->imaflag & TEX_MIPMAP) {
1392
if(ibuf->flags & IB_fields);
1393
else if(ibuf->mipmap[0]==NULL) {
1394
BLI_lock_thread(LOCK_IMAGE);
1396
if(ibuf->mipmap[0]==NULL)
1397
IMB_makemipmap(ibuf, tex->imaflag & TEX_GAUSS_MIP);
1399
BLI_unlock_thread(LOCK_IMAGE);
1403
if(tex->imaflag & TEX_USEALPHA) {
1404
if(tex->imaflag & TEX_CALCALPHA);
1453
image_mipmap_test(tex, ibuf);
1455
if (tex->imaflag & TEX_USEALPHA) {
1456
if (tex->imaflag & TEX_CALCALPHA);
1405
1457
else texres->talpha= 1;
1408
1460
texr.talpha= texres->talpha;
1410
if(tex->imaflag & TEX_IMAROT) {
1462
if (tex->imaflag & TEX_IMAROT) {
1458
1510
dyt[1]*= tex->filtersize;
1461
if(tex->imaflag & TEX_IMAROT) SWAP(float, minx, miny);
1513
if (tex->imaflag & TEX_IMAROT) SWAP(float, minx, miny);
1463
if(minx>0.25) minx= 0.25;
1464
else if(minx<0.00001f) minx= 0.00001f; /* side faces of unit-cube */
1465
if(miny>0.25) miny= 0.25;
1466
else if(miny<0.00001f) miny= 0.00001f;
1515
if (minx>0.25f) minx= 0.25f;
1516
else if (minx<0.00001f) minx= 0.00001f; /* side faces of unit-cube */
1517
if (miny>0.25f) miny= 0.25f;
1518
else if (miny<0.00001f) miny= 0.00001f;
1469
1521
/* repeat and clip */
1470
1522
imaprepeat= (tex->extend==TEX_REPEAT);
1471
1523
imapextend= (tex->extend==TEX_EXTEND);
1473
if(tex->extend == TEX_REPEAT) {
1474
if(tex->flag & (TEX_REPEAT_XMIR|TEX_REPEAT_YMIR)) {
1525
if (tex->extend == TEX_REPEAT) {
1526
if (tex->flag & (TEX_REPEAT_XMIR|TEX_REPEAT_YMIR)) {
1480
if(tex->extend == TEX_CHECKER) {
1532
if (tex->extend == TEX_CHECKER) {
1481
1533
int xs, ys, xs1, ys1, xs2, ys2, boundary;
1483
1535
xs= (int)floor(fx);
1484
1536
ys= (int)floor(fy);
1486
1538
// both checkers available, no boundary exceptions, checkerdist will eat aliasing
1487
if( (tex->flag & TEX_CHECKER_ODD) && (tex->flag & TEX_CHECKER_EVEN) ) {
1539
if ( (tex->flag & TEX_CHECKER_ODD) && (tex->flag & TEX_CHECKER_EVEN) ) {
1496
1548
ys2= (int)floor(fy+miny);
1497
1549
boundary= (xs1!=xs2) || (ys1!=ys2);
1500
if( (tex->flag & TEX_CHECKER_ODD)==0) {
1552
if ( (tex->flag & TEX_CHECKER_ODD)==0) {
1502
1554
else return retval;
1504
if( (tex->flag & TEX_CHECKER_EVEN)==0) {
1505
if((xs+ys) & 1) return retval;
1556
if ( (tex->flag & TEX_CHECKER_EVEN)==0) {
1557
if ((xs+ys) & 1) return retval;
1511
if(tex->flag & TEX_CHECKER_ODD) {
1512
if((xs1+ys) & 1) fx-= xs2;
1563
if (tex->flag & TEX_CHECKER_ODD) {
1564
if ((xs1+ys) & 1) fx-= xs2;
1515
if((ys1+xs) & 1) fy-= ys2;
1567
if ((ys1+xs) & 1) fy-= ys2;
1518
if(tex->flag & TEX_CHECKER_EVEN) {
1519
if((xs1+ys) & 1) fx-= xs1;
1570
if (tex->flag & TEX_CHECKER_EVEN) {
1571
if ((xs1+ys) & 1) fx-= xs1;
1522
if((ys1+xs) & 1) fy-= ys1;
1574
if ((ys1+xs) & 1) fy-= ys1;
1528
1580
/* scale around center, (0.5, 0.5) */
1529
if(tex->checkerdist<1.0) {
1530
fx= (fx-0.5)/(1.0-tex->checkerdist) +0.5;
1531
fy= (fy-0.5)/(1.0-tex->checkerdist) +0.5;
1532
minx/= (1.0-tex->checkerdist);
1533
miny/= (1.0-tex->checkerdist);
1581
if (tex->checkerdist<1.0f) {
1582
fx= (fx-0.5f)/(1.0f-tex->checkerdist) +0.5f;
1583
fy= (fy-0.5f)/(1.0f-tex->checkerdist) +0.5f;
1584
minx/= (1.0f-tex->checkerdist);
1585
miny/= (1.0f-tex->checkerdist);
1537
if(tex->extend == TEX_CLIPCUBE) {
1538
if(fx+minx<0.0 || fy+miny<0.0 || fx-minx>1.0 || fy-miny>1.0 || texvec[2]<-1.0 || texvec[2]>1.0) {
1589
if (tex->extend == TEX_CLIPCUBE) {
1590
if (fx+minx<0.0f || fy+miny<0.0f || fx-minx>1.0f || fy-miny>1.0f || texvec[2]<-1.0f || texvec[2]>1.0f) {
1542
else if(tex->extend==TEX_CLIP || tex->extend==TEX_CHECKER) {
1543
if(fx+minx<0.0 || fy+miny<0.0 || fx-minx>1.0 || fy-miny>1.0) {
1594
else if (tex->extend==TEX_CLIP || tex->extend==TEX_CHECKER) {
1595
if (fx+minx<0.0f || fy+miny<0.0f || fx-minx>1.0f || fy-miny>1.0f) {
1549
if(fx>1.0) fx = 1.0;
1550
else if(fx<0.0) fx= 0.0;
1601
if (fx>1.0f) fx = 1.0f;
1602
else if (fx<0.0f) fx= 0.0f;
1553
if(fx>1.0) fx -= (int)(fx);
1554
else if(fx<0.0) fx+= 1-(int)(fx);
1605
if (fx>1.0f) fx -= (int)(fx);
1606
else if (fx<0.0f) fx+= 1-(int)(fx);
1558
if(fy>1.0) fy = 1.0;
1559
else if(fy<0.0) fy= 0.0;
1610
if (fy>1.0f) fy = 1.0f;
1611
else if (fy<0.0f) fy= 0.0f;
1562
if(fy>1.0) fy -= (int)(fy);
1563
else if(fy<0.0) fy+= 1-(int)(fy);
1614
if (fy>1.0f) fy -= (int)(fy);
1615
else if (fy<0.0f) fy+= 1-(int)(fy);
1567
1619
/* warning no return! */
1568
if( (R.flag & R_SEC_FIELD) && (ibuf->flags & IB_fields) ) {
1620
if ( (R.flag & R_SEC_FIELD) && (ibuf->flags & IB_fields) ) {
1569
1621
ibuf->rect+= (ibuf->x*ibuf->y);
1573
if(tex->imaflag & TEX_MIPMAP) {
1625
if (tex->imaflag & TEX_MIPMAP) {
1574
1626
ImBuf *previbuf, *curibuf;
1575
1627
float bumpscale;
1579
1631
maxd= MAX2(dx, dy);
1580
if(maxd>0.5) maxd= 0.5;
1632
if (maxd>0.5f) maxd= 0.5f;
1582
1634
pixsize = 1.0f/ (float) MIN2(ibuf->x, ibuf->y);
1584
1636
bumpscale= pixsize/maxd;
1585
if(bumpscale>1.0f) bumpscale= 1.0f;
1637
if (bumpscale>1.0f) bumpscale= 1.0f;
1586
1638
else bumpscale*=bumpscale;
1589
1641
previbuf= curibuf= ibuf;
1590
while(curmap<IB_MIPMAP_LEVELS && ibuf->mipmap[curmap]) {
1591
if(maxd < pixsize) break;
1642
while (curmap<IB_MIPMAP_LEVELS && ibuf->mipmap[curmap]) {
1643
if (maxd < pixsize) break;
1592
1644
previbuf= curibuf;
1593
1645
curibuf= ibuf->mipmap[curmap];
1594
1646
pixsize= 1.0f / (float)MIN2(curibuf->x, curibuf->y);
1598
if(previbuf!=curibuf || (tex->imaflag & TEX_INTERPOL)) {
1650
if (previbuf!=curibuf || (tex->imaflag & TEX_INTERPOL)) {
1599
1651
/* sample at least 1 pixel */
1600
1652
if (minx < 0.5f / ibuf->x) minx = 0.5f / ibuf->x;
1601
1653
if (miny < 0.5f / ibuf->y) miny = 0.5f / ibuf->y;
1604
if(texres->nor && (tex->imaflag & TEX_NORMALMAP)==0) {
1656
if (texres->nor && (tex->imaflag & TEX_NORMALMAP)==0) {
1605
1657
/* a bit extra filter */
1606
1658
//minx*= 1.35f;
1607
1659
//miny*= 1.35f;
1609
boxsample(curibuf, fx-minx, fy-miny, fx+minx, fy+miny, texres, imaprepeat, imapextend, 0);
1661
boxsample(curibuf, fx-minx, fy-miny, fx+minx, fy+miny, texres, imaprepeat, imapextend);
1610
1662
val1= texres->tr+texres->tg+texres->tb;
1611
boxsample(curibuf, fx-minx+dxt[0], fy-miny+dxt[1], fx+minx+dxt[0], fy+miny+dxt[1], &texr, imaprepeat, imapextend, 0);
1663
boxsample(curibuf, fx-minx+dxt[0], fy-miny+dxt[1], fx+minx+dxt[0], fy+miny+dxt[1], &texr, imaprepeat, imapextend);
1612
1664
val2= texr.tr + texr.tg + texr.tb;
1613
boxsample(curibuf, fx-minx+dyt[0], fy-miny+dyt[1], fx+minx+dyt[0], fy+miny+dyt[1], &texr, imaprepeat, imapextend, 0);
1665
boxsample(curibuf, fx-minx+dyt[0], fy-miny+dyt[1], fx+minx+dyt[0], fy+miny+dyt[1], &texr, imaprepeat, imapextend);
1614
1666
val3= texr.tr + texr.tg + texr.tb;
1616
1668
/* don't switch x or y! */
1617
1669
texres->nor[0]= (val1-val2);
1618
1670
texres->nor[1]= (val1-val3);
1620
if(previbuf!=curibuf) { /* interpolate */
1672
if (previbuf!=curibuf) { /* interpolate */
1622
boxsample(previbuf, fx-minx, fy-miny, fx+minx, fy+miny, &texr, imaprepeat, imapextend, 0);
1674
boxsample(previbuf, fx-minx, fy-miny, fx+minx, fy+miny, &texr, imaprepeat, imapextend);
1625
1677
dx= 2.0f*(pixsize-maxd)/pixsize;
1627
1679
texres->ta= texr.ta; texres->tb= texr.tb;
1628
1680
texres->tg= texr.tg; texres->tr= texr.tr;
1638
1690
val1= dy*val1+ dx*(texr.tr + texr.tg + texr.tb);
1639
boxsample(previbuf, fx-minx+dxt[0], fy-miny+dxt[1], fx+minx+dxt[0], fy+miny+dxt[1], &texr, imaprepeat, imapextend, 0);
1691
boxsample(previbuf, fx-minx+dxt[0], fy-miny+dxt[1], fx+minx+dxt[0], fy+miny+dxt[1], &texr, imaprepeat, imapextend);
1640
1692
val2= dy*val2+ dx*(texr.tr + texr.tg + texr.tb);
1641
boxsample(previbuf, fx-minx+dyt[0], fy-miny+dyt[1], fx+minx+dyt[0], fy+miny+dyt[1], &texr, imaprepeat, imapextend, 0);
1693
boxsample(previbuf, fx-minx+dyt[0], fy-miny+dyt[1], fx+minx+dyt[0], fy+miny+dyt[1], &texr, imaprepeat, imapextend);
1642
1694
val3= dy*val3+ dx*(texr.tr + texr.tg + texr.tb);
1644
1696
texres->nor[0]= (val1-val2); /* vals have been interpolated above! */
1645
1697
texres->nor[1]= (val1-val3);
1649
1701
texres->tb= dy*texres->tb+ dx*texr.tb;
1650
1702
texres->tg= dy*texres->tg+ dx*texr.tg;
1664
boxsample(curibuf, minx, miny, maxx, maxy, texres, imaprepeat, imapextend, 0);
1716
boxsample(curibuf, minx, miny, maxx, maxy, texres, imaprepeat, imapextend);
1666
if(previbuf!=curibuf) { /* interpolate */
1667
boxsample(previbuf, minx, miny, maxx, maxy, &texr, imaprepeat, imapextend, 0);
1718
if (previbuf!=curibuf) { /* interpolate */
1719
boxsample(previbuf, minx, miny, maxx, maxy, &texr, imaprepeat, imapextend);
1669
1721
fx= 2.0f*(pixsize-maxd)/pixsize;
1672
1724
texres->ta= texr.ta; texres->tb= texr.tb;
1673
1725
texres->tg= texr.tg; texres->tr= texr.tr;
1676
1729
texres->tb= fy*texres->tb+ fx*texr.tb;
1677
1730
texres->tg= fy*texres->tg+ fx*texr.tg;
1689
1742
if (miny < 0.5f / ibuf->y) miny = 0.5f / ibuf->y;
1692
if(texres->nor && (tex->imaflag & TEX_NORMALMAP)==0) {
1693
boxsample(ibuf, fx-minx, fy-miny, fx+minx, fy+miny, texres, imaprepeat, imapextend, 0);
1745
if (texres->nor && (tex->imaflag & TEX_NORMALMAP)==0) {
1746
boxsample(ibuf, fx-minx, fy-miny, fx+minx, fy+miny, texres, imaprepeat, imapextend);
1694
1747
val1= texres->tr+texres->tg+texres->tb;
1695
boxsample(ibuf, fx-minx+dxt[0], fy-miny+dxt[1], fx+minx+dxt[0], fy+miny+dxt[1], &texr, imaprepeat, imapextend, 0);
1748
boxsample(ibuf, fx-minx+dxt[0], fy-miny+dxt[1], fx+minx+dxt[0], fy+miny+dxt[1], &texr, imaprepeat, imapextend);
1696
1749
val2= texr.tr + texr.tg + texr.tb;
1697
boxsample(ibuf, fx-minx+dyt[0], fy-miny+dyt[1], fx+minx+dyt[0], fy+miny+dyt[1], &texr, imaprepeat, imapextend, 0);
1750
boxsample(ibuf, fx-minx+dyt[0], fy-miny+dyt[1], fx+minx+dyt[0], fy+miny+dyt[1], &texr, imaprepeat, imapextend);
1698
1751
val3= texr.tr + texr.tg + texr.tb;
1700
1753
/* don't switch x or y! */
1702
1755
texres->nor[1]= (val1-val3);
1705
boxsample(ibuf, fx-minx, fy-miny, fx+minx, fy+miny, texres, imaprepeat, imapextend, 0);
1758
boxsample(ibuf, fx-minx, fy-miny, fx+minx, fy+miny, texres, imaprepeat, imapextend);
1708
if(tex->imaflag & TEX_CALCALPHA) {
1761
if (tex->imaflag & TEX_CALCALPHA) {
1709
1762
texres->ta= texres->tin= texres->ta*MAX3(texres->tr, texres->tg, texres->tb);
1711
1764
else texres->tin= texres->ta;
1713
if(tex->flag & TEX_NEGALPHA) texres->ta= 1.0f-texres->ta;
1766
if (tex->flag & TEX_NEGALPHA) texres->ta= 1.0f-texres->ta;
1715
if( (R.flag & R_SEC_FIELD) && (ibuf->flags & IB_fields) ) {
1768
if ( (R.flag & R_SEC_FIELD) && (ibuf->flags & IB_fields) ) {
1716
1769
ibuf->rect-= (ibuf->x*ibuf->y);
1719
if(texres->nor && (tex->imaflag & TEX_NORMALMAP)) {
1772
if (texres->nor && (tex->imaflag & TEX_NORMALMAP)) {
1720
1773
// qdn: normal from color
1721
texres->nor[0] = 2.f*(texres->tr - 0.5f);
1722
texres->nor[1] = 2.f*(0.5f - texres->tg);
1774
// The invert of the red channel is to make
1775
// the normal map compliant with the outside world.
1776
// It needs to be done because in Blender
1777
// the normal used in the renderer points inward. It is generated
1778
// this way in calc_vertexnormals(). Should this ever change
1779
// this negate must be removed.
1780
texres->nor[0] = -2.f*(texres->tr - 0.5f);
1781
texres->nor[1] = 2.f*(texres->tg - 0.5f);
1723
1782
texres->nor[2] = 2.f*(texres->tb - 0.5f);
1726
1785
/* de-premul, this is being premulled in shade_input_do_shade() */
1727
if(texres->ta!=1.0f && texres->ta>FLT_EPSILON) {
1786
if (texres->ta!=1.0f && texres->ta>1e-4f) {
1728
1787
fx= 1.0f/texres->ta;
1729
1788
texres->tr*= fx;
1730
1789
texres->tg*= fx;
1741
1800
TexResult texres;
1742
1801
ImBuf *ibuf= BKE_image_get_ibuf(ima, NULL);
1745
1804
result[0]= result[1]= result[2]= result[3]= 0.0f;
1749
if( (R.flag & R_SEC_FIELD) && (ibuf->flags & IB_fields) )
1808
if ( (R.flag & R_SEC_FIELD) && (ibuf->flags & IB_fields) )
1750
1809
ibuf->rect+= (ibuf->x*ibuf->y);
1752
boxsample(ibuf, fx, fy, fx+dx, fy+dy, &texres, 0, 1, 0);
1811
texres.talpha= 1; /* boxsample expects to be initialized */
1812
boxsample(ibuf, fx, fy, fx+dx, fy+dy, &texres, 0, 1);
1753
1813
result[0]= texres.tr;
1754
1814
result[1]= texres.tg;
1755
1815
result[2]= texres.tb;
1756
1816
result[3]= texres.ta;
1758
if( (R.flag & R_SEC_FIELD) && (ibuf->flags & IB_fields) )
1818
if ( (R.flag & R_SEC_FIELD) && (ibuf->flags & IB_fields) )
1759
1819
ibuf->rect-= (ibuf->x*ibuf->y);
1821
ima->flag|= IMA_USED_FOR_RENDER;
1762
1824
void ibuf_sample(ImBuf *ibuf, float fx, float fy, float dx, float dy, float *result)