Luke Cragg

Member
  • Content count

    8
  • Joined

  • Last visited

Community Reputation

110 Neutral

About Luke Cragg

  • Rank
    Newbie
  1. Cannot get textured quad visible

    I've sorted it. I wasn't clearing the depth buffer.   Although to be fair I thought this would have just rendered the image first frame then stuck like that.   Obviously being a problem once other objects had to be rendered.
  2. Cannot get textured quad visible

    Thanks, I was looking how to debug a pixel rather than a vertex.   It has told me that it is discarded because it has failed the depth test.   The vertices have a depth of 0.25 post vertex shader. Meaning they should be visible. Plus it is the only geometry being rendered so it cant be underneath anything else.   So it must either be my raster code   D3D11_RASTERIZER_DESC rastDesc; ZeroMemory( &rastDesc, sizeof( rastDesc ) ); rastDesc.FillMode = D3D11_FILL_SOLID ; rastDesc.CullMode = D3D11_CULL_NONE ; rastDesc.FrontCounterClockwise = false; rastDesc.DepthBias = 0.0f; rastDesc. DepthBiasClamp = 0.0f; rastDesc. SlopeScaledDepthBias = 0.0f; rastDesc.DepthClipEnable = true; rastDesc.ScissorEnable = false; rastDesc.MultisampleEnable = false; rastDesc.AntialiasedLineEnable = false; Program::GetInstance()->GetD3DDevice()->CreateRasterizerState(&rastDesc, & m_rasterizerState); Program::GetInstance()->GetD3DDeviceContext()->RSSetState(m_rasterizerState);   Or the projection Matrix's final two values.   Matrix view = XMMatrixIdentity( ); Matrix projection = XMMatrixOrthographicOffCenterLH( 0.0f, 1000.0f, 0.0f, 1000.0f, 0.0f, 2.0f ); m_viewProj = XMMatrixMultiply( view, projection ); But I thought what I had wrote meant anything between 0.0 and 2.0 in world space would be visible.
  3. Hi all.   I just wanted to do a simple 2D game using directx11 (as I have been using direct 9 mostly).   I set up a 2D sprite class which was to render 2 triangles making a square and giving it a texture to represent the sprite.   Now all this compiles but I cannot get the sprite visible on screen.     The directx breakdown on PIX is attached. It's showing that all my vertices are correct and the vertex shader is doing what it's supposed to.   [attachment=15626:PIX.png]     So can only assume it is something to do with the rasterizer or output merger as I have tried just outputting a colour from my pixel shader instead of a texture sample.   My rasterizer state is   D3D11_RASTERIZER_DESC rastDesc; ZeroMemory( &rastDesc, sizeof( rastDesc ) ); rastDesc.FillMode = D3D11_FILL_SOLID ; rastDesc.CullMode = D3D11_CULL_NONE ; rastDesc.FrontCounterClockwise = false; rastDesc.DepthBias = 0.0f; rastDesc. DepthBiasClamp = 0.0f; rastDesc. SlopeScaledDepthBias = 0.0f; rastDesc.DepthClipEnable = true; rastDesc.ScissorEnable = false; rastDesc.MultisampleEnable = false; rastDesc.AntialiasedLineEnable = false; Program::GetInstance()->GetD3DDevice()->CreateRasterizerState(&rastDesc, & m_rasterizerState); Program::GetInstance()->GetD3DDeviceContext()->RSSetState(m_rasterizerState); My blender state is   D3D11_BLEND_DESC blendDesc; ZeroMemory( &blendDesc, sizeof( blendDesc ) ); blendDesc.RenderTarget[0].BlendEnable = TRUE; blendDesc.RenderTarget[0].BlendOp = D3D11_BLEND_OP_ADD; blendDesc.RenderTarget[0].SrcBlend = D3D11_BLEND_SRC_ALPHA; blendDesc.RenderTarget[0].DestBlend = D3D11_BLEND_ONE; blendDesc.RenderTarget[0].BlendOpAlpha = D3D11_BLEND_OP_ADD; blendDesc.RenderTarget[0].SrcBlendAlpha = D3D11_BLEND_SRC1_ALPHA; blendDesc.RenderTarget[0].DestBlendAlpha = D3D11_BLEND_INV_SRC1_ALPHA; blendDesc.RenderTarget[0].RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_ALL; float blendFactor[4] = { 0.0f, 0.0f, 0.0f, 0.0f }; Program::GetInstance()->GetD3DDevice()->CreateBlendState( &blendDesc, &alphaBlendState_ ); Program::GetInstance()->GetD3DDeviceContext()->OMSetBlendState( alphaBlendState_, &blendFactor, 0xFFFFFFFF ); Im using this projection matrix also as it's 2D.   Matrix projection = XMMatrixOrthographicOffCenterLH( 0.0f, 1000.0f, 0.0f, 1000.0f, 0.0f, 2.0f );    I am all out of ideas as to what the issue could be.   Thanks    
  4. Well i create a matrix using MatrixScaling(x,y,z)  SCALING   then have world as    (SCALING * TRANSFORMATION)   so the only problem I could think of is that the w value of a normal is not scaled. But that confuses me a little.
  5. Worked straight away. Case closed. Do these forums have like a topic finished option or anything.
  6. Well the sphere is grey when I transform the normals but multicoloured (as expected) when I just render the normal as it came in the model. So it's something to do with the transformation for sure. I am going to try and use the transpose inverse matrix of the world matrix instead, even though I just thought that was necessary with non-uniform scaling.
  7. Ok good idea. I'll give it a go. thanks
  8. Hi everyone. I have a sphere model in .x format with normals, prooven by opening the directX viewer. I have loaded the model into a D3D9 Mesh using just D3DXLoadMeshFromX() and have also tried to clone the mesh with a defined vertex declaration. But I cant get my diffuse lighting to work.       //my models only need Normals, UV and position. D3DVERTEXELEMENT9 tempElem[4]= { {0, 0, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0}, {0, 12, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_NORMAL , 0}, {0, 24, D3DDECLTYPE_FLOAT2, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 0}, D3DDECL_END() };   meshSys->CloneMesh(D3DXMESH_SYSTEMMEM,tempElem,m_D3DDevice,&m_mesh);     /******************************************************STRUCTURES**********************/ struct VS_INPUT { float4 Position : POSITION; float3 Normal : NORMAL; float2 UV : TEXCOORD0; }; struct VS_OUTPUT { float4 Position : POSITION; float2 UV : TEXCOORD0; float4 WorldPos : TEXCOORD1; float4 WorldNormal : TEXCOORD2; }; /****************************************************************************************/ /****************************************************SHADERS**********************/ VS_OUTPUT vs_default(VS_INPUT In) { VS_OUTPUT Out; //TRANSFORM VERTEX INFO Out.Position = mul( In.Position, gWVP ); Out.WorldPos = mul( In.Position, gWorldMatrix); Out.WorldNormal = mul(float4(In.Normal,0.0), gWorldMatrix); Out.UV = In.UV; return Out; } float4 ps_default(VS_OUTPUT In) : COLOR0 { ////////////////////////////////////////////// //CALCULATE LIGHT AMOUNT ////////////////////////////////////////////// //PIXEL TO LIGHT POSITION float3 PixelToLightVec = gLightPosition - In.WorldPos; //COMPUTE SQUARED DISTANCE float LenSq = dot( PixelToLightVec, PixelToLightVec ); PixelToLightVec = normalize(gLightPosition - In.WorldPos); float3 WorldNormal = normalize(In.WorldNormal.xyz); float3 LightAmount = gRange * saturate( dot( WorldNormal, PixelToLightVec ) ) * gLightColour *(gLightFalloff * gLightFalloff) / LenSq; float3 reflection = normalize((PixelToLightVec + gCameraPos) * 0.5); float3 LightSpecular = LightAmount * pow( max( dot(WorldNormal, reflection), 0.0000001 ), gSpecularPower ); ////////////////////////////////////////////// //CALCULATE DIRECTIONAL LIGHT AMOUNT ///////////////////////////////////////////// float3 DirectionalLight = gDirectionalLightColour * max( dot(WorldNormal, normalize(gDirectionalLight)), 0.0 ); reflection = normalize((gDirectionalLight + gCameraPos) * 0.5); float3 DirectionalSpecular = DirectionalLight * pow( max( dot(WorldNormal, reflection), 0.0000001 ), gSpecularPower ); ////////////////////////////////////////////// //TOTAL LIGHT = RETURNED COLOUR ////////////////////////////////////////////// float3 DiffuseLight = gAmbientColour + DirectionalLight + LightAmount; float3 SpecularLight = DirectionalSpecular + LightSpecular; float4 colour = (tex2D(DiffuseSampler, In.UV) * float4(DiffuseLight,1.0f)) + (gSpecularMaterial * float4(SpecularLight,1.0f)); return colour; } /**************************************************************************************/    There is the shader which I use. The lights are in world space and so I transform the normal and the position into world space. I am only rotating and translating the mesh so I thought I didnt require the transpose inverse matrix.  The problem is the sphere appears with ambient lighting only. I have entered a vector where 'WorldNormal' is, manually in the DP calculations and this can brighten the sphere so the problem must be with the normals passed in from the mesh or the transformation from Vertex Shader, not the lights or their calculations. Any ideas.   Thank you