工具

着色器 Shader

SA 着色器(继承 DynamicResource)

extensions/Shader.h · 仅 SA · 继承 DynamicResource

加载与开关

构造时可直接指定 hlsl / fxc。设备丢失时走 DynamicResource 生命周期。

Shader(std::string const& Filename, bool bDebug = false);
void Load();
void Unload();
void Enable();
void Disable();
void EnablePSForRwImRender();
void DisablePSForRwImRender();

绑定纹理

绑到寄存器 idx

void PackTexture(RxD3D9InstanceData* mesh, unsigned int idx);
void PackTexture(RpMaterial* material, unsigned int idx);
void PackTexture(RwTexture* texture, unsigned int idx);
void SetMeshTexture(RxD3D9InstanceData* mesh, unsigned int idx);
void SetMaterialTexture(RpMaterial* material, unsigned int idx);
void SetTexture(RwTexture* texture, unsigned int idx);

塞常量参数

结构体注意 16 字节对齐 与补零。

template <class T>
bool PackPSParameters(T& parameters, unsigned int offset = 0);

template <class T>
bool PackVSParameters(T& parameters, unsigned int offset = 0);

源码与二进制

构造内会 Load。可另存为 fxc。

bool LoadFromSource(std::ifstream& file, bool bDebug);
bool LoadFromBinary(std::ifstream& file);
void Load();
bool SaveToBinary();
bool SaveToBinary(std::string const& Filename);
bool WriteToBinaryFile(std::ofstream& file);
static char* CompileShaderFromString(char const* str, char const* Entrypoint, char const* Version, bool bDebug);

矩阵与画矩形

static void GetWorldViewProj(
    RpAtomic* atomic,
    D3DMATRIX* world,
    D3DMATRIX* view,
    D3DMATRIX* proj,
    D3DMATRIX* wvp);

static void DrawRect(float left, float top, float right, float bottom);

On this page