Richard Boegli's CnC_Generals_Zero_Hour Fork WIP
This is documentation of Richard Boegil's Zero Hour Fork
 
Loading...
Searching...
No Matches
shd6bumpdiff.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/shd6bumpdiff.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 "shdbumpdiff.h"
46#include "shd6bumpdiff.h"
48#include "shdclassids.h"
49
50// shader code declarations
52
53
56
60{
62
64 (
65 Definition->Get_Texture_Name()
66 );
67
68 const Vector3& a=Definition->Get_Ambient();
69 Ambient.Set(a.X,a.Y,a.Z,1.0f);
70
71 const Vector3& d=Definition->Get_Diffuse();
72 Diffuse.Set(d.X,d.Y,d.Z,1.0f);
73}
74
79
81{
82 // Create vertex shader
83 DWORD vertex_shader_declaration[]=
84 {
85 D3DVSD_STREAM(0),
86 (D3DVSD_REG(0, D3DVSDT_FLOAT3)), // vertex position
87 (D3DVSD_REG(1, D3DVSDT_FLOAT3)), // vertex normal
88 (D3DVSD_REG(2, D3DVSDT_D3DCOLOR)), // vertex color
89 (D3DVSD_REG(3, D3DVSDT_FLOAT2)), // vertex texture coords
90 D3DVSD_END()
91 };
92
93 Vertex_Shader.Create
94 (
96 vertex_shader_declaration
97 );
98}
99
101{
102 Vertex_Shader.Destroy();
103}
104
105
106/**********************************************************************************************
108
111{
112 // vertex processing behavior
113 DX8Wrapper::Set_DX8_Render_State(D3DRS_SOFTWAREVERTEXPROCESSING,!Vertex_Shader.Is_Using_Hardware());
114
115 // fixed function uses pass through by default
116 DX8Wrapper::Set_DX8_Texture_Stage_State(0, D3DTSS_TEXCOORDINDEX, D3DTSS_TCI_PASSTHRU);
117 DX8Wrapper::Set_DX8_Texture_Stage_State(1, D3DTSS_TEXCOORDINDEX, D3DTSS_TCI_PASSTHRU);
118
119 // set vertex shader
121
122 DX8Wrapper::Set_DX8_Texture_Stage_State(0, D3DTSS_COLORARG1, D3DTA_TEXTURE);
123 DX8Wrapper::Set_DX8_Texture_Stage_State(0, D3DTSS_COLOROP, D3DTOP_MODULATE );
124 DX8Wrapper::Set_DX8_Texture_Stage_State(0, D3DTSS_COLORARG2, D3DTA_DIFFUSE );
125
126 DX8Wrapper::Set_DX8_Texture_Stage_State(1, D3DTSS_COLOROP, D3DTOP_DISABLE );
127 DX8Wrapper::Set_DX8_Texture_Stage_State(1, D3DTSS_ALPHAOP, D3DTOP_DISABLE );
128
129 // set constants
130 DX8Wrapper::Set_Vertex_Shader_Constant(CV_CONST, D3DXVECTOR4(0.0f, 1.0f, 0.5f, 2.0f), 1);
131
132 // calculate shader view projection matrix
133 Matrix4x4 view_matrix;
134 DX8Wrapper::Get_Transform(D3DTS_VIEW, view_matrix);
135
136 Matrix4x4 proj_matrix;
137 DX8Wrapper::Get_Transform(D3DTS_PROJECTION, proj_matrix);
138
139 Matrix4x4::Multiply(proj_matrix, view_matrix, &View_Projection_Matrix);
140}
141
142//**********************************************************************************************
144
147{
149
150 // set vertex shader constants
151 Matrix4x4 world;
152 DX8Wrapper::Get_Transform(D3DTS_WORLD, world);
153
154 Matrix4x4 world_view_proj_matrix;
155
156 Matrix4x4::Multiply(View_Projection_Matrix,world,&world_view_proj_matrix);
157
160
162 (
163 rinfo,
164 Ambient,
165 Diffuse
166 );
167}
168
170{
171 return 1;
172}
173
174unsigned Shd6BumpDiffClass::Get_Vertex_Size(unsigned stream) const
175{
176 return sizeof(VertexFormatXYZNDUV1);
177}
178
180(
181 unsigned stream,
182 void* dest_buffer,
183 const VertexStreamStruct& vss,
184 unsigned vertex_count
185)
186{
187 VertexFormatXYZNDUV1* verts=(VertexFormatXYZNDUV1*)dest_buffer;
188
189 for (unsigned i=0; i<vertex_count; ++i)
190 {
191 if (vss.Locations)
192 {
193 verts[i].x=vss.Locations[i][0];
194 verts[i].y=vss.Locations[i][1];
195 verts[i].z=vss.Locations[i][2];
196 }
197 else
198 {
199 verts[i].x=0.0f;
200 verts[i].y=0.0f;
201 verts[i].z=0.0f;
202 }
203
204 if (vss.DiffuseInt)
205 {
206 verts[i].diffuse=vss.DiffuseInt[i];
207 }
208 else
209 {
210 verts[i].diffuse=0xffffffff;
211 }
212
213 if (vss.Normals)
214 {
215 verts[i].nx=vss.Normals[i][0];
216 verts[i].ny=vss.Normals[i][1];
217 verts[i].nz=vss.Normals[i][2];
218 }
219 else
220 {
221 verts[i].nx=0.0f;
222 verts[i].ny=0.0f;
223 verts[i].nz=0.0f;
224 }
225
226 if (vss.UV[0])
227 {
228 verts[i].u1=vss.UV[0][i].U;
229 verts[i].v1=vss.UV[0][i].V;
230 }
231 else
232 {
233 verts[i].u1=0.0f;
234 verts[i].v1=0.0f;
235 }
236 }
237}
238
#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 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 friend Matrix4x4 Multiply(const Matrix4x4 &a, const Matrix4x4 &b)
Definition matrix4.h:743
static void Shutdown()
virtual unsigned Get_Vertex_Stream_Count() const
virtual void Copy_Vertex_Stream(unsigned stream, void *dest_buffer, const VertexStreamStruct &vss, unsigned vertex_count)
Shd6BumpDiffClass(const ShdDefClass *def)
virtual unsigned Get_Vertex_Size(unsigned stream) const
static Matrix4x4 View_Projection_Matrix
virtual void Apply_Instance(int cur_pass, RenderInfoClass &rinfo)
Apply per instance states for 1 pass DX6 specular with gloss map (no bump)
static void Init()
static ShdHWVertexShader Vertex_Shader
TextureClass * Texture
virtual void Apply_Shared(int cur_pass, RenderInfoClass &rinfo)
virtual ~Shd6BumpDiffClass()
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
DWORD shd6bumpdiff_vsh_code[]
#define CV_WORLD_VIEW_PROJECTION
#define CV_WORLD
@ SHDDEF_CLASSID_BUMPDIFF
Definition shdclassids.h:52
#define CV_CONST
const Vector3 * Normals
const Vector2 * UV[MAX_TEXTURE_STAGES]
const unsigned * DiffuseInt
const Vector3 * Locations