kgstation

Member
  • Content count

    66
  • Joined

  • Last visited

Community Reputation

205 Neutral

About kgstation

  • Rank
    Member
  1. Here is a class that load D2DBitmap and draw it. class YHMSprite { public: YHMSprite(const std::shared_ptr<DX::DeviceResources>& deviceResources); //YHMSprite(const std::shared_ptr<DX::DeviceResources>& deviceResources, LPCWSTR fileName); //YHMSprite(const std::shared_ptr<DX::DeviceResources>& deviceResources, Platform::String^ fileName); ~YHMSprite(); void LoadResource(LPCWSTR fileName); void Draw(float scale, float x, float y); void Draw(float scaleX, float scaleY, float x, float y); void Draw(float scaleX, float scaleY, float x, float y, float opacity); D2D1_SIZE_F GetBitmapSize(); private: std::shared_ptr<DX::DeviceResources> mDeviceResources; bool mIsResourceLoaded; ID2D1DrawingStateBlock *mStateBlock; ID2D1Bitmap *mBitmap; D2D1_SIZE_F mBitmapSize; }; And I create these resource YHMSprite::YHMSprite(const std::shared_ptr<DX::DeviceResources>& deviceResources) { mIsResourceLoaded = false; mDeviceResources = deviceResources; mDeviceResources->GetD2DFactory()->CreateDrawingStateBlock(&mStateBlock); } void YHMSprite::LoadResource(LPCWSTR fileName) { ComPtr<IWICBitmapDecoder> wicBitmapDecoder; mDeviceResources->GetWicImagingFactory()->CreateDecoderFromFilename(fileName, nullptr, GENERIC_READ, WICDecodeMetadataCacheOnDemand, &wicBitmapDecoder); ComPtr<IWICBitmapFrameDecode> wicBitmapFrame; wicBitmapDecoder->GetFrame(0, &wicBitmapFrame); ComPtr<IWICFormatConverter> wicFormatConverter; mDeviceResources->GetWicImagingFactory()->CreateFormatConverter(&wicFormatConverter); wicFormatConverter->Initialize(wicBitmapFrame.Get(), GUID_WICPixelFormat32bppPBGRA, WICBitmapDitherTypeNone, nullptr, 0.0, WICBitmapPaletteTypeCustom); double DpiX = 72.0f, DpiY = 72.0f; wicFormatConverter->GetResolution(&DpiX, &DpiY); mDeviceResources->GetD2DDeviceContext()->CreateBitmapFromWicBitmap(wicFormatConverter.Get(), BitmapProperties(PixelFormat(DXGI_FORMAT_B8G8R8A8_UNORM, D2D1_ALPHA_MODE_PREMULTIPLIED), static_cast<float>(DpiX), static_cast<float>(DpiY)), &mBitmap); mBitmapSize = mBitmap->GetSize(); mIsResourceLoaded = true; } In my code, I release these resource using this destruction function YHMSprite::~YHMSprite() { mBitmap->Release(); mStateBlock->Release(); }   I release my resource like this: YHMSprite* test = new YHMSprite(....); delete test; But it doesn't release test completed! Thanks.
  2. Question about post-processing

    Thanks for your reply and sorry for my poor english. My problem is that a glowed object may be sounded with another without glowed object.In my screen shot,I rendered one object two time, one with glow effect and one not, and the right result should be the  glowed object sounded by the without-glowed object, but as you can see, the glowed effect covered the without-glowed object,I don't know how to make it.
  3. I'm working for a post-processing effect for a long time. I use multi rendertarget to achieve this effect. But I met a problem. As the screen shot show,I rendered object two times, one with glow effect and one not, they are in same position,But the glow effect is just a 2D image.So the effect become unreal,just like a 2D image cover in a 3D scene. I want this effect looked like a 3D effect. How do I fixed it?
  4.   I have a scene and several people in my scene. People can release some skills. I want the post processing effect only work with skills!
  5. I'm using the 3rd way currently.Could you give me more detail?I do I mix these two rendertarget?
  6. I followed D3D Post Processing sample in windows 8.1. And I have successfully rendered my object with post processing effect. But now I met a problem.I have many objects to render.I want only a part of objects rendered with post processing effect.I know this problem is about rendertarget.But I don't know how to deal with it. Following is my code: void D3DPostProcessing::DrawWithoutPostProcessing() { m_d3dContext->OMSetRenderTargets(1, m_d3dRenderTargetView.GetAddressOf(), m_d3dDepthStencilView.Get()); const float clearColor[4] = { 0.071f, 0.040f, 0.561f, 1.0f }; m_d3dContext->ClearRenderTargetView(m_d3dRenderTargetView.Get(), clearColor); m_d3dContext->ClearDepthStencilView(m_d3dDepthStencilView.Get(), D3D11_CLEAR_DEPTH, 1.0f, 0); m_d3dContext->IASetInputLayout(m_inputLayout.Get()); unsigned int stride = sizeof(VertexPNTTBI); unsigned int offset = 0; m_d3dContext->IASetVertexBuffers(0, 1, mYHMMesh.Geometry[0].VertexBuffer.GetAddressOf(), &stride, &offset); m_d3dContext->IASetIndexBuffer(mYHMMesh.Geometry[0].IndexBuffer.Get(), DXGI_FORMAT_R16_UINT, 0); m_d3dContext->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST); m_d3dContext->VSSetShader(m_vertexShader.Get(), nullptr, 0); m_d3dContext->VSSetConstantBuffers(0, 1, m_constantBuffer.GetAddressOf()); // set the pixel shader stage state m_d3dContext->PSSetShader(m_pixelShader.Get(), nullptr, 0); m_d3dContext->PSSetShaderResources(0, 1, mYHMMesh.Geometry[0].textureSVR.GetAddressOf()); m_d3dContext->PSSetSamplers(0, 1, m_sampler.GetAddressOf()); m_d3dContext->DrawIndexed(mYHMMesh.Geometry[0].IndexCount, 0, 0); } void D3DPostProcessing::DrawPostProcessing() { m_d3dContext->OMSetRenderTargets(1, m_intermediateTextureRenderTargetView.GetAddressOf(), m_d3dDepthStencilView.Get()); const float clearColor[4] = { 0.071f, 0.040f, 0.561f, 1.0f }; m_d3dContext->ClearRenderTargetView(m_intermediateTextureRenderTargetView.Get(), clearColor); m_d3dContext->ClearDepthStencilView(m_d3dDepthStencilView.Get(), D3D11_CLEAR_DEPTH, 1.0f, 0); m_d3dContext->IASetInputLayout(m_inputLayout.Get()); unsigned int stride = sizeof(VertexPNTTBI); unsigned int offset = 0; m_d3dContext->IASetVertexBuffers(0, 1, mYHMMesh.Geometry[0].VertexBuffer.GetAddressOf(), &stride, &offset); m_d3dContext->IASetIndexBuffer(mYHMMesh.Geometry[0].IndexBuffer.Get(), DXGI_FORMAT_R16_UINT, 0); m_d3dContext->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST); m_d3dContext->VSSetShader(m_vertexShader.Get(), nullptr, 0); m_d3dContext->VSSetConstantBuffers(0, 1, m_constantBuffer.GetAddressOf()); // set the pixel shader stage state m_d3dContext->PSSetShader(m_pixelShader.Get(), nullptr, 0); m_d3dContext->PSSetShaderResources(0, 1, mYHMMesh.Geometry[0].textureSVR.GetAddressOf()); m_d3dContext->PSSetSamplers(0, 1, m_sampler.GetAddressOf()); // Save the backbuffer viewport D3D11_VIEWPORT oldViewPort[1]; unsigned int numberOfViewPorts = 1; m_d3dContext->RSGetViewports(&numberOfViewPorts, oldViewPort); // Setup the viewport to match the Intermediate Render Target D3D11_VIEWPORT viewPort = { 0 }; viewPort.Width = static_cast<float>(m_intermediateRenderTargetWidth); viewPort.Height = static_cast<float>(m_intermediateRenderTargetHeight); viewPort.MinDepth = 0.0f; viewPort.MaxDepth = 1.0f; viewPort.TopLeftX = 0; viewPort.TopLeftY = 0; m_d3dContext->RSSetViewports(1, &viewPort); m_d3dContext->DrawIndexed(mYHMMesh.Geometry[0].IndexCount, 0, 0); // Restore the backbuffer viewport m_d3dContext->RSSetViewports(numberOfViewPorts, oldViewPort); BrightPassDownFilter(); RenderGlow(); CombineGlow(); } In my code, both object rendered with post processing effect.Before rendering a post processing effect, I want to render one object that without post processing effect. Any help would be appreciated.Thanks. And this is my full code[attachment=20537:FullCode.rar]
  7. Triggered in this line  mDeviceResources->GetD2DDeviceContext()->CreateBitmapFromWicBitmap(wicFormatConverter.Get(), BitmapProperties(PixelFormat(DXGI_FORMAT_B8G8R8A8_UNORM, D2D1_ALPHA_MODE_PREMULTIPLIED), static_cast<float>(DpiX), static_cast<float>(DpiY)), &mBitmap);
  8. I'm using create_async to load bitmap. This works fine under release mode, but failed in debug mode. Following is my code Concurrency::create_async([&]() { mBackGround = new YHMSprite(mDeviceResources, L"Textures\\Menu\\background.png"); }); YHMSprite::YHMSprite(shared_ptr<DX::DeviceResources> &deviceResources, LPCWSTR fileName) { mDeviceResources = deviceResources; ComPtr<IWICBitmapDecoder> wicBitmapDecoder; mDeviceResources->GetWicImagingFactory()->CreateDecoderFromFilename(fileName, nullptr, GENERIC_READ, WICDecodeMetadataCacheOnDemand, &wicBitmapDecoder); ComPtr<IWICBitmapFrameDecode> wicBitmapFrame; wicBitmapDecoder->GetFrame(0, &wicBitmapFrame); ComPtr<IWICFormatConverter> wicFormatConverter; mDeviceResources->GetWicImagingFactory()->CreateFormatConverter(&wicFormatConverter); wicFormatConverter->Initialize(wicBitmapFrame.Get(), GUID_WICPixelFormat32bppPBGRA, WICBitmapDitherTypeNone, nullptr, 0.0, WICBitmapPaletteTypeCustom); double DpiX = 96.0f, DpiY = 96.0f; wicFormatConverter->GetResolution(&DpiX, &DpiY); mDeviceResources->GetD2DDeviceContext()->CreateBitmapFromWicBitmap(wicFormatConverter.Get(), BitmapProperties(PixelFormat(DXGI_FORMAT_B8G8R8A8_UNORM, D2D1_ALPHA_MODE_PREMULTIPLIED), static_cast<float>(DpiX), static_cast<float>(DpiY)), &mBitmap); mBitmapSize = mBitmap->GetSize(); mDeviceResources->GetD2DFactory()->CreateDrawingStateBlock(&mStateBlock); } I don't know what's wrong with it. My program triggered a breakpoint under debug mode.   Any help would be appreciated!  
  9.   Damn. Apparently the SurfaceRT isn't even (necessarily) big endian so I guess that advice would never have worked!    I tested my program with other model files.And found that not every model have this issue.
  10. Thanks for your reply.And I have tried your method.But it's wrong.My bone animation is correct.Only the skinned mesh is incorrect.
  11. My program is a windows store DirectX app. Just like the topic title, my code work well with win32.But when I debug my demo with my Surface RT.Some vertex position wrong.Just like the photo below.  I have do some test about my program. This is my VertexShaderInput: struct VertexShaderInput { float3 pos : POSITION; float3 norm : NORMAL; float2 tex : TEXCOORD0; float4 Tangent : TANGENT; float4 Weights : WEIGHTS; uint4 BoneIndices : BONEINDICES; }; When I use only pos, norm, tex data(mesh with no skinned animation data).My mesh displayed correctly. So I thought the problem may be the BoneIndices,it's uint4 type in my HLSL code. For more detail info, I paste my full hlsl code: cbuffer SimpleConstantBuffer : register(b0) { matrix model; matrix view; matrix projection; matrix gBoneTransforms[59]; }; struct VertexShaderInput { float3 pos : POSITION; float3 norm : NORMAL; float2 tex : TEXCOORD0; float4 Tangent : TANGENT; float4 Weights : WEIGHTS; uint4 BoneIndices : BONEINDICES; }; struct PixelShaderInput { float4 pos : SV_POSITION; float3 norm : NORMAL; float2 tex : TEXCOORD0; }; PixelShaderInput SimpleVertexShader(VertexShaderInput input) { PixelShaderInput vertexShaderOutput; float weights[4] = { 0.0f, 0.0f, 0.0f, 0.0f }; weights[0] = input.Weights.x; weights[1] = input.Weights.y; weights[2] = input.Weights.z; weights[3] = input.Weights.w; float4 pos = float4(input.pos, 1.0f); float4 skinnedPos = float4(0.0f, 0.0f, 0.0f, 0.0f); float4 norm = float4(normalize(input.norm), 0.0f); float4 normFinal = float4(0.0f, 0.0f, 0.0f, 1.0f); for (int i = 0; i < 4; ++i) { skinnedPos += weights[i] * mul(pos, gBoneTransforms[input.BoneIndices[i]]); normFinal += weights[i] * mul(norm, gBoneTransforms[input.BoneIndices[i]]); } skinnedPos.w = 1.0f; pos = mul(skinnedPos, model); pos = mul(pos, view); pos = mul(pos, projection); norm = mul(normFinal, model); vertexShaderOutput.pos = pos; vertexShaderOutput.tex = input.tex; vertexShaderOutput.norm = normalize(normFinal.xyz); return vertexShaderOutput; }   And the vertex structure in my code is: struct VertexPNTTBI { XMFLOAT3 pos; XMFLOAT3 norm; XMFLOAT2 tex; XMFLOAT4 tan; XMFLOAT4 blendWeight; BYTE blendIndice[4]; }; And my D3D11_INPUT_ELEMENT_DESC is: const D3D11_INPUT_ELEMENT_DESC VertexLayoutDesc[] = { { "POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0 }, { "NORMAL", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 12, D3D11_INPUT_PER_VERTEX_DATA, 0 }, { "TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 24, D3D11_INPUT_PER_VERTEX_DATA, 0 }, { "TANGENT", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 32, D3D11_INPUT_PER_VERTEX_DATA, 0 }, { "WEIGHTS", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 48, D3D11_INPUT_PER_VERTEX_DATA, 0 }, { "BONEINDICES", 0, DXGI_FORMAT_R8G8B8A8_UINT, 0, 64, D3D11_INPUT_PER_VERTEX_DATA, 0 }, }; These code work well with my local machine(win32).But I don't known if there are somethine I must change between WIN32 and ARM. I have been working on this problem for 4 days. Any help would be appreciated!Thanks.
  12. AccessDenied problem in Surface RT

          Finally I found problem occurred when I set indexbuffer. context->IASetIndexBuffer(mYHMMesh.Geometry[i].IndexBuffer.Get(), DXGI_FORMAT_R32_UINT, 0); DXGI_FORMAT_R32_UINT doesn't work for windows rt, but DXGI_FORMAT_R16_SINT works with some vertex position wrong. However, DXGI_FORMAT_R16_SINT doesn't work for win32. My indice is UINT type. This is really confused me.
  13. AccessDenied problem in Surface RT

    Thanks for your reply.My app work fine with win32, it use directx sdk provided by visual studio 2013 in windows 8.And after i try some method, i found it could be problem about the shader.Or my own file. This is the screen shot below All mYHMMesh data is from my own file.But it works fine in win32. before drawing, I give all skin matrix to shader like this for (int i = 0; i < mYHMMesh.boneInfo.BoneCount; i++) { XMStoreFloat4x4(&mSkinnedConstantBufferData.boneTransform[i], XMMatrixTranspose(XMMatrixMultiply( XMLoadFloat4x4(&boneOffset[i]), XMLoadFloat4x4(&boneTransforms[i][frameCount % mYHMMesh.boneInfo.yhmBone[i].FrameCount])))); } and my constantbufferdata and corresbonding cbuffer structure is struct SkinnedCBufferData { XMFLOAT4X4 model; XMFLOAT4X4 view; XMFLOAT4X4 projection; XMFLOAT4X4 boneTransform[59]; }; cbuffer simpleConstantBuffer : register(b0) { matrix model; matrix view; matrix projection; float4x4 gBoneTransform[59]; }; Still, I don't know what's wrong with my code  
  14. I try to run my mesh viewer program in my surface rt, but failed. VISUAL STUDIO 2013 give me this exception. Can anyone tell me what's happening?My program work fine with local machine.   First-chance exception at 0x75288E8F in ChemicalWar.exe: Microsoft C++ exception: Platform::AccessDeniedException ^ at memory location 0x022CF428. HRESULT:0x80070005 Access Deny?   WinRT information: Access Deny.   Stack trace: [External Code] ChemicalWar.exe!DX::ThrowIfFailed(HRESULT hr) Line 12 ChemicalWar.exe!DX::DeviceResources::CreateWindowSizeDependentResources() Line 196 ChemicalWar.exe!DX::DeviceResources::HandleDeviceLost() Line 333 ChemicalWar.exe!DX::DeviceResources::Present() Line 361 ChemicalWar.exe!ChemicalWar::App::[Windows::ApplicationModel::Core::IFrameworkView]::Run() Line 110 [External Code]   If there is a handler for this exception, the program may be safely continued.
  15. All problem solved!Problem is my mul function...