diff options
Diffstat (limited to 'libraries/irrlicht-1.8/source/Irrlicht/CD3D8MaterialRenderer.h')
-rw-r--r-- | libraries/irrlicht-1.8/source/Irrlicht/CD3D8MaterialRenderer.h | 1162 |
1 files changed, 581 insertions, 581 deletions
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/CD3D8MaterialRenderer.h b/libraries/irrlicht-1.8/source/Irrlicht/CD3D8MaterialRenderer.h index 5eb883c..fabc97e 100644 --- a/libraries/irrlicht-1.8/source/Irrlicht/CD3D8MaterialRenderer.h +++ b/libraries/irrlicht-1.8/source/Irrlicht/CD3D8MaterialRenderer.h | |||
@@ -1,581 +1,581 @@ | |||
1 | // Copyright (C) 2002-2012 Nikolaus Gebhardt | 1 | // Copyright (C) 2002-2012 Nikolaus Gebhardt |
2 | // This file is part of the "Irrlicht Engine". | 2 | // This file is part of the "Irrlicht Engine". |
3 | // For conditions of distribution and use, see copyright notice in irrlicht.h | 3 | // For conditions of distribution and use, see copyright notice in irrlicht.h |
4 | 4 | ||
5 | #ifndef __C_D3D8_MATERIAL_RENDERER_H_INCLUDED__ | 5 | #ifndef __C_D3D8_MATERIAL_RENDERER_H_INCLUDED__ |
6 | #define __C_D3D8_MATERIAL_RENDERER_H_INCLUDED__ | 6 | #define __C_D3D8_MATERIAL_RENDERER_H_INCLUDED__ |
7 | 7 | ||
8 | #include "IrrCompileConfig.h" | 8 | #include "IrrCompileConfig.h" |
9 | #ifdef _IRR_WINDOWS_API_ | 9 | #ifdef _IRR_WINDOWS_API_ |
10 | 10 | ||
11 | #ifdef _IRR_COMPILE_WITH_DIRECT3D_8_ | 11 | #ifdef _IRR_COMPILE_WITH_DIRECT3D_8_ |
12 | #include <d3d8.h> | 12 | #include <d3d8.h> |
13 | 13 | ||
14 | #include "IMaterialRenderer.h" | 14 | #include "IMaterialRenderer.h" |
15 | 15 | ||
16 | namespace irr | 16 | namespace irr |
17 | { | 17 | { |
18 | namespace video | 18 | namespace video |
19 | { | 19 | { |
20 | 20 | ||
21 | namespace | 21 | namespace |
22 | { | 22 | { |
23 | D3DMATRIX UnitMatrixD3D8; | 23 | D3DMATRIX UnitMatrixD3D8; |
24 | D3DMATRIX SphereMapMatrixD3D8; | 24 | D3DMATRIX SphereMapMatrixD3D8; |
25 | inline void setTextureColorStage(IDirect3DDevice8* dev, DWORD i, | 25 | inline void setTextureColorStage(IDirect3DDevice8* dev, DWORD i, |
26 | DWORD arg1, DWORD op, DWORD arg2) | 26 | DWORD arg1, DWORD op, DWORD arg2) |
27 | { | 27 | { |
28 | dev->SetTextureStageState(i, D3DTSS_COLOROP, op); | 28 | dev->SetTextureStageState(i, D3DTSS_COLOROP, op); |
29 | dev->SetTextureStageState(i, D3DTSS_COLORARG1, arg1); | 29 | dev->SetTextureStageState(i, D3DTSS_COLORARG1, arg1); |
30 | dev->SetTextureStageState(i, D3DTSS_COLORARG2, arg2); | 30 | dev->SetTextureStageState(i, D3DTSS_COLORARG2, arg2); |
31 | } | 31 | } |
32 | inline void setTextureColorStage(IDirect3DDevice8* dev, DWORD i, DWORD arg1) | 32 | inline void setTextureColorStage(IDirect3DDevice8* dev, DWORD i, DWORD arg1) |
33 | { | 33 | { |
34 | dev->SetTextureStageState(i, D3DTSS_COLOROP, D3DTOP_SELECTARG1); | 34 | dev->SetTextureStageState(i, D3DTSS_COLOROP, D3DTOP_SELECTARG1); |
35 | dev->SetTextureStageState(i, D3DTSS_COLORARG1, arg1); | 35 | dev->SetTextureStageState(i, D3DTSS_COLORARG1, arg1); |
36 | } | 36 | } |
37 | 37 | ||
38 | inline void setTextureAlphaStage(IDirect3DDevice8* dev, DWORD i, | 38 | inline void setTextureAlphaStage(IDirect3DDevice8* dev, DWORD i, |
39 | DWORD arg1, DWORD op, DWORD arg2) | 39 | DWORD arg1, DWORD op, DWORD arg2) |
40 | { | 40 | { |
41 | dev->SetTextureStageState(i, D3DTSS_ALPHAOP, op); | 41 | dev->SetTextureStageState(i, D3DTSS_ALPHAOP, op); |
42 | dev->SetTextureStageState(i, D3DTSS_ALPHAARG1, arg1); | 42 | dev->SetTextureStageState(i, D3DTSS_ALPHAARG1, arg1); |
43 | dev->SetTextureStageState(i, D3DTSS_ALPHAARG2, arg2); | 43 | dev->SetTextureStageState(i, D3DTSS_ALPHAARG2, arg2); |
44 | } | 44 | } |
45 | inline void setTextureAlphaStage(IDirect3DDevice8* dev, DWORD i, DWORD arg1) | 45 | inline void setTextureAlphaStage(IDirect3DDevice8* dev, DWORD i, DWORD arg1) |
46 | { | 46 | { |
47 | dev->SetTextureStageState(i, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1); | 47 | dev->SetTextureStageState(i, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1); |
48 | dev->SetTextureStageState(i, D3DTSS_ALPHAARG1, arg1); | 48 | dev->SetTextureStageState(i, D3DTSS_ALPHAARG1, arg1); |
49 | } | 49 | } |
50 | } // anonymous namespace | 50 | } // anonymous namespace |
51 | 51 | ||
52 | //! Base class for all internal D3D8 material renderers | 52 | //! Base class for all internal D3D8 material renderers |
53 | class CD3D8MaterialRenderer : public IMaterialRenderer | 53 | class CD3D8MaterialRenderer : public IMaterialRenderer |
54 | { | 54 | { |
55 | public: | 55 | public: |
56 | 56 | ||
57 | //! Constructor | 57 | //! Constructor |
58 | CD3D8MaterialRenderer(IDirect3DDevice8* d3ddev, video::IVideoDriver* driver) | 58 | CD3D8MaterialRenderer(IDirect3DDevice8* d3ddev, video::IVideoDriver* driver) |
59 | : pID3DDevice(d3ddev), Driver(driver) | 59 | : pID3DDevice(d3ddev), Driver(driver) |
60 | { | 60 | { |
61 | } | 61 | } |
62 | 62 | ||
63 | protected: | 63 | protected: |
64 | 64 | ||
65 | IDirect3DDevice8* pID3DDevice; | 65 | IDirect3DDevice8* pID3DDevice; |
66 | video::IVideoDriver* Driver; | 66 | video::IVideoDriver* Driver; |
67 | }; | 67 | }; |
68 | 68 | ||
69 | 69 | ||
70 | //! Solid material renderer | 70 | //! Solid material renderer |
71 | class CD3D8MaterialRenderer_SOLID : public CD3D8MaterialRenderer | 71 | class CD3D8MaterialRenderer_SOLID : public CD3D8MaterialRenderer |
72 | { | 72 | { |
73 | public: | 73 | public: |
74 | 74 | ||
75 | CD3D8MaterialRenderer_SOLID(IDirect3DDevice8* p, video::IVideoDriver* d) | 75 | CD3D8MaterialRenderer_SOLID(IDirect3DDevice8* p, video::IVideoDriver* d) |
76 | : CD3D8MaterialRenderer(p, d) {} | 76 | : CD3D8MaterialRenderer(p, d) {} |
77 | 77 | ||
78 | virtual void OnSetMaterial(const SMaterial& material, const SMaterial& lastMaterial, | 78 | virtual void OnSetMaterial(const SMaterial& material, const SMaterial& lastMaterial, |
79 | bool resetAllRenderstates, IMaterialRendererServices* services) | 79 | bool resetAllRenderstates, IMaterialRendererServices* services) |
80 | { | 80 | { |
81 | services->setBasicRenderStates(material, lastMaterial, resetAllRenderstates); | 81 | services->setBasicRenderStates(material, lastMaterial, resetAllRenderstates); |
82 | 82 | ||
83 | if (material.MaterialType != lastMaterial.MaterialType || resetAllRenderstates) | 83 | if (material.MaterialType != lastMaterial.MaterialType || resetAllRenderstates) |
84 | { | 84 | { |
85 | setTextureColorStage(pID3DDevice, 0, | 85 | setTextureColorStage(pID3DDevice, 0, |
86 | D3DTA_TEXTURE, D3DTOP_MODULATE, D3DTA_DIFFUSE); | 86 | D3DTA_TEXTURE, D3DTOP_MODULATE, D3DTA_DIFFUSE); |
87 | } | 87 | } |
88 | 88 | ||
89 | pID3DDevice->SetTextureStageState(1, D3DTSS_COLOROP, D3DTOP_DISABLE); | 89 | pID3DDevice->SetTextureStageState(1, D3DTSS_COLOROP, D3DTOP_DISABLE); |
90 | pID3DDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, FALSE); | 90 | pID3DDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, FALSE); |
91 | } | 91 | } |
92 | }; | 92 | }; |
93 | 93 | ||
94 | //! Generic Texture Blend | 94 | //! Generic Texture Blend |
95 | class CD3D8MaterialRenderer_ONETEXTURE_BLEND : public CD3D8MaterialRenderer | 95 | class CD3D8MaterialRenderer_ONETEXTURE_BLEND : public CD3D8MaterialRenderer |
96 | { | 96 | { |
97 | public: | 97 | public: |
98 | 98 | ||
99 | CD3D8MaterialRenderer_ONETEXTURE_BLEND(IDirect3DDevice8* p, video::IVideoDriver* d) | 99 | CD3D8MaterialRenderer_ONETEXTURE_BLEND(IDirect3DDevice8* p, video::IVideoDriver* d) |
100 | : CD3D8MaterialRenderer(p, d) {} | 100 | : CD3D8MaterialRenderer(p, d) {} |
101 | 101 | ||
102 | virtual void OnSetMaterial(const SMaterial& material, const SMaterial& lastMaterial, | 102 | virtual void OnSetMaterial(const SMaterial& material, const SMaterial& lastMaterial, |
103 | bool resetAllRenderstates, IMaterialRendererServices* services) | 103 | bool resetAllRenderstates, IMaterialRendererServices* services) |
104 | { | 104 | { |
105 | services->setBasicRenderStates(material, lastMaterial, resetAllRenderstates); | 105 | services->setBasicRenderStates(material, lastMaterial, resetAllRenderstates); |
106 | 106 | ||
107 | if (material.MaterialType != lastMaterial.MaterialType || | 107 | if (material.MaterialType != lastMaterial.MaterialType || |
108 | material.MaterialTypeParam != lastMaterial.MaterialTypeParam || | 108 | material.MaterialTypeParam != lastMaterial.MaterialTypeParam || |
109 | resetAllRenderstates) | 109 | resetAllRenderstates) |
110 | { | 110 | { |
111 | 111 | ||
112 | E_BLEND_FACTOR srcFact,dstFact; | 112 | E_BLEND_FACTOR srcFact,dstFact; |
113 | E_MODULATE_FUNC modulate; | 113 | E_MODULATE_FUNC modulate; |
114 | u32 alphaSource; | 114 | u32 alphaSource; |
115 | unpack_textureBlendFunc ( srcFact, dstFact, modulate, alphaSource, material.MaterialTypeParam ); | 115 | unpack_textureBlendFunc ( srcFact, dstFact, modulate, alphaSource, material.MaterialTypeParam ); |
116 | 116 | ||
117 | if (srcFact == EBF_SRC_COLOR && dstFact == EBF_ZERO) | 117 | if (srcFact == EBF_SRC_COLOR && dstFact == EBF_ZERO) |
118 | { | 118 | { |
119 | pID3DDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, FALSE); | 119 | pID3DDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, FALSE); |
120 | } | 120 | } |
121 | else | 121 | else |
122 | { | 122 | { |
123 | pID3DDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE); | 123 | pID3DDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE); |
124 | pID3DDevice->SetRenderState(D3DRS_SRCBLEND, getD3DBlend ( srcFact ) ); | 124 | pID3DDevice->SetRenderState(D3DRS_SRCBLEND, getD3DBlend ( srcFact ) ); |
125 | pID3DDevice->SetRenderState(D3DRS_DESTBLEND, getD3DBlend ( dstFact ) ); | 125 | pID3DDevice->SetRenderState(D3DRS_DESTBLEND, getD3DBlend ( dstFact ) ); |
126 | } | 126 | } |
127 | 127 | ||
128 | setTextureColorStage(pID3DDevice, 0, | 128 | setTextureColorStage(pID3DDevice, 0, |
129 | D3DTA_TEXTURE, getD3DModulate(modulate), D3DTA_DIFFUSE); | 129 | D3DTA_TEXTURE, getD3DModulate(modulate), D3DTA_DIFFUSE); |
130 | 130 | ||
131 | if ( alphaSource && (textureBlendFunc_hasAlpha ( srcFact ) || textureBlendFunc_hasAlpha ( dstFact ) )) | 131 | if ( alphaSource && (textureBlendFunc_hasAlpha ( srcFact ) || textureBlendFunc_hasAlpha ( dstFact ) )) |
132 | { | 132 | { |
133 | if (alphaSource==EAS_VERTEX_COLOR) | 133 | if (alphaSource==EAS_VERTEX_COLOR) |
134 | { | 134 | { |
135 | setTextureAlphaStage(pID3DDevice, 0, D3DTA_DIFFUSE); | 135 | setTextureAlphaStage(pID3DDevice, 0, D3DTA_DIFFUSE); |
136 | } | 136 | } |
137 | else if (alphaSource==EAS_TEXTURE) | 137 | else if (alphaSource==EAS_TEXTURE) |
138 | { | 138 | { |
139 | setTextureAlphaStage(pID3DDevice, 0, D3DTA_TEXTURE); | 139 | setTextureAlphaStage(pID3DDevice, 0, D3DTA_TEXTURE); |
140 | } | 140 | } |
141 | else | 141 | else |
142 | { | 142 | { |
143 | setTextureAlphaStage(pID3DDevice, 0, | 143 | setTextureAlphaStage(pID3DDevice, 0, |
144 | D3DTA_TEXTURE, D3DTOP_MODULATE, D3DTA_DIFFUSE); | 144 | D3DTA_TEXTURE, D3DTOP_MODULATE, D3DTA_DIFFUSE); |
145 | } | 145 | } |
146 | } | 146 | } |
147 | 147 | ||
148 | pID3DDevice->SetTextureStageState(1, D3DTSS_COLOROP, D3DTOP_DISABLE); | 148 | pID3DDevice->SetTextureStageState(1, D3DTSS_COLOROP, D3DTOP_DISABLE); |
149 | 149 | ||
150 | } | 150 | } |
151 | } | 151 | } |
152 | 152 | ||
153 | //! Returns if the material is transparent. | 153 | //! Returns if the material is transparent. |
154 | /** The scene management needs to know this for being able to sort the | 154 | /** The scene management needs to know this for being able to sort the |
155 | materials by opaque and transparent. | 155 | materials by opaque and transparent. |
156 | The return value could be optimized, but we'd need to know the | 156 | The return value could be optimized, but we'd need to know the |
157 | MaterialTypeParam for it. */ | 157 | MaterialTypeParam for it. */ |
158 | virtual bool isTransparent() const | 158 | virtual bool isTransparent() const |
159 | { | 159 | { |
160 | return true; | 160 | return true; |
161 | } | 161 | } |
162 | 162 | ||
163 | private: | 163 | private: |
164 | 164 | ||
165 | u32 getD3DBlend ( E_BLEND_FACTOR factor ) const | 165 | u32 getD3DBlend ( E_BLEND_FACTOR factor ) const |
166 | { | 166 | { |
167 | u32 r = 0; | 167 | u32 r = 0; |
168 | switch ( factor ) | 168 | switch ( factor ) |
169 | { | 169 | { |
170 | case EBF_ZERO: r = D3DBLEND_ZERO; break; | 170 | case EBF_ZERO: r = D3DBLEND_ZERO; break; |
171 | case EBF_ONE: r = D3DBLEND_ONE; break; | 171 | case EBF_ONE: r = D3DBLEND_ONE; break; |
172 | case EBF_DST_COLOR: r = D3DBLEND_DESTCOLOR; break; | 172 | case EBF_DST_COLOR: r = D3DBLEND_DESTCOLOR; break; |
173 | case EBF_ONE_MINUS_DST_COLOR: r = D3DBLEND_INVDESTCOLOR; break; | 173 | case EBF_ONE_MINUS_DST_COLOR: r = D3DBLEND_INVDESTCOLOR; break; |
174 | case EBF_SRC_COLOR: r = D3DBLEND_SRCCOLOR; break; | 174 | case EBF_SRC_COLOR: r = D3DBLEND_SRCCOLOR; break; |
175 | case EBF_ONE_MINUS_SRC_COLOR: r = D3DBLEND_INVSRCCOLOR; break; | 175 | case EBF_ONE_MINUS_SRC_COLOR: r = D3DBLEND_INVSRCCOLOR; break; |
176 | case EBF_SRC_ALPHA: r = D3DBLEND_SRCALPHA; break; | 176 | case EBF_SRC_ALPHA: r = D3DBLEND_SRCALPHA; break; |
177 | case EBF_ONE_MINUS_SRC_ALPHA: r = D3DBLEND_INVSRCALPHA; break; | 177 | case EBF_ONE_MINUS_SRC_ALPHA: r = D3DBLEND_INVSRCALPHA; break; |
178 | case EBF_DST_ALPHA: r = D3DBLEND_DESTALPHA; break; | 178 | case EBF_DST_ALPHA: r = D3DBLEND_DESTALPHA; break; |
179 | case EBF_ONE_MINUS_DST_ALPHA: r = D3DBLEND_INVDESTALPHA; break; | 179 | case EBF_ONE_MINUS_DST_ALPHA: r = D3DBLEND_INVDESTALPHA; break; |
180 | case EBF_SRC_ALPHA_SATURATE: r = D3DBLEND_SRCALPHASAT; break; | 180 | case EBF_SRC_ALPHA_SATURATE: r = D3DBLEND_SRCALPHASAT; break; |
181 | } | 181 | } |
182 | return r; | 182 | return r; |
183 | } | 183 | } |
184 | 184 | ||
185 | u32 getD3DModulate ( E_MODULATE_FUNC func ) const | 185 | u32 getD3DModulate ( E_MODULATE_FUNC func ) const |
186 | { | 186 | { |
187 | u32 r = D3DTOP_MODULATE; | 187 | u32 r = D3DTOP_MODULATE; |
188 | switch ( func ) | 188 | switch ( func ) |
189 | { | 189 | { |
190 | case EMFN_MODULATE_1X: r = D3DTOP_MODULATE; break; | 190 | case EMFN_MODULATE_1X: r = D3DTOP_MODULATE; break; |
191 | case EMFN_MODULATE_2X: r = D3DTOP_MODULATE2X; break; | 191 | case EMFN_MODULATE_2X: r = D3DTOP_MODULATE2X; break; |
192 | case EMFN_MODULATE_4X: r = D3DTOP_MODULATE4X; break; | 192 | case EMFN_MODULATE_4X: r = D3DTOP_MODULATE4X; break; |
193 | } | 193 | } |
194 | return r; | 194 | return r; |
195 | } | 195 | } |
196 | 196 | ||
197 | }; | 197 | }; |
198 | 198 | ||
199 | 199 | ||
200 | //! Solid 2 layer material renderer | 200 | //! Solid 2 layer material renderer |
201 | class CD3D8MaterialRenderer_SOLID_2_LAYER : public CD3D8MaterialRenderer | 201 | class CD3D8MaterialRenderer_SOLID_2_LAYER : public CD3D8MaterialRenderer |
202 | { | 202 | { |
203 | public: | 203 | public: |
204 | 204 | ||
205 | CD3D8MaterialRenderer_SOLID_2_LAYER(IDirect3DDevice8* p, video::IVideoDriver* d) | 205 | CD3D8MaterialRenderer_SOLID_2_LAYER(IDirect3DDevice8* p, video::IVideoDriver* d) |
206 | : CD3D8MaterialRenderer(p, d) {} | 206 | : CD3D8MaterialRenderer(p, d) {} |
207 | 207 | ||
208 | virtual void OnSetMaterial(const SMaterial& material, const SMaterial& lastMaterial, | 208 | virtual void OnSetMaterial(const SMaterial& material, const SMaterial& lastMaterial, |
209 | bool resetAllRenderstates, IMaterialRendererServices* services) | 209 | bool resetAllRenderstates, IMaterialRendererServices* services) |
210 | { | 210 | { |
211 | services->setBasicRenderStates(material, lastMaterial, resetAllRenderstates); | 211 | services->setBasicRenderStates(material, lastMaterial, resetAllRenderstates); |
212 | 212 | ||
213 | if (material.MaterialType != lastMaterial.MaterialType || resetAllRenderstates) | 213 | if (material.MaterialType != lastMaterial.MaterialType || resetAllRenderstates) |
214 | { | 214 | { |
215 | setTextureColorStage(pID3DDevice, 0, D3DTA_TEXTURE); | 215 | setTextureColorStage(pID3DDevice, 0, D3DTA_TEXTURE); |
216 | 216 | ||
217 | pID3DDevice->SetTextureStageState(1, D3DTSS_TEXCOORDINDEX, 0); | 217 | pID3DDevice->SetTextureStageState(1, D3DTSS_TEXCOORDINDEX, 0); |
218 | pID3DDevice->SetTextureStageState(1, D3DTSS_COLOROP, D3DTOP_BLENDDIFFUSEALPHA); | 218 | pID3DDevice->SetTextureStageState(1, D3DTSS_COLOROP, D3DTOP_BLENDDIFFUSEALPHA); |
219 | 219 | ||
220 | pID3DDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, FALSE); | 220 | pID3DDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, FALSE); |
221 | } | 221 | } |
222 | } | 222 | } |
223 | }; | 223 | }; |
224 | 224 | ||
225 | 225 | ||
226 | //! Transparent add color material renderer | 226 | //! Transparent add color material renderer |
227 | class CD3D8MaterialRenderer_TRANSPARENT_ADD_COLOR : public CD3D8MaterialRenderer | 227 | class CD3D8MaterialRenderer_TRANSPARENT_ADD_COLOR : public CD3D8MaterialRenderer |
228 | { | 228 | { |
229 | public: | 229 | public: |
230 | 230 | ||
231 | CD3D8MaterialRenderer_TRANSPARENT_ADD_COLOR(IDirect3DDevice8* p, video::IVideoDriver* d) | 231 | CD3D8MaterialRenderer_TRANSPARENT_ADD_COLOR(IDirect3DDevice8* p, video::IVideoDriver* d) |
232 | : CD3D8MaterialRenderer(p, d) {} | 232 | : CD3D8MaterialRenderer(p, d) {} |
233 | 233 | ||
234 | virtual void OnSetMaterial(const SMaterial& material, const SMaterial& lastMaterial, | 234 | virtual void OnSetMaterial(const SMaterial& material, const SMaterial& lastMaterial, |
235 | bool resetAllRenderstates, IMaterialRendererServices* services) | 235 | bool resetAllRenderstates, IMaterialRendererServices* services) |
236 | { | 236 | { |
237 | services->setBasicRenderStates(material, lastMaterial, resetAllRenderstates); | 237 | services->setBasicRenderStates(material, lastMaterial, resetAllRenderstates); |
238 | 238 | ||
239 | if (material.MaterialType != lastMaterial.MaterialType || resetAllRenderstates) | 239 | if (material.MaterialType != lastMaterial.MaterialType || resetAllRenderstates) |
240 | { | 240 | { |
241 | setTextureColorStage(pID3DDevice, 0, | 241 | setTextureColorStage(pID3DDevice, 0, |
242 | D3DTA_TEXTURE, D3DTOP_MODULATE, D3DTA_DIFFUSE); | 242 | D3DTA_TEXTURE, D3DTOP_MODULATE, D3DTA_DIFFUSE); |
243 | 243 | ||
244 | pID3DDevice->SetTextureStageState(1, D3DTSS_COLOROP, D3DTOP_DISABLE); | 244 | pID3DDevice->SetTextureStageState(1, D3DTSS_COLOROP, D3DTOP_DISABLE); |
245 | pID3DDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE); | 245 | pID3DDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE); |
246 | pID3DDevice->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_ONE); | 246 | pID3DDevice->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_ONE); |
247 | pID3DDevice->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCCOLOR); | 247 | pID3DDevice->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCCOLOR); |
248 | } | 248 | } |
249 | } | 249 | } |
250 | 250 | ||
251 | //! Returns if the material is transparent. The scene management needs to know this | 251 | //! Returns if the material is transparent. The scene management needs to know this |
252 | //! for being able to sort the materials by opaque and transparent. | 252 | //! for being able to sort the materials by opaque and transparent. |
253 | virtual bool isTransparent() const | 253 | virtual bool isTransparent() const |
254 | { | 254 | { |
255 | return true; | 255 | return true; |
256 | } | 256 | } |
257 | }; | 257 | }; |
258 | 258 | ||
259 | 259 | ||
260 | //! Transparent vertex alpha material renderer | 260 | //! Transparent vertex alpha material renderer |
261 | class CD3D8MaterialRenderer_TRANSPARENT_VERTEX_ALPHA : public CD3D8MaterialRenderer | 261 | class CD3D8MaterialRenderer_TRANSPARENT_VERTEX_ALPHA : public CD3D8MaterialRenderer |
262 | { | 262 | { |
263 | public: | 263 | public: |
264 | 264 | ||
265 | CD3D8MaterialRenderer_TRANSPARENT_VERTEX_ALPHA(IDirect3DDevice8* p, video::IVideoDriver* d) | 265 | CD3D8MaterialRenderer_TRANSPARENT_VERTEX_ALPHA(IDirect3DDevice8* p, video::IVideoDriver* d) |
266 | : CD3D8MaterialRenderer(p, d) {} | 266 | : CD3D8MaterialRenderer(p, d) {} |
267 | 267 | ||
268 | virtual void OnSetMaterial(const SMaterial& material, const SMaterial& lastMaterial, | 268 | virtual void OnSetMaterial(const SMaterial& material, const SMaterial& lastMaterial, |
269 | bool resetAllRenderstates, IMaterialRendererServices* services) | 269 | bool resetAllRenderstates, IMaterialRendererServices* services) |
270 | { | 270 | { |
271 | services->setBasicRenderStates(material, lastMaterial, resetAllRenderstates); | 271 | services->setBasicRenderStates(material, lastMaterial, resetAllRenderstates); |
272 | 272 | ||
273 | if (material.MaterialType != lastMaterial.MaterialType || resetAllRenderstates) | 273 | if (material.MaterialType != lastMaterial.MaterialType || resetAllRenderstates) |
274 | { | 274 | { |
275 | setTextureColorStage(pID3DDevice, 0, | 275 | setTextureColorStage(pID3DDevice, 0, |
276 | D3DTA_TEXTURE, D3DTOP_MODULATE, D3DTA_DIFFUSE); | 276 | D3DTA_TEXTURE, D3DTOP_MODULATE, D3DTA_DIFFUSE); |
277 | setTextureAlphaStage(pID3DDevice, 0, D3DTA_DIFFUSE); | 277 | setTextureAlphaStage(pID3DDevice, 0, D3DTA_DIFFUSE); |
278 | 278 | ||
279 | pID3DDevice->SetTextureStageState(1, D3DTSS_COLOROP, D3DTOP_DISABLE); | 279 | pID3DDevice->SetTextureStageState(1, D3DTSS_COLOROP, D3DTOP_DISABLE); |
280 | pID3DDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE); | 280 | pID3DDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE); |
281 | pID3DDevice->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA); | 281 | pID3DDevice->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA); |
282 | pID3DDevice->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA); | 282 | pID3DDevice->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA); |
283 | } | 283 | } |
284 | } | 284 | } |
285 | 285 | ||
286 | //! Returns if the material is transparent. The scene managment needs to know this | 286 | //! Returns if the material is transparent. The scene managment needs to know this |
287 | //! for being able to sort the materials by opaque and transparent. | 287 | //! for being able to sort the materials by opaque and transparent. |
288 | virtual bool isTransparent() const | 288 | virtual bool isTransparent() const |
289 | { | 289 | { |
290 | return true; | 290 | return true; |
291 | } | 291 | } |
292 | }; | 292 | }; |
293 | 293 | ||
294 | 294 | ||
295 | //! Transparent alpha channel material renderer | 295 | //! Transparent alpha channel material renderer |
296 | class CD3D8MaterialRenderer_TRANSPARENT_ALPHA_CHANNEL : public CD3D8MaterialRenderer | 296 | class CD3D8MaterialRenderer_TRANSPARENT_ALPHA_CHANNEL : public CD3D8MaterialRenderer |
297 | { | 297 | { |
298 | public: | 298 | public: |
299 | 299 | ||
300 | CD3D8MaterialRenderer_TRANSPARENT_ALPHA_CHANNEL(IDirect3DDevice8* p, video::IVideoDriver* d) | 300 | CD3D8MaterialRenderer_TRANSPARENT_ALPHA_CHANNEL(IDirect3DDevice8* p, video::IVideoDriver* d) |
301 | : CD3D8MaterialRenderer(p, d) {} | 301 | : CD3D8MaterialRenderer(p, d) {} |
302 | 302 | ||
303 | virtual void OnSetMaterial(const SMaterial& material, const SMaterial& lastMaterial, | 303 | virtual void OnSetMaterial(const SMaterial& material, const SMaterial& lastMaterial, |
304 | bool resetAllRenderstates, IMaterialRendererServices* services) | 304 | bool resetAllRenderstates, IMaterialRendererServices* services) |
305 | { | 305 | { |
306 | services->setBasicRenderStates(material, lastMaterial, resetAllRenderstates); | 306 | services->setBasicRenderStates(material, lastMaterial, resetAllRenderstates); |
307 | 307 | ||
308 | if (material.MaterialType != lastMaterial.MaterialType || resetAllRenderstates | 308 | if (material.MaterialType != lastMaterial.MaterialType || resetAllRenderstates |
309 | || material.MaterialTypeParam != lastMaterial.MaterialTypeParam ) | 309 | || material.MaterialTypeParam != lastMaterial.MaterialTypeParam ) |
310 | { | 310 | { |
311 | setTextureColorStage(pID3DDevice, 0, | 311 | setTextureColorStage(pID3DDevice, 0, |
312 | D3DTA_TEXTURE, D3DTOP_MODULATE, D3DTA_CURRENT); | 312 | D3DTA_TEXTURE, D3DTOP_MODULATE, D3DTA_CURRENT); |
313 | setTextureAlphaStage(pID3DDevice, 0, D3DTA_TEXTURE); | 313 | setTextureAlphaStage(pID3DDevice, 0, D3DTA_TEXTURE); |
314 | 314 | ||
315 | pID3DDevice->SetTextureStageState(1, D3DTSS_COLOROP, D3DTOP_DISABLE); | 315 | pID3DDevice->SetTextureStageState(1, D3DTSS_COLOROP, D3DTOP_DISABLE); |
316 | pID3DDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE); | 316 | pID3DDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE); |
317 | pID3DDevice->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA); | 317 | pID3DDevice->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA); |
318 | pID3DDevice->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA ); | 318 | pID3DDevice->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA ); |
319 | 319 | ||
320 | pID3DDevice->SetRenderState(D3DRS_ALPHAREF, core::floor32(material.MaterialTypeParam * 255.f)); | 320 | pID3DDevice->SetRenderState(D3DRS_ALPHAREF, core::floor32(material.MaterialTypeParam * 255.f)); |
321 | pID3DDevice->SetRenderState(D3DRS_ALPHAFUNC, D3DCMP_GREATEREQUAL); | 321 | pID3DDevice->SetRenderState(D3DRS_ALPHAFUNC, D3DCMP_GREATEREQUAL); |
322 | pID3DDevice->SetRenderState(D3DRS_ALPHATESTENABLE, TRUE); | 322 | pID3DDevice->SetRenderState(D3DRS_ALPHATESTENABLE, TRUE); |
323 | } | 323 | } |
324 | } | 324 | } |
325 | 325 | ||
326 | virtual void OnUnsetMaterial() | 326 | virtual void OnUnsetMaterial() |
327 | { | 327 | { |
328 | pID3DDevice->SetRenderState(D3DRS_ALPHATESTENABLE, FALSE); | 328 | pID3DDevice->SetRenderState(D3DRS_ALPHATESTENABLE, FALSE); |
329 | } | 329 | } |
330 | 330 | ||
331 | //! Returns if the material is transparent. The scene managment needs to know this | 331 | //! Returns if the material is transparent. The scene managment needs to know this |
332 | //! for being able to sort the materials by opaque and transparent. | 332 | //! for being able to sort the materials by opaque and transparent. |
333 | virtual bool isTransparent() const | 333 | virtual bool isTransparent() const |
334 | { | 334 | { |
335 | return true; | 335 | return true; |
336 | } | 336 | } |
337 | }; | 337 | }; |
338 | 338 | ||
339 | 339 | ||
340 | //! Transparent alpha channel material renderer | 340 | //! Transparent alpha channel material renderer |
341 | class CD3D8MaterialRenderer_TRANSPARENT_ALPHA_CHANNEL_REF : public CD3D8MaterialRenderer | 341 | class CD3D8MaterialRenderer_TRANSPARENT_ALPHA_CHANNEL_REF : public CD3D8MaterialRenderer |
342 | { | 342 | { |
343 | public: | 343 | public: |
344 | 344 | ||
345 | CD3D8MaterialRenderer_TRANSPARENT_ALPHA_CHANNEL_REF(IDirect3DDevice8* p, video::IVideoDriver* d) | 345 | CD3D8MaterialRenderer_TRANSPARENT_ALPHA_CHANNEL_REF(IDirect3DDevice8* p, video::IVideoDriver* d) |
346 | : CD3D8MaterialRenderer(p, d) {} | 346 | : CD3D8MaterialRenderer(p, d) {} |
347 | 347 | ||
348 | virtual void OnSetMaterial(const SMaterial& material, const SMaterial& lastMaterial, | 348 | virtual void OnSetMaterial(const SMaterial& material, const SMaterial& lastMaterial, |
349 | bool resetAllRenderstates, IMaterialRendererServices* services) | 349 | bool resetAllRenderstates, IMaterialRendererServices* services) |
350 | { | 350 | { |
351 | services->setBasicRenderStates(material, lastMaterial, resetAllRenderstates); | 351 | services->setBasicRenderStates(material, lastMaterial, resetAllRenderstates); |
352 | 352 | ||
353 | if (material.MaterialType != lastMaterial.MaterialType || resetAllRenderstates) | 353 | if (material.MaterialType != lastMaterial.MaterialType || resetAllRenderstates) |
354 | { | 354 | { |
355 | setTextureColorStage(pID3DDevice, 0, | 355 | setTextureColorStage(pID3DDevice, 0, |
356 | D3DTA_TEXTURE, D3DTOP_MODULATE, D3DTA_CURRENT); | 356 | D3DTA_TEXTURE, D3DTOP_MODULATE, D3DTA_CURRENT); |
357 | setTextureAlphaStage(pID3DDevice, 0, D3DTA_TEXTURE); | 357 | setTextureAlphaStage(pID3DDevice, 0, D3DTA_TEXTURE); |
358 | 358 | ||
359 | pID3DDevice->SetTextureStageState(1, D3DTSS_COLOROP, D3DTOP_DISABLE); | 359 | pID3DDevice->SetTextureStageState(1, D3DTSS_COLOROP, D3DTOP_DISABLE); |
360 | 360 | ||
361 | pID3DDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, FALSE); | 361 | pID3DDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, FALSE); |
362 | 362 | ||
363 | // 127 is required by EMT_TRANSPARENT_ALPHA_CHANNEL_REF | 363 | // 127 is required by EMT_TRANSPARENT_ALPHA_CHANNEL_REF |
364 | pID3DDevice->SetRenderState(D3DRS_ALPHAREF, 127); | 364 | pID3DDevice->SetRenderState(D3DRS_ALPHAREF, 127); |
365 | pID3DDevice->SetRenderState(D3DRS_ALPHAFUNC, D3DCMP_GREATEREQUAL); | 365 | pID3DDevice->SetRenderState(D3DRS_ALPHAFUNC, D3DCMP_GREATEREQUAL); |
366 | pID3DDevice->SetRenderState(D3DRS_ALPHATESTENABLE, TRUE); | 366 | pID3DDevice->SetRenderState(D3DRS_ALPHATESTENABLE, TRUE); |
367 | } | 367 | } |
368 | } | 368 | } |
369 | 369 | ||
370 | virtual void OnUnsetMaterial() | 370 | virtual void OnUnsetMaterial() |
371 | { | 371 | { |
372 | pID3DDevice->SetRenderState(D3DRS_ALPHATESTENABLE, FALSE); | 372 | pID3DDevice->SetRenderState(D3DRS_ALPHATESTENABLE, FALSE); |
373 | } | 373 | } |
374 | 374 | ||
375 | //! Returns if the material is transparent. The scene managment needs to know this | 375 | //! Returns if the material is transparent. The scene managment needs to know this |
376 | //! for being able to sort the materials by opaque and transparent. | 376 | //! for being able to sort the materials by opaque and transparent. |
377 | virtual bool isTransparent() const | 377 | virtual bool isTransparent() const |
378 | { | 378 | { |
379 | return false; // this material is not really transparent because it does no blending. | 379 | return false; // this material is not really transparent because it does no blending. |
380 | } | 380 | } |
381 | }; | 381 | }; |
382 | 382 | ||
383 | 383 | ||
384 | //! material renderer for all kinds of lightmaps | 384 | //! material renderer for all kinds of lightmaps |
385 | class CD3D8MaterialRenderer_LIGHTMAP : public CD3D8MaterialRenderer | 385 | class CD3D8MaterialRenderer_LIGHTMAP : public CD3D8MaterialRenderer |
386 | { | 386 | { |
387 | public: | 387 | public: |
388 | 388 | ||
389 | CD3D8MaterialRenderer_LIGHTMAP(IDirect3DDevice8* p, video::IVideoDriver* d) | 389 | CD3D8MaterialRenderer_LIGHTMAP(IDirect3DDevice8* p, video::IVideoDriver* d) |
390 | : CD3D8MaterialRenderer(p, d) {} | 390 | : CD3D8MaterialRenderer(p, d) {} |
391 | 391 | ||
392 | virtual void OnSetMaterial(const SMaterial& material, const SMaterial& lastMaterial, | 392 | virtual void OnSetMaterial(const SMaterial& material, const SMaterial& lastMaterial, |
393 | bool resetAllRenderstates, IMaterialRendererServices* services) | 393 | bool resetAllRenderstates, IMaterialRendererServices* services) |
394 | { | 394 | { |
395 | services->setBasicRenderStates(material, lastMaterial, resetAllRenderstates); | 395 | services->setBasicRenderStates(material, lastMaterial, resetAllRenderstates); |
396 | 396 | ||
397 | if (material.MaterialType != lastMaterial.MaterialType || resetAllRenderstates) | 397 | if (material.MaterialType != lastMaterial.MaterialType || resetAllRenderstates) |
398 | { | 398 | { |
399 | if (material.MaterialType >= EMT_LIGHTMAP_LIGHTING) | 399 | if (material.MaterialType >= EMT_LIGHTMAP_LIGHTING) |
400 | { | 400 | { |
401 | // with lighting | 401 | // with lighting |
402 | setTextureColorStage(pID3DDevice, 0, | 402 | setTextureColorStage(pID3DDevice, 0, |
403 | D3DTA_TEXTURE, D3DTOP_MODULATE, D3DTA_DIFFUSE); | 403 | D3DTA_TEXTURE, D3DTOP_MODULATE, D3DTA_DIFFUSE); |
404 | } | 404 | } |
405 | else | 405 | else |
406 | { | 406 | { |
407 | setTextureColorStage(pID3DDevice, 0, D3DTA_TEXTURE); | 407 | setTextureColorStage(pID3DDevice, 0, D3DTA_TEXTURE); |
408 | } | 408 | } |
409 | 409 | ||
410 | pID3DDevice->SetTextureStageState(1, D3DTSS_TEXCOORDINDEX, 1); | 410 | pID3DDevice->SetTextureStageState(1, D3DTSS_TEXCOORDINDEX, 1); |
411 | 411 | ||
412 | setTextureColorStage(pID3DDevice, 1, | 412 | setTextureColorStage(pID3DDevice, 1, |
413 | D3DTA_TEXTURE, | 413 | D3DTA_TEXTURE, |
414 | (material.MaterialType == EMT_LIGHTMAP_ADD)? | 414 | (material.MaterialType == EMT_LIGHTMAP_ADD)? |
415 | D3DTOP_ADD: | 415 | D3DTOP_ADD: |
416 | (material.MaterialType == EMT_LIGHTMAP_M4 || material.MaterialType == EMT_LIGHTMAP_LIGHTING_M4)? | 416 | (material.MaterialType == EMT_LIGHTMAP_M4 || material.MaterialType == EMT_LIGHTMAP_LIGHTING_M4)? |
417 | D3DTOP_MODULATE4X: | 417 | D3DTOP_MODULATE4X: |
418 | (material.MaterialType == EMT_LIGHTMAP_M2 || material.MaterialType == EMT_LIGHTMAP_LIGHTING_M2)? | 418 | (material.MaterialType == EMT_LIGHTMAP_M2 || material.MaterialType == EMT_LIGHTMAP_LIGHTING_M2)? |
419 | D3DTOP_MODULATE2X: | 419 | D3DTOP_MODULATE2X: |
420 | D3DTOP_MODULATE, | 420 | D3DTOP_MODULATE, |
421 | D3DTA_CURRENT); | 421 | D3DTA_CURRENT); |
422 | 422 | ||
423 | pID3DDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, FALSE); | 423 | pID3DDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, FALSE); |
424 | } | 424 | } |
425 | } | 425 | } |
426 | }; | 426 | }; |
427 | 427 | ||
428 | 428 | ||
429 | //! material renderer for detail maps | 429 | //! material renderer for detail maps |
430 | class CD3D8MaterialRenderer_DETAIL_MAP : public CD3D8MaterialRenderer | 430 | class CD3D8MaterialRenderer_DETAIL_MAP : public CD3D8MaterialRenderer |
431 | { | 431 | { |
432 | public: | 432 | public: |
433 | 433 | ||
434 | CD3D8MaterialRenderer_DETAIL_MAP(IDirect3DDevice8* p, video::IVideoDriver* d) | 434 | CD3D8MaterialRenderer_DETAIL_MAP(IDirect3DDevice8* p, video::IVideoDriver* d) |
435 | : CD3D8MaterialRenderer(p, d) {} | 435 | : CD3D8MaterialRenderer(p, d) {} |
436 | 436 | ||
437 | virtual void OnSetMaterial(const SMaterial& material, const SMaterial& lastMaterial, | 437 | virtual void OnSetMaterial(const SMaterial& material, const SMaterial& lastMaterial, |
438 | bool resetAllRenderstates, IMaterialRendererServices* services) | 438 | bool resetAllRenderstates, IMaterialRendererServices* services) |
439 | { | 439 | { |
440 | services->setBasicRenderStates(material, lastMaterial, resetAllRenderstates); | 440 | services->setBasicRenderStates(material, lastMaterial, resetAllRenderstates); |
441 | 441 | ||
442 | if (material.MaterialType != lastMaterial.MaterialType || resetAllRenderstates) | 442 | if (material.MaterialType != lastMaterial.MaterialType || resetAllRenderstates) |
443 | { | 443 | { |
444 | setTextureColorStage(pID3DDevice, 0, | 444 | setTextureColorStage(pID3DDevice, 0, |
445 | D3DTA_TEXTURE, D3DTOP_MODULATE, D3DTA_DIFFUSE); | 445 | D3DTA_TEXTURE, D3DTOP_MODULATE, D3DTA_DIFFUSE); |
446 | setTextureColorStage(pID3DDevice, 1, | 446 | setTextureColorStage(pID3DDevice, 1, |
447 | D3DTA_TEXTURE, D3DTOP_ADDSIGNED, D3DTA_CURRENT); | 447 | D3DTA_TEXTURE, D3DTOP_ADDSIGNED, D3DTA_CURRENT); |
448 | pID3DDevice->SetTextureStageState(1, D3DTSS_TEXCOORDINDEX, 1); | 448 | pID3DDevice->SetTextureStageState(1, D3DTSS_TEXCOORDINDEX, 1); |
449 | pID3DDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, FALSE); | 449 | pID3DDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, FALSE); |
450 | } | 450 | } |
451 | } | 451 | } |
452 | }; | 452 | }; |
453 | 453 | ||
454 | 454 | ||
455 | //! sphere map material renderer | 455 | //! sphere map material renderer |
456 | class CD3D8MaterialRenderer_SPHERE_MAP : public CD3D8MaterialRenderer | 456 | class CD3D8MaterialRenderer_SPHERE_MAP : public CD3D8MaterialRenderer |
457 | { | 457 | { |
458 | public: | 458 | public: |
459 | 459 | ||
460 | CD3D8MaterialRenderer_SPHERE_MAP(IDirect3DDevice8* p, video::IVideoDriver* d) | 460 | CD3D8MaterialRenderer_SPHERE_MAP(IDirect3DDevice8* p, video::IVideoDriver* d) |
461 | : CD3D8MaterialRenderer(p, d) {} | 461 | : CD3D8MaterialRenderer(p, d) {} |
462 | 462 | ||
463 | virtual void OnSetMaterial(const SMaterial& material, const SMaterial& lastMaterial, | 463 | virtual void OnSetMaterial(const SMaterial& material, const SMaterial& lastMaterial, |
464 | bool resetAllRenderstates, IMaterialRendererServices* services) | 464 | bool resetAllRenderstates, IMaterialRendererServices* services) |
465 | { | 465 | { |
466 | services->setBasicRenderStates(material, lastMaterial, resetAllRenderstates); | 466 | services->setBasicRenderStates(material, lastMaterial, resetAllRenderstates); |
467 | 467 | ||
468 | if (material.MaterialType != lastMaterial.MaterialType || resetAllRenderstates) | 468 | if (material.MaterialType != lastMaterial.MaterialType || resetAllRenderstates) |
469 | { | 469 | { |
470 | setTextureColorStage(pID3DDevice, 0, | 470 | setTextureColorStage(pID3DDevice, 0, |
471 | D3DTA_TEXTURE, D3DTOP_MODULATE, D3DTA_DIFFUSE); | 471 | D3DTA_TEXTURE, D3DTOP_MODULATE, D3DTA_DIFFUSE); |
472 | 472 | ||
473 | pID3DDevice->SetTextureStageState(1, D3DTSS_COLOROP, D3DTOP_DISABLE); | 473 | pID3DDevice->SetTextureStageState(1, D3DTSS_COLOROP, D3DTOP_DISABLE); |
474 | pID3DDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, FALSE); | 474 | pID3DDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, FALSE); |
475 | 475 | ||
476 | pID3DDevice->SetTransform( D3DTS_TEXTURE0, &SphereMapMatrixD3D8 ); | 476 | pID3DDevice->SetTransform( D3DTS_TEXTURE0, &SphereMapMatrixD3D8 ); |
477 | pID3DDevice->SetTextureStageState( 0, D3DTSS_TEXTURETRANSFORMFLAGS, D3DTTFF_COUNT2 ); | 477 | pID3DDevice->SetTextureStageState( 0, D3DTSS_TEXTURETRANSFORMFLAGS, D3DTTFF_COUNT2 ); |
478 | pID3DDevice->SetTextureStageState( 0, D3DTSS_TEXCOORDINDEX, D3DTSS_TCI_CAMERASPACENORMAL ); | 478 | pID3DDevice->SetTextureStageState( 0, D3DTSS_TEXCOORDINDEX, D3DTSS_TCI_CAMERASPACENORMAL ); |
479 | } | 479 | } |
480 | } | 480 | } |
481 | 481 | ||
482 | virtual void OnUnsetMaterial() | 482 | virtual void OnUnsetMaterial() |
483 | { | 483 | { |
484 | pID3DDevice->SetTextureStageState( 0, D3DTSS_TEXTURETRANSFORMFLAGS, D3DTTFF_DISABLE ); | 484 | pID3DDevice->SetTextureStageState( 0, D3DTSS_TEXTURETRANSFORMFLAGS, D3DTTFF_DISABLE ); |
485 | pID3DDevice->SetTextureStageState( 0, D3DTSS_TEXCOORDINDEX, 0); | 485 | pID3DDevice->SetTextureStageState( 0, D3DTSS_TEXCOORDINDEX, 0); |
486 | pID3DDevice->SetTransform( D3DTS_TEXTURE0, &UnitMatrixD3D8 ); | 486 | pID3DDevice->SetTransform( D3DTS_TEXTURE0, &UnitMatrixD3D8 ); |
487 | } | 487 | } |
488 | }; | 488 | }; |
489 | 489 | ||
490 | 490 | ||
491 | //! reflection 2 layer material renderer | 491 | //! reflection 2 layer material renderer |
492 | class CD3D8MaterialRenderer_REFLECTION_2_LAYER : public CD3D8MaterialRenderer | 492 | class CD3D8MaterialRenderer_REFLECTION_2_LAYER : public CD3D8MaterialRenderer |
493 | { | 493 | { |
494 | public: | 494 | public: |
495 | 495 | ||
496 | CD3D8MaterialRenderer_REFLECTION_2_LAYER(IDirect3DDevice8* p, video::IVideoDriver* d) | 496 | CD3D8MaterialRenderer_REFLECTION_2_LAYER(IDirect3DDevice8* p, video::IVideoDriver* d) |
497 | : CD3D8MaterialRenderer(p, d) {} | 497 | : CD3D8MaterialRenderer(p, d) {} |
498 | 498 | ||
499 | virtual void OnSetMaterial(const SMaterial& material, const SMaterial& lastMaterial, | 499 | virtual void OnSetMaterial(const SMaterial& material, const SMaterial& lastMaterial, |
500 | bool resetAllRenderstates, IMaterialRendererServices* services) | 500 | bool resetAllRenderstates, IMaterialRendererServices* services) |
501 | { | 501 | { |
502 | services->setBasicRenderStates(material, lastMaterial, resetAllRenderstates); | 502 | services->setBasicRenderStates(material, lastMaterial, resetAllRenderstates); |
503 | 503 | ||
504 | if (material.MaterialType != lastMaterial.MaterialType || resetAllRenderstates) | 504 | if (material.MaterialType != lastMaterial.MaterialType || resetAllRenderstates) |
505 | { | 505 | { |
506 | setTextureColorStage(pID3DDevice, 0, | 506 | setTextureColorStage(pID3DDevice, 0, |
507 | D3DTA_TEXTURE, D3DTOP_MODULATE, D3DTA_DIFFUSE); | 507 | D3DTA_TEXTURE, D3DTOP_MODULATE, D3DTA_DIFFUSE); |
508 | 508 | ||
509 | setTextureColorStage(pID3DDevice, 1, | 509 | setTextureColorStage(pID3DDevice, 1, |
510 | D3DTA_TEXTURE, D3DTOP_MODULATE, D3DTA_CURRENT); | 510 | D3DTA_TEXTURE, D3DTOP_MODULATE, D3DTA_CURRENT); |
511 | 511 | ||
512 | pID3DDevice->SetTransform( D3DTS_TEXTURE1, &SphereMapMatrixD3D8 ); | 512 | pID3DDevice->SetTransform( D3DTS_TEXTURE1, &SphereMapMatrixD3D8 ); |
513 | pID3DDevice->SetTextureStageState( 1, D3DTSS_TEXTURETRANSFORMFLAGS, D3DTTFF_COUNT2 ); | 513 | pID3DDevice->SetTextureStageState( 1, D3DTSS_TEXTURETRANSFORMFLAGS, D3DTTFF_COUNT2 ); |
514 | pID3DDevice->SetTextureStageState( 1, D3DTSS_TEXCOORDINDEX, D3DTSS_TCI_CAMERASPACEREFLECTIONVECTOR); | 514 | pID3DDevice->SetTextureStageState( 1, D3DTSS_TEXCOORDINDEX, D3DTSS_TCI_CAMERASPACEREFLECTIONVECTOR); |
515 | pID3DDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, FALSE); | 515 | pID3DDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, FALSE); |
516 | } | 516 | } |
517 | } | 517 | } |
518 | 518 | ||
519 | virtual void OnUnsetMaterial() | 519 | virtual void OnUnsetMaterial() |
520 | { | 520 | { |
521 | pID3DDevice->SetTextureStageState( 1, D3DTSS_TEXTURETRANSFORMFLAGS, D3DTTFF_DISABLE ); | 521 | pID3DDevice->SetTextureStageState( 1, D3DTSS_TEXTURETRANSFORMFLAGS, D3DTTFF_DISABLE ); |
522 | pID3DDevice->SetTextureStageState( 1, D3DTSS_TEXCOORDINDEX, 1); | 522 | pID3DDevice->SetTextureStageState( 1, D3DTSS_TEXCOORDINDEX, 1); |
523 | pID3DDevice->SetTransform( D3DTS_TEXTURE1, &UnitMatrixD3D8 ); | 523 | pID3DDevice->SetTransform( D3DTS_TEXTURE1, &UnitMatrixD3D8 ); |
524 | } | 524 | } |
525 | }; | 525 | }; |
526 | 526 | ||
527 | 527 | ||
528 | //! reflection 2 layer material renderer | 528 | //! reflection 2 layer material renderer |
529 | class CD3D8MaterialRenderer_TRANSPARENT_REFLECTION_2_LAYER : public CD3D8MaterialRenderer | 529 | class CD3D8MaterialRenderer_TRANSPARENT_REFLECTION_2_LAYER : public CD3D8MaterialRenderer |
530 | { | 530 | { |
531 | public: | 531 | public: |
532 | 532 | ||
533 | CD3D8MaterialRenderer_TRANSPARENT_REFLECTION_2_LAYER(IDirect3DDevice8* p, video::IVideoDriver* d) | 533 | CD3D8MaterialRenderer_TRANSPARENT_REFLECTION_2_LAYER(IDirect3DDevice8* p, video::IVideoDriver* d) |
534 | : CD3D8MaterialRenderer(p, d) {} | 534 | : CD3D8MaterialRenderer(p, d) {} |
535 | 535 | ||
536 | virtual void OnSetMaterial(const SMaterial& material, const SMaterial& lastMaterial, | 536 | virtual void OnSetMaterial(const SMaterial& material, const SMaterial& lastMaterial, |
537 | bool resetAllRenderstates, IMaterialRendererServices* services) | 537 | bool resetAllRenderstates, IMaterialRendererServices* services) |
538 | { | 538 | { |
539 | services->setBasicRenderStates(material, lastMaterial, resetAllRenderstates); | 539 | services->setBasicRenderStates(material, lastMaterial, resetAllRenderstates); |
540 | 540 | ||
541 | if (material.MaterialType != lastMaterial.MaterialType || resetAllRenderstates) | 541 | if (material.MaterialType != lastMaterial.MaterialType || resetAllRenderstates) |
542 | { | 542 | { |
543 | setTextureColorStage(pID3DDevice, 0, | 543 | setTextureColorStage(pID3DDevice, 0, |
544 | D3DTA_TEXTURE, D3DTOP_MODULATE, D3DTA_DIFFUSE); | 544 | D3DTA_TEXTURE, D3DTOP_MODULATE, D3DTA_DIFFUSE); |
545 | setTextureAlphaStage(pID3DDevice, 0, D3DTA_DIFFUSE); | 545 | setTextureAlphaStage(pID3DDevice, 0, D3DTA_DIFFUSE); |
546 | setTextureColorStage(pID3DDevice, 1, | 546 | setTextureColorStage(pID3DDevice, 1, |
547 | D3DTA_TEXTURE, D3DTOP_MODULATE, D3DTA_CURRENT); | 547 | D3DTA_TEXTURE, D3DTOP_MODULATE, D3DTA_CURRENT); |
548 | setTextureAlphaStage(pID3DDevice, 1, D3DTA_CURRENT); | 548 | setTextureAlphaStage(pID3DDevice, 1, D3DTA_CURRENT); |
549 | 549 | ||
550 | pID3DDevice->SetTransform(D3DTS_TEXTURE1, &SphereMapMatrixD3D8 ); | 550 | pID3DDevice->SetTransform(D3DTS_TEXTURE1, &SphereMapMatrixD3D8 ); |
551 | pID3DDevice->SetTextureStageState(1, D3DTSS_TEXTURETRANSFORMFLAGS, D3DTTFF_COUNT2 ); | 551 | pID3DDevice->SetTextureStageState(1, D3DTSS_TEXTURETRANSFORMFLAGS, D3DTTFF_COUNT2 ); |
552 | pID3DDevice->SetTextureStageState(1, D3DTSS_TEXCOORDINDEX, D3DTSS_TCI_CAMERASPACEREFLECTIONVECTOR); | 552 | pID3DDevice->SetTextureStageState(1, D3DTSS_TEXCOORDINDEX, D3DTSS_TCI_CAMERASPACEREFLECTIONVECTOR); |
553 | 553 | ||
554 | pID3DDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE); | 554 | pID3DDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE); |
555 | pID3DDevice->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA); | 555 | pID3DDevice->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA); |
556 | pID3DDevice->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA); | 556 | pID3DDevice->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA); |
557 | } | 557 | } |
558 | } | 558 | } |
559 | 559 | ||
560 | virtual void OnUnsetMaterial() | 560 | virtual void OnUnsetMaterial() |
561 | { | 561 | { |
562 | pID3DDevice->SetTextureStageState(1, D3DTSS_TEXTURETRANSFORMFLAGS, D3DTTFF_DISABLE); | 562 | pID3DDevice->SetTextureStageState(1, D3DTSS_TEXTURETRANSFORMFLAGS, D3DTTFF_DISABLE); |
563 | pID3DDevice->SetTextureStageState(1, D3DTSS_TEXCOORDINDEX, 1); | 563 | pID3DDevice->SetTextureStageState(1, D3DTSS_TEXCOORDINDEX, 1); |
564 | pID3DDevice->SetTransform(D3DTS_TEXTURE1, &UnitMatrixD3D8); | 564 | pID3DDevice->SetTransform(D3DTS_TEXTURE1, &UnitMatrixD3D8); |
565 | } | 565 | } |
566 | 566 | ||
567 | //! Returns if the material is transparent. The scene managment needs to know this | 567 | //! Returns if the material is transparent. The scene managment needs to know this |
568 | //! for being able to sort the materials by opaque and transparent. | 568 | //! for being able to sort the materials by opaque and transparent. |
569 | virtual bool isTransparent() const | 569 | virtual bool isTransparent() const |
570 | { | 570 | { |
571 | return true; | 571 | return true; |
572 | } | 572 | } |
573 | }; | 573 | }; |
574 | 574 | ||
575 | } // end namespace video | 575 | } // end namespace video |
576 | } // end namespace irr | 576 | } // end namespace irr |
577 | 577 | ||
578 | #endif | 578 | #endif |
579 | #endif | 579 | #endif |
580 | #endif | 580 | #endif |
581 | 581 | ||