Phew, a lot of work, and no new features...

Main target was to make the inner rendering loop using no globals anymore.
This is essential for proper usage while raytracing, it caused a lot of
hacks in the raycode as well, which even didn't work correctly for all
situations (textures especially).

Done this by creating a new local struct RenderInput, which replaces usage
of the global struct Render R. The latter now only is used to denote
image size, viewmatrix, and the like.

Making the inner render loops using no globals caused 1000s of vars to
be changed... but the result definitely is much nicer code, which enables
making 'real' shaders in a next stage.
It also enabled me to remove the hacks from ray.c

Then i went to the task of removing redundant code. Especially the calculus
of texture coords took place (identical) in three locations.
Most obvious is the change in the unified render part, which is much less
code now; it uses the same rendering routines as normal render now.
(Note; not for halos yet!)

I also removed 6 files called 'shadowbuffer' something. This was experimen-
tal stuff from NaN days. And again saved a lot of double used code.

Finally I went over the blenkernel and blender/src calls to render stuff.
Here the same local data is used now, resulting in less dependency.
I also moved render-texture to the render module, this was still in Kernel.
(new file: texture.c)

So! After this commit I will check on the autofiles, to try to fix that.
MSVC people have to do it themselves.
This commit will need quite some testing help, but I'm around!
This commit is contained in:
Ton Roosendaal 2003-12-21 21:52:51 +00:00
parent 16eec383fd
commit ec99255c27
47 changed files with 3067 additions and 5750 deletions

View File

@ -244,7 +244,6 @@ typedef struct Global {
#define B_ENDIAN 0
/* G.special1 */
#define G_HOLO 1
/* Memory is allocated where? blender.c */
extern Global G;

View File

@ -59,29 +59,6 @@ struct MTex *add_mtex(void);
struct Tex *copy_texture(struct Tex *tex);
void make_local_texture(struct Tex *tex);
void autotexname(struct Tex *tex);
void init_render_texture(struct Tex *tex);
void init_render_textures(void);
void end_render_texture(struct Tex *tex);
void end_render_textures(void);
int clouds(struct Tex *tex, float *texvec);
int blend(struct Tex *tex, float *texvec);
int wood(struct Tex *tex, float *texvec);
int marble(struct Tex *tex, float *texvec);
int magic(struct Tex *tex, float *texvec);
int stucci(struct Tex *tex, float *texvec);
int texnoise(struct Tex *tex);
int plugintex(struct Tex *tex, float *texvec, float *dxt, float *dyt);
void tubemap(float x, float y, float z, float *adr1, float *adr2);
void spheremap(float x, float y, float z, float *adr1, float *adr2);
void do_2d_mapping(struct MTex *mtex, float *t, float *dxt, float *dyt);
int multitex(struct Tex *tex, float *texvec, float *dxt, float *dyt);
void do_material_tex(void);
void do_halo_tex(struct HaloRen *har, float xn, float yn, float *colf);
void do_sky_tex(void);
void do_lamp_tex(struct LampRen *la, float *lavec);
void externtex(struct MTex *mtex, float *vec);
void externtexcol(struct MTex *mtex, float *orco, char *col);
void render_realtime_texture(void);
#endif

View File

@ -90,13 +90,6 @@ ListBase editNurb;
#include "render_types.h"
struct RE_Render R;
float Phong_Spec(float *n, float *l, float *v, int hard){return 0;}
float Blinn_Spec(float *n, float *l, float *v, float a, float b){return 0;}
float CookTorr_Spec(float *n, float *l, float *v, int hard){return 0;}
float Toon_Spec(float *n, float *l, float *v, float a, float b){return 0;}
float Toon_Diff(float *n, float *l, float *v, float a, float b){return 0;}
float OrenNayar_Diff(float *n, float *l, float *v, float a, float b){return 0;}
void waitcursor(int val){}
void allqueue(unsigned short event, short val){}
#define REDRAWVIEW3D 0x4010

View File

@ -46,9 +46,6 @@
#endif
#include "MEM_guardedalloc.h"
#include "nla.h" /* For __NLA: Please do not remove yet */
#include "render.h"
#include "IMB_imbuf_types.h"
#include "DNA_texture_types.h"
@ -88,6 +85,10 @@
#include "BKE_scene.h"
#include "BKE_subsurf.h"
#include "nla.h" /* For __NLA: Please do not remove yet */
#include "render.h"
/***/
typedef struct _FastLamp FastLamp;
@ -226,8 +227,6 @@ static void initfastshade(void)
FastLamp *fl;
float mat[4][4];
R.vlr= 0;
init_render_world();
if(fastlamplist) return;
@ -301,16 +300,18 @@ void freefastshade()
static void fastshade(float *co, float *nor, float *orco, Material *ma, char *col1, char *col2, char *vertcol)
{
ShadeInput shi;
FastLamp *fl;
float i, t, inp, soft, inpr, inpg, inpb, isr=0, isg=0, isb=0, lv[3], view[3], lampdist, ld;
float inpr1, inpg1, inpb1, isr1=0, isg1=0, isb1=0;
int a, back;
if(ma==0) return;
R.mat= ma;
R.matren= ma->ren;
ma= R.matren;
shi.mat= ma;
shi.matren= ma->ren;
shi.vlr= NULL; // have to do this!
ma= shi.matren;
if(ma->mode & MA_VERTEXCOLP) {
if(vertcol) {
ma->r= vertcol[3]/255.0;
@ -320,41 +321,41 @@ static void fastshade(float *co, float *nor, float *orco, Material *ma, char *co
}
if(ma->texco) {
VECCOPY(R.lo, orco);
VECCOPY(R.vn, nor);
VECCOPY(shi.lo, orco);
VECCOPY(shi.vn, nor);
if(ma->texco & TEXCO_GLOB) {
VECCOPY(R.gl, R.lo);
VECCOPY(shi.gl, shi.lo);
}
if(ma->texco & TEXCO_WINDOW) {
VECCOPY(R.winco, R.lo);
VECCOPY(shi.winco, shi.lo);
}
if(ma->texco & TEXCO_STICKY) {
VECCOPY(R.sticky, R.lo);
VECCOPY(shi.sticky, shi.lo);
}
if(ma->texco & TEXCO_UV) {
VECCOPY(R.uv, R.lo);
VECCOPY(shi.uv, shi.lo);
}
if(ma->texco & TEXCO_OBJECT) {
VECCOPY(R.co, R.lo);
VECCOPY(shi.co, shi.lo);
}
if(ma->texco & TEXCO_NORM) {
VECCOPY(R.orn, R.vn);
VECCOPY(shi.orn, shi.vn);
}
if(ma->texco & TEXCO_REFL) {
inp= 2.0*(R.vn[2]);
R.ref[0]= (inp*R.vn[0]);
R.ref[1]= (inp*R.vn[1]);
R.ref[2]= (-1.0+inp*R.vn[2]);
inp= 2.0*(shi.vn[2]);
shi.ref[0]= (inp*shi.vn[0]);
shi.ref[1]= (inp*shi.vn[1]);
shi.ref[2]= (-1.0+inp*shi.vn[2]);
}
if(ma->mode & MA_VERTEXCOLP) {
R.mat->r= ma->r;
R.mat->g= ma->g;
R.mat->b= ma->b;
shi.mat->r= ma->r;
shi.mat->g= ma->g;
shi.mat->b= ma->b;
}
do_material_tex();
do_material_tex(&shi);
}
if(ma->mode & MA_SHLESS) {

View File

@ -59,12 +59,13 @@
#include "BKE_key.h"
#include "BKE_ipo.h"
#include "BKE_screen.h"
#include "BKE_texture.h"
#include "BKE_blender.h"
#include "BKE_object.h"
#include "BKE_displist.h"
#include "BKE_lattice.h"
#include "render.h"
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

View File

@ -683,7 +683,8 @@ static void read_videoscape_nurbs(char *str)
static void read_videoscape(char *str)
{
int file, type;
unsigned int val, numlen;
unsigned int val;
unsigned short numlen;
char name[FILE_MAXDIR+FILE_MAXFILE], head[FILE_MAXFILE], tail[FILE_MAXFILE];
strcpy(name, str);
@ -2234,7 +2235,7 @@ void write_videoscape(char *str)
{
Base *base;
int file, val, lampdone=0;
unsigned int numlen;
unsigned short numlen;
char head[FILE_MAXFILE], tail[FILE_MAXFILE];
if(BLI_testextensie(str,".trace")) str[ strlen(str)-6]= 0;

View File

@ -514,7 +514,7 @@ void free_main(Main *mainvar)
ListBase *lb= lbarray[a];
ID *id;
while (id= lb->first) {
while ( (id= lb->first) ) {
free_libblock(lb, id);
}
}
@ -810,7 +810,7 @@ int new_id(ListBase *lb, ID *id, char *tname)
return (new_id(lb, id, left));
}
/* this format specifier is from hell... */
sprintf(id->name+2, "%s.%0.3d", left, nr);
sprintf(id->name+2, "%s.%.3d", left, nr);
}
sort_alpha_id(lb, id);

View File

@ -356,9 +356,6 @@ void *add_camera()
cam->clipsta= 0.1f;
cam->clipend= 100.0f;
cam->drawsize= 0.5f;
cam->netsta= 0.5f;
cam->netend= 10.0f;
cam->hold= 50;
return cam;
}

View File

@ -33,6 +33,7 @@
*/
#include <stdio.h>
#include <string.h>
#ifdef HAVE_CONFIG_H
#include <config.h>

File diff suppressed because it is too large Load Diff

View File

@ -48,9 +48,7 @@ typedef struct Camera {
short type, flag, drawzoom, hold;
float clipsta, clipend;
float netsta, netend; /* network camera (obsolete -ton) */
float lens, drawsize;
float hololen, hololen1; /* obsolete (ton) */
struct Ipo *ipo;
@ -67,9 +65,6 @@ typedef struct Camera {
#define CAM_SHOWLIMITS 1
#define CAM_SHOWMIST 2
#define CAM_HOLO1 16
#define CAM_HOLO2 32
#ifdef __cplusplus
}
#endif

View File

@ -85,34 +85,12 @@ struct View3D;
/* ------------------------------------------------------------------------- */
/* Needed for the outside world referring to shadowbuffers */
/* shadbuf.c (1) */
/* ------------------------------------------------------------------------- */
#ifndef RE_SHADOWBUFFERHANDLE
#define RE_SHADOWBUFFERHANDLE
#define RE_DECLARE_HANDLE(name) typedef struct name##__ { int unused; } *name
RE_DECLARE_HANDLE(RE_ShadowBufferHandle);
#endif
/**
* Create a new, empty shadow buffer with certain settings.
*
* @param mode 0 is a dummy buffer, 1 is the old buffer for
* c-based shadowing, 2 is the old buffer with c++ refit , 2 is a
* deep buffer
*/
extern RE_ShadowBufferHandle RE_createShadowBuffer(struct LampRen *lar,
float mat[][4],
int mode);
/**
* Delete a shadow buffer.
* @param shb handle to the buffer to be released
*/
extern void RE_deleteShadowBuffer(RE_ShadowBufferHandle shb);
void RE_initshadowbuf(struct LampRen *lar, float mat[][4]);
/* ------------------------------------------------------------------------- */
/* initrender (14) */
/* ------------------------------------------------------------------------- */
@ -140,7 +118,6 @@ void RE_setwindowclip(int mode, int jmode);
void RE_animrender(struct View3D *ogl_render_view3d);
void RE_free_render_data(void);
void RE_free_filt_mask(void);
void RE_holoview(void);
void RE_init_filt_mask(void);
void RE_init_render_data(void);
void RE_jitterate1(float *jit1, float *jit2, int num, float rad1);
@ -174,7 +151,30 @@ void RE_zbufferall_radio(struct RadView *vw, struct RNode **rg_elem, int rg_t
/* ------------------------------------------------------------------------- */
/* envmap (5) */
/* texture */
/* ------------------------------------------------------------------------- */
struct MTex;
struct Tex;
void init_render_textures(void);
void end_render_textures(void);
void init_render_texture(struct Tex *tex);
void end_render_texture(struct Tex *tex);
void tubemap(float x, float y, float z, float *adr1, float *adr2);
void spheremap(float x, float y, float z, float *adr1, float *adr2);
void do_material_tex(ShadeInput *shi);
void externtex(struct MTex *mtex, float *vec);
void externtexcol(struct MTex *mtex, float *orco, char *col);
void do_lamp_tex(struct LampRen *la, float *lavec, ShadeInput *shi);
void do_sky_tex(float *);
int multitex(struct Tex *tex, float *texvec, float *dxt, float *dyt, int osatex);
/* ------------------------------------------------------------------------- */
/* envmap (4) */
/* ------------------------------------------------------------------------- */
struct EnvMap;
struct Tex;
@ -183,8 +183,6 @@ void RE_free_envmap(struct EnvMap *env);
struct EnvMap *RE_add_envmap(void);
/* these two maybe not external? yes, they are, for texture.c */
struct EnvMap *RE_copy_envmap(struct EnvMap *env);
/* (used in texture.c) */
int RE_envmaptex(struct Tex *tex, float *texvec, float *dxt, float *dyt);
/* --------------------------------------------------------------------- */
/* rendercore (2) */
@ -196,9 +194,6 @@ int RE_envmaptex(struct Tex *tex, float *texvec, float *dxt, float *dyt);
float OrenNayar_Diff(float *n, float *l, float *v, float rough);
float Toon_Diff( float *n, float *l, float *v, float size, float smooth);
/* maybe not external */
void RE_calc_R_ref(void);
/* --------------------------------------------------------------------- */
/* renderdatabase (3) */
/* --------------------------------------------------------------------- */
@ -257,7 +252,7 @@ int RE_envmaptex(struct Tex *tex, float *texvec, float *dxt, float *dyt);
/* patch for the external if, to support the split for the ui */
void RE_addalphaAddfac(char *doel, char *bron, char addfac);
void RE_sky(char *col);
void RE_sky(float *view, char *col);
void RE_renderflare(struct HaloRen *har);
/**
* Shade the pixel at xn, yn for halo har, and write the result to col.

View File

@ -51,13 +51,20 @@
/* ------------------------------------------------------------------------- */
typedef struct RE_Render
/* localized renderloop data */
typedef struct ShadeInput
{
struct Material *mat, *matren;
struct VlakRen *vlr;
float co[3];
float lo[3], gl[3], uv[3], ref[3], orn[3], winco[3], sticky[3], vcol[3], rad[3];
float itot, i, ic, rgb, norm;
float vn[3], view[3], *vno, refcol[4];
float vn[3], view[3], refcol[4];
short osatex;
} ShadeInput;
/* here only stuff to initalize the render itself */
typedef struct RE_Render
{
float grvec[3], inprz, inprh;
float imat[3][3];
@ -65,7 +72,7 @@ typedef struct RE_Render
float persmat[4][4], persinv[4][4];
float winmat[4][4];
short flag, osatex, osa, rt;
short flag, osa, rt, pad;
/**
* Screen sizes and positions, in pixels
*/
@ -89,12 +96,6 @@ typedef struct RE_Render
int totvlak, totvert, tothalo, totlamp;
/* internal: these two are a sort of cache for the render pipe */
struct VlakRen *vlr;
int vlaknr;
/* external */
struct Material *mat, *matren;
/* internal, fortunately */
struct LampRen **la;
struct VlakRen **blovl;

View File

@ -1,71 +0,0 @@
/**
* $Id$
*
* ***** BEGIN GPL/BL DUAL LICENSE BLOCK *****
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version. The Blender
* Foundation also sells licenses for use in proprietary software under
* the Blender License. See http://www.blender.org/BL/ for information
* about this.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
* All rights reserved.
*
* The Original Code is: all of this file.
*
* Contributor(s): none yet.
*
* ***** END GPL/BL DUAL LICENSE BLOCK *****
*/
#ifndef RE_DUMMYSHADOWBUFFER_H
#define RE_DUMMYSHADOWBUFFER_H
#include "RE_ShadowBuffer.h"
struct LampRen;
class RE_DummyShadowBuffer : public RE_ShadowBuffer {
public:
/**
* Make an empty shadow buffer
*/
RE_DummyShadowBuffer(void);
/**
* Delete and clear this buffer
*/
virtual ~RE_DummyShadowBuffer(void);
/**
* Place this scene in the buffer
*/
virtual void importScene(struct LampRen* lar);
/**
* Always return a fixed shadow factor.
* @param inp ignored
* @param shb ignored
* @param shadowResult a vector of 3 floats with rgb shadow values
*/
virtual void readShadowValue(struct ShadBuf *shb,
float inp,
float* shadowResult);
};
#endif /* RE_SHADOWBUFFER_H */

View File

@ -1,62 +0,0 @@
/**
* $Id$
*
* ***** BEGIN GPL/BL DUAL LICENSE BLOCK *****
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version. The Blender
* Foundation also sells licenses for use in proprietary software under
* the Blender License. See http://www.blender.org/BL/ for information
* about this.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
* All rights reserved.
*
* The Original Code is: all of this file.
*
* Contributor(s): none yet.
*
* ***** END GPL/BL DUAL LICENSE BLOCK *****
*/
#ifndef RE_SHADOWBUFFER_H
#define RE_SHADOWBUFFER_H
#include <iostream.h>
struct ShadBuf;
struct LampRen;
class RE_ShadowBuffer {
public:
virtual ~RE_ShadowBuffer(void){};
/**
* Place this scene in the buffer
*/
virtual void importScene(struct LampRen* lar) = 0;
/**
* Test the shadow factor at a location in the buffer
* @param shadowResult a vector of 3 floats with rgb shadow values
*/
virtual void readShadowValue(struct ShadBuf *shb,
float inp,
float* shadowResult) = 0;
};
#endif /* RE_SHADOWBUFFER_H */

View File

@ -1,93 +0,0 @@
/**
* $Id$
*
* ***** BEGIN GPL/BL DUAL LICENSE BLOCK *****
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version. The Blender
* Foundation also sells licenses for use in proprietary software under
* the Blender License. See http://www.blender.org/BL/ for information
* about this.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
* All rights reserved.
*
* The Original Code is: all of this file.
*
* Contributor(s): none yet.
*
* ***** END GPL/BL DUAL LICENSE BLOCK *****
*/
#ifndef RE_BASICSHADOWBUFFER_H
#define RE_BASICSHADOWBUFFER_H
#include "RE_ShadowBuffer.h"
struct LampRen;
struct Lamp;
class RE_BasicShadowBuffer : public RE_ShadowBuffer {
private:
void lrectreadRectz(int x1, int y1, int x2, int y2, char *r1);
int sizeoflampbuf(struct ShadBuf *shb);
int firstreadshadbuf(struct ShadBuf *shb, int xs, int ys, int nr);
float readshadowbuf(struct ShadBuf *shb, int xs, int ys, int zs);
float readshadowbuf_halo(struct ShadBuf *shb, int xs, int ys, int zs);
float *give_jitter_tab(int samp);
int bias;
public:
/**
* Make a shadow buffer from these settings
*/
RE_BasicShadowBuffer(struct LampRen *lar, float mat[][4]);
/**
* Delete and clear this buffer
*/
virtual ~RE_BasicShadowBuffer(void);
/**
* Calculates shadowbuffers for a vector of shadow-giving lamps
* @param lar The vector of lamps
*/
void importScene(LampRen *lar);
/**
* Determines the shadow factor for a face and lamp. There is some
* communication with global variables here.
* @param shadres The RGB shadow factors: 1.0 for no shadow, 0.0 for complete
* shadow. There must be a float[3] to write the result to.
* @param shb The shadowbuffer to find the shadow factor in.
* @param inp The inproduct between viewvector and ?
*
*/
virtual void readShadowValue(struct ShadBuf *shb,
float inp,
float* shadowResult);
/**
* Determines the shadow factor for lamp <lar>, between <p1>
* and <p2>. (Which CS?)
*/
float shadow_halo(LampRen *lar, float *p1, float *p2);
};
#endif /* RE_BASICSHADOWBUFFER_H */

View File

@ -41,6 +41,7 @@
* (initrender.c)
*/
void make_envmaps(void);
int envmaptex(struct Tex *tex, float *texvec, float *dxt, float *dyt, int osatex);
#endif /* ENVMAP_EXT_H */

View File

@ -48,19 +48,19 @@
* t[2] - jitter mask
* t[3] - type ZB_POLY or ZB_HALO
* t[4] - max. distance
* mask is pixel coverage in bits
* @return pointer to the object
*/
void *renderPixel(float x, float y, int *t);
void *renderPixel(float x, float y, int *t, int mask);
void *renderHaloPixel(float x, float y, int haloNr) ;
/**
* Spothalos on otherwise empty pixels.
*/
void renderSpotHaloPixel(float x, float y, float* colbuf);
/**
* Set the sky blending to the indicated type.
*/
void setSkyBlendingMode(enum RE_SkyAlphaBlendingType mode);
void shadeHaloFloat(HaloRen *har,
float *col, unsigned int zz,
float dist, float xn,
float yn, short flarec);
/**
* Get the sky blending mode.
@ -71,47 +71,10 @@ enum RE_SkyAlphaBlendingType getSkyBlendingMode(void);
*/
void renderSkyPixelFloat(float x, float y);
/* ------------------------------------------------------------------------- */
/* All these are supposed to be internal. I should move these to a separate */
/* header. */
/**
* Determine colour for pixel at SCS x,y for face <vlaknr>. Result end up in
* <collector>
* @return pointer to this object's VlakRen
*/
void *renderFacePixel(float x, float y, int vlaknr);
/**
* Render this pixel for halo haloNr. Leave result in <collector>.
* @return pointer to this object's HaloRen
*/
void *renderHaloPixel(float x, float y, int haloNr);
/**
* Shade the halo at the given location
*/
void shadeHaloFloat(HaloRen *har, float *col, unsigned int zz,
float dist, float xn, float yn, short flarec);
/**
* Shade a sky pixel on a certain line, into collector[4]
* The x-coordinate (y as well, actually) are communicated through
* R.view[3]
*/
void shadeSkyPixel(float x, float y);
void shadeSpotHaloPixelFloat(float *col);
void spotHaloFloat(struct LampRen *lar, float *view, float *intens);
void shadeLampLusFloat(void);
/* this should be replaced by shadeSpotHaloPixelFloat(), but there's */
/* something completely fucked up here with the arith. */
/* void renderspothaloFix(unsigned short *col); */
void renderspothaloFix(float *col);
/* used by shadeSkyPixel: */
void shadeSkyPixelFloat(float y);
void shadeSkyPixelFloat(float y, float *view);
void renderSpotHaloPixel(float x, float y, float *target);
void shadeSkyPixel(float fx, float fy);
void fillBackgroundImage(float x, float y);
/* ------------------------------------------------------------------------- */

View File

@ -37,6 +37,7 @@
#include "render_types.h"
struct HaloRen;
struct ShadeInput;
typedef struct ShadeResult
{
@ -46,18 +47,21 @@ typedef struct ShadeResult
} ShadeResult;
float mistfactor(float *co); /* dist en hoogte, return alpha */
void renderspothalo(unsigned short *col);
void render_lighting_halo(struct HaloRen *har, float *colf);
unsigned int calchalo_z(struct HaloRen *har, unsigned int zz);
void shade_color(ShadeResult *shr);
void shade_lamp_loop(int mask, ShadeResult *shr);
float fresnel_fac(float *view, float *vn, float fresnel);
void render_lighting_halo(struct HaloRen *har, float *colf);
unsigned int calchalo_z(struct HaloRen *har, unsigned int zz);
void add_halo_flare(void);
void shade_input_set_coords(ShadeInput *shi, float u, float v, int i1, int i2, int i3);
void shade_color(struct ShadeInput *shi, ShadeResult *shr);
void shade_lamp_loop(struct ShadeInput *shi, ShadeResult *shr, int mask);
float fresnel_fac(float *view, float *vn, float fresnel);
void calc_R_ref(struct ShadeInput *shi);
float spec(float inp, int hard);
void add_halo_flare(void);
/**
* Apply the background (sky). Depending on the active alphamode and
@ -96,7 +100,8 @@ void zbufshadeDA(void); /* Delta Accum Pixel Struct */
/**
* Also called in: zbuf.c
*/
void shadepixel(float x, float y, int vlaknr, int mask);
void *shadepixel(float x, float y, int vlaknr, int mask, float *col);
void shadepixel_short(float x, float y, int vlaknr, int mask, unsigned short *shortcol);
/**
* Shade the pixel at xn, yn for halo har, and write the result to col.

View File

@ -38,8 +38,7 @@
#include "zbuf_types.h"
#include "render_types.h"
void do_lamphalo_tex(LampRen *lar, float *p1, float *p2, float *intens);
void spothalo(struct LampRen *lar, float *view, float *intens);
void spothalo(struct LampRen *lar, ShadeInput *shi, float *intens);
void add_filt_mask(unsigned int mask, unsigned short *col, unsigned int *rb1, unsigned int *rb2, unsigned int *rb3);
void addps(long *rd, int vlak, unsigned int z, short ronde);
PixStr *addpsmain(void);

View File

@ -37,14 +37,6 @@
#include "render_types.h"
#ifdef __cplusplus
extern "C" {
#endif
/** Init memory for old-style shodow buffers. */
void initshadowbuf(struct LampRen *lar, float mat[][4]);
/**
* Calculates shadowbuffers for a vector of shadow-giving lamps
* @param lar The vector of lamps
@ -60,7 +52,7 @@ void makeshadowbuf(LampRen *lar);
* @param inp The inproduct between viewvector and ?
*
*/
float testshadowbuf(struct ShadBuf *shb, float inp);
float testshadowbuf(struct ShadBuf *shb, float *rco, float inp);
/**
* Determines the shadow factor for lamp <lar>, between <p1>
@ -68,9 +60,6 @@ float testshadowbuf(struct ShadBuf *shb, float inp);
*/
float shadow_halo(LampRen *lar, float *p1, float *p2);
#ifdef __cplusplus
}
#endif
#endif /* SHADBUF_EXT_H */

View File

@ -1,80 +0,0 @@
/**
* $Id$
*
* ***** BEGIN GPL/BL DUAL LICENSE BLOCK *****
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version. The Blender
* Foundation also sells licenses for use in proprietary software under
* the Blender License. See http://www.blender.org/BL/ for information
* about this.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
* All rights reserved.
*
* The Original Code is: all of this file.
*
* Contributor(s): none yet.
*
* ***** END GPL/BL DUAL LICENSE BLOCK *****
*/
#ifndef SHADOWBUFFER_H
#define SHADOWBUFFER_H
#ifdef __cplusplus
extern "C" {
#endif
#ifndef RE_SHADOWBUFFERHANDLE
#define RE_SHADOWBUFFERHANDLE
#define RE_DECLARE_HANDLE(name) typedef struct name##__ { int unused; } *name
RE_DECLARE_HANDLE(RE_ShadowBufferHandle);
#endif
struct ShadBuf;
struct LampRen;
/**
* Calculates shadowbuffers for a vector of shadow-giving lamps
* @param lar The vector of lamps
* @returns a handle to the buffer
*/
extern void RE_buildShadowBuffer(RE_ShadowBufferHandle dsbh,
struct LampRen *lar);
/**
* Determines the shadow factor for a face and lamp. There is some
* communication with global variables here? Should be made explicit...
* @param shadres The RGB shadow factors: 1.0 for no shadow, 0.0 for complete
* shadow. There must be a float[3] to write the result to.
* @param shb The shadowbuffer to find the shadow factor in.
* @param inp The inproduct between viewvector and ?
*
*/
void RE_testshadowbuf(RE_ShadowBufferHandle dsbh,
struct ShadBuf* shbp,
float inp,
float* shadres);
/**
* Determines a shadow factor for halo-shadows.
*/
#ifdef __cplusplus
}
#endif
#endif /* SHADOWBUFFER_H */

View File

@ -33,42 +33,14 @@
*/
#ifndef TEXTURE_EXT_H
#define TEXTURE_EXT_H "$Id$"
#define TEXTURE_EXT_H "Copyright (C) 2001 NaN Technologies B.V.
#define TEXTURE_EXT_H
struct Tex;
struct MTex;
struct HaloRen;
struct LampRen;
/**
* Takes uv coordinates (R.uv[], O.dxuv, O.dyuv), find texture colour
* at that spot (using imagewrap()).
* Result is kept in R.vcol (float vector 3)
*/
void render_realtime_texture(void);
struct ShadeInput;
/**
* Do texture mapping for materials. Communicates with R.... variables.
*/
void do_material_tex(void);
/* unsorted */
int blend(struct Tex *tex, float *texvec);
int clouds(struct Tex *tex, float *texvec);
int cubemap(struct MTex *mtex, float x, float y, float z, float *adr1, float *adr2);
int cubemap_glob(struct MTex *mtex, float x, float y, float z, float *adr1, float *adr2);
int cubemap_ob(struct MTex *mtex, float x, float y, float z, float *adr1, float *adr2);
void do_2d_mapping(struct MTex *mtex, float *t, float *dxt, float *dyt);
void do_halo_tex(struct HaloRen *har, float xn, float yn, float *colf);
void do_lamp_tex(struct LampRen *la, float *lavec);
void do_sky_tex(void);
int magic(struct Tex *tex, float *texvec);
int marble(struct Tex *tex, float *texvec);
int multitex(struct Tex *tex, float *texvec, float *dxt, float *dyt);
int plugintex(struct Tex *tex, float *texvec, float *dxt, float *dyt);
int stucci(struct Tex *tex, float *texvec);
int texnoise(struct Tex *tex);
int wood(struct Tex *tex, float *texvec);
void render_realtime_texture(struct ShadeInput *shi);
#endif /* TEXTURE_EXT_H */

View File

@ -186,7 +186,7 @@ void zbuffer_abuf(void);
/**
* Shade this face at this location in SCS.
*/
void shadetrapixel(float x, float y, int vlak, int mask);
void shadetrapixel(float x, float y, int vlak, int mask, unsigned short *shortcol);
/**
* Determine the distance to the camera of this halo, in ZCS.

View File

@ -1,68 +0,0 @@
/**
* $Id$
*
* ***** BEGIN GPL/BL DUAL LICENSE BLOCK *****
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version. The Blender
* Foundation also sells licenses for use in proprietary software under
* the Blender License. See http://www.blender.org/BL/ for information
* about this.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
* All rights reserved.
*
* The Original Code is: all of this file.
*
* Contributor(s): none yet.
*
* ***** END GPL/BL DUAL LICENSE BLOCK *****
*/
#include "render_intern.h"
#include "RE_DummyShadowBuffer.h"
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
struct LampRen;
RE_DummyShadowBuffer::RE_DummyShadowBuffer(void)
{
/* empty for now */
// cout << "Constructing dummy SB\n";
}
RE_DummyShadowBuffer::~RE_DummyShadowBuffer(void)
{
/* empty for now */
// cout << "Deconstructing dummy SB\n";
}
void RE_DummyShadowBuffer::importScene(struct LampRen* lar)
{
/* empty for now */
// cout << "Importing scene in dummy SB\n";
}
void RE_DummyShadowBuffer::readShadowValue(struct ShadBuf *shb,
float inp,
float* shadowResult)
{
/* a sort of puple-ish colour */
shadowResult[0] = 1.0;
shadowResult[1] = 0.0;
shadowResult[2] = 0.5;
}

View File

@ -1,694 +0,0 @@
/**
* $Id$
*
* ***** BEGIN GPL/BL DUAL LICENSE BLOCK *****
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version. The Blender
* Foundation also sells licenses for use in proprietary software under
* the Blender License. See http://www.blender.org/BL/ for information
* about this.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
* All rights reserved.
*
* The Original Code is: all of this file.
*
* Contributor(s): none yet.
*
* ***** END GPL/BL DUAL LICENSE BLOCK *****
*/
#include <math.h>
#include <string.h>
#include "MEM_guardedalloc.h"
#include "BLI_arithb.h"
#include "DNA_lamp_types.h"
/* c stuff */
#include "MTC_matrixops.h"
#include "render.h"
#include "render_intern.h"
#include "renderHelp.h"
#include "jitter.h"
#include "zbuf.h"
#include "shadbuf.h"
/* own include */
#include "RE_basicShadowBuffer.h"
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
/* crud */
#define MIN2(x,y) ( (x)<(y) ? (x) : (y) )
/* ------------------------------------------------------------------------- */
/* The implementation of this one is a bit of a fraud still, as it
* still relies on everything internally to be done in C. Memory is
* allocated on the fly, and deallocated elsewhere... There's not much
* more than a handle for the implementation here. This is an exact
* copy of the old code, retrofitted for integration in the unified
* renderer.
*
* - the shadow values are tripled to make a shadow vector out of a
* single shadow value
*/
RE_BasicShadowBuffer::RE_BasicShadowBuffer(struct LampRen *lar, float mat[][4])
{
// cout << "Constructing basic SB\n";
bias = 0x00500000;
initshadowbuf(lar, mat); /* a ref to the shb is stored in the lar */
}
RE_BasicShadowBuffer::~RE_BasicShadowBuffer(void)
{
/* clean-up is done when the lar's are deleted */
// cout << "Destroying basic SB\n";
}
void RE_BasicShadowBuffer::lrectreadRectz(int x1, int y1,
int x2, int y2,
char *r1) /* reads part from rectz in r1 */
{
unsigned int len4, *rz;
if(x1>=R.rectx || x2>=R.rectx || y1>=R.recty || y2>=R.recty) return;
if(x1>x2 || y1>y2) return;
len4= 4*(x2- x1+1);
rz= R.rectz+R.rectx*y1+x1;
for(;y1<=y2;y1++) {
memcpy(r1,rz,len4);
rz+= R.rectx;
r1+= len4;
}
}
int RE_BasicShadowBuffer::sizeoflampbuf(struct ShadBuf *shb)
{
int num,count=0;
char *cp;
cp= shb->cbuf;
num= (shb->size*shb->size)/256;
while(num--) count+= *(cp++);
return 256*count;
}
float* RE_BasicShadowBuffer::give_jitter_tab(int samp)
{
/* these are all possible jitter tables, takes up some
* 12k, not really bad!
* For soft shadows, it saves memory and render time
*/
static int tab[17]={1, 4, 9, 16, 25, 36, 49, 64, 81, 100, 121, 144, 169, 196, 225, 256};
static float jit[1496][2];
static char ctab[17]= {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
int a, offset=0;
if(samp<2) samp= 2;
else if(samp>16) samp= 16;
for(a=0; a<samp-1; a++) offset+= tab[a];
if(ctab[samp]==0) {
initjit(jit[offset], samp*samp);
ctab[samp]= 1;
}
return jit[offset];
}
void RE_BasicShadowBuffer::importScene(LampRen *lar)
{
struct ShadBuf *shb= lar->shb;
float panophi;
float temp, wsize, dist;
int *rz, *rz1, verg, verg1;
unsigned long *ztile;
int a, x, y, minx, miny, byt1, byt2;
short temprx,tempry, square;
char *rc, *rcline, *ctile, *zt;
panophi = getPanoPhi();
/* store view vars */
temprx= R.rectx; tempry= R.recty;
R.rectx= R.recty= shb->size;
shb->jit= give_jitter_tab(shb->samp);
/* matrices and window: in R.winmat the transformation is being put,
transforming from observer view to lamp view, including lamp window matrix */
wsize= shb->pixsize*(shb->size/2.0);
i_window(-wsize, wsize, -wsize, wsize, shb->d, shb->far, shb->winmat);
MTC_Mat4MulMat4(shb->persmat, shb->viewmat, shb->winmat);
/* temp, will be restored */
MTC_Mat4SwapMat4(shb->persmat, R.winmat);
/* zbuffering */
if(R.rectz) MEM_freeN(R.rectz);
R.rectz= (unsigned int *)MEM_mallocN(sizeof(int)*shb->size*shb->size,"makeshadbuf");
rcline= (char*) MEM_mallocN(256*4+sizeof(int),"makeshadbuf2");
/* store: panorama rot */
temp= panophi;
panophi= 0.0;
pushTempPanoPhi(0.0);
/* pano interference here? */
setzbufvlaggen(projectvert);
popTempPanoPhi();
panophi= temp;
zbuffershad(lar);
square= lar->mode & LA_SQUARE;
/* create Z tiles (for compression): this system is 24 bits!!! */
ztile= shb->zbuf;
ctile= shb->cbuf;
for(y=0; y<shb->size; y+=16) {
if(y< shb->size/2) miny= y+15-shb->size/2;
else miny= y-shb->size/2;
for(x=0; x<shb->size; x+=16) {
/* is tile within spotbundle? */
a= shb->size/2;
if(x< a) minx= x+15-a;
else minx= x-a;
dist= sqrt( (float)(minx*minx+miny*miny) );
if(square==0 && dist>(float)(a+12)) { /* 12, tested with a onlyshadow lamp */
a= 256; verg= 0; /* 0x80000000; */ /* 0x7FFFFFFF; */
rz1= (&verg)+1;
}
else {
lrectreadRectz(x, y, MIN2(shb->size-1,x+15), MIN2(shb->size-1,y+15), rcline);
rz1= (int *)rcline;
verg= (*rz1 & 0xFFFFFF00);
for(a=0;a<256;a++,rz1++) {
if( (*rz1 & 0xFFFFFF00) != verg) break;
}
}
if(a==256) { /* complete empty tile */
*ctile= 0;
*ztile= *(rz1-1);
}
else {
/* ACOMP etc. are defined to work L/B endian */
rc= rcline;
rz1= (int *)rcline;
verg= rc[ACOMP];
verg1= rc[BCOMP];
rc+= 4;
byt1= 1; byt2= 1;
for(a=1;a<256;a++,rc+=4) {
byt1 &= (verg==rc[ACOMP]);
byt2 &= (verg1==rc[BCOMP]);
if(byt1==0) break;
}
if(byt1 && byt2) { /* only store byte */
*ctile= 1;
*ztile= (unsigned long)MEM_mallocN(256+4, "tile1");
rz= (int *)*ztile;
*rz= *rz1;
zt= (char *)(rz+1);
rc= rcline;
for(a=0; a<256; a++, zt++, rc+=4) *zt= rc[GCOMP];
}
else if(byt1) { /* store short */
*ctile= 2;
*ztile= (unsigned long)MEM_mallocN(2*256+4,"Tile2");
rz= (int *)*ztile;
*rz= *rz1;
zt= (char *)(rz+1);
rc= rcline;
for(a=0; a<256; a++, zt+=2, rc+=4) {
zt[0]= rc[BCOMP];
zt[1]= rc[GCOMP];
}
}
else { /* store triple */
*ctile= 3;
*ztile= (unsigned long)MEM_mallocN(3*256,"Tile3");
zt= (char *)*ztile;
rc= rcline;
for(a=0; a<256; a++, zt+=3, rc+=4) {
zt[0]= rc[ACOMP];
zt[1]= rc[BCOMP];
zt[2]= rc[GCOMP];
}
}
}
ztile++;
ctile++;
}
}
MEM_freeN(rcline);
MEM_freeN(R.rectz); R.rectz= 0;
R.rectx= temprx; R.recty= tempry;
MTC_Mat4SwapMat4(shb->persmat, R.winmat);
/* printf("lampbuf %d\n", sizeoflampbuf(shb)); */
}
int RE_BasicShadowBuffer::firstreadshadbuf(struct ShadBuf *shb, int xs, int ys, int nr)
{
/* return a 1 if fully compressed shadbuf-tile && z==const */
static int *rz;
int ofs;
char *ct;
/* always test borders of shadowbuffer */
if(xs<0) xs= 0; else if(xs>=shb->size) xs= shb->size-1;
if(ys<0) ys= 0; else if(ys>=shb->size) ys= shb->size-1;
/* z calc */
ofs= (ys>>4)*(shb->size>>4) + (xs>>4);
ct= shb->cbuf+ofs;
if(*ct==0) {
if(nr==0) {
rz= *( (int **)(shb->zbuf+ofs) );
return 1;
}
else if(rz!= *( (int **)(shb->zbuf+ofs) )) return 0;
return 1;
}
return 0;
}
float RE_BasicShadowBuffer::readshadowbuf(struct ShadBuf *shb,
int xs, int ys, int zs) /* return 1.0 : fully in light */
{
float temp;
int *rz, ofs;
int zsamp;
char *ct, *cz;
/* simple clip */
/* if(xs<0 || ys<0) return 1.0; */
/* if(xs>=shb->size || ys>=shb->size) return 1.0; */
/* always test borders of shadowbuffer */
if(xs<0) xs= 0; else if(xs>=shb->size) xs= shb->size-1;
if(ys<0) ys= 0; else if(ys>=shb->size) ys= shb->size-1;
/* z calc */
ofs= (ys>>4)*(shb->size>>4) + (xs>>4);
ct= shb->cbuf+ofs;
rz= *( (int **)(shb->zbuf+ofs) );
if(*ct==3) {
ct= ((char *)rz)+3*16*(ys & 15)+3*(xs & 15);
cz= (char *)&zsamp;
cz[ACOMP]= ct[0];
cz[BCOMP]= ct[1];
cz[GCOMP]= ct[2];
}
else if(*ct==2) {
ct= ((char *)rz);
ct+= 4+2*16*(ys & 15)+2*(xs & 15);
zsamp= *rz;
cz= (char *)&zsamp;
cz[BCOMP]= ct[0];
cz[GCOMP]= ct[1];
}
else if(*ct==1) {
ct= ((char *)rz);
ct+= 4+16*(ys & 15)+(xs & 15);
zsamp= *rz;
cz= (char *)&zsamp;
cz[GCOMP]= ct[0];
}
else {
/* got warning on this from DEC alpha (64 bits).... */
/* but it's working code! (ton) */
zsamp= (int) rz;
}
if(zsamp > zs) return 1.0; /* absolute no shadow */
else if( zsamp < zs-bias) return 0.0 ; /* absolute in shadow */
else { /* soft area */
temp= ( (float)(zs- zsamp) )/(float)bias;
return 1.0 - temp*temp;
}
}
void RE_BasicShadowBuffer::readShadowValue(struct ShadBuf *shb,
float inp,
float * shadres) /* return 1.0: no shadow */
{
float fac, co[4], dx[3], dy[3], aantal=0;
float xs1,ys1, siz, *j, xres, yres;
int xs,ys, zs;
short a,num;
float shadowfactor = 1.0;
#ifdef RE_NO_SHADOWS
shadres[0] = shadowfactor;
shadres[1] = shadowfactor;
shadres[2] = shadowfactor;
return;
#endif
/* rotate renderco en osaco */
siz= 0.5*(float)shb->size;
VECCOPY(co, R.co);
co[3]= 1.0;
MTC_Mat4MulVec4fl(shb->persmat, co); /* rational homogenic co */
xs1= siz*(1.0+co[0]/co[3]);
ys1= siz*(1.0+co[1]/co[3]);
/* Clip for z: near and far clip values of the shadow buffer. We
* can test for -1.0/1.0 because of the properties of the
* coordinate transformations. */
fac= (co[2]/co[3]);
if(fac>=1.0) {
shadres[0] = 0.0;
shadres[1] = 0.0;
shadres[2] = 0.0;
return;
} else if(fac<= -1.0) {
shadres[0] = 1.0;
shadres[1] = 1.0;
shadres[2] = 1.0;
return;
}
zs = (int) (((float)0x7FFFFFFF)*fac);
/* take num*num samples, increase area with fac */
num= shb->samp*shb->samp;
fac= shb->soft;
bias = (int) ((1.1-inp*inp)*shb->bias);
if(num==1) {
shadowfactor = readshadowbuf(shb,(int)xs1, (int)ys1, zs);
shadres[0] = shadowfactor;
shadres[1] = shadowfactor;
shadres[2] = shadowfactor;
return;
}
co[0]= R.co[0]+O.dxco[0];
co[1]= R.co[1]+O.dxco[1];
co[2]= R.co[2]+O.dxco[2];
co[3]= 1.0;
MTC_Mat4MulVec4fl(shb->persmat,co); /* rational hom co */
dx[0]= xs1- siz*(1.0+co[0]/co[3]);
dx[1]= ys1- siz*(1.0+co[1]/co[3]);
co[0]= R.co[0]+O.dyco[0];
co[1]= R.co[1]+O.dyco[1];
co[2]= R.co[2]+O.dyco[2];
co[3]= 1.0;
MTC_Mat4MulVec4fl(shb->persmat,co); /* rational hom co */
dy[0]= xs1- siz*(1.0+co[0]/co[3]);
dy[1]= ys1- siz*(1.0+co[1]/co[3]);
xres= fac*( fabs(dx[0])+fabs(dy[0]) );
yres= fac*( fabs(dx[1])+fabs(dy[1]) );
if(xres<fac) xres= fac;
if(yres<fac) yres= fac;
xs1-= (xres)/2;
ys1-= (yres)/2;
j= shb->jit;
if(xres<16.0 && yres<16.0) {
if(firstreadshadbuf(shb, (int)xs1, (int)ys1, 0)) {
if(firstreadshadbuf(shb, (int)(xs1+xres), (int)ys1, 1)) {
if(firstreadshadbuf(shb, (int)xs1, (int)(ys1+yres), 1)) {
if(firstreadshadbuf(shb, (int)(xs1+xres), (int)(ys1+yres), 1)) {
/* this return should do some renormalization, methinks */
shadowfactor = readshadowbuf(shb,(int)xs1, (int)ys1, zs);
shadres[0] = shadowfactor;
shadres[1] = shadowfactor;
shadres[2] = shadowfactor;
return;
}
}
}
}
}
for(a=num;a>0;a--) {
/* instead of jit i tried random: ugly! */
xs= (int) (xs1 + xres*j[0]);
ys= (int) (ys1 + yres*j[1]);
j+=2;
aantal+= readshadowbuf(shb, xs, ys, zs);
}
/* Renormalizes for the sample number: */
shadowfactor = aantal/( (float)(num) );
shadres[0] = shadowfactor;
shadres[1] = shadowfactor;
shadres[2] = shadowfactor;
return;
}
/* different function... sampling behind clipend can be LIGHT, bias is negative! */
/* return: light */
float RE_BasicShadowBuffer::readshadowbuf_halo(struct ShadBuf *shb, int xs, int ys, int zs)
{
float temp;
int *rz, ofs;
int zbias, zsamp;
char *ct, *cz;
/* simpleclip */
if(xs<0 || ys<0) return 0.0;
if(xs>=shb->size || ys>=shb->size) return 0.0;
/* z calc */
ofs= (ys>>4)*(shb->size>>4) + (xs>>4);
ct= shb->cbuf+ofs;
rz= *( (int **)(shb->zbuf+ofs) );
if(*ct==3) {
ct= ((char *)rz)+3*16*(ys & 15)+3*(xs & 15);
cz= (char *)&zsamp;
zsamp= 0;
cz[ACOMP]= ct[0];
cz[BCOMP]= ct[1];
cz[GCOMP]= ct[2];
}
else if(*ct==2) {
ct= ((char *)rz);
ct+= 4+2*16*(ys & 15)+2*(xs & 15);
zsamp= *rz;
cz= (char *)&zsamp;
cz[BCOMP]= ct[0];
cz[GCOMP]= ct[1];
}
else if(*ct==1) {
ct= ((char *)rz);
ct+= 4+16*(ys & 15)+(xs & 15);
zsamp= *rz;
cz= (char *)&zsamp;
cz[GCOMP]= ct[0];
}
else {
/* same as before */
/* still working code! (ton) */
zsamp= (int) rz;
}
/* NO schadow when sampled at 'eternal' distance */
if(zsamp >= 0x7FFFFE00) return 1.0;
if(zsamp > zs) return 1.0; /* absolute no shadww */
else {
/* bias is negative, so the (zs-bias) can be beyond 0x7fffffff */
zbias= 0x7fffffff - zs;
if(zbias > -bias) {
if( zsamp < zs-bias) return 0.0 ; /* absolute in shadow */
}
else return 0.0 ; /* absolute shadow */
}
/* soft area */
temp= ( (float)(zs- zsamp) )/(float)bias;
return 1.0 - temp*temp;
}
float RE_BasicShadowBuffer::shadow_halo(LampRen *lar, float *p1, float *p2)
{
/* p1 p2 already are rotated in spot-space */
ShadBuf *shb= lar->shb;
float co[4], siz;
float labda, labdao, labdax, labday, ldx, ldy;
float zf, xf1, yf1, zf1, xf2, yf2, zf2;
float count, lightcount;
int x, y, z, xs1, ys1;
int dx = 0, dy = 0;
siz= 0.5*(float)shb->size;
/* negative! The other side is more important */
bias= -shb->bias;
co[0]= p1[0];
co[1]= p1[1];
co[2]= p1[2]/lar->sh_zfac;
co[3]= 1.0;
MTC_Mat4MulVec4fl(shb->winmat, co); /* rational hom co */
xf1= siz*(1.0+co[0]/co[3]);
yf1= siz*(1.0+co[1]/co[3]);
zf1= (co[2]/co[3]);
co[0]= p2[0];
co[1]= p2[1];
co[2]= p2[2]/lar->sh_zfac;
co[3]= 1.0;
MTC_Mat4MulVec4fl(shb->winmat, co); /* rational hom co */
xf2= siz*(1.0+co[0]/co[3]);
yf2= siz*(1.0+co[1]/co[3]);
zf2= (co[2]/co[3]);
/* the 2dda (a pixel line formula) */
xs1= (int)xf1;
ys1= (int)yf1;
if(xf1 != xf2) {
if(xf2-xf1 > 0.0) {
labdax= (xf1-xs1-1.0)/(xf1-xf2);
ldx= -shb->shadhalostep/(xf1-xf2);
dx= shb->shadhalostep;
}
else {
labdax= (xf1-xs1)/(xf1-xf2);
ldx= shb->shadhalostep/(xf1-xf2);
dx= -shb->shadhalostep;
}
}
else {
labdax= 1.0;
ldx= 0.0;
}
if(yf1 != yf2) {
if(yf2-yf1 > 0.0) {
labday= (yf1-ys1-1.0)/(yf1-yf2);
ldy= -shb->shadhalostep/(yf1-yf2);
dy= shb->shadhalostep;
}
else {
labday= (yf1-ys1)/(yf1-yf2);
ldy= shb->shadhalostep/(yf1-yf2);
dy= -shb->shadhalostep;
}
}
else {
labday= 1.0;
ldy= 0.0;
}
x= xs1;
y= ys1;
labda= count= lightcount= 0.0;
/* printf("start %x %x \n", (int)(0x7FFFFFFF*zf1), (int)(0x7FFFFFFF*zf2)); */
while(1) {
labdao= labda;
if(labdax==labday) {
labdax+= ldx;
x+= dx;
labday+= ldy;
y+= dy;
}
else {
if(labdax<labday) {
labdax+= ldx;
x+= dx;
} else {
labday+= ldy;
y+= dy;
}
}
labda= MIN2(labdax, labday);
if(labda==labdao || labda>=1.0) break;
zf= zf1 + labda*(zf2-zf1);
count+= 1.0;
if(zf<= 0.0) lightcount += 1.0; /* close to the spot */
else {
/* make sure, behind the clipend we extend halolines. */
if(zf>=1.0) z= 0x7FFFF000;
else z= (int)(0x7FFFF000*zf);
lightcount+= readshadowbuf_halo(shb, x, y, z);
}
}
if(count!=0.0) return (lightcount/count);
return 0.0;
}

View File

@ -54,6 +54,7 @@
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <limits.h> /* INT_MIN,MAX are used here */
#include <stdio.h>
@ -381,7 +382,7 @@ void renderEdges(char *colourRect)
rz3= rz2 + bufWidth;
if (same_mat_redux) {
matptr_low = matBuffer;
matptr_low = (int *) matBuffer;
matptr_cent = matptr_low + bufWidth;
matptr_high = matptr_cent + bufWidth;
}

View File

@ -634,7 +634,7 @@ static void set_dxtdyt(float *dxts, float *dyts, float *dxt, float *dyt, int fac
/* ------------------------------------------------------------------------- */
extern float Tin, Ta, Tr, Tg, Tb; /* texture.c */
int RE_envmaptex(Tex *tex, float *texvec, float *dxt, float *dyt)
int envmaptex(Tex *tex, float *texvec, float *dxt, float *dyt, int osatex)
{
/* texvec should be the already reflected normal */
EnvMap *env;
@ -665,7 +665,7 @@ int RE_envmaptex(Tex *tex, float *texvec, float *dxt, float *dyt)
face= envcube_isect(vec, sco);
tex->ima= env->cube[face];
if(R.osatex) {
if(osatex) {
MTC_Mat4Mul3Vecfl(env->object->imat, dxt);
MTC_Mat4Mul3Vecfl(env->object->imat, dyt);

View File

@ -472,13 +472,10 @@ void RE_make_existing_file(char *name)
/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
/* code for holographic hack, used in the neogeo days. SHould be removed (ton) */
extern float holoofs; /* render.c */
void RE_setwindowclip(int mode, int jmode)
{
Camera *cam=0;
float lens, fac, minx, miny, maxx, maxy;
float lens, minx, miny, maxx, maxy;
float xd, yd, afmx, afmy;
if(G.scene->camera==0) return;
@ -554,24 +551,6 @@ void RE_setwindowclip(int mode, int jmode)
}
if(G.special1 & G_HOLO) {
if(G.scene->camera->type==OB_CAMERA) {
cam= G.scene->camera->data;
if(cam->flag & CAM_HOLO2) {
if(cam->netend==0.0) cam->netend= (G.scene->r.efra);
fac= ((G.scene->r.cfra)-1.0)/(cam->netend)-0.5;
fac*= (R.rectx);
fac*= cam->hololen1;
holoofs= -fac;
minx-= fac;
maxx-= fac;
}
}
}
minx= R.pixsize*(minx+xd);
maxx= R.pixsize*(maxx+xd);
miny= R.pixsize*(miny+yd);
@ -694,27 +673,6 @@ void addparttorect(short nr, Part *part)
/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
void RE_holoview()
{
Camera *cam;
float dist, fac, fy, fz;
if(G.scene==0 || G.scene->camera==0) return;
if(G.scene->camera->type==OB_CAMERA) {
cam= G.scene->camera->data;
if(cam->flag & (CAM_HOLO1|CAM_HOLO2)) {
fy= G.scene->camera->loc[1];
fz= G.scene->camera->loc[2];
dist= cam->hololen*sqrt( fy*fy+ fz*fz );
fac= ((G.scene->r.cfra)-(G.scene->r.sfra))/((float)((G.scene->r.efra)-(G.scene->r.sfra)));
G.scene->camera->loc[0]= -dist+ 2*fac*dist;
}
}
}
void add_to_blurbuf(int blur)
{
static unsigned int *blurrect= 0;
@ -818,17 +776,13 @@ void oldRenderLoop(void) /* here the PART and FIELD loops */
/* INIT */
BLI_srand( 2*(G.scene->r.cfra)+fi);
R.vlaknr= -1;
R.flag|= R_RENDERING;
if(fi==1) R.flag |= R_SEC_FIELD;
/* MOTIONBLUR loop */
if(R.r.mode & R_MBLUR) blur= R.osa;
else blur= 1;
while(blur--) {
@ -1210,9 +1164,6 @@ void RE_initrender(struct View3D *ogl_render_view3d)
RE_local_printrenderinfo((PIL_check_seconds_timer() - start_time), -1);
/* restore variables */
R.osatex= 0;
R.vlr= 0; /* at cubemap */
R.flag= 0;
}

View File

@ -271,25 +271,19 @@ void unifiedRenderingLoop(void) /* here the PART en FIELD loops */
R.afmy/= 2;
R.r.yasp*= 2;
R.ycor= ( (float)R.r.yasp)/( (float)R.r.xasp);
}
for(fi=0; fi<fields; fi++) {
/* INIT */
BLI_srand( 2*(G.scene->r.cfra)+fi);
R.vlaknr= -1;
R.flag|= R_RENDERING;
if(fi==1) R.flag |= R_SEC_FIELD;
/* MOTIONBLUR loop */
if(R.r.mode & R_MBLUR) blur= R.osa;
else blur= 1;
while(blur--) {

File diff suppressed because it is too large Load Diff

View File

@ -40,7 +40,6 @@
#include "DNA_mesh_types.h"
#include "BKE_utildefines.h"
#include "BKE_texture.h"
#include "BLI_arithb.h"
@ -49,6 +48,7 @@
#include "rendercore.h"
#include "pixelblending.h"
#include "jitter.h"
#include "texture.h"
#define OCRES 64
@ -74,7 +74,7 @@ typedef struct Octree {
typedef struct Isect {
float start[3], end[3];
float labda, u, v;
struct VlakRen *vlr, *vlrcontr;
struct VlakRen *vlr, *vlrcontr, *vlrorig;
short isect, mode; /* mode: DDA_SHADOW or DDA_MIRROR or DDA_SHADOW_TRA */
float ddalabda;
float col[4]; /* RGBA for shadow_tra */
@ -536,20 +536,20 @@ void makeoctree()
/* ************ raytracer **************** */
/* only for self-intersecting test with current render face (where ray left) */
static short intersection2(float r0, float r1, float r2, float rx1, float ry1, float rz1)
static short intersection2(VlakRen *vlr, float r0, float r1, float r2, float rx1, float ry1, float rz1)
{
VertRen *v1,*v2,*v3,*v4=NULL;
float x0,x1,x2,t00,t01,t02,t10,t11,t12,t20,t21,t22;
float m0, m1, m2, divdet, det, det1;
float u1, v, u2;
v1= R.vlr->v1;
v2= R.vlr->v2;
if(R.vlr->v4) {
v3= R.vlr->v4;
v4= R.vlr->v3;
v1= vlr->v1;
v2= vlr->v2;
if(vlr->v4) {
v3= vlr->v4;
v4= vlr->v3;
}
else v3= R.vlr->v3;
else v3= vlr->v3;
t00= v3->co[0]-v1->co[0];
t01= v3->co[1]-v1->co[1];
@ -726,23 +726,24 @@ static short intersection(Isect *is)
if(is->vlrcontr && vlrisect); // optimizing, the tests below are not needed
else if(is->labda< .1) {
VlakRen *vlr= is->vlrorig;
short de= 0;
if(v1==R.vlr->v1 || v2==R.vlr->v1 || v3==R.vlr->v1 || v4==R.vlr->v1) de++;
if(v1==R.vlr->v2 || v2==R.vlr->v2 || v3==R.vlr->v2 || v4==R.vlr->v2) de++;
if(v1==R.vlr->v3 || v2==R.vlr->v3 || v3==R.vlr->v3 || v4==R.vlr->v3) de++;
if(R.vlr->v4) {
if(v1==R.vlr->v4 || v2==R.vlr->v4 || v3==R.vlr->v4 || v4==R.vlr->v4) de++;
if(v1==vlr->v1 || v2==vlr->v1 || v3==vlr->v1 || v4==vlr->v1) de++;
if(v1==vlr->v2 || v2==vlr->v2 || v3==vlr->v2 || v4==vlr->v2) de++;
if(v1==vlr->v3 || v2==vlr->v3 || v3==vlr->v3 || v4==vlr->v3) de++;
if(vlr->v4) {
if(v1==vlr->v4 || v2==vlr->v4 || v3==vlr->v4 || v4==vlr->v4) de++;
}
if(de) {
/* so there's a shared edge or vertex, let's intersect ray with R.vlr
/* so there's a shared edge or vertex, let's intersect ray with vlr
itself, if that's true we can safely return 1, otherwise we assume
the intersection is invalid, 0 */
if(is->vlrcontr==NULL) {
is->vlrcontr= R.vlr;
vlrisect= intersection2(r0, r1, r2, is->start[0], is->start[1], is->start[2]);
is->vlrcontr= vlr;
vlrisect= intersection2(vlr, r0, r1, r2, is->start[0], is->start[1], is->start[2]);
}
if(vlrisect) return 1;
@ -923,7 +924,7 @@ static short cliptest(float p, float q, float *u1, float *u2)
}
/* return 1: found valid intersection */
/* starts with global R.vlr */
/* starts with is->vlrorig */
static int d3dda(Isect *is)
{
Node *no;
@ -939,11 +940,11 @@ static int d3dda(Isect *is)
/* do this before intersect calls */
raycount++;
R.vlr->raycount= raycount;
is->vlrorig->raycount= raycount;
is->vlrcontr= NULL; /* to check shared edge */
/* only for shadow! */
if(is->mode==DDA_SHADOW && g_oc.vlr_last!=NULL && g_oc.vlr_last!=R.vlr) {
if(is->mode==DDA_SHADOW && g_oc.vlr_last!=NULL && g_oc.vlr_last!=is->vlrorig) {
is->vlr= g_oc.vlr_last;
if(intersection(is)) return 1;
}
@ -1148,227 +1149,76 @@ static int d3dda(Isect *is)
return 0;
}
/* for now; mostly a duplicate of shadepixel() itself... could be unified once */
/* R.view has been set */
static void shade_ray(Isect *is, int mask, ShadeResult *shr)
{
VertRen *v1, *v2, *v3;
float n1[3], n2[3], n3[3];
float *o1, *o2, *o3;
float u, v, l;
int flip= 0;
char p1, p2, p3;
R.co[0]= is->start[0]+is->labda*(is->end[0]-is->start[0]);
R.co[1]= is->start[1]+is->labda*(is->end[1]-is->start[1]);
R.co[2]= is->start[2]+is->labda*(is->end[2]-is->start[2]);
R.vlaknr= -1; // signal to reset static variables in rendercore.c shadepixel
R.vlr= is->vlr;
R.mat= R.vlr->mat;
R.matren= R.mat->ren;
R.osatex= (R.matren->texco & TEXCO_OSA);
static void shade_ray(Isect *is, ShadeInput *shi, ShadeResult *shr, int mask)
{
VlakRen *vlr= is->vlr;
int flip= 0;
/* set up view vector */
VecSubf(shi->view, is->end, is->start);
/* render co */
shi->co[0]= is->start[0]+is->labda*(shi->view[0]);
shi->co[1]= is->start[1]+is->labda*(shi->view[1]);
shi->co[2]= is->start[2]+is->labda*(shi->view[2]);
Normalise(shi->view);
shi->vlr= vlr;
shi->mat= vlr->mat;
shi->matren= shi->mat->ren;
/* face normal, check for flip */
R.vno= R.vlr->n;
if((R.matren->mode & MA_RAYTRANSP)==0) {
l= R.vlr->n[0]*R.view[0]+R.vlr->n[1]*R.view[1]+R.vlr->n[2]*R.view[2];
if((shi->matren->mode & MA_RAYTRANSP)==0) {
float l= vlr->n[0]*shi->view[0]+vlr->n[1]*shi->view[1]+vlr->n[2]*shi->view[2];
if(l<0.0) {
flip= 1;
R.vlr->n[0]= -R.vlr->n[0];
R.vlr->n[1]= -R.vlr->n[1];
R.vlr->n[2]= -R.vlr->n[2];
R.vlr->puno= ~(R.vlr->puno);
vlr->n[0]= -vlr->n[0];
vlr->n[1]= -vlr->n[1];
vlr->n[2]= -vlr->n[2];
vlr->puno= ~(vlr->puno);
}
}
if(R.vlr->v4) {
if(is->isect==2) {
v1= R.vlr->v3;
p1= ME_FLIPV3;
} else {
v1= R.vlr->v1;
p1= ME_FLIPV1;
}
v2= R.vlr->v2;
v3= R.vlr->v4;
p2= ME_FLIPV2; p3= ME_FLIPV4;
}
else {
v1= R.vlr->v1;
v2= R.vlr->v2;
v3= R.vlr->v3;
p1= ME_FLIPV1; p2= ME_FLIPV2; p3= ME_FLIPV3;
}
if(R.vlr->flag & R_SMOOTH) { /* adjust punos (vertexnormals) */
if(R.vlr->puno & p1) {
n1[0]= -v1->n[0]; n1[1]= -v1->n[1]; n1[2]= -v1->n[2];
} else {
n1[0]= v1->n[0]; n1[1]= v1->n[1]; n1[2]= v1->n[2];
}
if(R.vlr->puno & p2) {
n2[0]= -v2->n[0]; n2[1]= -v2->n[1]; n2[2]= -v2->n[2];
} else {
n2[0]= v2->n[0]; n2[1]= v2->n[1]; n2[2]= v2->n[2];
}
if(R.vlr->puno & p3) {
n3[0]= -v3->n[0]; n3[1]= -v3->n[1]; n3[2]= -v3->n[2];
} else {
n3[0]= v3->n[0]; n3[1]= v3->n[1]; n3[2]= v3->n[2];
}
}
u= is->u;
v= is->v;
// Osa structs we leave unchanged now
shi->osatex= 0;
/* UV and TEX*/
if( (R.vlr->flag & R_SMOOTH) || (R.matren->texco & NEED_UV)) {
l= 1.0+u+v;
if(R.vlr->flag & R_SMOOTH) {
R.vn[0]= l*n3[0]-u*n1[0]-v*n2[0];
R.vn[1]= l*n3[1]-u*n1[1]-v*n2[1];
R.vn[2]= l*n3[2]-u*n1[2]-v*n2[2];
Normalise(R.vn);
}
else {
VECCOPY(R.vn, R.vlr->n);
}
if(R.matren->texco & TEXCO_ORCO) {
if(v2->orco) {
o1= v1->orco;
o2= v2->orco;
o3= v3->orco;
R.lo[0]= l*o3[0]-u*o1[0]-v*o2[0];
R.lo[1]= l*o3[1]-u*o1[1]-v*o2[1];
R.lo[2]= l*o3[2]-u*o1[2]-v*o2[2];
}
}
if(R.matren->texco & TEXCO_GLOB) {
VECCOPY(R.gl, R.co);
Mat4MulVecfl(R.viewinv, R.gl);
}
if(R.matren->texco & TEXCO_NORM) {
R.orn[0]= R.vn[0];
R.orn[1]= -R.vn[1];
R.orn[2]= R.vn[2];
}
if((R.matren->texco & TEXCO_UV) || (R.matren->mode & (MA_VERTEXCOL|MA_FACETEXTURE))) {
if(R.vlr->tface) {
float *uv1, *uv2, *uv3;
if( R.vlr->v4 || (R.vlr->flag & R_FACE_SPLIT) ) {
if(is->isect==2) uv1= R.vlr->tface->uv[2];
else uv1= R.vlr->tface->uv[0];
uv2= R.vlr->tface->uv[1];
uv3= R.vlr->tface->uv[3];
}
else {
uv1= R.vlr->tface->uv[0];
uv2= R.vlr->tface->uv[1];
uv3= R.vlr->tface->uv[2];
}
R.uv[0]= -1.0 + 2.0*(l*uv3[0]-u*uv1[0]-v*uv2[0]);
R.uv[1]= -1.0 + 2.0*(l*uv3[1]-u*uv1[1]-v*uv2[1]);
}
else {
R.uv[0]= 2.0*(u+.5);
R.uv[1]= 2.0*(v+.5);
}
}
if(R.matren->mode & MA_VERTEXCOL) {
char *cp3, *cp2, *cp1= (char *)R.vlr->vcol;
if(cp1) {
if( R.vlr->v4 || (R.vlr->flag & R_FACE_SPLIT) ) {
if(is->isect==2) cp1= (char *)(R.vlr->vcol+2);
else cp1= (char *)(R.vlr->vcol+0);
cp2= (char *)(R.vlr->vcol+1);
cp3= (char *)(R.vlr->vcol+3);
}
else {
cp1= (char *)(R.vlr->vcol+0);
cp2= (char *)(R.vlr->vcol+1);
cp3= (char *)(R.vlr->vcol+2);
}
R.vcol[0]= (l*cp3[3]-u*cp1[3]-v*cp2[3])/255.0;
R.vcol[1]= (l*cp3[2]-u*cp1[2]-v*cp2[2])/255.0;
R.vcol[2]= (l*cp3[1]-u*cp1[1]-v*cp2[1])/255.0;
}
else {
R.vcol[0]= 0.0;
R.vcol[1]= 0.0;
R.vcol[2]= 0.0;
}
}
if(R.matren->mode & MA_RADIO) {
R.rad[0]= (l*v3->rad[0] - u*v1->rad[0] - v*v2->rad[0]);
R.rad[1]= (l*v3->rad[1] - u*v1->rad[1] - v*v2->rad[1]);
R.rad[2]= (l*v3->rad[2] - u*v1->rad[2] - v*v2->rad[2]);
}
else {
R.rad[0]= R.rad[1]= R.rad[2]= 0.0;
}
if(R.matren->mode & MA_FACETEXTURE) {
if((R.matren->mode & MA_VERTEXCOL)==0) {
R.vcol[0]= 1.0;
R.vcol[1]= 1.0;
R.vcol[2]= 1.0;
}
if(R.vlr->tface) render_realtime_texture();
}
if(R.matren->texco & TEXCO_REFL) {
/* R.vn dot R.view */
float i= -2.0*(R.vn[0]*R.view[0]+R.vn[1]*R.view[1]+R.vn[2]*R.view[2]);
R.ref[0]= (R.view[0]+i*R.vn[0]);
R.ref[1]= (R.view[1]+i*R.vn[1]);
R.ref[2]= (R.view[2]+i*R.vn[2]);
}
if(vlr->v4) {
if(is->isect==2)
shade_input_set_coords(shi, is->u, is->v, 2, 1, 3);
else
shade_input_set_coords(shi, is->u, is->v, 0, 1, 3);
}
else {
VECCOPY(R.vn, R.vlr->n);
shade_input_set_coords(shi, is->u, is->v, 0, 1, 2);
}
shi->osatex= (shi->matren->texco & TEXCO_OSA);
if(is->mode==DDA_SHADOW_TRA) shade_color(shr);
if(is->mode==DDA_SHADOW_TRA) shade_color(shi, shr);
else {
shade_lamp_loop(mask, shr);
shade_lamp_loop(shi, shr, mask);
if(R.matren->translucency!=0.0) {
if(shi->matren->translucency!=0.0) {
ShadeResult shr_t;
VecMulf(R.vn, -1.0);
VecMulf(R.vlr->n, -1.0);
shade_lamp_loop(mask, &shr_t);
shr->diff[0]+= R.matren->translucency*shr_t.diff[0];
shr->diff[1]+= R.matren->translucency*shr_t.diff[1];
shr->diff[2]+= R.matren->translucency*shr_t.diff[2];
VecMulf(R.vn, -1.0);
VecMulf(R.vlr->n, -1.0);
VecMulf(shi->vn, -1.0);
VecMulf(vlr->n, -1.0);
shade_lamp_loop(shi, &shr_t, mask);
shr->diff[0]+= shi->matren->translucency*shr_t.diff[0];
shr->diff[1]+= shi->matren->translucency*shr_t.diff[1];
shr->diff[2]+= shi->matren->translucency*shr_t.diff[2];
VecMulf(shi->vn, -1.0);
VecMulf(vlr->n, -1.0);
}
}
if(flip) {
R.vlr->n[0]= -R.vlr->n[0];
R.vlr->n[1]= -R.vlr->n[1];
R.vlr->n[2]= -R.vlr->n[2];
R.vlr->puno= ~(R.vlr->puno);
vlr->n[0]= -vlr->n[0];
vlr->n[1]= -vlr->n[1];
vlr->n[2]= -vlr->n[2];
vlr->puno= ~(vlr->puno);
}
}
@ -1398,7 +1248,7 @@ static void refraction(float *refract, float *n, float *view, float index)
refract[2]= index*view[2] + fac*n[2];
}
static void calc_dx_dy_refract(float *ref, float *n, float *view, float index)
static void calc_dx_dy_refract(float *ref, float *n, float *view, float index, int smooth)
{
float dref[3], dview[3], dnor[3];
@ -1408,7 +1258,7 @@ static void calc_dx_dy_refract(float *ref, float *n, float *view, float index)
dview[1]= view[1];
dview[2]= view[2];
if(R.vlr->flag & R_SMOOTH) {
if(smooth) {
VecAddf(dnor, n, O.dxno);
refraction(dref, dnor, dview, index);
}
@ -1420,7 +1270,7 @@ static void calc_dx_dy_refract(float *ref, float *n, float *view, float index)
dview[0]= view[0];
dview[1]= view[1]+ O.dyview;
if(R.vlr->flag & R_SMOOTH) {
if(smooth) {
VecAddf(dnor, n, O.dyno);
refraction(dref, dnor, dview, index);
}
@ -1480,8 +1330,9 @@ static void color_combine(float *result, float fac1, float fac2, float *col1, fl
}
/* the main recursive tracer itself */
static void traceray(short depth, float *start, float *vec, float *col, int mask)
static void traceray(short depth, float *start, float *vec, float *col, VlakRen *vlr, int mask)
{
ShadeInput shi;
ShadeResult shr;
Isect isec;
float f, f1, fr, fg, fb;
@ -1492,33 +1343,19 @@ static void traceray(short depth, float *start, float *vec, float *col, int mask
isec.end[1]= start[1]+g_oc.ocsize*vec[1];
isec.end[2]= start[2]+g_oc.ocsize*vec[2];
isec.mode= DDA_MIRROR;
isec.vlrorig= vlr;
if( d3dda(&isec) ) {
/* set up view vector */
VECCOPY(R.view, vec);
Normalise(R.view);
shade_ray(&isec, mask, &shr);
shade_ray(&isec, &shi, &shr, mask);
if(depth>0) {
if(R.matren->mode & MA_RAYMIRROR) {
f= R.matren->ray_mirror;
if(f!=0.0) f*= fresnel_fac(R.view, R.vn, R.matren->fresnel_mir);
}
else f= 0.0;
/* have to do it here, make local vars... */
fr= R.matren->mirr;
fg= R.matren->mirg;
fb= R.matren->mirb;
if(R.matren->mode & MA_RAYTRANSP && shr.alpha!=1.0) {
if(shi.matren->mode & MA_RAYTRANSP && shr.alpha!=1.0) {
float f, f1, refract[3], tracol[3];
refraction(refract, R.vn, R.view, R.matren->ang);
traceray(depth-1, R.co, refract, tracol, mask);
refraction(refract, shi.vn, shi.view, shi.matren->ang);
traceray(depth-1, shi.co, refract, tracol, shi.vlr, mask);
f= shr.alpha; f1= 1.0-f;
shr.diff[0]= f*shr.diff[0] + f1*tracol[0];
@ -1527,10 +1364,16 @@ static void traceray(short depth, float *start, float *vec, float *col, int mask
shr.alpha= 1.0;
}
if(shi.matren->mode & MA_RAYMIRROR) {
f= shi.matren->ray_mirror;
if(f!=0.0) f*= fresnel_fac(shi.view, shi.vn, shi.matren->fresnel_mir);
}
else f= 0.0;
if(f!=0.0) {
reflection(ref, R.vn, R.view, NULL);
traceray(depth-1, R.co, ref, col, mask);
reflection(ref, shi.vn, shi.view, NULL);
traceray(depth-1, shi.co, ref, col, shi.vlr, mask);
f1= 1.0-f;
@ -1540,10 +1383,12 @@ static void traceray(short depth, float *start, float *vec, float *col, int mask
//col[1]+= shr.spec[1];
//col[2]+= shr.spec[2];
fr= shi.matren->mirr;
fg= shi.matren->mirg;
fb= shi.matren->mirb;
col[0]= f*fr*(1.0-shr.spec[0])*col[0] + f1*shr.diff[0] + shr.spec[0];
col[1]= f*fg*(1.0-shr.spec[1])*col[1] + f1*shr.diff[1] + shr.spec[1];
col[2]= f*fb*(1.0-shr.spec[2])*col[2] + f1*shr.diff[2] + shr.spec[2];
}
else {
@ -1562,10 +1407,10 @@ static void traceray(short depth, float *start, float *vec, float *col, int mask
else { /* sky */
char skycol[4];
VECCOPY(R.view, vec);
Normalise(R.view);
VECCOPY(shi.view, vec);
Normalise(shi.view);
RE_sky(skycol);
RE_sky(shi.view, skycol);
col[0]= skycol[0]/255.0;
col[1]= skycol[1]/255.0;
@ -1662,86 +1507,72 @@ static void *jitter_cube(int resol)
/* extern call from render loop */
void ray_trace(int mask, ShadeResult *shr)
void ray_trace(ShadeInput *shi, ShadeResult *shr, int mask)
{
VlakRen *vlr;
float i, f, f1, fr, fg, fb, vec[3], mircol[3], tracol[3];
int do_tra, do_mir;
do_tra= ((R.matren->mode & MA_RAYTRANSP) && shr->alpha!=1.0);
do_mir= ((R.matren->mode & MA_RAYMIRROR) && R.matren->ray_mirror!=0.0);
vlr= R.vlr;
do_tra= ((shi->matren->mode & MA_RAYTRANSP) && shr->alpha!=1.0);
do_mir= ((shi->matren->mode & MA_RAYMIRROR) && shi->matren->ray_mirror!=0.0);
vlr= shi->vlr;
if(R.r.mode & R_OSA) {
float accum[3], rco[3], ref[3], dxref[3], dyref[3];
float accum[3], rco[3], ref[3];
float accur[3], refract[3], divr=0.0, div= 0.0;
int j;
if(do_tra) calc_dx_dy_refract(refract, R.vn, R.view, R.matren->ang);
if(do_tra) calc_dx_dy_refract(refract, shi->vn, shi->view, shi->matren->ang, vlr->flag & R_SMOOTH);
if(do_mir) {
if(vlr->flag & R_SMOOTH)
reflection(ref, shi->vn, shi->view, vlr->n);
else
reflection(ref, shi->vn, shi->view, NULL);
}
accum[0]= accum[1]= accum[2]= 0.0;
accur[0]= accur[1]= accur[2]= 0.0;
/* store variables which change during tracing */
VECCOPY(rco, R.co);
VECCOPY(ref, R.ref);
VECCOPY(dxref, O.dxref);
VECCOPY(dyref, O.dyref);
for(j=0; j<R.osa; j++) {
if(mask & 1<<j) {
if(do_tra || do_mir) {
rco[0]= shi->co[0] + (jit[j][0]-0.5)*O.dxco[0] + (jit[j][1]-0.5)*O.dyco[0];
rco[1]= shi->co[1] + (jit[j][0]-0.5)*O.dxco[1] + (jit[j][1]-0.5)*O.dyco[1];
rco[2]= shi->co[2] + (jit[j][0]-0.5)*O.dxco[2] + (jit[j][1]-0.5)*O.dyco[2];
}
if(do_tra) {
vec[0]= refract[0] + (jit[j][0]-0.5)*O.dxrefract[0] + (jit[j][1]-0.5)*O.dyrefract[0] ;
vec[1]= refract[1] + (jit[j][0]-0.5)*O.dxrefract[1] + (jit[j][1]-0.5)*O.dyrefract[1] ;
vec[2]= refract[2] + (jit[j][0]-0.5)*O.dxrefract[2] + (jit[j][1]-0.5)*O.dyrefract[2] ;
R.co[0]+= (jit[j][0]-0.5)*O.dxco[0] + (jit[j][1]-0.5)*O.dyco[0] ;
R.co[1]+= (jit[j][0]-0.5)*O.dxco[1] + (jit[j][1]-0.5)*O.dyco[1] ;
R.co[2]+= (jit[j][0]-0.5)*O.dxco[2] + (jit[j][1]-0.5)*O.dyco[2] ;
traceray(R.matren->ray_depth_tra, R.co, vec, tracol, mask);
traceray(shi->matren->ray_depth_tra, rco, vec, tracol, shi->vlr, mask);
VecAddf(accur, accur, tracol);
divr+= 1.0;
/* restore */
VECCOPY(R.co, rco);
R.vlr= vlr;
R.mat= vlr->mat;
R.matren= R.mat->ren;
}
if(do_mir) {
vec[0]= ref[0] + 2.0*(jit[j][0]-0.5)*dxref[0] + 2.0*(jit[j][1]-0.5)*dyref[0] ;
vec[1]= ref[1] + 2.0*(jit[j][0]-0.5)*dxref[1] + 2.0*(jit[j][1]-0.5)*dyref[1] ;
vec[2]= ref[2] + 2.0*(jit[j][0]-0.5)*dxref[2] + 2.0*(jit[j][1]-0.5)*dyref[2] ;
vec[0]= ref[0] + 2.0*(jit[j][0]-0.5)*O.dxref[0] + 2.0*(jit[j][1]-0.5)*O.dyref[0] ;
vec[1]= ref[1] + 2.0*(jit[j][0]-0.5)*O.dxref[1] + 2.0*(jit[j][1]-0.5)*O.dyref[1] ;
vec[2]= ref[2] + 2.0*(jit[j][0]-0.5)*O.dxref[2] + 2.0*(jit[j][1]-0.5)*O.dyref[2] ;
/* prevent normal go to backside */
i= vec[0]*R.vlr->n[0]+ vec[1]*R.vlr->n[1]+ vec[2]*R.vlr->n[2];
i= vec[0]*vlr->n[0]+ vec[1]*vlr->n[1]+ vec[2]*vlr->n[2];
if(i>0.0) {
i+= .01;
vec[0]-= i*R.vlr->n[0];
vec[1]-= i*R.vlr->n[1];
vec[2]-= i*R.vlr->n[2];
vec[0]-= i*vlr->n[0];
vec[1]-= i*vlr->n[1];
vec[2]-= i*vlr->n[2];
}
R.co[0]+= (jit[j][0]-0.5)*O.dxco[0] + (jit[j][1]-0.5)*O.dyco[0] ;
R.co[1]+= (jit[j][0]-0.5)*O.dxco[1] + (jit[j][1]-0.5)*O.dyco[1] ;
R.co[2]+= (jit[j][0]-0.5)*O.dxco[2] + (jit[j][1]-0.5)*O.dyco[2] ;
/* we use a new mask here, only shadow uses it */
/* result in accum, this is copied to shade_lamp_loop */
traceray(R.matren->ray_depth, R.co, vec, mircol, 1<<j);
traceray(shi->matren->ray_depth, rco, vec, mircol, shi->vlr, 1<<j);
VecAddf(accum, accum, mircol);
div+= 1.0;
/* restore */
VECCOPY(R.co, rco);
R.vlr= vlr;
R.mat= vlr->mat;
R.matren= R.mat->ren;
}
}
}
@ -1755,10 +1586,10 @@ void ray_trace(int mask, ShadeResult *shr)
}
if(div!=0.0) {
i= R.matren->ray_mirror;
fr= R.matren->mirr;
fg= R.matren->mirg;
fb= R.matren->mirb;
i= shi->matren->ray_mirror;
fr= shi->matren->mirr;
fg= shi->matren->mirg;
fb= shi->matren->mirb;
/* result */
f= i*fr*(1.0-shr->spec[0]); f1= 1.0-i; f/= div;
@ -1774,47 +1605,32 @@ void ray_trace(int mask, ShadeResult *shr)
else {
if(do_tra) {
float rvn[3], view[3], rco[3], ref[3], refract[3];
float refract[3];
/* store variables which change during tracing */
VECCOPY(view, R.view);
VECCOPY(rco, R.co);
VECCOPY(rvn, R.vn);
VECCOPY(ref, R.ref);
refraction(refract, R.vn, R.view, R.matren->ang);
traceray(R.matren->ray_depth_tra, R.co, refract, tracol, mask);
refraction(refract, shi->vn, shi->view, shi->matren->ang);
traceray(shi->matren->ray_depth_tra, shi->co, refract, tracol, shi->vlr, mask);
f= shr->alpha; f1= 1.0-f;
shr->diff[0]= f*shr->diff[0] + f1*tracol[0];
shr->diff[1]= f*shr->diff[1] + f1*tracol[1];
shr->diff[2]= f*shr->diff[2] + f1*tracol[2];
shr->alpha= 1.0;
/* store variables which change during tracing */
VECCOPY(R.view, view);
VECCOPY(R.co, rco);
VECCOPY(R.ref, ref);
VECCOPY(R.vn, rvn);
R.vlr= vlr;
R.mat= vlr->mat;
R.matren= R.mat->ren;
}
if(do_mir) {
i= R.matren->ray_mirror*fresnel_fac(R.view, R.vn, R.matren->fresnel_mir);
i= shi->matren->ray_mirror*fresnel_fac(shi->view, shi->vn, shi->matren->fresnel_mir);
if(i!=0.0) {
fr= R.matren->mirr;
fg= R.matren->mirg;
fb= R.matren->mirb;
fr= shi->matren->mirr;
fg= shi->matren->mirg;
fb= shi->matren->mirb;
if(R.vlr->flag & R_SMOOTH)
reflection(vec, R.vn, R.view, R.vlr->n);
if(vlr->flag & R_SMOOTH)
reflection(vec, shi->vn, shi->view, vlr->n);
else
reflection(vec, R.vn, R.view, NULL);
reflection(vec, shi->vn, shi->view, NULL);
traceray(R.matren->ray_depth, R.co, vec, mircol, mask);
traceray(shi->matren->ray_depth, shi->co, vec, mircol, shi->vlr, mask);
f= i*fr*(1.0-shr->spec[0]); f1= 1.0-i;
shr->diff[0]= f*mircol[0] + f1*shr->diff[0];
@ -1843,72 +1659,111 @@ static void addAlphaLight(float *old, float *over)
}
static int ray_trace_shadow_tra(Isect *isec, int depth)
static void ray_trace_shadow_tra(Isect *is, int depth)
{
/* ray to lamp, find first face that intersects, check alpha properties,
if it has alpha<1 continue. exit when alpha is full */
ShadeInput shi;
ShadeResult shr;
if( d3dda(isec)) {
VlakRen *vlr=NULL;
float col[4], rvn[3], view[3], rco[3], ref[3];
if( d3dda(is)) {
float col[4];
/* we got a face */
/* store variables which change during tracing */
if(depth==DEPTH_SHADOW_TRA) {
vlr= R.vlr;
VECCOPY(view, R.view);
VECCOPY(rco, R.co);
VECCOPY(rvn, R.vn);
VECCOPY(ref, R.ref);
}
/* set up view vector */
VecSubf(R.view, isec->end, isec->start);
Normalise(R.view);
shade_ray(isec, 0, &shr);
shade_ray(is, &shi, &shr, 0); // mask not needed
/* add color */
VECCOPY(col, shr.diff);
col[3]= shr.alpha;
addAlphaLight(isec->col, col);
addAlphaLight(is->col, col);
if(depth>0 && isec->col[3]<1.0) {
VECCOPY(isec->start, R.co);
ray_trace_shadow_tra(isec, depth-1);
if(depth>0 && is->col[3]<1.0) {
/* adapt isect struct */
VECCOPY(is->start, shi.co);
is->vlrorig= shi.vlr;
ray_trace_shadow_tra(is, depth-1);
}
else if(isec->col[3]>1.0) isec->col[3]= 1.0;
else if(is->col[3]>1.0) is->col[3]= 1.0;
/* restore variables which change during tracing */
if(depth==DEPTH_SHADOW_TRA) {
VECCOPY(R.view, view);
VECCOPY(R.co, rco);
VECCOPY(R.ref, ref);
VECCOPY(R.vn, rvn);
R.vlr= vlr;
R.mat= vlr->mat;
R.matren= R.mat->ren;
}
}
return 0;
}
int ray_trace_shadow_rad(ShadeInput *ship, ShadeResult *shr)
{
static int counter=0, only_one= 0;
extern float hashvectf[];
Isect isec;
ShadeInput shi;
ShadeResult shr_t;
float vec[3], accum[3], div= 0.0;
int a;
if(only_one) {
return 0;
}
only_one= 1;
accum[0]= accum[1]= accum[2]= 0.0;
isec.mode= DDA_MIRROR;
isec.vlrorig= ship->vlr;
for(a=0; a<8*8; a++) {
counter+=3;
counter %= 768;
VECCOPY(vec, hashvectf+counter);
if(ship->vn[0]*vec[0]+ship->vn[1]*vec[1]+ship->vn[2]*vec[2]>0.0) {
vec[0]-= vec[0];
vec[1]-= vec[1];
vec[2]-= vec[2];
}
VECCOPY(isec.start, ship->co);
isec.end[0]= isec.start[0] + g_oc.ocsize*vec[0];
isec.end[1]= isec.start[1] + g_oc.ocsize*vec[1];
isec.end[2]= isec.start[2] + g_oc.ocsize*vec[2];
if( d3dda(&isec)) {
float fac;
shade_ray(&isec, &shi, &shr_t, 0); // mask not needed
fac= isec.labda*isec.labda;
fac= 1.0;
accum[0]+= fac*(shr_t.diff[0]+shr_t.spec[0]);
accum[1]+= fac*(shr_t.diff[1]+shr_t.spec[1]);
accum[2]+= fac*(shr_t.diff[2]+shr_t.spec[2]);
div+= fac;
}
else div+= 1.0;
}
if(div!=0.0) {
shr->diff[0]+= accum[0]/div;
shr->diff[1]+= accum[1]/div;
shr->diff[2]+= accum[2]/div;
}
shr->alpha= 1.0;
only_one= 0;
return 1;
}
/* extern call from shade_lamp_loop */
void ray_shadow(LampRen *lar, float *shadfac, int mask)
void ray_shadow(ShadeInput *shi, LampRen *lar, float *shadfac, int mask)
{
Isect isec;
float fac, div=0.0, lampco[3];
if(R.matren->mode & MA_SHADOW_TRA) isec.mode= DDA_SHADOW_TRA;
if(shi->matren->mode & MA_SHADOW_TRA) isec.mode= DDA_SHADOW_TRA;
else isec.mode= DDA_SHADOW;
shadfac[3]= 1.0; // 1=full light
if(lar->type==LA_SUN || lar->type==LA_HEMI) {
lampco[0]= R.co[0] - g_oc.ocsize*lar->vec[0];
lampco[1]= R.co[1] - g_oc.ocsize*lar->vec[1];
lampco[2]= R.co[2] - g_oc.ocsize*lar->vec[2];
lampco[0]= shi->co[0] - g_oc.ocsize*lar->vec[0];
lampco[1]= shi->co[1] - g_oc.ocsize*lar->vec[1];
lampco[2]= shi->co[2] - g_oc.ocsize*lar->vec[2];
}
else {
VECCOPY(lampco, lar->co);
@ -1923,10 +1778,13 @@ void ray_shadow(LampRen *lar, float *shadfac, int mask)
for(j=0; j<R.osa; j++) {
if(mask & 1<<j) {
isec.start[0]= R.co[0] + (jit[j][0]-0.5)*O.dxco[0] + (jit[j][1]-0.5)*O.dyco[0] ;
isec.start[1]= R.co[1] + (jit[j][0]-0.5)*O.dxco[1] + (jit[j][1]-0.5)*O.dyco[1] ;
isec.start[2]= R.co[2] + (jit[j][0]-0.5)*O.dxco[2] + (jit[j][1]-0.5)*O.dyco[2] ;
/* set up isec */
isec.start[0]= shi->co[0] + (jit[j][0]-0.5)*O.dxco[0] + (jit[j][1]-0.5)*O.dyco[0] ;
isec.start[1]= shi->co[1] + (jit[j][0]-0.5)*O.dxco[1] + (jit[j][1]-0.5)*O.dyco[1] ;
isec.start[2]= shi->co[2] + (jit[j][0]-0.5)*O.dxco[2] + (jit[j][1]-0.5)*O.dyco[2] ;
VECCOPY(isec.end, lampco);
isec.vlrorig= shi->vlr;
if(isec.mode==DDA_SHADOW_TRA) {
isec.col[0]= isec.col[1]= isec.col[2]= 1.0;
isec.col[3]= 0.0; //alpha
@ -1951,8 +1809,11 @@ void ray_shadow(LampRen *lar, float *shadfac, int mask)
else shadfac[3]= 1.0-fac/div;
}
else {
VECCOPY(isec.start, R.co);
/* set up isec */
VECCOPY(isec.start, shi->co);
VECCOPY(isec.end, lampco);
isec.vlrorig= shi->vlr;
if(isec.mode==DDA_SHADOW_TRA) {
isec.col[0]= isec.col[1]= isec.col[2]= 1.0;
isec.col[3]= 0.0; //alpha
@ -1974,8 +1835,9 @@ void ray_shadow(LampRen *lar, float *shadfac, int mask)
float vec[3];
int a, j=0;
VECCOPY(isec.start, R.co);
VECCOPY(isec.start, shi->co);
isec.vlrorig= shi->vlr;
fac= 0.0;
a= lar->ray_samp*lar->ray_samp;
jitlamp= jitter_plane(lar->ray_samp);
@ -1992,9 +1854,9 @@ void ray_shadow(LampRen *lar, float *shadfac, int mask)
isec.end[2]= lampco[2]+vec[2];
if(R.r.mode & R_OSA) {
isec.start[0]= R.co[0] + (jit[j][0]-0.5)*O.dxco[0] + (jit[j][1]-0.5)*O.dyco[0] ;
isec.start[1]= R.co[1] + (jit[j][0]-0.5)*O.dxco[1] + (jit[j][1]-0.5)*O.dyco[1] ;
isec.start[2]= R.co[2] + (jit[j][0]-0.5)*O.dxco[2] + (jit[j][1]-0.5)*O.dyco[2] ;
isec.start[0]= shi->co[0] + (jit[j][0]-0.5)*O.dxco[0] + (jit[j][1]-0.5)*O.dyco[0] ;
isec.start[1]= shi->co[1] + (jit[j][0]-0.5)*O.dxco[1] + (jit[j][1]-0.5)*O.dyco[1] ;
isec.start[2]= shi->co[2] + (jit[j][0]-0.5)*O.dxco[2] + (jit[j][1]-0.5)*O.dyco[2] ;
j++;
if(j>=R.osa) j= 0;
}

View File

@ -42,7 +42,6 @@
#include "shadbuf.h"
#include "envmap.h"
#include "renderHelp.h"
#include "shadowBuffer.h"
#include "radio.h"
#ifdef HAVE_CONFIG_H
@ -67,17 +66,7 @@ void prepareScene()
/* SHADOW BUFFER */
for(a=0; a<R.totlamp; a++) {
if(RE_local_test_break()) break;
/* Again, switch between old and new shadowing system. The
* buffer objects were initially created in
* blenderWorldManipulation.c */
if (R.r.mode & R_UNIFIED) {
if (R.la[a]->shadowBufOb) {
RE_buildShadowBuffer(R.la[a]->shadowBufOb,
R.la[a]);
}
} else {
if(R.la[a]->shb) makeshadowbuf(R.la[a]);
}
if(R.la[a]->shb) makeshadowbuf(R.la[a]);
}
/* RADIO */

File diff suppressed because it is too large Load Diff

View File

@ -58,6 +58,7 @@
*/
#include <math.h>
#include <string.h>
#include "MEM_guardedalloc.h"
#include "BLI_arithb.h"

View File

@ -77,7 +77,7 @@ float *give_jitter_tab(int samp);
/* ------------------------------------------------------------------------- */
void initshadowbuf(LampRen *lar, float mat[][4])
void RE_initshadowbuf(LampRen *lar, float mat[][4])
{
struct ShadBuf *shb;
float hoek, temp, viewinv[4][4];
@ -436,7 +436,7 @@ float readshadowbuf(struct ShadBuf *shb, int xs, int ys, int zs) /* return 1.0 :
}
float testshadowbuf(struct ShadBuf *shb, float inp) /* return 1.0: no shadow at all */
float testshadowbuf(struct ShadBuf *shb, float *rco, float inp) /* return 1.0: no shadow at all */
{
float fac, co[4], dx[3], dy[3], aantal=0;
float xs1,ys1, siz, *j, xres, yres;
@ -451,7 +451,7 @@ float testshadowbuf(struct ShadBuf *shb, float inp) /* return 1.0: no shadow a
/* rotate renderco en osaco */
siz= 0.5*(float)shb->size;
VECCOPY(co, R.co);
VECCOPY(co, rco);
co[3]= 1.0;
MTC_Mat4MulVec4fl(shb->persmat, co); /* rational hom co */
@ -483,17 +483,17 @@ float testshadowbuf(struct ShadBuf *shb, float inp) /* return 1.0: no shadow a
return readshadowbuf(shb,(int)xs1, (int)ys1, zs);
}
co[0]= R.co[0]+O.dxco[0];
co[1]= R.co[1]+O.dxco[1];
co[2]= R.co[2]+O.dxco[2];
co[0]= rco[0]+O.dxco[0];
co[1]= rco[1]+O.dxco[1];
co[2]= rco[2]+O.dxco[2];
co[3]= 1.0;
MTC_Mat4MulVec4fl(shb->persmat,co); /* rational hom co */
dx[0]= xs1- siz*(1.0+co[0]/co[3]);
dx[1]= ys1- siz*(1.0+co[1]/co[3]);
co[0]= R.co[0]+O.dyco[0];
co[1]= R.co[1]+O.dyco[1];
co[2]= R.co[2]+O.dyco[2];
co[0]= rco[0]+O.dyco[0];
co[1]= rco[1]+O.dyco[1];
co[2]= rco[2]+O.dyco[2];
co[3]= 1.0;
MTC_Mat4MulVec4fl(shb->persmat,co); /* rational hom co */
dy[0]= xs1- siz*(1.0+co[0]/co[3]);

View File

@ -1,102 +0,0 @@
/**
* $Id$
*
* ***** BEGIN GPL/BL DUAL LICENSE BLOCK *****
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version. The Blender
* Foundation also sells licenses for use in proprietary software under
* the Blender License. See http://www.blender.org/BL/ for information
* about this.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
* All rights reserved.
*
* The Original Code is: all of this file.
*
* Contributor(s): none yet.
*
* ***** END GPL/BL DUAL LICENSE BLOCK *****
*/
#include <assert.h>
#include "render.h"
#include "render_intern.h"
#include "shadbuf.h"
#include "shadowBuffer.h" /* the C header */
#include "RE_ShadowBuffer.h" /* the base buffer */
#include "RE_DummyShadowBuffer.h" /* A dummy shadow buffer */
#include "RE_basicShadowBuffer.h" /* the 'old' shadow buffer */
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
struct ShadBuf;
struct LampRen;
struct Lamp;
/*
* Creates a shadow buffer of a certain type
*/
RE_ShadowBufferHandle RE_createShadowBuffer(struct LampRen *lar,
float mat[][4],
int mode)
{
/* make a dummy: this always returns a fixed value */
RE_ShadowBuffer* buf = NULL;
switch (mode) {
case 0:
buf = new RE_DummyShadowBuffer();
break;
case 1:
/* loop to the old c-based buffer */
/* memory release is done implicitly! */
initshadowbuf(lar, mat);
break;
case 2:
buf = new RE_BasicShadowBuffer(lar, mat);
break;
case 3:
// cout << "Deep shadow buffer requested\n";
break;
default:
// cerr << "Bad shadow buffer type specified\n";
; /* nada */
}
return (RE_ShadowBufferHandle) buf;
}
void RE_deleteShadowBuffer(RE_ShadowBufferHandle buf)
{
// cout << "requesting buffer delete\n";
assert(buf);
delete (RE_ShadowBuffer*) buf;
}
void RE_buildShadowBuffer(RE_ShadowBufferHandle buf,
struct LampRen *lar)
{
assert(buf);
((RE_ShadowBuffer*) buf)->importScene(lar);
}
void RE_testshadowbuf(RE_ShadowBufferHandle buf,
struct ShadBuf* shbp,
float inp,
float* shadres)
{
assert(buf);
((RE_ShadowBuffer*) buf)->readShadowValue(shbp, inp, shadres);
}

File diff suppressed because it is too large Load Diff

View File

@ -122,7 +122,7 @@ extern char *centmask; /* compute its colour on a point _on_ the face. */
/* guarantee we use valid coordinates. */
/* unsorted */
extern float holoofs, fmask[256];
extern float fmask[256];
extern unsigned short usegamtab, shortcol[4],
*mask1[9], *mask2[9],/* *igamtab1, */ *igamtab2/*, *gamtab */;
@ -225,7 +225,7 @@ void zBufShadeAdvanced()
y = 0;
while ( (y < bufferHeight) && keepLooping) {
calcZBufLine(y);
R.vlaknr= -1; /* huh? why reset this counter? for shadePixel! */
renderZBufLine(y);
transferColourBufferToOutput(y);
@ -435,10 +435,10 @@ int composeStack(int zrow[RE_MAX_FACES_PER_PIXEL][RE_PIXELFIELDSIZE],
ys= (float)y+centLut[i >> 4];
/* stack face ----------- */
stack[ptr].data = renderPixel(xs, ys, zrow[totvlak]);
stack[ptr].mask = zrow[totvlak][RE_MASK];
stack[ptr].data = renderPixel(xs, ys, zrow[totvlak], stack[ptr].mask);
stack[ptr].faceType = zrow[totvlak][RE_TYPE];
cpFloatColV(collector, stack[ptr].colour);
stack[ptr].mask = zrow[totvlak][RE_MASK];
/* This is done so that spothalos are properly overlayed on halos */
/* maybe we need to check the colour here... */
@ -1468,9 +1468,10 @@ void eraseColBuf(RE_COLBUFTYPE *buf) {
/* ------------------------------------------------------------------------- */
int calcDepth(float x, float y, void* data, int type)
int calcDepth(float x, float y, void *data, int type)
{
float view[3];
if (type & RE_POLY) {
VlakRen* vlr = (VlakRen*) data;
VertRen* v1;
@ -1483,31 +1484,28 @@ int calcDepth(float x, float y, void* data, int type)
dvlak= v1->co[0]*vlr->n[0]+v1->co[1]*vlr->n[1]+v1->co[2]*vlr->n[2];
/* jitter has been added to x, y ! */
/* view vector R.view: screen coords */
if( (G.special1 & G_HOLO) &&
((Camera *)G.scene->camera->data)->flag & CAM_HOLO2) {
R.view[0]= (x+(R.xstart) + 0.5 +holoofs);
} else R.view[0]= (x+(R.xstart) + 0.5 );
/* view vector view: screen coords */
view[0]= (x+(R.xstart) + 0.5 );
if(R.flag & R_SEC_FIELD) {
if(R.r.mode & R_ODDFIELD) R.view[1]= (y + R.ystart)*R.ycor;
else R.view[1]= (y+R.ystart + 1.0)*R.ycor;
} else R.view[1]= (y+R.ystart + 0.5 )*R.ycor;
if(R.r.mode & R_ODDFIELD) view[1]= (y + R.ystart)*R.ycor;
else view[1]= (y+R.ystart + 1.0)*R.ycor;
} else view[1]= (y+R.ystart + 0.5 )*R.ycor;
/* for pano, another rotation in the xz plane is needed.... */
/* this is ok, in WCS */
R.view[2]= -R.viewfac; /* distance to viewplane */
view[2]= -R.viewfac; /* distance to viewplane */
/* face normal dot view vector: but how can this work? */
deler = MTC_dot3Float(vlr->n, R.view);
deler = MTC_dot3Float(vlr->n, view);
if (deler!=0.0) fac = dvlak/deler;
else fac = 0.0;
/* indices are wrong.... but gives almost the right value? */
hoco_z = (fac*R.view[2]) * R.winmat[2][2] + R.winmat[3][2];
hoco_w = (fac*R.view[2]) * R.winmat[2][3] + R.winmat[3][3];
hoco_z = (fac*view[2]) * R.winmat[2][2] + R.winmat[3][2];
hoco_w = (fac*view[2]) * R.winmat[2][3] + R.winmat[3][3];
zbuf_co = 0x7FFFFFFF*(hoco_z/hoco_w);

View File

@ -2170,25 +2170,24 @@ int vergzvlak(const void *a1, const void *a2)
return 0;
}
void shadetrapixel(float x, float y, int vlak, int mask)
void shadetrapixel(float x, float y, int vlak, int mask, unsigned short *shortcol)
{
if( (vlak & 0x7FFFFF) > R.totvlak) {
printf("error in shadetrapixel nr: %d\n", (vlak & 0x7FFFFF));
return;
}
shadepixel(x, y, vlak, mask);
shadepixel_short(x, y, vlak, mask, shortcol);
}
extern unsigned short usegamtab;
extern unsigned short shortcol[4];
void abufsetrow(int y)
{
APixstr *ap, *apn;
float xs, ys;
int x, part, a, b, zrow[100][3], totvlak, alpha[32], tempgam, nr, intcol[4];
int sval, tempRf;
unsigned short *col, tempcol[4], sampcol[16*4], *scol;
unsigned short *col, shortcol[4], tempcol[4], sampcol[16*4], *scol;
if(y<0) return;
if(R.osa>16) {
@ -2253,7 +2252,7 @@ void abufsetrow(int y)
else {
xs= x; ys= y;
}
shadetrapixel(xs, ys, ap->p[0], ap->mask[0]);
shadetrapixel(xs, ys, ap->p[0], ap->mask[0], shortcol);
nr= count_mask(ap->mask[0]);
if( (R.r.mode & R_OSA) && nr<R.osa) {
@ -2297,7 +2296,7 @@ void abufsetrow(int y)
else {
xs= x; ys= y;
}
shadetrapixel(xs, ys, zrow[totvlak][1], 0xFFFF);
shadetrapixel(xs, ys, zrow[totvlak][1], 0xFFFF, shortcol);
a= count_mask(zrow[totvlak][2]);
if( (R.r.mode & R_OSA ) && a<R.osa) {
@ -2305,20 +2304,20 @@ void abufsetrow(int y)
memset(sampcol, 0, 4*2*R.osa);
sval= addtosampcol(sampcol, shortcol, zrow[totvlak][2]);
/* sval==0: alpha completely full */
while( (sval != 0) && (totvlak>0) ) {
a= count_mask(zrow[totvlak-1][2]);
if(a==R.osa) break;
totvlak--;
b= centmask[ zrow[totvlak][2] ];
xs= (float)x+centLut[b & 15];
ys= (float)y+centLut[b>>4];
shadetrapixel(xs, ys, zrow[totvlak][1], zrow[totvlak][2]);
sval= addtosampcol(sampcol, shortcol, zrow[totvlak][2]);
}
/* sval==0: alpha completely full */
while( (sval != 0) && (totvlak>0) ) {
a= count_mask(zrow[totvlak-1][2]);
if(a==R.osa) break;
totvlak--;
b= centmask[ zrow[totvlak][2] ];
xs= (float)x+centLut[b & 15];
ys= (float)y+centLut[b>>4];
shadetrapixel(xs, ys, zrow[totvlak][1], zrow[totvlak][2], shortcol);
sval= addtosampcol(sampcol, shortcol, zrow[totvlak][2]);
}
scol= sampcol;
intcol[0]= scol[0]; intcol[1]= scol[1];
intcol[2]= scol[2]; intcol[3]= scol[3];
@ -2345,7 +2344,7 @@ void abufsetrow(int y)
}
}
else addAlphaUnderShort(col, shortcol);
if(col[3]>=0xFFF0) break;
}
}
@ -2353,7 +2352,7 @@ void abufsetrow(int y)
}
usegamtab= tempgam;
R.flag= tempRf;
R.flag= tempRf;
}
/* end of zbuf.c */

View File

@ -1883,32 +1883,12 @@ void RE_add_render_lamp(Object *ob, int doshadbuf)
}
}
}
if( (R.r.mode & R_SHADOW) && (lar->mode & LA_SHAD)
&& (la->type==LA_SPOT) && doshadbuf ) {
if( (R.r.mode & R_SHADOW) && (lar->mode & LA_SHAD) && (la->type==LA_SPOT) && doshadbuf ) {
/* Per lamp, one shadow buffer is made. */
if (R.r.mode & R_UNIFIED) {
int mode;
/* For the UR, I want to stick to the cpp version. I can
* put a switch here for the different shadow buffers. At
* this point, the type of shadow buffer is
* determined. The actual calculations are done during the
* render pre operations. */
if (lar->mode & LA_DEEP_SHADOW) {
mode = 0; /* dummy, for testing */
} else if (2) {
mode = 2; /* old-style buffer */
}
lar->shadowBufOb = (void*) RE_createShadowBuffer(lar,
ob->obmat,
mode);
} else {
RE_createShadowBuffer(lar,
ob->obmat,
1); /* mode = 1 is old buffer */
}
RE_initshadowbuf(lar, ob->obmat);
}
lar->org= MEM_dupallocN(lar);
}
@ -2704,12 +2684,6 @@ void RE_freeRotateBlenderScene(void)
/* FREE */
for(a=0; a<R.totlamp; a++) {
/* for the shadow buf object integration */
if (R.la[a]->shadowBufOb) {
RE_deleteShadowBuffer((RE_ShadowBufferHandle) R.la[a]->shadowBufOb);
}
if(R.la[a]->shb) {
shb= R.la[a]->shb;
v= (shb->size*shb->size)/256;
@ -2821,8 +2795,6 @@ void RE_rotateBlenderScene(void)
ob= ob->id.next;
}
if(G.special1 & G_HOLO) RE_holoview();
/* because of optimal calculation tracking/lattices/etc: and extra where_is_ob here */
base= G.scene->base.first;

View File

@ -53,9 +53,6 @@
#include "MTC_matrixops.h"
#include "render.h"
#include "mydevice.h"
#include "DNA_texture_types.h"
#include "DNA_world_types.h"
#include "DNA_camera_types.h"
@ -85,6 +82,8 @@
#include "PIL_time.h"
#include "RE_renderconverter.h"
#include "render.h"
#include "mydevice.h"
#define PR_RECTX 141
#define PR_RECTY 141
@ -102,12 +101,7 @@ static float pr_facx, pr_facy;
/* implementation */
static short snijpunt(float *v1,
float *v2,
float *v3,
float *rtlabda,
float *ray1,
float *ray2)
static short snijpunt(float *v1, float *v2, float *v3, float *rtlabda, float *ray1, float *ray2)
{
float x0,x1,x2,t00,t01,t02,t10,t11,t12,t20,t21,t22;
float m0,m1,m2,deeldet,det1,det2,det3;
@ -172,9 +166,7 @@ static int rcubi[3][4]= {
{3, 0, 2, 6} };
static int ray_previewrender(int x,
int y,
float *vec)
static int ray_previewrender(int x, int y, float *vec, float *vn)
{
float scalef= 12.8/100.0;
float ray1[3], ray2[3];
@ -205,7 +197,7 @@ static int ray_previewrender(int x,
if(hitface > -1) {
CalcNormFloat(rcubev[rcubi[hitface][0]], rcubev[rcubi[hitface][1]], rcubev[rcubi[hitface][2]], R.vn);
CalcNormFloat(rcubev[rcubi[hitface][0]], rcubev[rcubi[hitface][1]], rcubev[rcubi[hitface][2]], vn);
vec[0]= (minlabda*(ray1[0]-ray2[0])+ray2[0])/3.7;
vec[1]= (minlabda*(ray1[1]-ray2[1])+ray2[1])/3.7;
@ -375,37 +367,38 @@ void BIF_previewdraw(void)
static void sky_preview_pixel(float lens, int x, int y, char *rect)
{
float view[3];
if(R.wrld.skytype & WO_SKYPAPER) {
R.view[0]= (2*x)/(float)PR_RECTX;
R.view[1]= (2*y)/(float)PR_RECTY;
R.view[2]= 0.0;
view[0]= (2*x)/(float)PR_RECTX;
view[1]= (2*y)/(float)PR_RECTY;
view[2]= 0.0;
}
else {
R.view[0]= x;
R.view[1]= y;
R.view[2]= -lens*PR_RECTX/32.0;
Normalise(R.view);
view[0]= x;
view[1]= y;
view[2]= -lens*PR_RECTX/32.0;
Normalise(view);
}
RE_sky(rect);
RE_sky(view, rect);
}
static void lamp_preview_pixel(LampRen *la, int x, int y, char *rect)
static void lamp_preview_pixel(ShadeInput *shi, LampRen *la, int x, int y, char *rect)
{
float inpr, i, t, dist, distkw, vec[3];
int col;
R.co[0]= (float)x/(PR_RECTX/4);
R.co[1]= (float)y/(PR_RECTX/4);
R.co[2]= 0;
shi->co[0]= (float)x/(PR_RECTX/4);
shi->co[1]= (float)y/(PR_RECTX/4);
shi->co[2]= 0;
vec[0]= 0.02*x;
vec[1]= 0.02*y;
vec[2]= 0.005*PR_RECTX;
VECCOPY(R.view, vec);
dist= Normalise(R.view);
VECCOPY(shi->view, vec);
dist= Normalise(shi->view);
if(la->mode & LA_TEXTURE) do_lamp_tex(la, vec);
if(la->mode & LA_TEXTURE) do_lamp_tex(la, vec, shi);
if(la->type==LA_SUN || la->type==LA_HEMI) {
dist= 1.0;
@ -433,10 +426,10 @@ static void lamp_preview_pixel(LampRen *la, int x, int y, char *rect)
if(la->mode & LA_SQUARE) {
/* slightly smaller... */
inpr= 1.7*cos(MAX2(fabs(R.view[0]/R.view[2]) , fabs(R.view[1]/R.view[2]) ));
inpr= 1.7*cos(MAX2(fabs(shi->view[0]/shi->view[2]) , fabs(shi->view[1]/shi->view[2]) ));
}
else {
inpr= R.view[2];
inpr= shi->view[2];
}
t= la->spotsi;
@ -453,7 +446,7 @@ static void lamp_preview_pixel(LampRen *la, int x, int y, char *rect)
}
dist*=inpr;
}
else if(la->type==LA_LOCAL) dist*= R.view[2];
else if(la->type==LA_LOCAL) dist*= shi->view[2];
col= 255.0*dist*la->r;
if(col<=0) rect[0]= 0; else if(col>=255) rect[0]= 255; else rect[0]= col;
@ -578,7 +571,7 @@ static void previewflare(SpaceButs *sbuts, HaloRen *har, unsigned int *rect)
extern float Tin, Tr, Tg, Tb, Ta; /* texture.c */
static void texture_preview_pixel(Tex *tex, int x, int y, char *rect)
{
float i, v1, xsq, ysq, texvec[3];
float i, v1, xsq, ysq, texvec[3], dummy[3];
int rgbnor, tracol, skip=0;
if(tex->type==TEX_IMAGE) {
@ -634,12 +627,12 @@ static void texture_preview_pixel(Tex *tex, int x, int y, char *rect)
/* does not return Tin */
if(tex->type==TEX_STUCCI) {
tex->nor= R.vn;
R.vn[0]= 1.0;
R.vn[1]= R.vn[2]= 0.0;
tex->nor= dummy;
dummy[0]= 1.0;
dummy[1]= dummy[2]= 0.0;
}
if(skip==0) rgbnor= multitex(tex, texvec, 0, 0);
if(skip==0) rgbnor= multitex(tex, texvec, NULL, NULL, 0);
else rgbnor= 1;
if(rgbnor & 1) {
@ -705,7 +698,7 @@ static void refraction_prv(int *x, int *y, float *n, float index)
}
static void shade_preview_pixel(float *vec, int x, int y,char *rect, int smooth)
static void shade_preview_pixel(ShadeInput *shi, float *vec, int x, int y,char *rect, int smooth)
{
extern float fresnel_fac(float *view, float *vn, float fresnel);
Material *mat;
@ -716,7 +709,7 @@ static void shade_preview_pixel(float *vec, int x, int y,char *rect, int smooth)
int temp, a;
char tracol;
mat= R.matren;
mat= shi->matren;
v1= 1.0/PR_RECTX;
view[0]= v1*x;
@ -724,12 +717,12 @@ static void shade_preview_pixel(float *vec, int x, int y,char *rect, int smooth)
view[2]= 1.0;
Normalise(view);
R.refcol[0]= R.refcol[1]= R.refcol[2]= R.refcol[3]= 0.0;
shi->refcol[0]= shi->refcol[1]= shi->refcol[2]= shi->refcol[3]= 0.0;
/* texture handling */
if(mat->texco) {
VECCOPY(R.lo, vec);
VECCOPY(shi->lo, vec);
if(mat->pr_type==MA_CUBE) {
@ -738,50 +731,54 @@ static void shade_preview_pixel(float *vec, int x, int y,char *rect, int smooth)
eul[2]= (45)*M_PI/180.0;
EulToMat3(eul, tmat);
MTC_Mat3MulVecfl(tmat, R.lo);
MTC_Mat3MulVecfl(tmat, R.vn);
MTC_Mat3MulVecfl(tmat, shi->lo);
MTC_Mat3MulVecfl(tmat, shi->vn);
/* hack for cubemap, why!!! */
SWAP(float, R.vn[0], R.vn[1]);
SWAP(float, shi->vn[0], shi->vn[1]);
}
if(mat->texco & TEXCO_GLOB) {
VECCOPY(R.gl, R.lo);
VECCOPY(shi->gl, shi->lo);
}
if(mat->texco & TEXCO_WINDOW) {
VECCOPY(R.winco, R.lo);
VECCOPY(shi->winco, shi->lo);
}
if(mat->texco & TEXCO_STICKY) {
VECCOPY(R.sticky, R.lo);
VECCOPY(shi->sticky, shi->lo);
}
if(mat->texco & TEXCO_UV) {
VECCOPY(R.uv, R.lo);
VECCOPY(shi->uv, shi->lo);
}
if(mat->texco & TEXCO_OBJECT) {
VECCOPY(R.co, R.lo);
VECCOPY(shi->co, shi->lo);
}
if(mat->texco & TEXCO_NORM) {
R.orn[0]= R.vn[0];
R.orn[1]= -R.vn[1];
R.orn[2]= R.vn[2];
shi->orn[0]= shi->vn[0];
shi->orn[1]= shi->vn[1];
shi->orn[2]= shi->vn[2];
}
if(mat->texco & TEXCO_REFL) {
/* for bump texture */
VECCOPY(R.view, view);
VECCOPY(shi->view, view);
inp= -2.0*(R.vn[0]*view[0]+R.vn[1]*view[1]+R.vn[2]*view[2]);
R.ref[0]= (view[0]+inp*R.vn[0]);
R.ref[1]= (view[1]+inp*R.vn[1]);
if(smooth) R.ref[1]= -R.ref[1];
R.ref[2]= (view[2]+inp*R.vn[2]);
inp= -2.0*(shi->vn[0]*view[0]+shi->vn[1]*view[1]+shi->vn[2]*view[2]);
shi->ref[0]= (view[0]+inp*shi->vn[0]);
shi->ref[1]= (view[1]+inp*shi->vn[1]);
shi->ref[2]= (view[2]+inp*shi->vn[2]);
}
do_material_tex();
do_material_tex(shi);
if(mat->texco & TEXCO_REFL) {
/* normals in render are pointing different... rhm */
if(smooth) shi->ref[1]= -shi->ref[1];
}
if(mat->pr_type==MA_CUBE) {
/* rotate normal back for normals texture */
SWAP(float, R.vn[0], R.vn[1]);
SWAP(float, shi->vn[0], shi->vn[1]);
MTC_Mat3Inv(imat, tmat);
MTC_Mat3MulVecfl(imat, R.vn);
MTC_Mat3MulVecfl(imat, shi->vn);
}
}
@ -808,7 +805,7 @@ static void shade_preview_pixel(float *vec, int x, int y,char *rect, int smooth)
lv[2]= vec[2]-la[2];
Normalise(lv);
inp= R.vn[0]*lv[0]+R.vn[1]*lv[1]+R.vn[2]*lv[2];
inp= shi->vn[0]*lv[0]+shi->vn[1]*lv[1]+shi->vn[2]*lv[2];
if(inp<0.0) inp= 0.0;
if(mat->spec) {
@ -818,13 +815,13 @@ static void shade_preview_pixel(float *vec, int x, int y,char *rect, int smooth)
float specfac;
if(mat->spec_shader==MA_SPEC_PHONG)
specfac= Phong_Spec(R.vn, lv, view, mat->har);
specfac= Phong_Spec(shi->vn, lv, view, mat->har);
else if(mat->spec_shader==MA_SPEC_COOKTORR)
specfac= CookTorr_Spec(R.vn, lv, view, mat->har);
specfac= CookTorr_Spec(shi->vn, lv, view, mat->har);
else if(mat->spec_shader==MA_SPEC_BLINN)
specfac= Blinn_Spec(R.vn, lv, view, mat->refrac, (float)mat->har);
specfac= Blinn_Spec(shi->vn, lv, view, mat->refrac, (float)mat->har);
else
specfac= Toon_Spec(R.vn, lv, view, mat->param[2], mat->param[3]);
specfac= Toon_Spec(shi->vn, lv, view, mat->param[2], mat->param[3]);
inprspec= specfac*mat->spec;
@ -835,8 +832,8 @@ static void shade_preview_pixel(float *vec, int x, int y,char *rect, int smooth)
}
}
/* diffuse shaders */
if(mat->diff_shader==MA_DIFF_ORENNAYAR) inp= OrenNayar_Diff(R.vn, lv, view, mat->roughness);
else if(mat->diff_shader==MA_DIFF_TOON) inp= Toon_Diff(R.vn, lv, view, mat->param[0], mat->param[1]);
if(mat->diff_shader==MA_DIFF_ORENNAYAR) inp= OrenNayar_Diff(shi->vn, lv, view, mat->roughness);
else if(mat->diff_shader==MA_DIFF_TOON) inp= Toon_Diff(shi->vn, lv, view, mat->param[0], mat->param[1]);
// else Lambert
inp= (mat->ref*inp + mat->emit);
@ -855,33 +852,33 @@ static void shade_preview_pixel(float *vec, int x, int y,char *rect, int smooth)
int fac;
/* rotate a bit in x */
y= R.ref[1]; z= R.ref[2];
R.ref[1]= 0.98*y - 0.17*z;
R.ref[2]= 0.17*y + 0.98*z;
y= shi->ref[1]; z= shi->ref[2];
shi->ref[1]= 0.98*y - 0.17*z;
shi->ref[2]= 0.17*y + 0.98*z;
/* scale */
div= (0.85*R.ref[1]);
div= (0.85*shi->ref[1]);
R.refcol[0]= mat->ray_mirror*fresnel_fac(view, R.vn, mat->fresnel_mir);
shi->refcol[0]= mat->ray_mirror*fresnel_fac(view, shi->vn, mat->fresnel_mir);
if(div<0.0) {
/* minus 0.5 prevents too many small tiles in distance */
fac= (int)(R.ref[0]/(div-0.1) ) + (int)(R.ref[2]/(div-0.1) );
fac= (int)(shi->ref[0]/(div-0.1) ) + (int)(shi->ref[2]/(div-0.1) );
if(fac & 1) col= 0.8;
else col= 0.3;
R.refcol[1]= R.refcol[0]*col;
R.refcol[2]= R.refcol[1];
R.refcol[3]= R.refcol[2];
shi->refcol[1]= shi->refcol[0]*col;
shi->refcol[2]= shi->refcol[1];
shi->refcol[3]= shi->refcol[2];
}
else {
R.refcol[1]= 0.0;
R.refcol[2]= R.refcol[0]*0.3*div;
R.refcol[3]= R.refcol[0]*0.8*div;
shi->refcol[1]= 0.0;
shi->refcol[2]= shi->refcol[0]*0.3*div;
shi->refcol[3]= shi->refcol[0]*0.8*div;
}
}
if(R.refcol[0]==0.0) {
if(shi->refcol[0]==0.0) {
a= 255.0*( mat->r*ir +mat->ambr +isr);
if(a>255) a=255; else if(a<0) a= 0;
rect[0]= a;
@ -893,13 +890,13 @@ static void shade_preview_pixel(float *vec, int x, int y,char *rect, int smooth)
rect[2]= a;
}
else {
a= 255.0*( mat->mirr*R.refcol[1] + (1.0 - mat->mirr*R.refcol[0])*(mat->r*ir +mat->ambr) +isr);
a= 255.0*( mat->mirr*shi->refcol[1] + (1.0 - mat->mirr*shi->refcol[0])*(mat->r*ir +mat->ambr) +isr);
if(a>255) a=255; else if(a<0) a= 0;
rect[0]= a;
a= 255.0*( mat->mirg*R.refcol[2] + (1.0 - mat->mirg*R.refcol[0])*(mat->g*ig +mat->ambg) +isg);
a= 255.0*( mat->mirg*shi->refcol[2] + (1.0 - mat->mirg*shi->refcol[0])*(mat->g*ig +mat->ambg) +isg);
if(a>255) a=255; else if(a<0) a= 0;
rect[1]= a;
a= 255.0*( mat->mirb*R.refcol[3] + (1.0 - mat->mirb*R.refcol[0])*(mat->b*ib +mat->ambb) +isb);
a= 255.0*( mat->mirb*shi->refcol[3] + (1.0 - mat->mirb*shi->refcol[0])*(mat->b*ib +mat->ambb) +isb);
if(a>255) a=255; else if(a<0) a= 0;
rect[2]= a;
}
@ -909,7 +906,7 @@ static void shade_preview_pixel(float *vec, int x, int y,char *rect, int smooth)
if(mat->mode & (MA_ZTRA|MA_RAYTRANSP))
if(mat->fresnel_tra!=0.0)
alpha*= fresnel_fac(view, R.vn, mat->fresnel_tra);
alpha*= fresnel_fac(view, shi->vn, mat->fresnel_tra);
/* ztra shade */
if(mat->spectra!=0.0) {
@ -921,7 +918,7 @@ static void shade_preview_pixel(float *vec, int x, int y,char *rect, int smooth)
if(alpha!=1.0) {
if(mat->mode & MA_RAYTRANSP) {
refraction_prv(&x, &y, R.vn, mat->ang);
refraction_prv(&x, &y, shi->vn, mat->ang);
}
tracol= previewback(mat->pr_back, x, y) & 255;
@ -947,6 +944,7 @@ void BIF_previewrender(SpaceButs *sbuts)
HaloRen har;
Object *ob;
uiBlock *block;
ShadeInput shi;
float lens = 0.0, vec[3];
int x, y, starty, startx, endy, endx, radsq, xsq, ysq, last = 0;
unsigned int *rect;
@ -994,7 +992,7 @@ void BIF_previewrender(SpaceButs *sbuts)
MTC_Mat4One(R.viewmat);
MTC_Mat4One(R.viewinv);
R.osatex= 0;
shi.osatex= 0;
if(mat) {
/* rendervars */
@ -1014,9 +1012,9 @@ void BIF_previewrender(SpaceButs *sbuts)
if(mat->mtex[x]->object) MTC_Mat4One(mat->mtex[x]->object->imat);
}
}
R.vlr= 0;
R.mat= mat;
R.matren= mat->ren;
shi.vlr= 0;
shi.mat= mat;
shi.matren= mat->ren;
if(mat->mode & MA_HALO) init_previewhalo(&har, mat);
}
@ -1123,25 +1121,25 @@ void BIF_previewrender(SpaceButs *sbuts)
if(mat->pr_type==MA_SPHERE) {
if(xsq+ysq <= radsq) {
R.vn[0]= x;
R.vn[1]= y;
R.vn[2]= sqrt( (float)(radsq-xsq-ysq) );
Normalise(R.vn);
shi.vn[0]= x;
shi.vn[1]= y;
shi.vn[2]= sqrt( (float)(radsq-xsq-ysq) );
Normalise(shi.vn);
vec[0]= R.vn[0];
vec[1]= R.vn[2];
vec[2]= -R.vn[1];
vec[0]= shi.vn[0];
vec[1]= shi.vn[2];
vec[2]= -shi.vn[1];
shade_preview_pixel(vec, x, y, (char *)rect, 1);
shade_preview_pixel(&shi, vec, x, y, (char *)rect, 1);
}
else {
rect[0]= previewback(mat->pr_back, x, y);
}
}
else if(mat->pr_type==MA_CUBE) {
if( ray_previewrender(x, y, vec) ) {
if( ray_previewrender(x, y, vec, shi.vn) ) {
shade_preview_pixel(vec, x, y, (char *)rect, 0);
shade_preview_pixel(&shi, vec, x, y, (char *)rect, 0);
}
else {
rect[0]= previewback(mat->pr_back, x, y);
@ -1152,10 +1150,10 @@ void BIF_previewrender(SpaceButs *sbuts)
vec[1]= y*(2.0/PR_RECTX);
vec[2]= 0.0;
R.vn[0]= R.vn[1]= 0.0;
R.vn[2]= 1.0;
shi.vn[0]= shi.vn[1]= 0.0;
shi.vn[2]= 1.0;
shade_preview_pixel(vec, x, y, (char *)rect, 0);
shade_preview_pixel(&shi, vec, x, y, (char *)rect, 0);
}
}
}
@ -1167,7 +1165,7 @@ void BIF_previewrender(SpaceButs *sbuts)
}
else if(la) {
for(x=startx; x<endx; x++, rect++) {
lamp_preview_pixel(lar, x, y, (char *)rect);
lamp_preview_pixel(&shi, lar, x, y, (char *)rect);
}
}
else {

View File

@ -61,6 +61,7 @@
#include "DNA_mesh_types.h"
#include "DNA_lamp_types.h"
#include "DNA_screen_types.h"
#include "DNA_scene_types.h"
#include "DNA_userdef_types.h"
#include "DNA_view3d_types.h"
@ -106,8 +107,6 @@
#include "mydevice.h"
#include "blendef.h"
#include "render.h"
static int tbx1, tbx2, tby1, tby2, tbfontyofs, tbmain=0;
static int tbmemx=TBOXX/2, tbmemy=(TBOXEL-0.5)*TBOXH, tboldwin, addmode= 0;

View File

@ -544,7 +544,7 @@ void setwinmatrixview3d(rctf *rect) /* rect: for picking */
{
Camera *cam=0;
float d, near, far, winx = 0.0, winy = 0.0;
float lens, dfac, tfac, fac, x1, y1, x2, y2;
float lens, dfac, fac, x1, y1, x2, y2;
short orth;
lens= G.vd->lens;
@ -615,21 +615,7 @@ void setwinmatrixview3d(rctf *rect) /* rect: for picking */
x2= -x1;
y1= -dfac*(winy/fac);
y2= -y1;
if(G.vd->persp==2 && (G.special1 & G_HOLO)) {
if(cam && (cam->flag & CAM_HOLO2)) {
tfac= fac/4.0; /* the fac is 1280/640 corrected for obszoom */
if(cam->netend==0.0) cam->netend= EFRA;
fac= (G.scene->r.cfra-1.0)/(cam->netend)-0.5;
fac*= tfac*(x2-x1);
fac*= ( cam->hololen1 );
x1-= fac;
x2-= fac;
}
}
orth= 0;
}
@ -691,8 +677,6 @@ void setviewmatrixview3d()
{
Camera *cam;
if(G.special1 & G_HOLO) RE_holoview();
if(G.vd->persp>=2) { /* obs/camera */
if(G.vd->camera) {

View File

@ -53,7 +53,6 @@
#include "DNA_userdef_types.h"
#include "render_types.h"
#include "render.h"
#include "BKE_global.h"
#include "BKE_scene.h"

View File

@ -35,9 +35,9 @@
#include "DNA_scene_types.h"
#include "DNA_texture_types.h" // EnvMap{}
#include "DNA_image_types.h" // Image{}
#include "render.h"
#include "BKE_utildefines.h" // ELEM
#include "BIF_writeimage.h"
#include "render.h"
#ifdef HAVE_CONFIG_H
#include <config.h>

View File

@ -56,8 +56,6 @@
#include "BIF_writemovie.h"
#include "BIF_toolbox.h"
#include "render.h"
#define error(str) {perror(str) ; error("%s", str); G.afbreek= 1;}
#define QUIT(str) {error(str); return;}