Richard Boegli's CnC_Generals_Zero_Hour Fork WIP
This is documentation of Richard Boegil's Zero Hour Fork
 
Loading...
Searching...
No Matches
shd6bumpspec.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/shd6bumpspec.cpp $*
26 * *
27 * $Org Author:: Kenny_m
28 *
29 * $Author:: Kenny_m
30 *
31 * $Modtime:: 7/11/02 10:36p $*
32 * *
33 * $Revision:: 1 $*
34 * *
35 *---------------------------------------------------------------------------------------------*
36 * Functions: *
37 * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
38
39#include "dx8fvf.h"
40#include "dx8wrapper.h"
41#include "assetmgr.h"
42#include "rinfo.h"
43#include "camera.h"
44
45#include "shdbumpspec.h"
46#include "shd6bumpspec.h"
48#include "shdclassids.h"
49
50// shader code declarations
52
55
59{
61
63 (
64 Definition->Get_Texture_Name()
65 );
66
67 const Vector3& a=Definition->Get_Ambient();
68 Ambient.Set(a.X,a.Y,a.Z,1.0f);
69
70 const Vector3& d=Definition->Get_Diffuse();
71 Diffuse.Set(d.X,d.Y,d.Z,1.0f);
72
73 const Vector3& s=Definition->Get_Specular();
74 Specular.Set(s.X,s.Y,s.Z,1.0f);
75}
76
81
83{
84 // Create vertex shader
85 DWORD vertex_shader_declaration[]=
86 {
87 D3DVSD_STREAM(0),
88 (D3DVSD_REG(0, D3DVSDT_FLOAT3)), // vertex position
89 (D3DVSD_REG(1, D3DVSDT_FLOAT3)), // vertex normal
90 (D3DVSD_REG(2, D3DVSDT_D3DCOLOR)), // vertex color
91 (D3DVSD_REG(3, D3DVSDT_FLOAT2)), // vertex texture coords
92 D3DVSD_END()
93 };
94
95 Vertex_Shader.Create
96 (
98 vertex_shader_declaration
99 );
100}
101
103{
104 Vertex_Shader.Destroy();
105}
106
107
108/**********************************************************************************************
110
113{
114 // vertex processing behavior
115 DX8Wrapper::Set_DX8_Render_State(D3DRS_SOFTWAREVERTEXPROCESSING,!Vertex_Shader.Is_Using_Hardware());
116
117 // fixed function uses pass through by default
118 DX8Wrapper::Set_DX8_Texture_Stage_State(0, D3DTSS_TEXCOORDINDEX, D3DTSS_TCI_PASSTHRU);
119 DX8Wrapper::Set_DX8_Texture_Stage_State(1, D3DTSS_TEXCOORDINDEX, D3DTSS_TCI_PASSTHRU);
120
121 // set vertex shader
123
124 const Matrix3D& cam=rinfo.Camera.Get_Transform();
125
126 // set constants
128 (
130 D3DXVECTOR4
131 (
132 cam.Get_X_Translation(),
133 cam.Get_Y_Translation(),
134 cam.Get_Z_Translation(),
135 1.0f
136 ),
137 1
138 );
139
140 // set texture stage settings
141 if (DX8Wrapper::Get_Current_Caps()->Support_ModAlphaAddClr())
142 {
143 DX8Wrapper::Set_DX8_Texture_Stage_State(0, D3DTSS_COLORARG1, D3DTA_TEXTURE);
144 DX8Wrapper::Set_DX8_Texture_Stage_State(0, D3DTSS_COLOROP, D3DTOP_MODULATE );
145 DX8Wrapper::Set_DX8_Texture_Stage_State(0, D3DTSS_COLORARG2, D3DTA_DIFFUSE );
146
147 DX8Wrapper::Set_DX8_Texture_Stage_State(0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE);
148 DX8Wrapper::Set_DX8_Texture_Stage_State(0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1 );
149
150 DX8Wrapper::Set_DX8_Texture_Stage_State(1, D3DTSS_COLORARG1, D3DTA_CURRENT );
151 DX8Wrapper::Set_DX8_Texture_Stage_State(1, D3DTSS_COLOROP, D3DTOP_MODULATEALPHA_ADDCOLOR);
152 DX8Wrapper::Set_DX8_Texture_Stage_State(1, D3DTSS_COLORARG2, D3DTA_SPECULAR );
153
154 DX8Wrapper::Set_DX8_Texture_Stage_State(1, D3DTSS_ALPHAARG1, D3DTA_CURRENT);
155 DX8Wrapper::Set_DX8_Texture_Stage_State(1, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1 );
156
157 DX8Wrapper::Set_DX8_Texture_Stage_State(2, D3DTSS_COLOROP, D3DTOP_DISABLE );
158 DX8Wrapper::Set_DX8_Texture_Stage_State(2, D3DTSS_ALPHAOP, D3DTOP_DISABLE );
159 }
160 else
161 {
162 DX8Wrapper::Set_DX8_Texture_Stage_State(0, D3DTSS_COLORARG1, D3DTA_TEXTURE);
163 DX8Wrapper::Set_DX8_Texture_Stage_State(0, D3DTSS_COLOROP, D3DTOP_MODULATE );
164 DX8Wrapper::Set_DX8_Texture_Stage_State(0, D3DTSS_COLORARG2, D3DTA_DIFFUSE );
165
166 DX8Wrapper::Set_DX8_Texture_Stage_State(1, D3DTSS_COLOROP, D3DTOP_DISABLE );
167 DX8Wrapper::Set_DX8_Texture_Stage_State(1, D3DTSS_ALPHAOP, D3DTOP_DISABLE );
168 }
169
170 // set constants
171 DX8Wrapper::Set_Vertex_Shader_Constant(CV_CONST, D3DXVECTOR4(0.0f, 1.0f, 0.5f, 2.0f), 1);
172
173 // calculate shader view projection matrix
174 Matrix4x4 view_matrix;
175 DX8Wrapper::Get_Transform(D3DTS_VIEW, view_matrix);
176
177 Matrix4x4 proj_matrix;
178 DX8Wrapper::Get_Transform(D3DTS_PROJECTION, proj_matrix);
179
180 Matrix4x4::Multiply(proj_matrix, view_matrix, &View_Projection_Matrix);
181}
182
183//**********************************************************************************************
185
188{
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,
208 );
209}
210
212{
213 return 1;
214}
215
216unsigned Shd6BumpSpecClass::Get_Vertex_Size(unsigned stream) const
217{
218 return sizeof(VertexFormatXYZNDUV1);
219}
220
222(
223 unsigned stream,
224 void* dest_buffer,
225 const VertexStreamStruct& vss,
226 unsigned vertex_count
227)
228{
229 VertexFormatXYZNDUV1* verts=(VertexFormatXYZNDUV1*)dest_buffer;
230
231 for (unsigned i=0; i<vertex_count; ++i)
232 {
233 if (vss.Locations)
234 {
235 verts[i].x=vss.Locations[i][0];
236 verts[i].y=vss.Locations[i][1];
237 verts[i].z=vss.Locations[i][2];
238 }
239 else
240 {
241 verts[i].x=0.0f;
242 verts[i].y=0.0f;
243 verts[i].z=0.0f;
244 }
245
246 if (vss.DiffuseInt)
247 {
248 verts[i].diffuse=vss.DiffuseInt[i];
249 }
250 else
251 {
252 verts[i].diffuse=0xffffffff;
253 }
254
255 if (vss.Normals)
256 {
257 verts[i].nx=vss.Normals[i][0];
258 verts[i].ny=vss.Normals[i][1];
259 verts[i].nz=vss.Normals[i][2];
260 }
261 else
262 {
263 verts[i].nx=0.0f;
264 verts[i].ny=0.0f;
265 verts[i].nz=0.0f;
266 }
267
268 if (vss.UV[0])
269 {
270 verts[i].u1=vss.UV[0][i].U;
271 verts[i].v1=vss.UV[0][i].V;
272 }
273 else
274 {
275 verts[i].u1=0.0f;
276 verts[i].v1=0.0f;
277 }
278 }
279}
280
#define NULL
Definition BaseType.h:92
unsigned long DWORD
Definition bittype.h:57
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 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 Get_Transform(D3DTRANSFORMSTATETYPE transform, Matrix4x4 &m)
static void Set_DX8_Render_State(D3DRENDERSTATETYPE state, unsigned value)
Definition dx8wrapper.h:874
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 friend Matrix4x4 Multiply(const Matrix4x4 &a, const Matrix4x4 &b)
Definition matrix4.h:743
CameraClass & Camera
Definition rinfo.h:100
const Matrix3D & Get_Transform(void) const
Definition rendobj.h:617
virtual unsigned Get_Vertex_Stream_Count() const
virtual void Copy_Vertex_Stream(unsigned stream, void *dest_buffer, const VertexStreamStruct &vss, unsigned vertex_count)
static void Init()
static void Shutdown()
virtual ~Shd6BumpSpecClass()
TextureClass * Texture
static ShdHWVertexShader Vertex_Shader
virtual unsigned Get_Vertex_Size(unsigned stream) const
virtual void Apply_Instance(int cur_pass, RenderInfoClass &rinfo)
Apply per instance states for 1 pass DX6 specular with gloss map (no bump)
Shd6BumpSpecClass(const ShdDefClass *def)
static Matrix4x4 View_Projection_Matrix
virtual void Apply_Shared(int cur_pass, RenderInfoClass &rinfo)
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
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
#define REF_PTR_RELEASE(x)
Definition refcount.h:80
#define CV_WORLD_VIEW_PROJECTION
#define CV_WORLD
#define CV_EYE_WORLD
DWORD shd6bumpspec_vsh_code[]
@ SHDDEF_CLASSID_BUMPSPEC
Definition shdclassids.h:51
#define CV_CONST
const Vector3 * Normals
const Vector2 * UV[MAX_TEXTURE_STAGES]
const unsigned * DiffuseInt
const Vector3 * Locations