Richard Boegli's CnC_Generals_Zero_Hour Fork WIP
This is documentation of Richard Boegil's Zero Hour Fork
 
Loading...
Searching...
No Matches
shd8bumpspec.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/shd8bumpspec.cpp $*
26 * *
27 * $Author:: Kenny_m
28 *
29 * $Modtime:: 5/27/02 3:40p $*
30 * *
31 * $Revision:: 1 $*
32 * *
33 *---------------------------------------------------------------------------------------------*
34 * Functions: *
35 * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
36
37#include "dx8fvf.h"
38#include "dx8wrapper.h"
39#include "assetmgr.h"
40#include "rinfo.h"
41#include "camera.h"
42#include "shdmesh.h"
43#include "texproject.h"
44
45#include "shdbumpspec.h"
46#include "shd8bumpspec.h"
48#include "shdclassids.h"
49
50// shader code declarations
55
56
62
67{
69
71 (
72 Definition->Get_Texture_Name()
73 );
74
76 (
77 Definition->Get_Bump_Map_Name()
78 );
79
80 const Vector3& a=Definition->Get_Ambient();
81 Ambient.Set(a.X,a.Y,a.Z,0.0f);
82
83 const Vector3& d=Definition->Get_Diffuse();
84 Diffuse.Set(d.X,d.Y,d.Z,0.0f);
85
86 const Vector3& s=Definition->Get_Specular();
87 Specular.Set(s.X,s.Y,s.Z,0.0f);
88
89 const Vector2& db=Definition->Get_Diffuse_Bumpiness();
90 const Vector2& ds=Definition->Get_Specular_Bumpiness();
91 Bumpiness.Set(db.X,db.Y,ds.X,ds.Y);
92}
93
99
101{
102 // Create vertex shader
103 DWORD vertex_shader_declaration[]=
104 {
105 D3DVSD_STREAM(0),
106 (D3DVSD_REG(0, D3DVSDT_FLOAT3)), // vertex position
107 (D3DVSD_REG(1, D3DVSDT_FLOAT3)), // vertex normal
108 (D3DVSD_REG(2, D3DVSDT_D3DCOLOR)), // vertex color
109 (D3DVSD_REG(3, D3DVSDT_FLOAT2)), // vertex texture coords
110 (D3DVSD_REG(4, D3DVSDT_FLOAT3)), // vertex S basis
111 (D3DVSD_REG(5, D3DVSDT_FLOAT3)), // vertex T basis
112 (D3DVSD_REG(6, D3DVSDT_FLOAT3)), // vertex SxT basis
113 D3DVSD_END()
114 };
115
116 Pixel_Shader.Create
117 (
119 );
120 Vertex_Shader.Create
121 (
123 vertex_shader_declaration
124 );
125
127 (
129 );
131 (
133 vertex_shader_declaration
134 );
135}
136
138{
139 Vertex_Shader.Destroy();
140 Pixel_Shader.Destroy();
141 Self_Shadow_Pixel_Shader.Destroy();
143}
144
146{
147 // set vertex shader
148 if (cur_pass==0)
149 {
151 }
152 else
153 {
155 }
156
157 // set vertex shader constants
158 DX8Wrapper::Set_Vertex_Shader_Constant(CV_CONST, D3DXVECTOR4(0.0f, 1.0f, 0.5f, 2.0f), 1);
159
160 const Matrix3D& cam=rinfo.Camera.Get_Transform();
161
162 // set constants
164 (
166 D3DXVECTOR4
167 (
168 cam.Get_X_Translation(),
169 cam.Get_Y_Translation(),
170 cam.Get_Z_Translation(),
171 1.0f
172 ),
173 1
174 );
175
176 // set pixel shader
177 if (cur_pass==0)
178 {
180 }
181 else
182 {
184 }
185
186 // set constants
187 DX8Wrapper::Set_Vertex_Shader_Constant(CV_CONST, D3DXVECTOR4(0.0f, 1.0f, 0.5f, 2.0f), 1);
188
189 // calculate shader view projection matrix
190 Matrix4x4 view_matrix;
191 DX8Wrapper::Get_Transform(D3DTS_VIEW, view_matrix);
192
193 Matrix4x4 proj_matrix;
194 DX8Wrapper::Get_Transform(D3DTS_PROJECTION, proj_matrix);
195
196 Matrix4x4::Multiply(proj_matrix, view_matrix, &View_Projection_Matrix);
197}
198
200{
201 if (cur_pass==0)
202 {
205 }
206 else
207 {
209
210
212
214 }
215
216 // set vertex shader constants
217 Matrix4x4 world;
218 DX8Wrapper::Get_Transform(D3DTS_WORLD, world);
219
220 Matrix4x4 world_view_proj_matrix;
221
222 Matrix4x4::Multiply(View_Projection_Matrix,world,&world_view_proj_matrix);
223
226
228 (
229 rinfo,
230 Ambient,
231 Diffuse,
233 );
234
236}
237
239{
240 return 1;
241}
242
243unsigned Shd8BumpSpecClass::Get_Vertex_Size(unsigned stream) const
244{
245 return sizeof(VertexFormatXYZNDUV1TG3);
246}
247
249(
250 unsigned stream,
251 void* dest_buffer,
252 const VertexStreamStruct& vss,
253 unsigned vertex_count
254)
255{
257
258 for (unsigned i=0; i<vertex_count; ++i)
259 {
260 if (vss.Locations)
261 {
262 verts[i].x=vss.Locations[i][0];
263 verts[i].y=vss.Locations[i][1];
264 verts[i].z=vss.Locations[i][2];
265 }
266 else
267 {
268 verts[i].x=0.0f;
269 verts[i].y=0.0f;
270 verts[i].z=0.0f;
271 }
272
273 if (vss.DiffuseInt)
274 {
275 verts[i].diffuse=vss.DiffuseInt[i];
276 }
277 else
278 {
279 verts[i].diffuse=0xffffffff;
280 }
281
282 if (vss.Normals)
283 {
284 verts[i].nx=vss.Normals[i][0];
285 verts[i].ny=vss.Normals[i][1];
286 verts[i].nz=vss.Normals[i][2];
287 }
288 else
289 {
290 verts[i].nx=0.0f;
291 verts[i].ny=0.0f;
292 verts[i].nz=0.0f;
293 }
294
295 if (vss.UV[0])
296 {
297 verts[i].u1=vss.UV[0][i].U;
298 verts[i].v1=vss.UV[0][i].V;
299 }
300 else
301 {
302 verts[i].u1=0.0f;
303 verts[i].v1=0.0f;
304 }
305
306 if (vss.S)
307 {
308 verts[i].Sx=vss.S[i].X;
309 verts[i].Sy=vss.S[i].Y;
310 verts[i].Sz=vss.S[i].Z;
311 }
312 else
313 {
314 verts[i].Sx=0.0f;
315 verts[i].Sy=0.0f;
316 verts[i].Sz=0.0f;
317 }
318
319 if (vss.T)
320 {
321 verts[i].Tx=vss.T[i].X;
322 verts[i].Ty=vss.T[i].Y;
323 verts[i].Tz=vss.T[i].Z;
324 }
325 else
326 {
327 verts[i].Tx=0.0f;
328 verts[i].Ty=0.0f;
329 verts[i].Tz=0.0f;
330 }
331
332 if (vss.SxT)
333 {
334 verts[i].SxTx=vss.SxT[i].X;
335 verts[i].SxTy=vss.SxT[i].Y;
336 verts[i].SxTz=vss.SxT[i].Z;
337 }
338 else
339 {
340 verts[i].SxTx=0.0f;
341 verts[i].SxTy=0.0f;
342 verts[i].SxTz=0.0f;
343 }
344 }
345}
346
348(
349 ShdMeshClass* mesh,
350 RenderInfoClass* rinfo,
351 int pass
352)
353{
354 if (mesh->Is_Applying_Shadow_Map())
355 {
356 if (pass==1) // just do once
357 {
358 // is rendering self shadowed object
359 Setup_Self_Shadow_Info(*mesh,*rinfo);
360 }
361 return (pass==1);
362 }
363
364 return (pass==0);
365}
366
367
368/**********************************************************************************************
370
373{
375
376 //set special texture matrix for shadow mapping
377 ZTextureClass* smap=DX8Wrapper::Get_Shadow_Map(0); // todo KJM assign shadow map from rinfo
378
379 if (!smap) return;
380
381 float off_x=0.5f+(0.5f/(float)smap->Get_Width());
382 float off_y=0.5f+(0.5f/(float)smap->Get_Height());
383
384 unsigned int bits=Get_Num_Depth_Bits(smap->Get_Texture_Format());
385 float range=(float)(0xFFFFFFFF>>(32-bits));
386 float bias=0.0f;//-0.001f*range;
387 Matrix4x4 sb_mat
388 (
389 Vector4(0.5f, 0.0f, 0.0f, 0.0f),
390 Vector4(0.0f, -0.5f, 0.0f, 0.0f),
391 Vector4(0.0f, 0.0f, range, 0.0f),
392 Vector4(off_x, off_y, bias, 1.0f)
393 );
394
395 Matrix4x4 view2tex;
396 Matrix4x4::Multiply(sb_mat,tex_mat,&view2tex);
397
398 Matrix4x4 world;
399 world.Init(mesh.Get_Transform());
400
401 Matrix4x4 view;
402 view.Init(rinfo.Camera.Get_View_Matrix());
403
404 Matrix4x4 vw_mat;
405 Matrix4x4::Multiply(world,view,&vw_mat);
406
408}
#define NULL
Definition BaseType.h:92
unsigned long DWORD
Definition bittype.h:57
void Get_View_Matrix(Matrix3D *set_tm)
Definition camera.cpp:801
static void Set_Vertex_Shader_Constant(int reg, const void *data, int count)
Definition dx8wrapper.h:739
static void Set_Texture(unsigned stage, TextureBaseClass *texture)
static void Set_Vertex_Shader(DWORD vertex_shader)
Definition dx8wrapper.h:719
static void Set_Pixel_Shader(DWORD pixel_shader)
Definition dx8wrapper.h:730
static ZTextureClass * Get_Shadow_Map(int idx)
Definition dx8wrapper.h:508
static void Get_Transform(D3DTRANSFORMSTATETYPE transform, Matrix4x4 &m)
WWINLINE float Get_X_Translation(void) const
Definition matrix3d.h:224
WWINLINE float Get_Z_Translation(void) const
Definition matrix3d.h:226
WWINLINE float Get_Y_Translation(void) const
Definition matrix3d.h:225
WWINLINE void Init(const Matrix3D &m)
Definition matrix4.h:319
WWINLINE friend Matrix4x4 Multiply(const Matrix4x4 &a, const Matrix4x4 &b)
Definition matrix4.h:743
const Matrix4x4 & Get_Texture_Transform(void) const
MatrixMapperClass * Peek_Mapper() const
Definition projector.h:74
CameraClass & Camera
Definition rinfo.h:100
const Matrix3D & Get_Transform(void) const
Definition rendobj.h:617
virtual bool Pass_Selection(ShdMeshClass *, RenderInfoClass *, int)
static ShdHWPixelShader Pixel_Shader
static ShdHWVertexShader Self_Shadow_Vertex_Shader
static Matrix4x4 View_Projection_Matrix
static void Shutdown()
virtual unsigned Get_Vertex_Stream_Count() const
virtual unsigned Get_Vertex_Size(unsigned stream) const
Shd8BumpSpecClass(const ShdDefClass *def)
void Setup_Self_Shadow_Info(ShdMeshClass &mesh, RenderInfoClass &rinfo)
static ShdHWVertexShader Vertex_Shader
virtual void Apply_Shared(int cur_pass, RenderInfoClass &rinfo)
static ShdHWPixelShader Self_Shadow_Pixel_Shader
virtual void Apply_Instance(int cur_pass, RenderInfoClass &rinfo)
static void Init()
TextureClass * Texture
virtual ~Shd8BumpSpecClass()
Matrix4x4 Self_Shadow_Transform
virtual void Copy_Vertex_Stream(unsigned stream, void *dest_buffer, const VertexStreamStruct &vss, unsigned vertex_count)
TextureClass * NormalMap
static void Light(RenderInfoClass &rinfo, Vector4 &ambient, Vector4 &diffuse, Vector4 &specular)
Apply generic lighting.
ShdInterfaceClass(const ShdDefClass *def, int class_id)
Constructor.
const ShdDefClass * Definition
TexProjectClass * Peek_Texture_Projector() const
Definition shdmesh.h:166
bool Is_Applying_Shadow_Map() const
Definition shdmesh.h:164
int Get_Width() const
Definition texture.h:124
int Get_Height() const
Definition texture.h:128
float V
Definition vector2.h:80
float Y
Definition vector2.h:79
float X
Definition vector2.h:74
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
WW3DZFormat Get_Texture_Format() const
Definition texture.h:367
#define REF_PTR_RELEASE(x)
Definition refcount.h:80
#define CV_WORLD_VIEW_PROJECTION
#define CV_WORLD
#define CV_EYE_WORLD
#define CV_BUMPINESS
#define CV_TEXMAP
DWORD shd8bumpspec_psh_code[]
DWORD shd8bumpspec_vsh_code[]
DWORD shd8ssbumpspec_psh_code[]
DWORD shd8ssbumpspec_vsh_code[]
@ SHDDEF_CLASSID_BUMPSPEC
Definition shdclassids.h:51
#define CV_CONST
const Vector3 * Normals
const Vector2 * UV[MAX_TEXTURE_STAGES]
const Vector3 * S
const Vector3 * SxT
const Vector3 * T
const unsigned * DiffuseInt
const Vector3 * Locations
unsigned Get_Num_Depth_Bits(WW3DZFormat zformat)