1 // Copyright (C) 2002-2012 Nikolaus Gebhardt / Thomas Alten
\r
2 // This file is part of the "Irrlicht Engine".
\r
3 // For conditions of distribution and use, see copyright notice in irrlicht.h
\r
5 #include "IrrCompileConfig.h"
\r
6 #include "IBurningShader.h"
\r
8 #if defined(_IRR_COMPILE_WITH_BURNINGSVIDEO_) && 0
\r
17 /*! Render states define set-up states for all kinds of vertex and pixel processing.
\r
18 Some render states set up vertex processing, and some set up pixel processing (see Render States).
\r
19 Render states can be saved and restored using stateblocks (see State Blocks Save and Restore State).
\r
21 enum BD3DRENDERSTATETYPE
\r
24 Depth-buffering state as one member of the BD3DZBUFFERTYPE enumerated type.
\r
25 Set this state to D3DZB_TRUE to enable z-buffering,
\r
26 D3DZB_USEW to enable w-buffering, or D3DZB_FALSE to disable depth buffering.
\r
27 The default value for this render state is D3DZB_TRUE if a depth stencil was created
\r
28 along with the swap chain by setting the EnableAutoDepthStencil member of the
\r
29 D3DPRESENT_PARAMETERS structure to TRUE, and D3DZB_FALSE otherwise.
\r
33 /*! BD3DRS_FILLMODE
\r
34 One or more members of the D3DFILLMODE enumerated type. The default value is D3DFILL_SOLID.
\r
38 /*! BD3DRS_SHADEMODE
\r
39 One or more members of the D3DSHADEMODE enumerated type. The default value is D3DSHADE_GOURAUD.
\r
43 /*! BD3DRS_ZWRITEENABLE
\r
44 TRUE to enable the application to write to the depth buffer. The default value is TRUE.
\r
45 This member enables an application to prevent the system from updating the depth buffer with
\r
46 new depth values. If FALSE, depth comparisons are still made according to the render state
\r
47 D3DRS_ZFUNC, assuming that depth buffering is taking place, but depth values are not written
\r
50 BD3DRS_ZWRITEENABLE,
\r
52 /*! BD3DRS_ALPHATESTENABLE
\r
53 TRUE to enable per pixel alpha testing. If the test passes, the pixel is processed by the frame
\r
54 buffer. Otherwise, all frame-buffer processing is skipped for the pixel. The test is done by
\r
55 comparing the incoming alpha value with the reference alpha value, using the comparison function
\r
56 provided by the D3DRS_ALPHAFUNC render state. The reference alpha value is determined by the value
\r
57 set for D3DRS_ALPHAREF. For more information, see Alpha Testing State.
\r
58 The default value of this parameter is FALSE.
\r
60 BD3DRS_ALPHATESTENABLE,
\r
62 /*! BD3DRS_SRCBLEND
\r
63 One member of the BD3DBLEND enumerated type. The default value is BD3DBLEND_ONE.
\r
67 /*! BD3DRS_DESTBLEND
\r
68 One member of the BD3DBLEND enumerated type. The default value is BD3DBLEND_ZERO.
\r
73 Specifies how back-facing triangles are culled, if at all. This can be set to one
\r
74 member of the BD3DCULL enumerated type. The default value is BD3DCULL_CCW.
\r
79 One member of the BD3DCMPFUNC enumerated type. The default value is BD3DCMP_LESSEQUAL.
\r
80 This member enables an application to accept or reject a pixel, based on its distance from
\r
81 the camera. The depth value of the pixel is compared with the depth-buffer value. If the depth
\r
82 value of the pixel passes the comparison function, the pixel is written.
\r
84 The depth value is written to the depth buffer only if the render state is TRUE.
\r
85 Software rasterizers and many hardware accelerators work faster if the depth test fails,
\r
86 because there is no need to filter and modulate the texture if the pixel is not going to be
\r
91 /*! BD3DRS_ALPHAREF
\r
92 Value that specifies a reference alpha value against which pixels are tested when alpha testing
\r
93 is enabled. This is an 8-bit value placed in the low 8 bits of the DWORD render-state value.
\r
94 Values can range from 0x00000000 through 0x000000FF. The default value is 0.
\r
98 /*! BD3DRS_ALPHAFUNC
\r
99 One member of the BD3DCMPFUNC enumerated type. The default value is BD3DCMP_ALWAYS.
\r
100 This member enables an application to accept or reject a pixel, based on its alpha value.
\r
104 /*! BD3DRS_DITHERENABLE
\r
105 TRUE to enable dithering. The default value is FALSE.
\r
107 BD3DRS_DITHERENABLE,
\r
109 /*! BD3DRS_ALPHABLENDENABLE
\r
110 TRUE to enable alpha-blended transparency. The default value is FALSE.
\r
111 The type of alpha blending is determined by the BD3DRS_SRCBLEND and BD3DRS_DESTBLEND render states.
\r
113 BD3DRS_ALPHABLENDENABLE,
\r
115 /*! BD3DRS_FOGENABLE
\r
116 TRUE to enable fog blending. The default value is FALSE. For more information about using fog
\r
117 blending, see Fog.
\r
121 /*! BD3DRS_SPECULARENABLE
\r
122 TRUE to enable specular highlights. The default value is FALSE.
\r
123 Specular highlights are calculated as though every vertex in the object being lit is at the
\r
124 object's origin. This gives the expected results as long as the object is modeled around the
\r
125 origin and the distance from the light to the object is relatively large. In other cases, the
\r
126 results as undefined.
\r
127 When this member is set to TRUE, the specular color is added to the base color after the
\r
128 texture cascade but before alpha blending.
\r
130 BD3DRS_SPECULARENABLE,
\r
132 /*! BD3DRS_FOGCOLOR
\r
133 Value whose type is D3DCOLOR. The default value is 0. For more information about fog color,
\r
138 /*! BD3DRS_FOGTABLEMODE
\r
139 The fog formula to be used for pixel fog. Set to one of the members of the D3DFOGMODE
\r
140 enumerated type. The default value is D3DFOG_NONE. For more information about pixel fog,
\r
143 BD3DRS_FOGTABLEMODE,
\r
145 /*! BD3DRS_FOGSTART
\r
146 Depth at which pixel or vertex fog effects begin for linear fog mode. The default value is 0.0f.
\r
147 Depth is specified in world space for vertex fog and either device space [0.0, 1.0] or world
\r
148 space for pixel fog. For pixel fog, these values are in device space when the system uses z for
\r
149 fog calculations and world-world space when the system is using eye-relative fog (w-fog). For
\r
150 more information, see Fog Parameters and Eye-Relative vs. Z-based Depth.
\r
151 Values for the this render state are floating-point values.
\r
152 Because the IDirect3DDevice9::SetRenderState method accepts DWORD values, your
\r
153 application must cast a variable that contains the value, as shown in the following code example.
\r
154 pDevice9->SetRenderState( BD3DRS_FOGSTART, *((DWORD*) (&fFogStart)));
\r
159 Depth at which pixel or vertex fog effects end for linear fog mode. The default value is 1.0f.
\r
160 Depth is specified in world space for vertex fog and either device space [0.0, 1.0] or world space
\r
161 for pixel fog. For pixel fog, these values are in device space when the system uses z for fog
\r
162 calculations and in world space when the system is using eye-relative fog (w-fog). For more
\r
163 information, see Fog Parameters and Eye-Relative vs. Z-based Depth.
\r
164 Values for this render state are floating-point values.
\r
168 /*! BD3DRS_FOGDENSITY
\r
169 Fog density for pixel or vertex fog used in the exponential fog modes (D3DFOG_EXP and D3DFOG_EXP2).
\r
170 Valid density values range from 0.0 through 1.0. The default value is 1.0. For more information,
\r
171 see Fog Parameters.
\r
172 Values for this render state are floating-point values.
\r
177 /*! BD3DRS_RANGEFOGENABLE
\r
178 TRUE to enable range-based vertex fog. The default value is FALSE, in which case the system
\r
179 uses depth-based fog. In range-based fog, the distance of an object from the viewer is used
\r
180 to compute fog effects, not the depth of the object (that is, the z-coordinate) in the scene.
\r
181 In range-based fog, all fog methods work as usual, except that they use range instead of depth
\r
182 in the computations.
\r
183 Range is the correct factor to use for fog computations, but depth is commonly used instead
\r
184 because range is time-consuming to compute and depth is generally already available. Using depth
\r
185 to calculate fog has the undesirable effect of having the fogginess of peripheral objects change
\r
186 as the viewer's eye moves - in this case, the depth changes and the range remains constant.
\r
188 Because no hardware currently supports per-pixel range-based fog, range correction is offered
\r
189 only for vertex fog.
\r
190 For more information, see Vertex Fog.
\r
192 BD3DRS_RANGEFOGENABLE = 48,
\r
194 /*! BD3DRS_STENCILENABLE
\r
195 TRUE to enable stenciling, or FALSE to disable stenciling. The default value is FALSE.
\r
196 For more information, see Stencil Buffer Techniques.
\r
198 BD3DRS_STENCILENABLE = 52,
\r
200 /*! BD3DRS_STENCILFAIL
\r
201 Stencil operation to perform if the stencil test fails. Values are from the D3DSTENCILOP
\r
202 enumerated type. The default value is D3DSTENCILOP_KEEP.
\r
204 BD3DRS_STENCILFAIL = 53,
\r
206 /*! BD3DRS_STENCILZFAIL
\r
207 Stencil operation to perform if the stencil test passes and the depth test (z-test) fails.
\r
208 Values are from the D3DSTENCILOP enumerated type. The default value is D3DSTENCILOP_KEEP.
\r
210 BD3DRS_STENCILZFAIL = 54,
\r
212 /*! BD3DRS_STENCILPASS
\r
213 Stencil operation to perform if both the stencil and the depth (z) tests pass. Values are
\r
214 from the D3DSTENCILOP enumerated type. The default value is D3DSTENCILOP_KEEP.
\r
216 BD3DRS_STENCILPASS = 55,
\r
218 /*! BD3DRS_STENCILFUNC
\r
219 Comparison function for the stencil test. Values are from the D3DCMPFUNC enumerated type.
\r
220 The default value is D3DCMP_ALWAYS.
\r
221 The comparison function is used to compare the reference value to a stencil buffer entry.
\r
222 This comparison applies only to the bits in the reference value and stencil buffer entry that
\r
223 are set in the stencil mask (set by the D3DRS_STENCILMASK render state). If TRUE, the stencil
\r
226 BD3DRS_STENCILFUNC = 56,
\r
228 /*! BD3DRS_STENCILREF
\r
229 An int reference value for the stencil test. The default value is 0.
\r
231 BD3DRS_STENCILREF = 57,
\r
233 /*! BD3DRS_STENCILMASK
\r
234 Mask applied to the reference value and each stencil buffer entry to determine the significant
\r
235 bits for the stencil test. The default mask is 0xFFFFFFFF.
\r
237 BD3DRS_STENCILMASK = 58,
\r
239 /*! BD3DRS_STENCILWRITEMASK
\r
240 Write mask applied to values written into the stencil buffer. The default mask is 0xFFFFFFFF.
\r
242 BD3DRS_STENCILWRITEMASK = 59,
\r
244 /*! BD3DRS_TEXTUREFACTOR
\r
245 Color used for multiple-texture blending with the D3DTA_TFACTOR texture-blending argument or the
\r
246 D3DTOP_BLENDFACTORALPHA texture-blending operation. The associated value is a D3DCOLOR variable.
\r
247 The default value is opaque white (0xFFFFFFFF).
\r
249 BD3DRS_TEXTUREFACTOR = 60,
\r
252 Texture-wrapping behavior for multiple sets of texture coordinates. Valid values for this
\r
253 render state can be any combination of the D3DWRAPCOORD_0 (or D3DWRAP_U), D3DWRAPCOORD_1
\r
254 (or D3DWRAP_V), D3DWRAPCOORD_2 (or D3DWRAP_W), and D3DWRAPCOORD_3 flags. These cause the system
\r
255 to wrap in the direction of the first, second, third, and fourth dimensions, sometimes referred
\r
256 to as the s, t, r, and q directions, for a given texture. The default value for this render state
\r
257 is 0 (wrapping disabled in all directions).
\r
259 BD3DRS_WRAP0 = 128,
\r
260 BD3DRS_WRAP1 = 129,
\r
261 BD3DRS_WRAP2 = 130,
\r
262 BD3DRS_WRAP3 = 131,
\r
263 BD3DRS_WRAP4 = 132,
\r
264 BD3DRS_WRAP5 = 133,
\r
265 BD3DRS_WRAP6 = 134,
\r
266 BD3DRS_WRAP7 = 135,
\r
268 /*! BD3DRS_CLIPPING
\r
269 TRUE to enable primitive clipping by Direct3D, or FALSE to disable it. The default value is TRUE.
\r
271 BD3DRS_CLIPPING = 136,
\r
273 /*! BD3DRS_LIGHTING
\r
274 TRUE to enable Direct3D lighting, or FALSE to disable it. The default value is TRUE. Only
\r
275 vertices that include a vertex normal are properly lit; vertices that do not contain a normal
\r
276 employ a dot product of 0 in all lighting calculations.
\r
278 BD3DRS_LIGHTING = 137,
\r
281 Ambient light color. This value is of type D3DCOLOR. The default value is 0.
\r
283 BD3DRS_AMBIENT = 139,
\r
285 /*! BD3DRS_FOGVERTEXMODE
\r
286 Fog formula to be used for vertex fog. Set to one member of the BD3DFOGMODE enumerated type.
\r
287 The default value is D3DFOG_NONE.
\r
289 BD3DRS_FOGVERTEXMODE = 140,
\r
291 /*! BD3DRS_COLORVERTEX
\r
292 TRUE to enable per-vertex color or FALSE to disable it. The default value is TRUE. Enabling
\r
293 per-vertex color allows the system to include the color defined for individual vertices in its
\r
294 lighting calculations.
\r
295 For more information, see the following render states:
\r
296 BD3DRS_DIFFUSEMATERIALSOURCE
\r
297 BD3DRS_SPECULARMATERIALSOURCE
\r
298 BD3DRS_AMBIENTMATERIALSOURCE
\r
299 BD3DRS_EMISSIVEMATERIALSOURCE
\r
301 BD3DRS_COLORVERTEX = 141,
\r
303 /*! BD3DRS_LOCALVIEWER
\r
304 TRUE to enable camera-relative specular highlights, or FALSE to use orthogonal specular
\r
305 highlights. The default value is TRUE. Applications that use orthogonal projection should
\r
308 BD3DRS_LOCALVIEWER = 142,
\r
310 /*! BD3DRS_NORMALIZENORMALS
\r
311 TRUE to enable automatic normalization of vertex normals, or FALSE to disable it. The default
\r
312 value is FALSE. Enabling this feature causes the system to normalize the vertex normals for
\r
313 vertices after transforming them to camera space, which can be computationally time-consuming.
\r
315 BD3DRS_NORMALIZENORMALS = 143,
\r
317 /*! BD3DRS_DIFFUSEMATERIALSOURCE
\r
318 Diffuse color source for lighting calculations. Valid values are members of the
\r
319 D3DMATERIALCOLORSOURCE enumerated type. The default value is D3DMCS_COLOR1. The value for this
\r
320 render state is used only if the D3DRS_COLORVERTEX render state is set to TRUE.
\r
322 BD3DRS_DIFFUSEMATERIALSOURCE = 145,
\r
324 /*! BD3DRS_SPECULARMATERIALSOURCE
\r
325 Specular color source for lighting calculations. Valid values are members of the
\r
326 D3DMATERIALCOLORSOURCE enumerated type. The default value is D3DMCS_COLOR2.
\r
328 BD3DRS_SPECULARMATERIALSOURCE = 146,
\r
330 /*! D3DRS_AMBIENTMATERIALSOURCE
\r
331 Ambient color source for lighting calculations. Valid values are members of the
\r
332 D3DMATERIALCOLORSOURCE enumerated type. The default value is D3DMCS_MATERIAL.
\r
334 BD3DRS_AMBIENTMATERIALSOURCE = 147,
\r
336 /*! D3DRS_EMISSIVEMATERIALSOURCE
\r
337 Emissive color source for lighting calculations. Valid values are members of the
\r
338 D3DMATERIALCOLORSOURCE enumerated type. The default value is D3DMCS_MATERIAL.
\r
340 BD3DRS_EMISSIVEMATERIALSOURCE = 148,
\r
342 /*! D3DRS_VERTEXBLEND
\r
343 Number of matrices to use to perform geometry blending, if any. Valid values are members
\r
344 of the D3DVERTEXBLENDFLAGS enumerated type. The default value is D3DVBF_DISABLE.
\r
346 BD3DRS_VERTEXBLEND = 151,
\r
348 /* D3DRS_CLIPPLANEENABLE
\r
349 Enables or disables user-defined clipping planes. Valid values are any DWORD in which the
\r
350 status of each bit (set or not set) toggles the activation state of a corresponding user-defined
\r
351 clipping plane. The least significant bit (bit 0) controls the first clipping plane at index 0,
\r
352 and subsequent bits control the activation of clipping planes at higher indexes. If a bit is set,
\r
353 the system applies the appropriate clipping plane during scene rendering. The default value is 0.
\r
354 The D3DCLIPPLANEn macros are defined to provide a convenient way to enable clipping planes.
\r
356 BD3DRS_CLIPPLANEENABLE = 152,
\r
357 BD3DRS_POINTSIZE = 154,
\r
358 BD3DRS_POINTSIZE_MIN = 155,
\r
359 BD3DRS_POINTSPRITEENABLE = 156,
\r
360 BD3DRS_POINTSCALEENABLE = 157,
\r
361 BD3DRS_POINTSCALE_A = 158,
\r
362 BD3DRS_POINTSCALE_B = 159,
\r
363 BD3DRS_POINTSCALE_C = 160,
\r
364 BD3DRS_MULTISAMPLEANTIALIAS = 161,
\r
365 BD3DRS_MULTISAMPLEMASK = 162,
\r
366 BD3DRS_PATCHEDGESTYLE = 163,
\r
367 BD3DRS_DEBUGMONITORTOKEN = 165,
\r
368 BD3DRS_POINTSIZE_MAX = 166,
\r
369 BD3DRS_INDEXEDVERTEXBLENDENABLE = 167,
\r
370 BD3DRS_COLORWRITEENABLE = 168,
\r
371 BD3DRS_TWEENFACTOR = 170,
\r
372 BD3DRS_BLENDOP = 171,
\r
373 BD3DRS_POSITIONDEGREE = 172,
\r
374 BD3DRS_NORMALDEGREE = 173,
\r
375 BD3DRS_SCISSORTESTENABLE = 174,
\r
376 BD3DRS_SLOPESCALEDEPTHBIAS = 175,
\r
377 BD3DRS_ANTIALIASEDLINEENABLE = 176,
\r
378 BD3DRS_MINTESSELLATIONLEVEL = 178,
\r
379 BD3DRS_MAXTESSELLATIONLEVEL = 179,
\r
380 BD3DRS_ADAPTIVETESS_X = 180,
\r
381 BD3DRS_ADAPTIVETESS_Y = 181,
\r
382 BD3DRS_ADAPTIVETESS_Z = 182,
\r
383 BD3DRS_ADAPTIVETESS_W = 183,
\r
384 BD3DRS_ENABLEADAPTIVETESSELLATION = 184,
\r
385 BD3DRS_TWOSIDEDSTENCILMODE = 185,
\r
386 BD3DRS_CCW_STENCILFAIL = 186,
\r
387 BD3DRS_CCW_STENCILZFAIL = 187,
\r
388 BD3DRS_CCW_STENCILPASS = 188,
\r
389 BD3DRS_CCW_STENCILFUNC = 189,
\r
390 BD3DRS_COLORWRITEENABLE1 = 190,
\r
391 BD3DRS_COLORWRITEENABLE2 = 191,
\r
392 BD3DRS_COLORWRITEENABLE3 = 192,
\r
393 BD3DRS_BLENDFACTOR = 193,
\r
394 BD3DRS_SRGBWRITEENABLE = 194,
\r
395 BD3DRS_DEPTHBIAS = 195,
\r
396 BD3DRS_WRAP8 = 198,
\r
397 BD3DRS_WRAP9 = 199,
\r
398 BD3DRS_WRAP10 = 200,
\r
399 BD3DRS_WRAP11 = 201,
\r
400 BD3DRS_WRAP12 = 202,
\r
401 BD3DRS_WRAP13 = 203,
\r
402 BD3DRS_WRAP14 = 204,
\r
403 BD3DRS_WRAP15 = 205,
\r
404 BD3DRS_SEPARATEALPHABLENDENABLE = 206,
\r
405 BD3DRS_SRCBLENDALPHA = 207,
\r
406 BD3DRS_DESTBLENDALPHA = 208,
\r
407 BD3DRS_BLENDOPALPHA = 209,
\r
414 /*! Defines constants that describe depth-buffer formats
\r
415 Members of this enumerated type are used with the D3DRS_ZENABLE render state.
\r
417 enum BD3DZBUFFERTYPE
\r
419 BD3DZB_FALSE = 0, // Disable depth buffering
\r
420 BD3DZB_TRUE = 1, // Enable z-buffering
\r
421 BD3DZB_USEW = 2 //Enable w-buffering.
\r
424 //! Defines the supported compare functions.
\r
427 BD3DCMP_NEVER = 1,// Always fail the test.
\r
428 BD3DCMP_LESS, // Accept the new pixel if its value is less than the value of the current pixel.
\r
429 BD3DCMP_EQUAL, // Accept the new pixel if its value equals the value of the current pixel.
\r
430 BD3DCMP_LESSEQUAL, // Accept the new pixel if its value is less than or equal to the value of the current pixel.
\r
431 BD3DCMP_GREATER, // Accept the new pixel if its value is greater than the value of the current pixel.
\r
432 BD3DCMP_NOTEQUAL, // Accept the new pixel if its value does not equal the value of the current pixel.
\r
433 BD3DCMP_GREATEREQUAL,// Accept the new pixel if its value is greater than or equal to the value of the current pixel.
\r
434 BD3DCMP_ALWAYS // Always pass the test.
\r
437 enum BD3DMATERIALCOLORSOURCE
\r
439 BD3DMCS_MATERIAL = 0, // Use the color from the current material.
\r
440 BD3DMCS_COLOR1 = 1, // Use the diffuse vertex color.
\r
441 BD3DMCS_COLOR2 = 2 // Use the specular vertex color.
\r
445 //! Defines constants that describe the supported shading modes.
\r
449 Flat shading mode. The color and specular component of the first vertex in the triangle
\r
450 are used to determine the color and specular component of the face. These colors remain
\r
451 constant across the triangle; that is, they are not interpolated. The specular alpha is
\r
454 BD3DSHADE_FLAT = 1,
\r
456 /*! BD3DSHADE_GOURAUD
\r
457 Gouraud shading mode. The color and specular components of the face are determined by a
\r
458 linear interpolation between all three of the triangle's vertices.
\r
460 BD3DSHADE_GOURAUD = 2,
\r
462 /*! BD3DSHADE_PHONG
\r
465 BD3DSHADE_PHONG = 3
\r
468 /*! Defines constants describing the fill mode
\r
469 The values in this enumerated type are used by the BD3DRS_FILLMODE render state
\r
473 BD3DFILL_POINT = 1, // Fill points.
\r
474 BD3DFILL_WIREFRAME = 2, // Fill wireframes.
\r
475 BD3DFILL_SOLID = 3 // Fill solids.
\r
480 /*! Defines the supported culling modes.
\r
481 The values in this enumerated type are used by the B3DRS_CULLMODE render state.
\r
482 The culling modes define how back faces are culled when rendering a geometry.
\r
486 BD3DCULL_NONE = 1, // Do not cull back faces.
\r
487 BD3DCULL_CW = 2, // Cull back faces with clockwise vertices.
\r
488 BD3DCULL_CCW = 3 // Cull back faces with counterclockwise vertices.
\r
491 struct SShaderParam
\r
496 u32 RenderState [ BD3DRS_MAX_TYPE ];
\r
497 void SetRenderState ( BD3DRENDERSTATETYPE state, u32 value );
\r
500 void SShaderParam::SetRenderState ( BD3DRENDERSTATETYPE state, u32 value )
\r
502 RenderState [ state ] = value;
\r
507 class CBurningShader_Raster_Reference : public IBurningShader
\r
512 CBurningShader_Raster_Reference(CBurningVideoDriver* driver);
\r
514 //! draws an indexed triangle list
\r
515 virtual void drawTriangle ( const s4DVertex *a,const s4DVertex *b,const s4DVertex *c ) _IRR_OVERRIDE_;
\r
517 virtual void setMaterial ( const SBurningShaderMaterial &material ) _IRR_OVERRIDE_;
\r
524 sScanLineData line;
\r
525 sPixelShaderData pShader;
\r
528 void pShader_EMT_LIGHTMAP_M4 ();
\r
530 SShaderParam ShaderParam;
\r
532 REALINLINE u32 depthFunc ();
\r
533 REALINLINE void depthWrite ();
\r
539 CBurningShader_Raster_Reference::CBurningShader_Raster_Reference(CBurningVideoDriver* driver)
\r
540 : IBurningShader(driver)
\r
543 setDebugName("CBurningShader_Raster_Reference");
\r
550 void CBurningShader_Raster_Reference::pShader_EMT_LIGHTMAP_M4 ()
\r
552 tFixPoint r0, g0, b0;
\r
553 tFixPoint r1, g1, b1;
\r
555 f32 inversew = fix_inverse32 ( line.w[0] );
\r
557 getSample_texture ( r0, g0, b0, &IT[0], tofix ( line.t[0][0].x,inversew), tofix ( line.t[0][0].y,inversew) );
\r
558 getSample_texture ( r1, g1, b1, &IT[1], tofix ( line.t[1][0].x,inversew), tofix ( line.t[1][0].y,inversew) );
\r
561 pShader.dst[pShader.i] = fix_to_sample( clampfix_maxcolor ( imulFix_tex2 ( r0, r1 ) ),
\r
562 clampfix_maxcolor ( imulFix_tex2 ( g0, g1 ) ),
\r
563 clampfix_maxcolor ( imulFix_tex2 ( b0, b1 ) )
\r
570 void CBurningShader_Raster_Reference::pShader_1 ()
\r
572 tFixPoint r0, g0, b0;
\r
573 tFixPoint tx0, ty0;
\r
575 const f32 inversew = fix_inverse32 ( line.w[0] );
\r
577 tx0 = tofix ( line.t[0][0].x, inversew );
\r
578 ty0 = tofix ( line.t[0][0].y, inversew );
\r
580 getSample_texture ( r0, g0, b0, &IT[0], tx0, ty0 );
\r
581 pShader.dst[pShader.i] = fix_to_sample( r0, g0, b0 );
\r
588 void CBurningShader_Raster_Reference::setMaterial ( const SBurningShaderMaterial &material )
\r
590 const video::SMaterial &m = material.org;
\r
595 ShaderParam.ColorUnits = 0;
\r
596 ShaderParam.TextureUnits = 0;
\r
597 for ( i = 0; i != BURNING_MATERIAL_MAX_TEXTURES; ++i )
\r
599 if ( m.getTexture( i ) )
\r
600 ShaderParam.TextureUnits = i;
\r
604 ShaderParam.SetRenderState( BD3DRS_SHADEMODE,
\r
605 m.GouraudShading ? BD3DSHADE_GOURAUD : BD3DSHADE_FLAT
\r
609 ShaderParam.SetRenderState( BD3DRS_FILLMODE,
\r
610 m.Wireframe ? BD3DFILL_WIREFRAME : m.PointCloud ? BD3DFILL_POINT : BD3DFILL_SOLID
\r
613 // back face culling
\r
614 ShaderParam.SetRenderState( BD3DRS_CULLMODE,
\r
615 m.BackfaceCulling ? BD3DCULL_CCW : BD3DCULL_NONE
\r
619 ShaderParam.SetRenderState( BD3DRS_LIGHTING, m.Lighting );
\r
621 // specular highlights
\r
622 enable = F32_LOWER_EQUAL_0 ( m.Shininess );
\r
623 ShaderParam.SetRenderState( BD3DRS_SPECULARENABLE, enable);
\r
624 ShaderParam.SetRenderState( BD3DRS_NORMALIZENORMALS, enable);
\r
625 ShaderParam.SetRenderState( BD3DRS_SPECULARMATERIALSOURCE, (m.ColorMaterial==ECM_SPECULAR)?BD3DMCS_COLOR1:BD3DMCS_MATERIAL);
\r
627 // depth buffer enable and compare
\r
628 ShaderParam.SetRenderState( BD3DRS_ZENABLE, (material.org.ZBuffer==video::ECFN_DISABLED) ? BD3DZB_FALSE : BD3DZB_USEW);
\r
629 switch (material.org.ZBuffer)
\r
632 ShaderParam.SetRenderState(BD3DRS_ZFUNC, BD3DCMP_NEVER);
\r
634 case ECFN_LESSEQUAL:
\r
635 ShaderParam.SetRenderState(BD3DRS_ZFUNC, BD3DCMP_LESSEQUAL);
\r
638 ShaderParam.SetRenderState(BD3DRS_ZFUNC, BD3DCMP_EQUAL);
\r
641 ShaderParam.SetRenderState(BD3DRS_ZFUNC, BD3DCMP_LESSEQUAL);
\r
643 case ECFN_NOTEQUAL:
\r
644 ShaderParam.SetRenderState(BD3DRS_ZFUNC, BD3DCMP_NOTEQUAL);
\r
646 case ECFN_GREATEREQUAL:
\r
647 ShaderParam.SetRenderState(BD3DRS_ZFUNC, BD3DCMP_GREATEREQUAL);
\r
650 ShaderParam.SetRenderState(BD3DRS_ZFUNC, BD3DCMP_GREATER);
\r
653 ShaderParam.SetRenderState(BD3DRS_ZFUNC, BD3DCMP_ALWAYS);
\r
657 // depth buffer write
\r
658 ShaderParam.SetRenderState( BD3DRS_ZWRITEENABLE, m.ZWriteEnable != video::EZW_OFF );
\r
663 REALINLINE u32 CBurningShader_Raster_Reference::depthFunc ()
\r
665 if ( ShaderParam.RenderState [ BD3DRS_ZENABLE ] )
\r
667 switch ( ShaderParam.RenderState [ BD3DRS_ZFUNC ] )
\r
669 case BD3DCMP_LESSEQUAL:
\r
670 return line.w[0] >= pShader.z[ pShader.i];
\r
671 case BD3DCMP_EQUAL:
\r
672 return line.w[0] == pShader.z[ pShader.i];
\r
680 REALINLINE void CBurningShader_Raster_Reference::depthWrite ()
\r
682 if ( ShaderParam.RenderState [ BD3DRS_ZWRITEENABLE ] )
\r
684 pShader.z[pShader.i] = line.w[0];
\r
690 REALINLINE void CBurningShader_Raster_Reference::scanline2()
\r
692 // apply top-left fill-convention, left
\r
693 pShader.xStart = fill_convention_left( line.x[0] );
\r
694 pShader.xEnd = fill_convention_right( line.x[1] );
\r
696 pShader.dx = pShader.xEnd - pShader.xStart;
\r
697 if ( pShader.dx < 0 )
\r
701 const f32 invDeltaX = fill_step_x( line.x[1] - line.x[0] );
\r
702 const f32 subPixel = ( (f32) pShader.xStart ) - line.x[0];
\r
704 // store slopes in endpoint, and correct first pixel
\r
706 line.w[0] += (line.w[1] = (line.w[1] - line.w[0]) * invDeltaX) * subPixel;
\r
710 #if BURNING_MATERIAL_MAX_COLORS > 0
\r
711 for ( i = 0; i != ShaderParam.ColorUnits; ++i )
\r
713 line.c[i][1] = (line.c[i][1] - line.c[i][0]) * invDeltaX;
\r
714 line.c[i][0] += line.c[i][1] * subPixel;
\r
718 for ( i = 0; i != ShaderParam.TextureUnits; ++i )
\r
720 line.t[i][1] = (line.t[i][1] - line.t[i][0]) * invDeltaX;
\r
721 line.t[i][0] += line.t[i][1] * subPixel;
\r
724 SOFTWARE_DRIVER_2_CLIPCHECK_REF;
\r
725 pShader.dst = (tVideoSample*) ( (u8*) RenderTarget->getData() + ( line.y * RenderTarget->getPitch() ) + ( pShader.xStart << SOFTWARE_DRIVER_2_RENDERTARGET_GRANULARITY) );
\r
726 pShader.z = (fp24*) ( (u8*) DepthBuffer->lock() + ( line.y * DepthBuffer->getPitch() ) + ( pShader.xStart << SOFTWARE_DRIVER_2_RENDERTARGET_GRANULARITY) );
\r
728 for ( pShader.i = 0; pShader.i <= pShader.dx; ++pShader.i )
\r
735 // advance next pixel
\r
736 line.w[0] += line.w[1];
\r
738 #if BURNING_MATERIAL_MAX_COLORS > 0
\r
739 for ( i = 0; i != ShaderParam.ColorUnits; ++i )
\r
741 line.c[i][0] += line.c[i][1];
\r
744 for ( i = 0; i != ShaderParam.TextureUnits; ++i )
\r
746 line.t[i][0] += line.t[i][1];
\r
754 REALINLINE void CBurningShader_Raster_Reference::scanline ()
\r
758 // apply top-left fill-convention, left
\r
759 pShader.xStart = fill_convention_left( line.x[0] );
\r
760 pShader.xEnd = fill_convention_right( line.x[1] );
\r
762 pShader.dx = pShader.xEnd - pShader.xStart;
\r
763 if ( pShader.dx < 0 )
\r
767 const f32 invDeltaX = fill_step_x( line.x[1] - line.x[0] );
\r
769 // search z-buffer for first not occulled pixel
\r
770 pShader.z = (fp24*) ( (u8*) DepthBuffer->lock() + ( line.y * DepthBuffer->getPitch() ) + ( pShader.xStart << SOFTWARE_DRIVER_2_RENDERTARGET_GRANULARITY) );
\r
773 const f32 subPixel = ( (f32) pShader.xStart ) - line.x[0];
\r
775 const f32 b = (line.w[1] - line.w[0]) * invDeltaX;
\r
776 f32 a = line.w[0] + ( b * subPixel );
\r
780 if ( ShaderParam.RenderState [ BD3DRS_ZENABLE ] )
\r
783 switch ( ShaderParam.RenderState [ BD3DRS_ZFUNC ] )
\r
785 case BD3DCMP_LESSEQUAL:
\r
786 condition = a < pShader.z[pShader.i];
\r
788 case BD3DCMP_EQUAL:
\r
789 condition = a != pShader.z[pShader.i];
\r
795 while ( a < pShader.z[pShader.i] )
\r
800 if ( pShader.i > pShader.dx )
\r
805 // lazy setup rest of scanline
\r
810 pShader.dst = (tVideoSample*) ( (u8*) RenderTarget->getData() + ( line.y * RenderTarget->getPitch() ) + ( pShader.xStart << SOFTWARE_DRIVER_2_RENDERTARGET_GRANULARITY) );
\r
812 a = (f32) pShader.i + subPixel;
\r
814 #if BURNING_MATERIAL_MAX_COLORS > 0
\r
815 for ( i = 0; i != ShaderParam.ColorUnits; ++i )
\r
817 line.c[i][1] = (line.c[i][1] - line.c[i][0]) * invDeltaX;
\r
818 line.c[i][0] += line.c[i][1] * a;
\r
822 for ( i = 0; i != ShaderParam.TextureUnits; ++i )
\r
824 line.t[i][1] = (line.t[i][1] - line.t[i][0]) * invDeltaX;
\r
825 line.t[i][0] += line.t[i][1] * a;
\r
828 for ( ; pShader.i <= pShader.dx; ++pShader.i )
\r
830 if ( line.w[0] >= pShader.z[pShader.i] )
\r
832 pShader.z[pShader.i] = line.w[0];
\r
834 pShader_EMT_LIGHTMAP_M4 ();
\r
837 line.w[0] += line.w[1];
\r
839 #if BURNING_MATERIAL_MAX_COLORS > 0
\r
840 for ( i = 0; i != ShaderParam.ColorUnits; ++i )
\r
842 line.c[i][0] += line.c[i][1];
\r
845 for ( i = 0; i != ShaderParam.TextureUnits; ++i )
\r
847 line.t[i][0] += line.t[i][1];
\r
854 void CBurningShader_Raster_Reference::drawTriangle(const s4DVertex* burning_restrict a, const s4DVertex* burning_restrict b, const s4DVertex* burning_restrict c)
\r
856 sScanConvertData scan;
\r
859 // sort on height, y
\r
860 if ( F32_A_GREATER_B ( a->Pos.y , b->Pos.y ) ) swapVertexPointer(&a, &b);
\r
861 if ( F32_A_GREATER_B ( b->Pos.y , c->Pos.y ) ) swapVertexPointer(&b, &c);
\r
862 if ( F32_A_GREATER_B ( a->Pos.y , b->Pos.y ) ) swapVertexPointer(&a, &b);
\r
865 // calculate delta y of the edges
\r
866 scan.invDeltaY[0] = fill_step_y( c->Pos.y - a->Pos.y );
\r
867 scan.invDeltaY[1] = fill_step_y( b->Pos.y - a->Pos.y );
\r
868 scan.invDeltaY[2] = fill_step_y( c->Pos.y - b->Pos.y );
\r
870 if ( F32_LOWER_EQUAL_0 ( scan.invDeltaY[0] ) )
\r
874 // find if the major edge is left or right aligned
\r
877 temp[0] = a->Pos.x - c->Pos.x;
\r
878 temp[1] = a->Pos.y - c->Pos.y;
\r
879 temp[2] = b->Pos.x - a->Pos.x;
\r
880 temp[3] = b->Pos.y - a->Pos.y;
\r
882 scan.left = ( temp[0] * temp[3] - temp[1] * temp[2] ) > (f32) 0.0 ? 0 : 1;
\r
883 scan.right = 1 - scan.left;
\r
885 // calculate slopes for the major edge
\r
886 scan.slopeX[0] = (c->Pos.x - a->Pos.x) * scan.invDeltaY[0];
\r
887 scan.x[0] = a->Pos.x;
\r
889 scan.slopeW[0] = (c->Pos.w - a->Pos.w) * scan.invDeltaY[0];
\r
890 scan.w[0] = a->Pos.w;
\r
892 #if BURNING_MATERIAL_MAX_COLORS > 0
\r
893 for ( i = 0; i != ShaderParam.ColorUnits; ++i )
\r
895 scan.c[i][0] = a->Color[i];
\r
896 scan.slopeC[i][0] = (c->Color[i] - a->Color[i]) * scan.invDeltaY[0];
\r
900 for ( i = 0; i != ShaderParam.TextureUnits; ++i )
\r
902 scan.t[i][0] = a->Tex[i];
\r
903 scan.slopeT[i][0] = (c->Tex[i] - a->Tex[i]) * scan.invDeltaY[0];
\r
906 // top left fill convention y run
\r
912 // rasterize upper sub-triangle
\r
913 if ( F32_GREATER_0 ( scan.invDeltaY[1] ) )
\r
915 // calculate slopes for top edge
\r
916 scan.slopeX[1] = (b->Pos.x - a->Pos.x) * scan.invDeltaY[1];
\r
917 scan.x[1] = a->Pos.x;
\r
919 scan.slopeW[1] = (b->Pos.w - a->Pos.w) * scan.invDeltaY[1];
\r
920 scan.w[1] = a->Pos.w;
\r
922 #if BURNING_MATERIAL_MAX_COLORS > 0
\r
923 for ( i = 0; i != ShaderParam.ColorUnits; ++i )
\r
925 scan.c[i][1] = a->Color[i];
\r
926 scan.slopeC[i][1] = (b->Color[i] - a->Color[i]) * scan.invDeltaY[1];
\r
929 for ( i = 0; i != ShaderParam.TextureUnits; ++i )
\r
931 scan.t[i][1] = a->Tex[i];
\r
932 scan.slopeT[i][1] = (b->Tex[i] - a->Tex[i]) * scan.invDeltaY[1];
\r
935 // apply top-left fill convention, top part
\r
936 yStart = fill_convention_left( a->Pos.y );
\r
937 yEnd = fill_convention_right( b->Pos.y );
\r
939 subPixel = ( (f32) yStart ) - a->Pos.y;
\r
941 // correct to pixel center
\r
942 scan.x[0] += scan.slopeX[0] * subPixel;
\r
943 scan.x[1] += scan.slopeX[1] * subPixel;
\r
945 scan.w[0] += scan.slopeW[0] * subPixel;
\r
946 scan.w[1] += scan.slopeW[1] * subPixel;
\r
948 #if BURNING_MATERIAL_MAX_COLORS > 0
\r
949 for ( i = 0; i != ShaderParam.ColorUnits; ++i )
\r
951 scan.c[i][0] += scan.slopeC[i][0] * subPixel;
\r
952 scan.c[i][1] += scan.slopeC[i][1] * subPixel;
\r
955 for ( i = 0; i != ShaderParam.TextureUnits; ++i )
\r
957 scan.t[i][0] += scan.slopeT[i][0] * subPixel;
\r
958 scan.t[i][1] += scan.slopeT[i][1] * subPixel;
\r
961 // rasterize the edge scanlines
\r
962 for( line.y = yStart; line.y <= yEnd; line.y += SOFTWARE_DRIVER_2_STEP_Y)
\r
964 line.x[scan.left] = scan.x[0];
\r
965 line.w[scan.left] = scan.w[0];
\r
967 line.x[scan.right] = scan.x[1];
\r
968 line.w[scan.right] = scan.w[1];
\r
970 #if BURNING_MATERIAL_MAX_COLORS > 0
\r
971 for ( i = 0; i != ShaderParam.ColorUnits; ++i )
\r
973 line.c[i][scan.left] = scan.c[i][0];
\r
974 line.c[i][scan.right] = scan.c[i][1];
\r
977 for ( i = 0; i != ShaderParam.TextureUnits; ++i )
\r
979 line.t[i][scan.left] = scan.t[i][0];
\r
980 line.t[i][scan.right] = scan.t[i][1];
\r
983 // render a scanline
\r
986 scan.x[0] += scan.slopeX[0];
\r
987 scan.x[1] += scan.slopeX[1];
\r
989 scan.w[0] += scan.slopeW[0];
\r
990 scan.w[1] += scan.slopeW[1];
\r
992 #if BURNING_MATERIAL_MAX_COLORS > 0
\r
993 for ( i = 0; i != ShaderParam.ColorUnits; ++i )
\r
995 scan.c[i][0] += scan.slopeC[i][0];
\r
996 scan.c[i][1] += scan.slopeC[i][1];
\r
999 for ( i = 0; i != ShaderParam.TextureUnits; ++i )
\r
1001 scan.t[i][0] += scan.slopeT[i][0];
\r
1002 scan.t[i][1] += scan.slopeT[i][1];
\r
1008 // rasterize lower sub-triangle
\r
1009 if ( F32_GREATER_0 ( scan.invDeltaY[2] ) )
\r
1011 // advance to middle point
\r
1012 if ( F32_GREATER_0 ( scan.invDeltaY[1] ) )
\r
1014 temp[0] = b->Pos.y - a->Pos.y; // dy
\r
1016 scan.x[0] = a->Pos.x + scan.slopeX[0] * temp[0];
\r
1017 scan.w[0] = a->Pos.w + scan.slopeW[0] * temp[0];
\r
1019 #if BURNING_MATERIAL_MAX_COLORS > 0
\r
1020 for ( i = 0; i != ShaderParam.ColorUnits; ++i )
\r
1022 scan.c[i][0] = a->Color[i] + scan.slopeC[i][0] * temp[0];
\r
1025 for ( i = 0; i != ShaderParam.TextureUnits; ++i )
\r
1027 scan.t[i][0] = a->Tex[i] + scan.slopeT[i][0] * temp[0];
\r
1031 // calculate slopes for bottom edge
\r
1032 scan.slopeX[1] = (c->Pos.x - b->Pos.x) * scan.invDeltaY[2];
\r
1033 scan.x[1] = b->Pos.x;
\r
1035 scan.slopeW[1] = (c->Pos.w - b->Pos.w) * scan.invDeltaY[2];
\r
1036 scan.w[1] = b->Pos.w;
\r
1038 #if BURNING_MATERIAL_MAX_COLORS > 0
\r
1039 for ( i = 0; i != ShaderParam.ColorUnits; ++i )
\r
1041 scan.c[i][1] = b->Color[i];
\r
1042 scan.slopeC[i][1] = (c->Color[i] - b->Color[i]) * scan.invDeltaY[2];
\r
1045 for ( i = 0; i != ShaderParam.TextureUnits; ++i )
\r
1047 scan.t[i][1] = b->Tex[i];
\r
1048 scan.slopeT[i][1] = (c->Tex[i] - b->Tex[i]) * scan.invDeltaY[2];
\r
1051 // apply top-left fill convention, top part
\r
1052 yStart = fill_convention_left( b->Pos.y );
\r
1053 yEnd = fill_convention_right( c->Pos.y );
\r
1056 subPixel = ( (f32) yStart ) - b->Pos.y;
\r
1058 // correct to pixel center
\r
1059 scan.x[0] += scan.slopeX[0] * subPixel;
\r
1060 scan.x[1] += scan.slopeX[1] * subPixel;
\r
1062 scan.w[0] += scan.slopeW[0] * subPixel;
\r
1063 scan.w[1] += scan.slopeW[1] * subPixel;
\r
1065 #if BURNING_MATERIAL_MAX_COLORS > 0
\r
1066 for ( i = 0; i != ShaderParam.ColorUnits; ++i )
\r
1068 scan.c[i][0] += scan.slopeC[i][0] * subPixel;
\r
1069 scan.c[i][1] += scan.slopeC[i][1] * subPixel;
\r
1072 for ( i = 0; i != ShaderParam.TextureUnits; ++i )
\r
1074 scan.t[i][0] += scan.slopeT[i][0] * subPixel;
\r
1075 scan.t[i][1] += scan.slopeT[i][1] * subPixel;
\r
1078 // rasterize the edge scanlines
\r
1079 for( line.y = yStart; line.y <= yEnd; line.y += SOFTWARE_DRIVER_2_STEP_Y)
\r
1081 line.x[scan.left] = scan.x[0];
\r
1082 line.w[scan.left] = scan.w[0];
\r
1084 line.x[scan.right] = scan.x[1];
\r
1085 line.w[scan.right] = scan.w[1];
\r
1087 #if BURNING_MATERIAL_MAX_COLORS > 0
\r
1088 for ( i = 0; i != ShaderParam.ColorUnits; ++i )
\r
1090 line.c[i][scan.left] = scan.c[i][0];
\r
1091 line.c[i][scan.right] = scan.c[i][1];
\r
1094 for ( i = 0; i != ShaderParam.TextureUnits; ++i )
\r
1096 line.t[i][scan.left] = scan.t[i][0];
\r
1097 line.t[i][scan.right] = scan.t[i][1];
\r
1100 // render a scanline
\r
1103 scan.x[0] += scan.slopeX[0];
\r
1104 scan.x[1] += scan.slopeX[1];
\r
1106 scan.w[0] += scan.slopeW[0];
\r
1107 scan.w[1] += scan.slopeW[1];
\r
1109 #if BURNING_MATERIAL_MAX_COLORS > 0
\r
1110 for ( i = 0; i != ShaderParam.ColorUnits; ++i )
\r
1112 scan.c[i][0] += scan.slopeC[i][0];
\r
1113 scan.c[i][1] += scan.slopeC[i][1];
\r
1116 for ( i = 0; i != ShaderParam.TextureUnits; ++i )
\r
1118 scan.t[i][0] += scan.slopeT[i][0];
\r
1119 scan.t[i][1] += scan.slopeT[i][1];
\r
1126 } // end namespace video
\r
1127 } // end namespace irr
\r
1137 //! creates a flat triangle renderer
\r
1138 IBurningShader* createTriangleRendererReference(CBurningVideoDriver* driver)
\r
1140 return new CBurningShader_Raster_Reference(driver);
\r
1144 } // end namespace video
\r
1145 } // end namespace irr
\r
1147 #endif // _IRR_COMPILE_WITH_BURNINGSVIDEO_
\r