I'd post code if there wasn't a ton of it split across several files, but here's a pix screenshot.
http://i.imgur.com/DlEZr.png
Posted 24 April 2012 - 11:12 PM
Posted 25 April 2012 - 12:17 AM
swapChainDesc.BufferCount = 1; swapChainDesc.BufferDesc.Width = screenWidth; swapChainDesc.BufferDesc.Height = screenHeight; swapChainDesc.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM; swapChainDesc.BufferDesc.RefreshRate.Numerator = 0; swapChainDesc.BufferDesc.RefreshRate.Denominator = 1; swapChainDesc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT; swapChainDesc.OutputWindow = hwnd; swapChainDesc.SampleDesc.Count = 1; swapChainDesc.SampleDesc.Quality = 0; swapChainDesc.Windowed = true; swapChainDesc.BufferDesc.ScanlineOrdering = DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED; swapChainDesc.BufferDesc.Scaling = DXGI_MODE_SCALING_UNSPECIFIED; swapChainDesc.SwapEffect = DXGI_SWAP_EFFECT_DISCARD; swapChainDesc.Flags = 0; featureLevel = D3D_FEATURE_LEVEL_11_0; result = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, &featureLevel, 1, D3D11_SDK_VERSION, &swapChainDesc, &mSwapChain, &mDevice, NULL, &mContext);
// Get the pointer to the back buffer. result = mSwapChain->GetBuffer(0, __uuidof(ID3D11Texture2D), (LPVOID*)&backBufferPtr); // Create the render target view with the back buffer pointer. result = mDevice->CreateRenderTargetView(backBufferPtr, NULL, &mRenderTargetView);
// Set up the description of the depth buffer. depthBufferDesc.Width = screenWidth; depthBufferDesc.Height = screenHeight; depthBufferDesc.MipLevels = 1; depthBufferDesc.ArraySize = 1; depthBufferDesc.Format = DXGI_FORMAT_D24_UNORM_S8_UINT; depthBufferDesc.SampleDesc.Count = 1; depthBufferDesc.SampleDesc.Quality = 0; depthBufferDesc.Usage = D3D11_USAGE_DEFAULT; depthBufferDesc.BindFlags = D3D11_BIND_DEPTH_STENCIL; depthBufferDesc.CPUAccessFlags = 0; depthBufferDesc.MiscFlags = 0; // Create the texture for the depth buffer using the filled out description. mDevice->CreateTexture2D(&depthBufferDesc, NULL, &mDepthStencilBuffer); // Set up the description of the stencil state. depthStencilDesc.DepthEnable = true; depthStencilDesc.DepthWriteMask = D3D11_DEPTH_WRITE_MASK_ALL; depthStencilDesc.DepthFunc = D3D11_COMPARISON_LESS; depthStencilDesc.StencilEnable = true; depthStencilDesc.StencilReadMask = D3D11_DEFAULT_STENCIL_READ_MASK; depthStencilDesc.StencilWriteMask = D3D11_DEFAULT_STENCIL_WRITE_MASK; // Stencil operations if pixel is front-facing. depthStencilDesc.FrontFace.StencilFailOp = D3D11_STENCIL_OP_KEEP; depthStencilDesc.FrontFace.StencilDepthFailOp = D3D11_STENCIL_OP_INCR; depthStencilDesc.FrontFace.StencilPassOp = D3D11_STENCIL_OP_KEEP; depthStencilDesc.FrontFace.StencilFunc = D3D11_COMPARISON_ALWAYS; // Stencil operations if pixel is back-facing. depthStencilDesc.BackFace.StencilFailOp = D3D11_STENCIL_OP_KEEP; depthStencilDesc.BackFace.StencilDepthFailOp = D3D11_STENCIL_OP_DECR; depthStencilDesc.BackFace.StencilPassOp = D3D11_STENCIL_OP_KEEP; depthStencilDesc.BackFace.StencilFunc = D3D11_COMPARISON_ALWAYS; // Create the depth stencil state. mDevice->CreateDepthStencilState(&depthStencilDesc, &mDepthStencilState); // Set the depth stencil state. mContext->OMSetDepthStencilState(mDepthStencilState, 1); // Set up the depth stencil view description. depthStencilViewDesc.Format = DXGI_FORMAT_D24_UNORM_S8_UINT; depthStencilViewDesc.ViewDimension = D3D11_DSV_DIMENSION_TEXTURE2D; depthStencilViewDesc.Texture2D.MipSlice = 0; // Create the depth stencil view. mDevice->CreateDepthStencilView(mDepthStencilBuffer, &depthStencilViewDesc, &mDepthStencilView); // Bind the render target view and depth stencil view to the pipeline. mContext->OMSetRenderTargets(1, &mRenderTargetView, mDepthStencilView);
// Setup the raster description which will determine how and what polygons will be drawn. rasterDesc.AntialiasedLineEnable = false; rasterDesc.CullMode = D3D11_CULL_NONE; rasterDesc.DepthBias = 0; rasterDesc.DepthBiasClamp = 0.0f; rasterDesc.DepthClipEnable = true; rasterDesc.FillMode = D3D11_FILL_SOLID; rasterDesc.FrontCounterClockwise = false; rasterDesc.MultisampleEnable = false; rasterDesc.ScissorEnable = false; rasterDesc.SlopeScaledDepthBias = 0.0f; // Create the rasterizer state from the description we just filled out. mDevice->CreateRasterizerState(&rasterDesc, &mRasterState); // Now set the rasterizer state. mContext->RSSetState(mRasterState);
// Setup the viewport for rendering. viewport.Width = (float)screenWidth; viewport.Height = (float)screenHeight; viewport.MinDepth = 0.0f; viewport.MaxDepth = 1.0f; viewport.TopLeftX = 0.0f; viewport.TopLeftY = 0.0f; // Create the viewport. mContext->RSSetViewports(1, &viewport);
D3DX11_PASS_SHADER_DESC effectVsDesc; mPass->GetVertexShaderDesc(&effectVsDesc); D3DX11_EFFECT_SHADER_DESC effectVsDesc2; effectVsDesc.pShaderVariable->GetShaderDesc(effectVsDesc.ShaderIndex, &effectVsDesc2); const void *vsCodePtr = effectVsDesc2.pBytecode; unsigned vsCodeLen = effectVsDesc2.BytecodeLength; D3D11_INPUT_ELEMENT_DESC polygonLayout[2]; polygonLayout[0].SemanticName = "POSITION"; polygonLayout[0].SemanticIndex = 0; polygonLayout[0].Format = DXGI_FORMAT_R32G32B32_FLOAT; polygonLayout[0].InputSlot = 0; polygonLayout[0].AlignedByteOffset = 0; polygonLayout[0].InputSlotClass = D3D11_INPUT_PER_VERTEX_DATA; polygonLayout[0].InstanceDataStepRate = 0; polygonLayout[1].SemanticName = "TEXCOORD"; polygonLayout[1].SemanticIndex = 0; polygonLayout[1].Format = DXGI_FORMAT_R32G32_FLOAT; polygonLayout[1].InputSlot = 0; polygonLayout[1].AlignedByteOffset = D3D11_APPEND_ALIGNED_ELEMENT; polygonLayout[1].InputSlotClass = D3D11_INPUT_PER_VERTEX_DATA; polygonLayout[1].InstanceDataStepRate = 0; GraphicsMan->GetDevice()->CreateInputLayout(polygonLayout, sizeof(polygonLayout) / sizeof(polygonLayout[0]), vsCodePtr, vsCodeLen, &mLayout);
Posted 25 April 2012 - 12:53 AM
float color[] = { 160.0 / 255.0, 69.0 / 255.0, 32.0 / 255.0, 0 };
// Clear the back buffer.
mContext->ClearRenderTargetView(mRenderTargetView, color);
// Clear the depth buffer.
mContext->ClearDepthStencilView(mDepthStencilView, D3D11_CLEAR_DEPTH, 1.0f, 0);
// Set vertex/index buffer.
mBuffer.ApplyBuffer();
// Update camera.
mCamera.Update();
// Set shader technique, pass, vars, and apply.
mEffect.SetTechnique(0);
mEffect.SetPass(0);
Matrix mx; D3DXMatrixIdentity(&mx);
mEffect.SetVariable("World", mx);
mEffect.SetVariable("View", mCamera.GetView());
mEffect.SetVariable("Projection", mCamera.GetProjection());
mEffect.Apply();
// Draw
mContext->DrawIndexed(mBuffer.GetIndexCount(), 0, 0);
// Present
mSwapChain->Present(0, 0);
Posted 25 April 2012 - 01:41 AM
float4x4 World;
float4x4 View;
float4x4 Projection;
texture2D Texture;
SamplerState textureSampler {
Filter = MIN_MAG_MIP_LINEAR;
AddressU = Wrap;
AddressV = Wrap;
};
struct VertexShaderInput
{
float4 Position : POSITION0;
//float4 Normal : NORMAL0;
float2 TextureCoordinate : TEXCOORD0;
};
struct VertexShaderOutput
{
float4 Position : POSITION0;
float2 TextureCoordinate : TEXCOORD1;
};
VertexShaderOutput VertexShaderFunction(VertexShaderInput input)
{
VertexShaderOutput output;
//output.Position = input.Position;
output.Position = mul(input.Position, World);
output.Position = mul(output.Position, View);
output.Position = mul(output.Position, Projection);
output.TextureCoordinate = input.TextureCoordinate;
return output;
};
float4 PixelShaderFunction(VertexShaderOutput input) : SV_TARGET
{
float3 color = float3(255, 255, 255);
color = normalize(color);
return float4(color, 1);
//return Texture.Sample(textureSampler, input.TextureCoordinate);
};
technique11 Textured
{
pass p0
{
SetVertexShader(CompileShader(vs_5_0, VertexShaderFunction()));
SetPixelShader(CompileShader(ps_5_0, PixelShaderFunction()));
}
};
Posted 25 April 2012 - 02:05 AM
float4 PixelShaderFunction(VertexShaderOutput input) : SV_TARGET
{
float3 color = float3(255, 255, 255);
color = normalize(color);
return float4(color, 1);
//return Texture.Sample(textureSampler, input.TextureCoordinate);
};
mD3D11DeviceContext->RSSetState(0); mD3D11DeviceContext->OMSetBlendState(0, 0, 0xFFFFFFFF); mD3D11DeviceContext->OMSetDepthStencilState(0, 0);
Posted 25 April 2012 - 02:14 AM
Shader colors range from 0.0 to 1.0. If you normalize (255, 255, 255) it'll be about (0.58, 0.58, 0.58) and that's just gray.
You could simply do return float4(1, 1, 1, 1) to return white color.
Posted 25 April 2012 - 02:34 AM
polygonLayout[0].Format = DXGI_FORMAT_R32G32B32_FLOAT;However in the shader you try to accept 4 floats:
float4 Position : POSITION0;
float4x4 World;
float4x4 View;
float4x4 Projection;
texture2D Texture;
SamplerState textureSampler {
Filter = MIN_MAG_MIP_LINEAR;
AddressU = Wrap;
AddressV = Wrap;
};
struct VertexShaderInput {
float3 Position : POSITION0;
float2 TextureCoordinate : TEXCOORD0;
};
struct VertexShaderOutput {
float4 Position : SV_POSITION;
float2 TextureCoordinate : TEXCOORD0;
};
VertexShaderOutput VertexShaderFunction(VertexShaderInput input) {
VertexShaderOutput output;
output.Position = mul(float4(input.Position, 1), World);
output.Position = mul(output.Position, View);
output.Position = mul(output.Position, Projection);
output.TextureCoordinate = input.TextureCoordinate;
return output;
};
float4 PixelShaderFunction(VertexShaderOutput input) : SV_TARGET {
return float4(1, 1, 1, 1)
};
technique11 Textured {
pass p0 {
SetVertexShader(CompileShader(vs_5_0, VertexShaderFunction()));
SetPixelShader(CompileShader(ps_5_0, PixelShaderFunction()));
}
};
Posted 25 April 2012 - 04:57 AM
it seems you send 3 floats for position to the shader:
polygonLayout[0].Format = DXGI_FORMAT_R32G32B32_FLOAT;
However in the shader you try to accept 4 floats:
float4 Position : POSITION0;