前田稔(Maeda Minoru)の超初心者のプログラム入門
C:\Program Files (x86)\Microsoft DirectX SDK (June 2010)\Samples\Media\ |
ID3D10Effect* g_pEffect = NULL; ID3D10InputLayout* g_pLayout = NULL; ID3D10EffectTechnique* g_pRender = NULL; CDXUTSDKMesh g_Mesh; ID3D10EffectMatrixVariable* g_pWorldVariable = NULL; ID3D10EffectMatrixVariable* g_pViewVariable = NULL; ID3D10EffectMatrixVariable* g_pProjectionVariable = NULL; CModelViewerCamera g_Camera; |
//g_pColorVariable = g_pEffect->GetVariableByName( "Color" )->AsVector(); |
HRESULT CALLBACK OnD3D10CreateDevice( ID3D10Device* pd3dDevice, const DXGI_SURFACE_DESC* pBackBufferSurfaceDesc, void* pUserContext ) { HRESULT hr; : : V_RETURN( DXUTFindDXSDKMediaFileCch( str, MAX_PATH, L"Color.fx" ) ); DWORD dwShaderFlags = D3D10_SHADER_ENABLE_STRICTNESS; V_RETURN( D3DX10CreateEffectFromFile( str, NULL, NULL, "fx_4_0", dwShaderFlags, 0, pd3dDevice, NULL, NULL, &g_pEffect, NULL, NULL ) ); // Obtain the technique g_pRender = g_pEffect->GetTechniqueByName( "Render" ); g_pWorldVariable = g_pEffect->GetVariableByName( "World" )->AsMatrix(); g_pViewVariable = g_pEffect->GetVariableByName( "View" )->AsMatrix(); g_pProjectionVariable = g_pEffect->GetVariableByName( "Projection" )->AsMatrix(); // Define the input layout const D3D10_INPUT_ELEMENT_DESC layout[] = { { "POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D10_INPUT_PER_VERTEX_DATA, 0 }, { "NORMAL", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 12, D3D10_INPUT_PER_VERTEX_DATA, 0 }, { "COLOR", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 24, D3D10_INPUT_PER_VERTEX_DATA, 0 }, }; UINT numElements = sizeof( layout ) / sizeof( layout[0] ); // Create the input layout D3D10_PASS_DESC PassDesc; g_pRender->GetPassByIndex( 0 )->GetDesc( &PassDesc ); V_RETURN( pd3dDevice->CreateInputLayout( layout, numElements, PassDesc.pIAInputSignature, PassDesc.IAInputSignatureSize, &g_pLayout ) ); // Set the input layout pd3dDevice->IASetInputLayout( g_pLayout ); // Load the mesh SetCurrentDirectory(L"C:\\DATA\\Sdkmesh"); V_RETURN( g_Mesh.Create( pd3dDevice, L"bigship1.sdkmesh", true ) ); : : |
//-------------------------------------------------------------------------------------- // File: Color.fx 頂点座標+法線ベクトル+色 前田 稔 //-------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------- // Constant Buffer Variables //-------------------------------------------------------------------------------------- matrix World; matrix View; matrix Projection; //-------------------------------------------------------------------------------------- // Global variables //-------------------------------------------------------------------------------------- cbuffer cb0 { float3 g_vLightDir = float3(-0.707,0.707,-0.5); // 光源の座標 }; //-------------------------------------------------------------------------------------- // Vertex shader output structure //-------------------------------------------------------------------------------------- struct VS_INPUT { float4 Pos : POSITION; float4 Norm : NORMAL; float4 Color : COLOR0; }; struct PS_INPUT { float4 Pos : SV_POSITION; float4 Norm : NORMAL; float4 Color : COLOR0; }; //-------------------------------------------------------------------------------------- // Vertex Shader //-------------------------------------------------------------------------------------- PS_INPUT VS( VS_INPUT input ) { PS_INPUT output = (PS_INPUT)0; output.Pos = mul( input.Pos, World ); output.Pos = mul( output.Pos, View ); output.Pos = mul( output.Pos, Projection ); output.Norm = mul( input.Norm, World ); output.Color = input.Color; return output; } //-------------------------------------------------------------------------------------- float4 PS( PS_INPUT input ) : SV_Target { return input.Color * saturate( dot( normalize(input.Norm), g_vLightDir ) ); } //-------------------------------------------------------------------------------------- technique10 Render { pass P0 { SetVertexShader( CompileShader( vs_4_0, VS() ) ); SetGeometryShader( NULL ); SetPixelShader( CompileShader( ps_4_0, PS() ) ); } } |
const D3D10_INPUT_ELEMENT_DESC layout[] = { { "POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D10_INPUT_PER_VERTEX_DATA, 0 }, { "NORMAL", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 12, D3D10_INPUT_PER_VERTEX_DATA, 0 }, { "COLOR", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 24, D3D10_INPUT_PER_VERTEX_DATA, 0 }, }; |
struct VS_INPUT { float4 Pos : POSITION; float4 Norm : NORMAL; float4 Color : COLOR0; }; |