Move git root from Client/ to src/ to track all source code: - Client: Game client source (moved to Client/Client/) - Server: Game server source - GameTools: Development tools - CryptoSource: Encryption utilities - database: Database scripts - Script: Game scripts - rylCoder_16.02.2008_src: Legacy coder tools - GMFont, Game: Additional resources 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
131 lines
3.8 KiB
C++
131 lines
3.8 KiB
C++
// Shader_RainV.cpp: implementation of the CShader_RainV class.
|
|
//
|
|
//////////////////////////////////////////////////////////////////////
|
|
|
|
#include "Shader_RainV.h"
|
|
#include "SceneManager.h"
|
|
#include <sys/types.h>
|
|
#include <sys/timeb.h>
|
|
//////////////////////////////////////////////////////////////////////
|
|
// Construction/Destruction
|
|
//////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
CShader_RainV::CShader_RainV()
|
|
{
|
|
|
|
DWORD vertexshaderdeclaration[]=
|
|
{
|
|
D3DVSD_STREAM(0),
|
|
(D3DVSD_REG(0, D3DVSDT_FLOAT3)), // vertex position
|
|
(D3DVSD_REG(3, D3DVSDT_FLOAT3)), // vertex normal
|
|
(D3DVSD_REG(1, D3DVSDT_FLOAT1)), // vertex Ani Time
|
|
D3DVSD_END()
|
|
};
|
|
|
|
// Create Vertex Shader
|
|
|
|
CreateVertexShader("c:/MP-project/Shaders/5_Rain.vsh",vertexshaderdeclaration);
|
|
m_pRainTexture = new CTexture;
|
|
CTexture::SetPath(EFFECTTEXTUREPATH);
|
|
m_pRainTexture->Load("Rain.dds");
|
|
|
|
m_pDevice = CSceneManager::GetDevice();
|
|
|
|
}
|
|
|
|
CShader_RainV::~CShader_RainV()
|
|
{
|
|
if(m_pRainTexture != NULL) {
|
|
delete m_pRainTexture;
|
|
m_pRainTexture = NULL;
|
|
|
|
}
|
|
}
|
|
void CShader_RainV::SetupVertexShaderConstants() {
|
|
/*
|
|
static _timeb start;
|
|
static int firstTime = 1;
|
|
|
|
if (firstTime!=0)
|
|
{
|
|
_ftime(&start);
|
|
firstTime = 0;
|
|
}
|
|
|
|
struct _timeb now;
|
|
_ftime(&now);
|
|
|
|
float deltaTime(static_cast<float>(now.time - start.time));
|
|
deltaTime += static_cast<float>(0.001f * (now.millitm - start.millitm));
|
|
//deltaTime *= 0.3f;
|
|
deltaTime *= 1.3f;
|
|
*/
|
|
/*
|
|
static float fDeltaTime = 0.0f;
|
|
fDeltaTime = (rand() % 100) / 100.0f;*/
|
|
/* fDeltaTime += 0.5f;
|
|
if(fDeltaTime >1.0f)
|
|
fDeltaTime = 0.0f;
|
|
*/
|
|
m_pDevice->SetTexture(0,m_pRainTexture->GetTexture());
|
|
/* Vertex ShaderConstant */
|
|
|
|
D3DXVECTOR4 vecLightDir(0.0f, 0.0f, -1.0f, 0.0f);
|
|
D3DXVec4Normalize(&vecLightDir,&vecLightDir);
|
|
|
|
m_pDevice->SetVertexShaderConstant(CV_LIGHT_DIRECTION, &vecLightDir, 1); // 4 -> 22
|
|
|
|
|
|
D3DXVECTOR4 vecConstNumber(0.0f, 0.5f, 0.35f, 2.0f);
|
|
//D3DXVECTOR4 vecConstNumber(0.0f, 0.5f, 1.0f, 2.0f);
|
|
m_pDevice->SetVertexShaderConstant(CV_CONSTS_1, &vecConstNumber, 1); // 9->42
|
|
|
|
D3DXVECTOR4 vecConstNumber2(25000.0f, 0.05f, 0.1f, 0.2f);
|
|
//D3DXVECTOR4 vecConstNumber2(100.0f, 0.05f, 0.1f, 0.2f);
|
|
m_pDevice->SetVertexShaderConstant(CV_CONSTS_2, &vecConstNumber2, 1); //18->55
|
|
|
|
|
|
D3DXMATRIX matView,matInvView;
|
|
m_pDevice->GetTransform(D3DTS_VIEW,&matView);
|
|
D3DXMatrixInverse(&matInvView,NULL,&matView);
|
|
D3DXVECTOR3 vecViewPos = D3DXVECTOR3(matInvView._41,matInvView._42,matInvView._43);
|
|
|
|
m_pDevice->SetVertexShaderConstant(CV_EYE_POS_WORLD, &vecViewPos, 1); // 10->24
|
|
////
|
|
D3DXMATRIX matWorld,matTWorld,matInvWorld;//,matView,matProject;
|
|
D3DXMATRIX matProject;
|
|
D3DXMATRIX matWorldViewProject;
|
|
|
|
m_pDevice->GetTransform(D3DTS_WORLD,&matWorld);
|
|
D3DXMatrixTranspose(&matTWorld,&matWorld);
|
|
|
|
m_pDevice->GetTransform(D3DTS_PROJECTION,&matProject);
|
|
D3DXMatrixIdentity(&matWorldViewProject);
|
|
|
|
D3DXMatrixMultiply(&matWorldViewProject,&matWorld,&matView);
|
|
D3DXMatrixMultiply(&matWorldViewProject,&matWorldViewProject,&matProject);
|
|
D3DXMatrixTranspose(&matWorldViewProject,&matWorldViewProject);
|
|
m_pDevice->SetVertexShaderConstant(CV_WORLDVIEWPROJ_0,&matWorldViewProject,4); // 0->2
|
|
|
|
D3DXMatrixInverse(&matInvWorld,NULL,&matWorld);
|
|
m_pDevice->SetVertexShaderConstant(CV_WORLDIT_0,&matInvWorld,4);//5->29
|
|
m_pDevice->SetVertexShaderConstant(CV_WORLD_0,&matTWorld,4);//11->13
|
|
|
|
m_pDevice->SetVertexShaderConstant(CV_RAINDIRECTION, D3DXVECTOR4(0.40f, 0.9f, 0.0f, 0.0f), 1); // Rain direction 17->60
|
|
// m_pDevice->SetVertexShaderConstant(CV_RAINANI, D3DXVECTOR4(deltaTime, 0.0f, 0.0f, 0.0f), 1); // Anim Time index 19->61
|
|
|
|
m_pDevice->SetVertexShaderConstant(CV_ZERO, D3DXVECTOR4(1.0f, 1.0f, 1.0f, 0.5f), 1);
|
|
|
|
}
|
|
void CShader_RainV::Apply() {
|
|
if(m_pDevice == NULL)
|
|
return ;
|
|
|
|
m_pDevice->SetVertexShader(m_dwVertexShader);
|
|
m_pDevice->SetPixelShader(NULL);
|
|
SetupVertexShaderConstants();
|
|
|
|
}
|