Richard Boegli's CnC_Generals_Zero_Hour Fork WIP
This is documentation of Richard Boegil's Zero Hour Fork
 
Loading...
Searching...
No Matches
shdglossmask.cpp
Go to the documentation of this file.
1/*
2** Command & Conquer Generals Zero Hour(tm)
3** Copyright 2025 Electronic Arts Inc.
4**
5** This program is free software: you can redistribute it and/or modify
6** it under the terms of the GNU General Public License as published by
7** the Free Software Foundation, either version 3 of the License, or
8** (at your option) any later version.
9**
10** This program is distributed in the hope that it will be useful,
11** but WITHOUT ANY WARRANTY; without even the implied warranty of
12** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13** GNU General Public License for more details.
14**
15** You should have received a copy of the GNU General Public License
16** along with this program. If not, see <http://www.gnu.org/licenses/>.
17*/
18
19 /***********************************************************************************************
20 *** C O N F I D E N T I A L --- W E S T W O O D S T U D I O S ***
21 ***********************************************************************************************
22 * *
23 * Project Name : WWSHADE *
24 * *
25 * $Archive:: wwshade/shdglossmask.cpp $*
26 * *
27 * $Org Author:: Kenny_m
28 *
29 * $Author:: Kenny_m
30 *
31 * $Modtime:: 8/01/02 11:39a $*
32 * *
33 * $Revision:: 1 $*
34 * *
35 *---------------------------------------------------------------------------------------------*
36 * Functions: *
37 * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
38
39#include <d3dx8math.h>
40#include "dx8fvf.h"
41#include "dx8wrapper.h"
42#include "assetmgr.h"
43
44#include "shdglossmask.h"
45
46#include "editable.h"
47#include "shdclassids.h"
48#include "shddeffactory.h"
49#include "shdinterface.h"
50#include "shdhwshader.h"
51
52#include "persistfactory.h"
53#include "wwhack.h"
54
55DECLARE_FORCE_LINK(GlossMaskShader);
57
58
59// Save-Load methods for ShdDefClass
60enum
61{
62 CHUNKID_VARIABLES = 0x16490460,
63
65
69};
70
73 Ambient(1,1,1),
74 Diffuse(1,1,1),
75 Specular(1,1,1)
76{
77 NAMED_TEXTURE_FILENAME_PARAM(ShdGlossMaskDefClass, TextureName, "Texture Name", "Targa Files", ".tga");
78
82}
83
85: ShdDefClass(that),
86 Ambient(that.Ambient),
87 Diffuse(that.Diffuse),
88 Specular(that.Specular)
89{
90 TextureName=that.TextureName;
91}
92
96
98{
99 return true;
100}
101
103{
104 ShdDefClass::Save(csave);
105
107
108 bool retval = true;
109
110 // only save the file name
111 char fname[_MAX_PATH];
112
113 _splitpath(TextureName,NULL,NULL,fname,NULL);
114 strcat(fname,".tga");
115 TextureName=fname;
116
118
119 WRITE_MICRO_CHUNK(csave, VARID_AMBIENT_COLOR, Ambient);
120 WRITE_MICRO_CHUNK(csave, VARID_DIFFUSE_COLOR, Diffuse);
121 WRITE_MICRO_CHUNK(csave, VARID_SPECULAR_COLOR, Specular);
122
123 csave.End_Chunk();
124
125 return retval;
126}
127
129{
130 ShdDefClass::Load(cload);
131
132 // Loop through all the microchunks that define the variables
133 while (cload.Open_Chunk()) {
134 switch (cload.Cur_Chunk_ID())
135 {
137 while (cload.Open_Micro_Chunk())
138 {
139 switch (cload.Cur_Micro_Chunk_ID())
140 {
142
143 READ_MICRO_CHUNK(cload, VARID_AMBIENT_COLOR, Ambient);
144 READ_MICRO_CHUNK(cload, VARID_DIFFUSE_COLOR, Diffuse);
145 READ_MICRO_CHUNK(cload, VARID_SPECULAR_COLOR, Specular);
146 }
147
148 cload.Close_Micro_Chunk();
149 }
150 break;
151
152 default:
153 break;
154 }
155
156 cload.Close_Chunk();
157 }
158
159 return true;
160}
161
162
167
172
177
178
179
181
185{
187
189 (
190 Definition->Get_Texture_Name()
191 );
192
193 const Vector3& a=Definition->Get_Ambient();
194 Ambient.Set(a.X,a.Y,a.Z,1.0f);
195
196 const Vector3& d=Definition->Get_Diffuse();
197 Diffuse.Set(d.X,d.Y,d.Z,1.0f);
198
199 const Vector3& s=Definition->Get_Specular();
200 Specular.Set(s.X,s.Y,s.Z,1.0f);
201
202 Material=new D3DMATERIAL8;
203 memset(Material,0,sizeof(D3DMATERIAL8));
204 Material->Ambient.r=a.X; Material->Ambient.g=a.Y; Material->Ambient.b=a.Z;
205 Material->Diffuse.r=d.X; Material->Diffuse.g=d.Y; Material->Diffuse.b=d.Z;
206 Material->Specular.r=s.X; Material->Specular.g=s.Y; Material->Specular.b=s.Z;
207 Material->Power=20;
208}
209
214
218
222
223
224/**********************************************************************************************
226
229{
230 // fixed function uses pass through by default
231 DX8Wrapper::Set_DX8_Texture_Stage_State(0, D3DTSS_TEXCOORDINDEX, D3DTSS_TCI_PASSTHRU);
232
233 // set vertex shader
235
236 // set texture stage settings
237 if (DX8Wrapper::Get_Current_Caps()->Support_ModAlphaAddClr())
238 {
239 DX8Wrapper::Set_DX8_Texture_Stage_State(0, D3DTSS_COLORARG1, D3DTA_TEXTURE);
240 DX8Wrapper::Set_DX8_Texture_Stage_State(0, D3DTSS_COLOROP, D3DTOP_MODULATE );
241 DX8Wrapper::Set_DX8_Texture_Stage_State(0, D3DTSS_COLORARG2, D3DTA_DIFFUSE );
242
243 DX8Wrapper::Set_DX8_Texture_Stage_State(0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE);
244 DX8Wrapper::Set_DX8_Texture_Stage_State(0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1 );
245
246 DX8Wrapper::Set_DX8_Texture_Stage_State(1, D3DTSS_COLORARG1, D3DTA_CURRENT );
247 DX8Wrapper::Set_DX8_Texture_Stage_State(1, D3DTSS_COLOROP, D3DTOP_MODULATEALPHA_ADDCOLOR);
248 DX8Wrapper::Set_DX8_Texture_Stage_State(1, D3DTSS_COLORARG2, D3DTA_SPECULAR );
249
250 DX8Wrapper::Set_DX8_Texture_Stage_State(1, D3DTSS_ALPHAARG1, D3DTA_CURRENT);
251 DX8Wrapper::Set_DX8_Texture_Stage_State(1, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1 );
252
253 DX8Wrapper::Set_DX8_Texture_Stage_State(2, D3DTSS_COLOROP, D3DTOP_DISABLE );
254 DX8Wrapper::Set_DX8_Texture_Stage_State(2, D3DTSS_ALPHAOP, D3DTOP_DISABLE );
255 }
256 else
257 {
258 DX8Wrapper::Set_DX8_Texture_Stage_State(0, D3DTSS_COLORARG1, D3DTA_TEXTURE);
259 DX8Wrapper::Set_DX8_Texture_Stage_State(0, D3DTSS_COLOROP, D3DTOP_MODULATE );
260 DX8Wrapper::Set_DX8_Texture_Stage_State(0, D3DTSS_COLORARG2, D3DTA_DIFFUSE );
261
262 DX8Wrapper::Set_DX8_Texture_Stage_State(1, D3DTSS_COLOROP, D3DTOP_DISABLE );
263 DX8Wrapper::Set_DX8_Texture_Stage_State(1, D3DTSS_ALPHAOP, D3DTOP_DISABLE );
264 }
265
266
267 DX8Wrapper::Set_DX8_Render_State(D3DRS_LIGHTING, TRUE);
268
269 DX8Wrapper::Set_DX8_Render_State(D3DRS_AMBIENTMATERIALSOURCE,D3DMCS_MATERIAL);
270 DX8Wrapper::Set_DX8_Render_State(D3DRS_DIFFUSEMATERIALSOURCE,D3DMCS_MATERIAL);
271 DX8Wrapper::Set_DX8_Render_State(D3DRS_SPECULARMATERIALSOURCE,D3DMCS_MATERIAL);
272 DX8Wrapper::Set_DX8_Render_State(D3DRS_EMISSIVEMATERIALSOURCE,D3DMCS_MATERIAL);
273
275
276}
277
278//**********************************************************************************************
280
283{
285
286 if (DX8Wrapper::Get_Current_Caps()->Support_ModAlphaAddClr())
287 {
289 }
290
292}
293
295{
296 return 1;
297}
298
299unsigned Shd6GlossMaskClass::Get_Vertex_Size(unsigned stream) const
300{
301 return sizeof(VertexFormatXYZNDUV1);
302}
303
305(
306 unsigned stream,
307 void* dest_buffer,
308 const VertexStreamStruct& vss,
309 unsigned vertex_count
310)
311{
312 VertexFormatXYZNDUV1* verts=(VertexFormatXYZNDUV1*)dest_buffer;
313
314 for (unsigned i=0; i<vertex_count; ++i)
315 {
316 if (vss.Locations)
317 {
318 verts[i].x=vss.Locations[i][0];
319 verts[i].y=vss.Locations[i][1];
320 verts[i].z=vss.Locations[i][2];
321 }
322 else
323 {
324 verts[i].x=0.0f;
325 verts[i].y=0.0f;
326 verts[i].z=0.0f;
327 }
328
329 if (vss.DiffuseInt)
330 {
331 verts[i].diffuse=vss.DiffuseInt[i];
332 }
333 else
334 {
335 verts[i].diffuse=0xffffffff;
336 }
337
338 if (vss.Normals)
339 {
340 verts[i].nx=vss.Normals[i][0];
341 verts[i].ny=vss.Normals[i][1];
342 verts[i].nz=vss.Normals[i][2];
343 }
344 else
345 {
346 verts[i].nx=0.0f;
347 verts[i].ny=0.0f;
348 verts[i].nz=0.0f;
349 }
350
351 if (vss.UV[0])
352 {
353 verts[i].u1=vss.UV[0][i].U;
354 verts[i].v1=vss.UV[0][i].V;
355 }
356 else
357 {
358 verts[i].u1=0.0f;
359 verts[i].v1=0.0f;
360 }
361 }
362}
363
#define NULL
Definition BaseType.h:92
#define TRUE
Definition BaseType.h:109
#define WRITE_MICRO_CHUNK_WWSTRING(csave, id, var)
Definition chunkio.h:309
#define WRITE_MICRO_CHUNK(csave, id, var)
Definition chunkio.h:293
#define READ_MICRO_CHUNK(cload, id, var)
Definition chunkio.h:334
#define READ_MICRO_CHUNK_WWSTRING(cload, id, var)
Definition chunkio.h:351
@ CHUNKID_VARIABLES
bool Close_Micro_Chunk()
Definition chunkio.cpp:585
bool Close_Chunk()
Definition chunkio.cpp:448
uint32 Cur_Chunk_ID()
Definition chunkio.cpp:484
uint32 Cur_Micro_Chunk_ID()
Definition chunkio.cpp:622
bool Open_Chunk()
Definition chunkio.cpp:412
bool Open_Micro_Chunk()
Definition chunkio.cpp:557
bool Begin_Chunk(uint32 id)
Definition chunkio.cpp:108
bool End_Chunk()
Definition chunkio.cpp:148
static void Set_Texture(unsigned stage, TextureBaseClass *texture)
static void Set_DX8_Material(const D3DMATERIAL8 *mat)
Definition dx8wrapper.h:849
static const DX8Caps * Get_Current_Caps()
Definition dx8wrapper.h:536
static void Set_DX8_Texture_Stage_State(unsigned stage, D3DTEXTURESTAGESTATETYPE state, unsigned value)
Definition dx8wrapper.h:899
static void Set_Vertex_Shader(DWORD vertex_shader)
Definition dx8wrapper.h:719
static void Set_DX8_Render_State(D3DRENDERSTATETYPE state, unsigned value)
Definition dx8wrapper.h:874
virtual unsigned Get_Vertex_Size(unsigned stream) const
virtual ~Shd6GlossMaskClass()
virtual void Copy_Vertex_Stream(unsigned stream, void *dest_buffer, const VertexStreamStruct &vss, unsigned vertex_count)
TextureClass * Texture
static void Shutdown()
virtual void Apply_Instance(int cur_pass, RenderInfoClass &rinfo)
Apply per instance states for 1 pass DX6.
virtual unsigned Get_Vertex_Stream_Count() const
virtual void Apply_Shared(int cur_pass, RenderInfoClass &rinfo)
D3DMATERIAL8 * Material
static Matrix4x4 View_Projection_Matrix
Shd6GlossMaskClass(const ShdDefClass *def)
ShdDefClass(uint32 class_id)
Definition shddef.cpp:45
virtual bool Load(ChunkLoadClass &cload)
Load this ShdDef from a chunk loader.
Definition shddef.cpp:160
virtual bool Save(ChunkSaveClass &csave)
Serialize this ShdDef into a chunk saver.
Definition shddef.cpp:140
virtual void Shutdown()
virtual ~ShdGlossMaskDefClass()
virtual bool Is_Valid_Config(StringClass &message)
virtual ShdInterfaceClass * Create() const
virtual bool Save(ChunkSaveClass &csave)
Serialize this ShdDef into a chunk saver.
virtual bool Load(ChunkLoadClass &cload)
Load this ShdDef from a chunk loader.
ShdInterfaceClass(const ShdDefClass *def, int class_id)
Constructor.
const ShdDefClass * Definition
float V
Definition vector2.h:80
float U
Definition vector2.h:75
float X
Definition vector3.h:90
float Z
Definition vector3.h:92
float Y
Definition vector3.h:91
virtual TextureClass * Get_Texture(const char *filename, MipCountType mip_level_count=MIP_LEVELS_ALL, WW3DFormat texture_format=WW3D_FORMAT_UNKNOWN, bool allow_compression=true, TextureBaseClass::TexAssetType type=TextureBaseClass::TEX_REGULAR, bool allow_reduction=true)
static WW3DAssetManager * Get_Instance(void)
Definition assetmgr.h:205
@ DX8_FVF_XYZNDUV1
Definition dx8fvf.h:63
#define NAMED_EDITABLE_PARAM(_class, type, data, name)
Definition editable.h:308
#define NAMED_TEXTURE_FILENAME_PARAM(_class, data, name, desc, extension)
Definition editable.h:326
#define REF_PTR_RELEASE(x)
Definition refcount.h:80
@ VARID_DIFFUSE_COLOR
@ VARID_AMBIENT_COLOR
@ VARID_TEXTURE_NAME
@ VARID_SPECULAR_COLOR
@ SHDDEF_CLASSID_GLOSSMASK
Definition shdclassids.h:50
#define REGISTER_SHDDEF(T, ID, NAME)
const Vector3 * Normals
const Vector2 * UV[MAX_TEXTURE_STAGES]
const unsigned * DiffuseInt
const Vector3 * Locations
#define DECLARE_FORCE_LINK(module)
Definition wwhack.h:48