From 6053b61b5b1d1d3f24d16865ec00759b59c1f046 Mon Sep 17 00:00:00 2001 From: TwinAphex51224 Date: Sat, 10 Mar 2012 15:31:54 +0100 Subject: [PATCH] (360) MVP stuff - right now ouputs black - to be fixed shortly --- 360/main.c | 5 ++++- 360/media/shaders/stock.cg | 40 +++++++++++++++++++++++--------------- 360/xdk360_video.cpp | 30 +++++++++++++++++++++++++--- 360/xdk360_video.h | 2 ++ 4 files changed, 57 insertions(+), 20 deletions(-) diff --git a/360/main.c b/360/main.c index f28d1c2c26..c8e549986c 100644 --- a/360/main.c +++ b/360/main.c @@ -53,6 +53,7 @@ typedef struct _STRING { char * Buffer; } STRING; +char DEFAULT_SHADER_FILE[MAX_PATH_LENGTH]; char SYS_CONFIG_FILE[MAX_PATH_LENGTH]; extern "C" int __stdcall ObCreateSymbolicLink( STRING*, STRING*); @@ -134,6 +135,7 @@ static void set_default_settings (void) { //g_settings g_settings.rewind_enable = false; + strlcpy(g_settings.video.cg_shader_path, DEFAULT_SHADER_FILE, sizeof(g_settings.video.cg_shader_path)); g_settings.video.vsync = true; g_settings.video.smooth = true; g_settings.video.aspect_ratio = -1.0f; @@ -445,7 +447,8 @@ static void get_environment_settings (void) } } - + + strlcpy(DEFAULT_SHADER_FILE, "game:\\media\\shaders\\stock.cg", sizeof(DEFAULT_SHADER_FILE)); strlcpy(SYS_CONFIG_FILE, "game:\\ssnes.cfg", sizeof(SYS_CONFIG_FILE)); } diff --git a/360/media/shaders/stock.cg b/360/media/shaders/stock.cg index 8460b6cf0f..8e0d14156e 100644 --- a/360/media/shaders/stock.cg +++ b/360/media/shaders/stock.cg @@ -1,32 +1,40 @@ -sampler2D tex : register(s0); +sampler2D decal : register(s0); +float4x4 modelViewProj : register(c0); -struct PS_IN +struct FP_IN { - float2 coord : TEXCOORD0; + float2 texCoord : TEXCOORD0; }; -struct VS_IN +struct VP_IN { - float2 pos : POSITION; - float2 coord : TEXCOORD0; + float2 position : POSITION; + float2 texCoord : TEXCOORD0; }; -struct VS_OUT +struct VP_OUT { - float4 pos : POSITION; - float2 coord : TEXCOORD0; + float4 oPosition : POSITION; + float2 otexCoord : TEXCOORD0; }; -float4 main_fragment(PS_IN input) : COLOR +struct FP_OUT { - return tex2D(tex, input.coord); -} + float4 color : COLOR; +}; -VS_OUT main_vertex(VS_IN input) +FP_OUT main_fragment(FP_IN input) : COLOR { - VS_OUT output; - output.pos = float4(input.pos, 0.0, 1.0); - output.coord = input.coord; + FP_OUT output; + output.color = tex2D(decal, input.texCoord); + return output; +} + +VP_OUT main_vertex(VP_IN input) +{ + VP_OUT output; + output.oPosition = mul(modelViewProj, input.position); + output.otexCoord = input.texCoord; return output; } diff --git a/360/xdk360_video.cpp b/360/xdk360_video.cpp index 4f1ce11d79..1328e41e61 100644 --- a/360/xdk360_video.cpp +++ b/360/xdk360_video.cpp @@ -230,7 +230,7 @@ static void *xdk360_gfx_init(const video_info_t *video, const input_driver_t **i ID3DXBuffer* pErrorMsg = NULL; HRESULT hr = D3DXCompileShaderFromFile( - "game:\\media\\shaders\\stock.cg", //filepath + g_settings.video.cg_shader_path, //filepath NULL, //macros NULL, //includes "main_vertex", // main function @@ -238,13 +238,13 @@ static void *xdk360_gfx_init(const video_info_t *video, const input_driver_t **i 0, // flags &pShaderCodeV, // compiled operations &pErrorMsg, // errors - NULL); // constants + &vid->constantTable); // constants if (SUCCEEDED(hr)) { SSNES_LOG("Vertex shader program from [%s] successfully compiled.\n", "game:\\media\\shaders\\stock.cg"); HRESULT hr = D3DXCompileShaderFromFile( - "game:\\media\\shaders\\stock.cg", //filepath + g_settings.video.cg_shader_path, //filepath NULL, //macros NULL, //includes "main_fragment", // main function @@ -319,6 +319,24 @@ static void *xdk360_gfx_init(const video_info_t *video, const input_driver_t **i vp.MaxZ = 1.0f; D3DDevice_SetViewport(vid->xdk360_render_device, &vp); + // World matrix + XMMATRIX matWorld = XMMatrixIdentity(); + + // View matrix + XMVECTOR vEyePt = XMVectorSet( 0.0f, -4.0f, -4.0f, 0.0f ); + XMVECTOR vLookatPt = XMVectorSet( 0.0f, 0.0f, 0.0f, 0.0f ); + XMVECTOR vUp = XMVectorSet( 0.0f, 1.0f, 0.0f, 0.0f ); + XMMATRIX matView = XMMatrixLookAtLH( vEyePt, vLookatPt, vUp ); + + // Determine the aspect ratio + FLOAT fAspectRatio = ( FLOAT )vid->d3dpp.BackBufferWidth / ( FLOAT )vid->d3dpp.BackBufferHeight; + + // Projection matrix + XMMATRIX matProj = XMMatrixPerspectiveFovLH( XM_PI / 4, fAspectRatio, 1.0f, 200.0f ); + + // World*view*projection + vid->modelViewProj = matWorld * matView * matProj; + return vid; } @@ -397,6 +415,12 @@ static bool xdk360_gfx_frame(void *data, const void *frame, g_console.force_resize_enable = false; } + vid->xdk360_render_device->SetVertexShaderConstantF(0, (FLOAT*)&vid->modelViewProj, 4); + + vid->constantTable->SetDefaults(vid->xdk360_render_device); + + //TODO: Update the shader constants + D3DLOCKED_RECT d3dlr; D3DTexture_LockRect(vid->lpTexture, 0, &d3dlr, NULL, D3DLOCK_NOSYSLOCK); for (unsigned y = 0; y < height; y++) diff --git a/360/xdk360_video.h b/360/xdk360_video.h index b4c5871e61..53cc3b22fb 100644 --- a/360/xdk360_video.h +++ b/360/xdk360_video.h @@ -53,8 +53,10 @@ typedef struct xdk360_video IDirect3DVertexBuffer9* vertex_buf; IDirect3DTexture9* font_texture; IDirect3DTexture9* lpTexture; + LPD3DXCONSTANTTABLE constantTable; D3DPRESENT_PARAMETERS d3dpp; XVIDEO_MODE video_mode; + XMMATRIX modelViewProj; } xdk360_video_t; enum