FreeWRL / FreeX3D 4.3.0
Component_Shape.h
1/*
2
3
4Proximity sensor macro.
5
6*/
7
8/****************************************************************************
9 This file is part of the FreeWRL/FreeX3D Distribution.
10
11 Copyright 2009 CRC Canada. (http://www.crc.gc.ca)
12
13 FreeWRL/FreeX3D is free software: you can redistribute it and/or modify
14 it under the terms of the GNU Lesser Public License as published by
15 the Free Software Foundation, either version 3 of the License, or
16 (at your option) any later version.
17
18 FreeWRL/FreeX3D is distributed in the hope that it will be useful,
19 but WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 GNU General Public License for more details.
22
23 You should have received a copy of the GNU General Public License
24 along with FreeWRL/FreeX3D. If not, see <http://www.gnu.org/licenses/>.
25****************************************************************************/
26
27
28
29#ifndef __FREEWRL_SCENEGRAPH_SHAPE_H__
30#define __FREEWRL_SCENEGRAPH_SHAPE_H__
31
32
33/*******************************************************/
34
35
36/*
37
38 Bit-wise operations here - these can be OR'd together to
39 create the specific shader we want.
40
41 DO NOT MESS UP THE BITS! (look at these in binary for
42 proper or-ing of the values)
43
44Sept 25, 2016:
45shaderflags changed from int to struct { int, int, int }
46{
47 base, built from bit flags, and is also a fallback if userShader is desired but doesn't compile
48 effect (castle Effect)
49 user shader number (programmableShader)
50}
51- Could have done one long long int with 3 ranges, or int[3] instead; struct seems handy.
52- In general needed more breathing room, especially for new effects which are bit mask or-able together, unlike
53 user shaders that do only one user shader at a time
54- now to test if its a usershader, just test if .usershaders != 0 (they start at 1)
55- need to memset(,0,) the struct if creating fresh
56- if need more bits in the future, add another member or change one to longlong
57 and look for places where we see if its == ie in opengl_utils.c
58 if (me->whichOne.base == rq_cap0.base && me->whichOne.effects == rq_cap0.effects && me->whichOne.usershaders == rq_cap0.usershaders) {
59
60*/
61
62typedef struct {
63unsigned long long base;
64int effects;
65int usershaders;
66int volume;
67int depth;
68int debug;
70
71shaderflagsstruct getShaderFlags();
72void popShaderFlags(void);
73void pushShaderFlags(shaderflagsstruct);
74s_shader_capabilities_t *getMyShaders(shaderflagsstruct);
75enum {
76 MAT_NONE = 0,
77 MAT_UNLIT = 1,
78 MAT_REGULAR = 2,
79 MAT_PHYSICAL = 3,
80};
81
82
83#define NO_APPEARANCE_SHADER 0x0001
84#define MATERIAL_APPEARANCE_SHADER 0x0002
85#define TWO_MATERIAL_APPEARANCE_SHADER 0x0004
86#define PHYSICAL_MATERIAL_APPEARANCE_SHADER 0x0008
87#define UNLIT_MATERIAL_APPEARANCE_SHADER 0x0010
88#define ONE_TEX_APPEARANCE_SHADER 0x0020
89#define MULTI_TEX_APPEARANCE_SHADER 0x0040
90
91/* PolyRep (etc) color field present */
92#define COLOUR_MATERIAL_SHADER 0x00080
93
94/* - fillProperties present */
95#define FILL_PROPERTIES_SHADER 0x00100
96
97/* - lines, points */
98#define HAVE_LINEPOINTS_COLOR 0x00200
99#define HAVE_LINEPOINTS_APPEARANCE 0x00400
100
101/* TextureCoordinateGenerator */
102#define HAVE_TEXTURECOORDINATEGENERATOR 0x00800
103
104/* CubeMapTexturing */
105#define HAVE_CUBEMAP_TEXTURE 0x01000
106/* more OR-able flags for compositing shaders */
107#define FOG_APPEARANCE_SHADER 0X02000
108#define HAVE_FOG_COORDS 0x04000
109#define MODULATE_COLOR 0x08000
110#define MODULATE_ALPHA 0x10000
111#define MODULATE_TEXTURE 0x20000
112#define SHADINGSTYLE_FLAT 0x40000
113#define SHADINGSTYLE_GOURAUD 0x80000
114#define SHADINGSTYLE_PHONG 0x100000
115#define SHADINGSTYLE_WIRE 0x200000
116#define MAT_FIRST 0x400000
117#define WANT_ANAGLYPH 0x800000
118#define TEX3D_SHADER 0X1000000
119#define TEX3D_LAYER_SHADER 0x2000000
120#define CLIPPLANE_SHADER 0x4000000
121#define PARTICLE_SHADER 0X8000000
122#define HAVE_UNLIT_COLOR 0x10000000
123#define HAVE_PROJECTIVETEXTURE 0X20000000
124#define LINE_PROPERTIES_SHADER 0X40000000
125#define POINT_PROPERTIES_SHADER 0x80000000
126#define SKINNING_SHADER 0X100000000
127#define DISPLACER_SHADER 0x200000000
128//can go up to 2^32 - for future components like volume, particle, hanim
129
130//goes into flags.volume
131#define SHADERFLAGS_VOLUME_DATA_BASIC 0x001
132#define SHADERFLAGS_VOLUME_DATA_SEGMENT 0x002
133#define SHADERFLAGS_VOLUME_DATA_ISO 0x004
134#define SHADERFLAGS_VOLUME_DATA_ISO_MODE3 0x008
135//#define SHADERFLAGS_VOLUME_STYLE_OPACITY 0x001
136//#define SHADERFLAGS_VOLUME_STYLE_BLENDED 0x002
137//#define SHADERFLAGS_VOLUME_STYLE_BOUNDARY 0x004
138//#define SHADERFLAGS_VOLUME_STYLE_CARTOON 0x008
139//#define SHADERFLAGS_VOLUME_STYLE_COMPOSED 0x010
140//#define SHADERFLAGS_VOLUME_STYLE_EDGE 0x020
141//#define SHADERFLAGS_VOLUME_STYLE_PROJECTION 0x040
142//#define SHADERFLAGS_VOLUME_STYLE_SHADED 0x080
143//#define SHADERFLAGS_VOLUME_STYLE_SILHOUETTE 0x100
144//#define SHADERFLAGS_VOLUME_STYLE_TONE 0x200
145
146#define SHADERFLAGS_VOLUME_STYLE_DEFAULT 1
147#define SHADERFLAGS_VOLUME_STYLE_OPACITY 2
148#define SHADERFLAGS_VOLUME_STYLE_BLENDED 3
149#define SHADERFLAGS_VOLUME_STYLE_BOUNDARY 4
150#define SHADERFLAGS_VOLUME_STYLE_CARTOON 5
151#define SHADERFLAGS_VOLUME_STYLE_COMPOSED 6
152#define SHADERFLAGS_VOLUME_STYLE_EDGE 7
153#define SHADERFLAGS_VOLUME_STYLE_PROJECTION 8
154#define SHADERFLAGS_VOLUME_STYLE_SHADED 9
155#define SHADERFLAGS_VOLUME_STYLE_SILHOUETTE 10
156#define SHADERFLAGS_VOLUME_STYLE_TONE 11
157/*******************************************************/
158
159
161 float diffuse[3]; //MAT_REGULAR
162 float emissive[3];
163 float specular[3]; //MAT_REGULAR
164 float ambient; //MAT_REGULAR
165 float shininess; //MAT_REGULAR
166 float transparency;
167 float normalScale; // normalScale 1, all
168 float occlusion; // occlusionStrength MAT_REGULAR, MAT_PHYSICAL
169 float baseColor[3]; //MAT_PHYSICAL
170 float metallic; //MAT_PHYSICAL
171 float roughness; //MAT_PHYSICAL
172 int type; //MAT_TYPE: 0 MAT_NONE 1 MAT_EMISSIVE 2 MAT_REGULAR 3 MAT_PHYSICAL
173 // used in frag, for texture maps:
174 int transdex; // which tindex to use for transparency -1 None, else 0-3
175 // multi-te4xtues are dis-aggregated at send-to-shader stage
176 int tindex[10]; //sampler textureUnit[tindex] indexes,
177 int binding[10]; //for debugging, persists for a child_shape rendering the GL_TEXTURE0+i texture binding point used
178 int mode[10]; //multitexture modulate mode
179 int source[10]; //multitexture modulate mode
180 int func[10]; //multitexture modulate mode
181 int cmap[10]; //index of appropriate varying vec3 texCoord[cmap] to use in frag shader
182 int samplr[10]; // 0=texture2D 1=cubeMap sampler (could have SH sphereical harmonic, cubeShadow, other??)
183 int nt; // number of single texture maps 0 if none
185 //iunit [0] normal [1] emissive [2] occlusion [3] diffuse OR base [4] shininess OR metallicRoughness [5] specular [6] ambient
186 struct X3D_Node *textures[7]; //emissive,normal,[occlusion,{diffuse,ambient,specular,shininess}, or {base,smetallic}]
187 int tcount[7]; // for material.textureXXX if its a single texture 1, if multitexture n
188 int tstart[7]; // where in tindex to start looping
189 //int cindex[7]; //texture coordinate channel
190 char* map[7]; //xxxTextureMapping (pointer / shallow copy, don't free)
191 //int mtex[5]; //flag = 1 if it's a multitexture / needs multitexture functionality applied
192 int mt; // number of multitextures 0 if none, just a CPU-side flag to set MTEX in shader, don't send
193};
194
195// helpers for sharing sampler2D (and texture units)
196void clear_material_samplers();
197void clear_materialparameters_per_draw_counts();
198void initialize_front_and_back_material_params();
199int share_or_next_material_sampler_index_2D(GLint texture);
200GLint tunit2D(int index);
201int share_or_next_material_sampler_index_Cube(GLint texture);
202GLint tunitCube(int index);
203
205 /* material properties for current shape */
206 struct fw_MaterialParameters fw_FrontMaterial;
207 struct fw_MaterialParameters fw_BackMaterial;
208
209 /* which shader is active; 0 = no shader active */
210 s_shader_capabilities_t *currentShaderProperties;
211
212 //float transparency;
213 //GLfloat emissionColour[3];
214 GLint cubeFace; /* for cubemapping, if 0, not cube mapping */
215 int cullFace; /* is this single-sided or two-sided? Simply used to reduce calls to
216 GL_ENABLE(GL_CULL_FACE), etc */
217 int twosided; //if we have a real Appearance.backMaterial or Appearance.TwoSidedMaterial(deprecated) = 1, else 0.
218
219 // FillProperties
220 bool hatchedBool;
221 bool filledBool;
222 GLfloat hatchPercent[2];
223 GLfloat hatchScale[2]; //non-web3d standard but keep it for now
224 GLfloat hatchColour[4];
225 int hatchAlgo;
226
227 //LineProperties and linetypes
228 int linetype;
229 float lineperiod;
230 float linewidth; //this goes direct to our frag shader
231 float * linetype_uv;
232 float * linetype_tse;
233 int linestrip_start_style;
234 int linestrip_end_style;
235
236 //PointProperties and PointSet
237 GLfloat pointSize; //this goes to old opengl internal geometry shader
238 int pointMethod; //0 = GL_POINTS (old, simple way) 1= GL_TRIANGLES (a quad per point sprite, like ParticleSystems)
239 int markerType; //1=Dot 2+ various compiled-in crosses and circles
240 float pointsizeRange[2];
241 float pointsizeAttenuation[3];
242 int pointColorMode;
243
244 //TextureCoordinateGenerator value - a "TCGT_XXX" type
245 int texCoordGeneratorType;
246};
247
248struct matpropstruct* getAppearanceProperties();
249void setUserShaderNode(struct X3D_Node *me);
250
251
252#define MIN_NODE_TRANSPARENCY 0.0f
253#define MAX_NODE_TRANSPARENCY 0.99f /* if 1.0, then occlusion culling will cause flashing */
254
255#define RENDER_MATERIAL_SUBNODES(which) \
256 { struct X3D_Node *tmpN; \
257 POSSIBLE_PROTO_EXPANSION(struct X3D_Node *, which,tmpN) \
258 if(tmpN) { \
259 render_node(tmpN); \
260 } \
261 }
262
263
264#define SET_SHADER_SELECTED_FALSE(x3dNode) \
265 switch (X3D_NODE(x3dNode)->_nodeType) { \
266 case NODE_ComposedShader: \
267 X3D_COMPOSEDSHADER(x3dNode)->isSelected = FALSE; \
268 break; \
269 case NODE_ProgramShader: \
270 X3D_PROGRAMSHADER(x3dNode)->isSelected = FALSE; \
271 break; \
272 case NODE_PackagedShader: \
273 X3D_PROGRAMSHADER(x3dNode)->isSelected = FALSE; \
274 break; \
275 default: { \
276 /* this is NOT a shader; should we say something, or just \
277 ignore? Lets ignore, for now */ \
278 } \
279 }
280
281#define SET_FOUND_GOOD_SHADER(x3dNode) \
282 switch (X3D_NODE(x3dNode)->_nodeType) { \
283 case NODE_ComposedShader: \
284 foundGoodShader = X3D_COMPOSEDSHADER(x3dNode)->isValid; \
285 X3D_COMPOSEDSHADER(x3dNode)->isSelected = foundGoodShader; \
286 break; \
287 case NODE_ProgramShader: \
288 foundGoodShader = X3D_PROGRAMSHADER(x3dNode)->isValid; \
289 X3D_PROGRAMSHADER(x3dNode)->isSelected = foundGoodShader; \
290 break; \
291 case NODE_PackagedShader: \
292 foundGoodShader = X3D_PROGRAMSHADER(x3dNode)->isValid; \
293 X3D_PACKAGEDSHADER(x3dNode)->isSelected = foundGoodShader; \
294 break; \
295 default: { \
296 /* this is NOT a shader; should we say something, or just \
297 ignore? Lets ignore, for now */ \
298 } \
299 }
300
301/*
302enum {
303PM_NONE = 0, //reserve 0 for render_PointSet to thunk to opengl GL_POINTS when no PointProperties node
304PM_SCREEN = 1,
305PM_OBJECT = 2,
306PM_FANCY = 3,
307} pointproperties_pointmethod;
308*/
309
310#define PM_NONE 0
311#define PM_SCREEN 1
312#define PM_OBJECT 2
313#define PM_FANCY 3
314
315#endif /* __FREEWRL_SCENEGRAPH_SHAPE_H__ */