Richard Boegli's CnC_Generals_Zero_Hour Fork WIP
This is documentation of Richard Boegil's Zero Hour Fork
 
Loading...
Searching...
No Matches
shd8bumpdiff.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/shd8bumpdiff.cpp $*
26 * *
27 * $Author:: Kenny_m
28 *
29 * $Modtime:: 07/08/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 "shdbumpdiff.h"
46#include "shd8bumpdiff.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 Vector2& db=Definition->Get_Diffuse_Bumpiness();
87 Bumpiness.Set(db.X,db.Y,0,0);
88}
89
95
97{
98 // Create vertex shader
99 DWORD vertex_shader_declaration[]=
100 {
101 D3DVSD_STREAM(0),
102 (D3DVSD_REG(0, D3DVSDT_FLOAT3)), // vertex position
103 (D3DVSD_REG(1, D3DVSDT_FLOAT3)), // vertex normal
104 (D3DVSD_REG(2, D3DVSDT_D3DCOLOR)), // vertex color
105 (D3DVSD_REG(3, D3DVSDT_FLOAT2)), // vertex texture coords
106 (D3DVSD_REG(4, D3DVSDT_FLOAT3)), // vertex S basis
107 (D3DVSD_REG(5, D3DVSDT_FLOAT3)), // vertex T basis
108 (D3DVSD_REG(6, D3DVSDT_FLOAT3)), // vertex SxT basis
109 D3DVSD_END()
110 };
111
113
114 Vertex_Shader.Create
115 (
117 vertex_shader_declaration
118 );
119
122 (
124 vertex_shader_declaration
125 );
126}
127
129{
130 Vertex_Shader.Destroy();
131 Pixel_Shader.Destroy();
132 Self_Shadow_Pixel_Shader.Destroy();
134}
135
137{
138 // set vertex shader
139 if (cur_pass==0)
140 {
142 }
143 else
144 {
146 }
147
148 // set vertex shader constants
149 DX8Wrapper::Set_Vertex_Shader_Constant(CV_CONST, D3DXVECTOR4(0.0f, 1.0f, 0.5f, 2.0f), 1);
150
151 // set pixel shader
152 if (cur_pass==0)
153 {
155 }
156 else
157 {
159 }
160
161 // set constants
162 DX8Wrapper::Set_Vertex_Shader_Constant(CV_CONST, D3DXVECTOR4(0.0f, 1.0f, 0.5f, 2.0f), 1);
163
164 // calculate shader view projection matrix
165 Matrix4x4 view_matrix;
166 DX8Wrapper::Get_Transform(D3DTS_VIEW, view_matrix);
167
168 Matrix4x4 proj_matrix;
169 DX8Wrapper::Get_Transform(D3DTS_PROJECTION, proj_matrix);
170
171 Matrix4x4::Multiply(proj_matrix, view_matrix, &View_Projection_Matrix);
172}
173
175{
176 if (cur_pass==0)
177 {
180 }
181 else
182 {
184
185
187
189 }
190
191 // set vertex shader constants
192 Matrix4x4 world;
193 DX8Wrapper::Get_Transform(D3DTS_WORLD, world);
194
195 Matrix4x4 world_view_proj_matrix;
196
197 Matrix4x4::Multiply(View_Projection_Matrix,world,&world_view_proj_matrix);
198
201
203 (
204 rinfo,
205 Ambient,
206 Diffuse
207 );
208
210}
211
213{
214 return 1;
215}
216
217unsigned Shd8BumpDiffClass::Get_Vertex_Size(unsigned stream) const
218{
219 return sizeof(VertexFormatXYZNDUV1TG3);
220}
221
223(
224 unsigned stream,
225 void* dest_buffer,
226 const VertexStreamStruct& vss,
227 unsigned vertex_count
228)
229{
231
232 for (unsigned i=0; i<vertex_count; ++i)
233 {
234 if (vss.Locations)
235 {
236 verts[i].x=vss.Locations[i][0];
237 verts[i].y=vss.Locations[i][1];
238 verts[i].z=vss.Locations[i][2];
239 }
240 else
241 {
242 verts[i].x=0.0f;
243 verts[i].y=0.0f;
244 verts[i].z=0.0f;
245 }
246
247 if (vss.DiffuseInt)
248 {
249 verts[i].diffuse=vss.DiffuseInt[i];
250 }
251 else
252 {
253 verts[i].diffuse=0xffffffff;
254 }
255
256 if (vss.Normals)
257 {
258 verts[i].nx=vss.Normals[i][0];
259 verts[i].ny=vss.Normals[i][1];
260 verts[i].nz=vss.Normals[i][2];
261 }
262 else
263 {
264 verts[i].nx=0.0f;
265 verts[i].ny=0.0f;
266 verts[i].nz=0.0f;
267 }
268
269 if (vss.UV[0])
270 {
271 verts[i].u1=vss.UV[0][i].U;
272 verts[i].v1=vss.UV[0][i].V;
273 }
274 else
275 {
276 verts[i].u1=0.0f;
277 verts[i].v1=0.0f;
278 }
279
280 if (vss.S)
281 {
282 verts[i].Sx=vss.S[i].X;
283 verts[i].Sy=vss.S[i].Y;
284 verts[i].Sz=vss.S[i].Z;
285 }
286 else
287 {
288 verts[i].Sx=0.0f;
289 verts[i].Sy=0.0f;
290 verts[i].Sz=0.0f;
291 }
292
293 if (vss.T)
294 {
295 verts[i].Tx=vss.T[i].X;
296 verts[i].Ty=vss.T[i].Y;
297 verts[i].Tz=vss.T[i].Z;
298 }
299 else
300 {
301 verts[i].Tx=0.0f;
302 verts[i].Ty=0.0f;
303 verts[i].Tz=0.0f;
304 }
305
306 if (vss.SxT)
307 {
308 verts[i].SxTx=vss.SxT[i].X;
309 verts[i].SxTy=vss.SxT[i].Y;
310 verts[i].SxTz=vss.SxT[i].Z;
311 }
312 else
313 {
314 verts[i].SxTx=0.0f;
315 verts[i].SxTy=0.0f;
316 verts[i].SxTz=0.0f;
317 }
318 }
319}
320
322(
323 ShdMeshClass* mesh,
324 RenderInfoClass* rinfo,
325 int pass
326)
327{
328 if (mesh->Is_Applying_Shadow_Map())
329 {
330 if (pass==1) // just do once
331 {
332 // is rendering self shadowed object
333 Setup_Self_Shadow_Info(*mesh,*rinfo);
334 }
335 return (pass==1);
336 }
337
338 return (pass==0);
339}
340
341
342/**********************************************************************************************
344
347{
349
350 //set special texture matrix for shadow mapping
351 ZTextureClass* smap=DX8Wrapper::Get_Shadow_Map(0); // todo KJM assign shadow map from rinfo
352
353 if (!smap) return;
354
355 float off_x=0.5f+(0.5f/(float)smap->Get_Width());
356 float off_y=0.5f+(0.5f/(float)smap->Get_Height());
357
358 unsigned int bits=Get_Num_Depth_Bits(smap->Get_Texture_Format());
359 float range=(float)(0xFFFFFFFF>>(32-bits));
360 float bias=0.0f;//-0.001f*range;
361 Matrix4x4 sb_mat
362 (
363 Vector4(0.5f, 0.0f, 0.0f, 0.0f),
364 Vector4(0.0f, -0.5f, 0.0f, 0.0f),
365 Vector4(0.0f, 0.0f, range, 0.0f),
366 Vector4(off_x, off_y, bias, 1.0f)
367 );
368
369 Matrix4x4 view2tex;
370 Matrix4x4::Multiply(sb_mat,tex_mat,&view2tex);
371
372 Matrix4x4 world;
373 world.Init(mesh.Get_Transform());
374
375 Matrix4x4 view;
376 view.Init(rinfo.Camera.Get_View_Matrix());
377
378 Matrix4x4 vw_mat;
379 Matrix4x4::Multiply(world,view,&vw_mat);
380
382}
#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 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 void Apply_Instance(int cur_pass, RenderInfoClass &rinfo)
virtual ~Shd8BumpDiffClass()
static Matrix4x4 View_Projection_Matrix
virtual void Apply_Shared(int cur_pass, RenderInfoClass &rinfo)
static ShdHWPixelShader Pixel_Shader
static void Shutdown()
TextureClass * NormalMap
virtual unsigned Get_Vertex_Stream_Count() const
static ShdHWPixelShader Self_Shadow_Pixel_Shader
void Setup_Self_Shadow_Info(ShdMeshClass &mesh, RenderInfoClass &rinfo)
static ShdHWVertexShader Vertex_Shader
TextureClass * Texture
Shd8BumpDiffClass(const ShdDefClass *def)
static void Init()
static ShdHWVertexShader Self_Shadow_Vertex_Shader
virtual unsigned Get_Vertex_Size(unsigned stream) const
Matrix4x4 Self_Shadow_Transform
virtual void Copy_Vertex_Stream(unsigned stream, void *dest_buffer, const VertexStreamStruct &vss, unsigned vertex_count)
virtual bool Pass_Selection(ShdMeshClass *, RenderInfoClass *, int)
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_BUMPINESS
DWORD shd8bumpdiff_psh_code[]
DWORD shd8bumpdiff_vsh_code[]
#define CV_TEXMAP
DWORD shd8ssbumpdiff_psh_code[]
DWORD shd8ssbumpdiff_vsh_code[]
@ SHDDEF_CLASSID_BUMPDIFF
Definition shdclassids.h:52
#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)