2 * ***** BEGIN GPL LICENSE BLOCK *****
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software Foundation,
16 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * The Original Code is Copyright (C) 2006 by Blender Foundation
19 * All rights reserved.
21 * The Original Code is: all of this file.
23 * Contributor(s): none yet.
25 * ***** END GPL/BL DUAL LICENSE BLOCK *****
27 /** \file RE_shader_ext.h
32 #ifndef __RE_SHADER_EXT_H__
33 #define __RE_SHADER_EXT_H__
35 /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
36 /* this include is for shading and texture exports */
37 /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
39 /* localized texture result data */
40 /* note; tr tg tb ta has to remain in this order */
41 typedef struct TexResult {
42 float tin, tr, tg, tb, ta;
47 /* localized shade result data */
48 typedef struct ShadeResult {
53 float diff[3]; /* diffuse with no ramps, shadow, etc */
54 float diffshad[3]; /* diffuse with shadow */
55 float spec[3]; /* specular with shadow */
56 float shad[4]; /* shad[3] is shadow intensity */
67 /* only here for quick copy */
68 struct ShadeInputCopy {
72 struct StrandRen *strand;
73 struct ObjectInstanceRen *obi;
74 struct ObjectRen *obr;
76 float facenor[3]; /* copy from face */
77 short flippednor; /* is facenor flipped? */
78 struct VertRen *v1, *v2, *v3; /* vertices can be in any order for quads... */
79 short i1, i2, i3; /* original vertex indices */
82 float vn[3], vno[3]; /* actual render normal, and a copy to restore it */
83 float n1[3], n2[3], n3[3]; /* vertex normals, corrected */
84 int mode; /* base material mode (OR-ed result of entire node tree) */
87 typedef struct ShadeInputUV {
88 float dxuv[3], dyuv[3], uv[3];
92 typedef struct ShadeInputCol {
97 /* localized renderloop data */
98 typedef struct ShadeInput {
99 /* copy from face, also to extract tria from quad */
100 /* note it mirrors a struct above for quick copy */
102 struct Material *mat;
104 struct StrandRen *strand;
105 struct ObjectInstanceRen *obi;
106 struct ObjectRen *obr;
108 float facenor[3]; /* copy from face */
109 short flippednor; /* is facenor flipped? */
110 struct VertRen *v1, *v2, *v3; /* vertices can be in any order for quads... */
111 short i1, i2, i3; /* original vertex indices */
114 float vn[3], vno[3]; /* actual render normal, and a copy to restore it */
115 float n1[3], n2[3], n3[3]; /* vertex normals, corrected */
116 int mode; /* base material mode (OR-ed result of entire node tree) */
118 /* internal face coordinates */
119 float u, v, dx_u, dx_v, dy_u, dy_v;
120 float co[3], view[3], camera_co[3];
122 /* copy from material, keep synced so we can do memcopy */
123 /* current size: 23*4 */
125 float specr, specg, specb;
126 float mirr, mirg, mirb;
127 float ambr, ambb, ambg;
129 float amb, emit, ang, spectra, ray_mirror;
130 float alpha, refl, spec, zoffs, add;
132 /* end direct copy from material */
134 /* individual copies: */
135 int har; /* hardness */
137 /* texture coordinates */
138 float lo[3], gl[3], ref[3], orn[3], winco[3], vcol[4];
139 float refcol[4], displace[3];
140 float strandco, tang[3], nmapnorm[3], nmaptang[4], stress, winspeed[4];
141 float duplilo[3], dupliuv[3];
143 ShadeInputUV uv[8]; /* 8 = MAX_MTFACE */
144 ShadeInputCol col[8]; /* 8 = MAX_MCOL */
145 int totuv, totcol, actuv, actcol;
147 /* dx/dy OSA coordinates */
148 float dxco[3], dyco[3];
149 float dxlo[3], dylo[3], dxgl[3], dygl[3];
150 float dxref[3], dyref[3], dxorn[3], dyorn[3];
151 float dxno[3], dyno[3], dxview, dyview;
152 float dxlv[3], dylv[3];
153 float dxwin[3], dywin[3];
154 float dxrefract[3], dyrefract[3];
155 float dxstrand, dystrand;
157 /* AO is a pre-process now */
158 float ao[3], indirect[3], env[3];
160 int xs, ys; /* pixel to be rendered */
161 int mask; /* subsample mask */
162 float scanco[3]; /* original scanline coordinate without jitter */
164 int samplenr; /* sample counter, to detect if we should do shadow again */
165 int depth; /* 1 or larger on raytrace shading */
166 int volume_depth; /* number of intersections through volumes */
168 /* for strand shading, normal at the surface */
169 float surfnor[3], surfdist;
171 /* from initialize, part or renderlayer */
172 bool do_preview; /* for nodes, in previewrender */
173 bool do_manage; /* color management flag */
174 short thread, sample; /* sample: ShadeSample array index */
175 short nodes; /* indicate node shading, temp hack to prevent recursion */
178 int layflag, passflag, combinedflag;
179 struct Group *light_override;
180 struct Material *mat_override;
183 RayCounter raycounter;
188 typedef struct BakeImBufuserData {
189 float *displacement_buffer;
193 /* node shaders... */
200 /* this one uses nodes */
201 int multitex_ext(struct Tex *tex, float texvec[3], float dxt[3], float dyt[3], int osatex, struct TexResult *texres, struct ImagePool *pool, bool scene_color_manage);
203 int multitex_ext_safe(struct Tex *tex, float texvec[3], struct TexResult *texres, struct ImagePool *pool, bool scene_color_manage);
204 /* only for internal node usage */
205 int multitex_nodes(struct Tex *tex, float texvec[3], float dxt[3], float dyt[3], int osatex, struct TexResult *texres,
206 const short thread, short which_output, struct ShadeInput *shi, struct MTex *mtex,
207 struct ImagePool *pool);
208 float RE_lamp_get_data(struct ShadeInput *shi, struct Object *lamp_obj, float col[4], float lv[3], float *dist, float shadow[4]);
210 /* shaded view and bake */
214 int RE_bake_shade_all_selected(struct Render *re, int type, struct Object *actob, short *do_update, float *progress);
215 struct Image *RE_bake_shade_get_image(void);
216 void RE_bake_ibuf_filter(struct ImBuf *ibuf, char *mask, const int filter);
217 void RE_bake_ibuf_normalize_displacement(struct ImBuf *ibuf, float *displacement, char *mask, float displacement_min, float displacement_max);
218 float RE_bake_make_derivative(struct ImBuf *ibuf, float *heights_buffer, const char *mask,
219 const float height_min, const float height_max,
222 #define BAKE_RESULT_OK 0
223 #define BAKE_RESULT_NO_OBJECTS 1
224 #define BAKE_RESULT_FEEDBACK_LOOP 2
226 #endif /* __RE_SHADER_EXT_H__ */