From da92a49ed9251a0210b13a7f1c340f9bd16e26cc Mon Sep 17 00:00:00 2001 From: Zack Buhman Date: Mon, 22 Dec 2025 17:25:07 -0600 Subject: [PATCH] simple pixel shader --- main.cpp | 27 +++++++++++++++++++++++++++ main.psh | 9 +++++++++ main.vsh | 3 ++- 3 files changed, 38 insertions(+), 1 deletion(-) create mode 100644 main.psh diff --git a/main.cpp b/main.cpp index d843aa2..2a97e56 100644 --- a/main.cpp +++ b/main.cpp @@ -29,6 +29,7 @@ IDirect3DVertexBuffer9 * g_pVB = NULL; IDirect3DVertexDeclaration9 * g_pVertexDeclaration = NULL; ID3DXConstantTable * g_pConstantTable = NULL; IDirect3DVertexShader9 * g_pVertexShader = NULL; +IDirect3DPixelShader9 * g_pPixelShader = NULL; IDirectInput8 * g_pDI = NULL; IDirectInputDevice8 * g_pdiDevice; @@ -149,6 +150,7 @@ void Render() g_pd3dDevice->SetVertexDeclaration(g_pVertexDeclaration); g_pd3dDevice->SetVertexShader(g_pVertexShader); + g_pd3dDevice->SetPixelShader(g_pPixelShader); g_pd3dDevice->SetStreamSource(0, g_pVB, 0, (sizeof (CUSTOMVERTEX))); g_pd3dDevice->DrawPrimitive(D3DPT_TRIANGLELIST, 0, 1); @@ -374,6 +376,31 @@ int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PWSTR pCmdLine return 0; } + ////////////////////////////////////////////////////////////////////// + // pixel shader + ////////////////////////////////////////////////////////////////////// + + res = D3DXCompileShaderFromFile(L"main.psh", // pSrcFile + NULL, // pDefines + NULL, // pInclude + "Main", // pFunctionName + "ps_3_0", // pProfile + dwShaderFlags, // Flags + &pCode, // ppShader + NULL, // ppErrorMsgs + &g_pConstantTable // ppConstantTable + ); + if (FAILED(res)) { + fprintf(stderr, "D3DXCompileShader\n"); + return 0; + } + res = g_pd3dDevice->CreatePixelShader((DWORD*)pCode->GetBufferPointer(), &g_pPixelShader); + pCode->Release(); + if(FAILED(res)) { + fprintf(stderr, "CreatePixelShader\n"); + return 0; + } + // fprintf(stderr, "success\n"); diff --git a/main.psh b/main.psh new file mode 100644 index 0000000..cacd727 --- /dev/null +++ b/main.psh @@ -0,0 +1,9 @@ +struct VS_OUTPUT +{ + float4 Position : POSITION; // vertex position + float4 Diffuse : COLOR0; // vertex diffuse color +}; + +float4 Main(VS_OUTPUT In) : COLOR { + return float4(1, 1, 1, 1) - In.Diffuse; +} diff --git a/main.vsh b/main.vsh index a979cf4..14a28a5 100644 --- a/main.vsh +++ b/main.vsh @@ -16,7 +16,8 @@ VS_OUTPUT Main(VS_INPUT Input) { VS_OUTPUT Output; - Output.Position = mul(float4(Input.Position, 1.0), mWorldViewProj); + //Output.Position = mul(float4(Input.Position, 1.0), mWorldViewProj); + Output.Position = float4(Input.Position, 1.0); Output.Diffuse = Input.Color; return Output;