(360) MVP stuff - right now ouputs black - to be fixed shortly

This commit is contained in:
TwinAphex51224 2012-03-10 15:31:54 +01:00
parent 7489f387c1
commit 6053b61b5b
4 changed files with 57 additions and 20 deletions

View File

@ -53,6 +53,7 @@ typedef struct _STRING {
char * Buffer; char * Buffer;
} STRING; } STRING;
char DEFAULT_SHADER_FILE[MAX_PATH_LENGTH];
char SYS_CONFIG_FILE[MAX_PATH_LENGTH]; char SYS_CONFIG_FILE[MAX_PATH_LENGTH];
extern "C" int __stdcall ObCreateSymbolicLink( STRING*, STRING*); extern "C" int __stdcall ObCreateSymbolicLink( STRING*, STRING*);
@ -134,6 +135,7 @@ static void set_default_settings (void)
{ {
//g_settings //g_settings
g_settings.rewind_enable = false; 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.vsync = true;
g_settings.video.smooth = true; g_settings.video.smooth = true;
g_settings.video.aspect_ratio = -1.0f; 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)); strlcpy(SYS_CONFIG_FILE, "game:\\ssnes.cfg", sizeof(SYS_CONFIG_FILE));
} }

View File

@ -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 position : POSITION;
float2 coord : TEXCOORD0; float2 texCoord : TEXCOORD0;
}; };
struct VS_OUT struct VP_OUT
{ {
float4 pos : POSITION; float4 oPosition : POSITION;
float2 coord : TEXCOORD0; 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; FP_OUT output;
output.pos = float4(input.pos, 0.0, 1.0); output.color = tex2D(decal, input.texCoord);
output.coord = input.coord; return output;
}
VP_OUT main_vertex(VP_IN input)
{
VP_OUT output;
output.oPosition = mul(modelViewProj, input.position);
output.otexCoord = input.texCoord;
return output; return output;
} }

View File

@ -230,7 +230,7 @@ static void *xdk360_gfx_init(const video_info_t *video, const input_driver_t **i
ID3DXBuffer* pErrorMsg = NULL; ID3DXBuffer* pErrorMsg = NULL;
HRESULT hr = D3DXCompileShaderFromFile( HRESULT hr = D3DXCompileShaderFromFile(
"game:\\media\\shaders\\stock.cg", //filepath g_settings.video.cg_shader_path, //filepath
NULL, //macros NULL, //macros
NULL, //includes NULL, //includes
"main_vertex", // main function "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 0, // flags
&pShaderCodeV, // compiled operations &pShaderCodeV, // compiled operations
&pErrorMsg, // errors &pErrorMsg, // errors
NULL); // constants &vid->constantTable); // constants
if (SUCCEEDED(hr)) if (SUCCEEDED(hr))
{ {
SSNES_LOG("Vertex shader program from [%s] successfully compiled.\n", "game:\\media\\shaders\\stock.cg"); SSNES_LOG("Vertex shader program from [%s] successfully compiled.\n", "game:\\media\\shaders\\stock.cg");
HRESULT hr = D3DXCompileShaderFromFile( HRESULT hr = D3DXCompileShaderFromFile(
"game:\\media\\shaders\\stock.cg", //filepath g_settings.video.cg_shader_path, //filepath
NULL, //macros NULL, //macros
NULL, //includes NULL, //includes
"main_fragment", // main function "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; vp.MaxZ = 1.0f;
D3DDevice_SetViewport(vid->xdk360_render_device, &vp); 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; return vid;
} }
@ -397,6 +415,12 @@ static bool xdk360_gfx_frame(void *data, const void *frame,
g_console.force_resize_enable = false; 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; D3DLOCKED_RECT d3dlr;
D3DTexture_LockRect(vid->lpTexture, 0, &d3dlr, NULL, D3DLOCK_NOSYSLOCK); D3DTexture_LockRect(vid->lpTexture, 0, &d3dlr, NULL, D3DLOCK_NOSYSLOCK);
for (unsigned y = 0; y < height; y++) for (unsigned y = 0; y < height; y++)

View File

@ -53,8 +53,10 @@ typedef struct xdk360_video
IDirect3DVertexBuffer9* vertex_buf; IDirect3DVertexBuffer9* vertex_buf;
IDirect3DTexture9* font_texture; IDirect3DTexture9* font_texture;
IDirect3DTexture9* lpTexture; IDirect3DTexture9* lpTexture;
LPD3DXCONSTANTTABLE constantTable;
D3DPRESENT_PARAMETERS d3dpp; D3DPRESENT_PARAMETERS d3dpp;
XVIDEO_MODE video_mode; XVIDEO_MODE video_mode;
XMMATRIX modelViewProj;
} xdk360_video_t; } xdk360_video_t;
enum enum