Jump to content
  • Advertisement


  • Content Count

  • Joined

  • Last visited

Community Reputation

374 Neutral

About DgekGD

  • Rank
  1. Create separate classes for Shaders, Vertex Buffers etc.     For example i have the following class for vertex shader: class VertexShaderDX11 { protected: ID3D11VertexShader* m_pShader; InputAssemblerStateDX11* m_pState; public: VertexShaderDX11() { m_pState = new InputAssemblerStateDX11(); } ~VertexShaderDX11() { SAFE_RELEASE(m_pShader); SAFE_DELETE(m_pState); } ABOOL Create(BlobDX11 & shaderbuffer, INPUT_LAYOUT* layout, AUINT8 num, AUINT16 topology); AVOID Set() const; };   Note that it has pointer to the InputAssembler structure (it stores information about Input Assembler stage as for vertex shader you have to have right input topology).     In your sprite class you can reference shader for rendering and bind it to the pipeline before you render your sprite. Don't recompile shader all the time! Compile it one time and then just have a pointer to an object of your shader class which stores compiled shader.  Multiple sprites can use single shader for rendering just having pointer to it.
  2. DgekGD

    Deactivate a rigid body in Bullet

    I guess, you can use btRigidBody::setFlags method and set proper flags to configure behavior for your rigid body. Here is a list of all flags(line 117). 
  3. DgekGD

    Missile Pathing for 2D game

     Okay. Imagine you missile is going to the right (1, 0) - x and y coordinates accordingly. Currently it has position (200, 200). It's target lies in the point (300, 200), so target angle between missile direction and X axis is zero(targetOrientation = 0) and current angle of missile direction and X axis is zero(missile.orientation = 0)    Next frame your target moves to the position (200, 100), probably you won't have such a huge jumps in just a single frame, but i try to show you an idea. So your desired direction for a missile is (0,1) now which make angle of Pi/2 (90 degrees) with X axis. So you start to rotate your missile. Your maxAngularAcceleration value should be already is defined for each missile, so you increase its rotation :missile.rotation += missile.angularAcceleration * time  and than orientation (or angle between direction and X axis) :  missile.orientation += missile.rotation * time.    Than you use current angle to get movement direction. Start with creating Z axis rotation matrix (Z axis goes into your screen or out of your screen) and multiply vector (1, 0) with this matrix. As a result you will get rotated vector. That you can multiply it by speed scalar. You can read this small tutorial if you still have some questions regarding retrieving direction from current angle.    I hope it helps ;) Let me know if you still have some questions :)
  4. DgekGD

    Missile Pathing for 2D game

    Yep, atan2 function will work, perhaps you have to swap deltaX and deltaY arguments to get an angle from X axis.      Orientation - is a desired angle or current angle ( position for movement )   Rotation - is a speed orientation is changed (velocity for movement )   angularAcceleration - is a speed rotation is changed (acceleration for movement)    I hope everything is clear now:)
  5. DgekGD

    Missile Pathing for 2D game

    Basically, when your missile updates it's target position(it's not necessary to do every single frame) find target angle of rotation, so that missile points in right direction (with the help of atan2 function). And than update missile rotation as you update its position. Here is an example: missile.angularAcceleration = targetOrientation - missile.orientation; if (missile.angularAcceleration < 0) missile.angularAcceleration = -maxAngularAcceleration; else missile.angularAcceleration = maxAngularAcceleration; missile.orientation += missile.rotation * time; missile.rotation += missile.angularAcceleration * time; if (missile.rotation > maxRotation) missile.rotation = maxRotation; It's far not ideal implementation, just to give you an idea. Actually, you can make your rotation even smoother with the use of slow down radius for example(when angle to rotate remains small it starts to slow down a little bit). Also, maybe you fill need some radius of satisfaction(it's doubtful that your object will rotate EXACTLY at the angle you need and it will end up in flickering).
  6. DgekGD

    Debug pixel shader

    Actually, there are a lot of things that can go wrong in your code and i don't see any explicit error here. In pixel shader try return float4(1.0f, 1.0f, 1.0f, 1.0f); If you see your object white, probably problem lies in binding texture resource (DefaultTexture in your shader code). If still nothing appears, check that you update constant buffers with matrices correctly for the vertex shader and bind right render target for your pixel shader. Or maybe you placed vertices in the wrong order and rasterizer culls your geometry, try D3D11_CULL_NONE.
  7. DgekGD

    BulletPhysics Question

    Hi! When using Bullet Physics in your game you implement some BulletInternalTickCallback( btDynamicsWorld * const world, btScalar const timeStep ) method bullet uses as internal callback. dynamicsWorld->setInternalTickCallback( BulletInternalTickCallback ); dynamicsWorld declared as btDynamicsWorld* In this method you want to make loop like that: // look at all contacts btDispatcher * const pDispatcher = world->getDispatcher(); for ( int manifoldInd=0; manifoldIdx<pDispatcher->getNumManifolds(); manifoldInd++ ) { //get manifold btPersistentManifold const * const pManifold = pDispatcher->getManifoldByIndexInternal( manifoldInd ); assert( manifold ); // get colliding bodies btRigidBody const * const pBody0 = static_cast<btRigidBody const *>(pManifold->getBody0()); btRigidBody const * const pBody1 = static_cast<btRigidBody const *>(pManifold->getBody1()); ... So you acquired pointers to your colliding bodies. The next thing you want to do is: make an external list of colliding pairs of objects and update it every frame. So you can compare if the pair of colliding objects is already in the list, so you have continuous contact, otherwise they are just collided. Other data about collision you can get from btPersistentManifold object. For keeping material data of the object you can create external wrapper for every physics body like: struct PhysicsBody { btRigidBody const * const pBody; enum Material m_Mat; };
  8. DgekGD

    Physics engine book

    Usually every physics engine has full documentation how to use it. If you want to really know how physics engines work I would recommend this book.
  9. DgekGD

    Problem Loading pixel Shader

    I cannot see any problem right now, but you can check exact value of 'r' after executing this function. It contains value that can point you to an error. Take a look here.
  10. DgekGD

    DirectX 9.0a SDK

    You can download sdk from here . It includes everything you need for directx programming(9, 10, 11);
  11. DgekGD

    Calculating In-Game map positions

    One of the approaches is to make two more render passes for your scene. The first new one would render to texture everything from the camera which is located in the sky. In the second new render pass you render this texture to the place on the screen you want.
  12. Indeed, it would have helped to find error in my program faster. Now, i create device with debug layer enabled in debug mode;) I appreciate your explanation. By the way, i managed to rapair my shader to work correctly. It suffered the same problem, I didn't unbound first texture's RTV before binding resource as SRV in the Compute Shader
  13. Setting NULL UAV for the place of UAV of my texture helped! Before that, i tried to set the compute shader itself to NULL, it didn't help me. My gaussian filter still does't worked corretly, but I think I can handle it as the main problem solved:) Thanks for your help!
  14. Yep, I heard that to read and write simultaneously I need to cast format to D3D11_FORMAT_R32_UINT for UAV... But I don't read and write to the resource at the same time. 1)For the first render pass i don't use the second texture at all. 2)Than in Compute Shader I use the first texture for reading (shader resource view) and the second one for writing (unordered access view). 3)Final pass: I use the second texture for reading as shader resource view Or maybe i misunderstand something ...
  15. Hi, guys! I'm trying to implement Gaussian Filter using compute shader. I have two texture resources. Firstly, I render entire scene to the first texture. Then I apply gaussian filter for this texture using compute shader( which writes results to the second texture). And finally, i use shader resource view of the second texture in final render pass (pixel shader just executes texture.Sample). But as result i just get black screen:( Initialize textures and their resource views: //Texture used for rendering ID3D11Texture2D* renderTargetTexture; ID3D11RenderTargetView* renderTargetTextureView; ID3D11ShaderResourceView* shaderRenderTextureView; //texture to which result of gaussian filter will be applied ID3D11Texture2D* gaussTexture; ID3D11UnorderedAccessView* gaussTextureUAView; ID3D11ShaderResourceView* gaussTextureSRView; ID3D11RenderTargetView* gaussTextureRTView; /***** Create Texture Render Target View *****/ D3D11_TEXTURE2D_DESC textureDesc; D3D11_RENDER_TARGET_VIEW_DESC renderTargetViewDesc; D3D11_SHADER_RESOURCE_VIEW_DESC shaderResourceViewDesc; //create render texture ZeroMemory(&amp;textureDesc, sizeof(D3D11_TEXTURE2D_DESC)); textureDesc.Width = textureWidth; textureDesc.Height = textureHeight; textureDesc.MipLevels = 1; textureDesc.ArraySize = 1; textureDesc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT; textureDesc.SampleDesc.Count = 1; textureDesc.Usage = D3D11_USAGE_DEFAULT; textureDesc.BindFlags = D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE; textureDesc.CPUAccessFlags = 0; textureDesc.MiscFlags = 0; hr = d3d11Device->CreateTexture2D(&amp;textureDesc, NULL, &amp;renderTargetTexture); if (FAILED(hr)) return false; //create render target view renderTargetViewDesc.Format = textureDesc.Format; renderTargetViewDesc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2D; renderTargetViewDesc.Texture2D.MipSlice = 0; hr = d3d11Device->CreateRenderTargetView(renderTargetTexture, &amp;renderTargetViewDesc, &amp;renderTargetTextureView); if (FAILED(hr)) return false; //create shader resource view shaderResourceViewDesc.Format = textureDesc.Format; shaderResourceViewDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D; shaderResourceViewDesc.Texture2D.MostDetailedMip = 0; shaderResourceViewDesc.Texture2D.MipLevels = 1; hr = d3d11Device->CreateShaderResourceView(renderTargetTexture, &amp;shaderResourceViewDesc, &amp;shaderRenderTextureView); if (FAILED(hr)) return false; /*** GAUSSIAN TEXTURE ***/ D3D11_TEXTURE2D_DESC gtDesc; D3D11_SHADER_RESOURCE_VIEW_DESC srView; D3D11_UNORDERED_ACCESS_VIEW_DESC uaDesc; D3D11_RENDER_TARGET_VIEW_DESC rtDesc; //create gauss texture ZeroMemory(&amp;gtDesc, sizeof(gtDesc)); gtDesc.Width = textureWidth; gtDesc.Height = textureHeight; gtDesc.MipLevels = 1; gtDesc.ArraySize = 1; gtDesc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT; gtDesc.SampleDesc.Count = 1; gtDesc.Usage = D3D11_USAGE_DEFAULT; gtDesc.BindFlags = D3D11_BIND_UNORDERED_ACCESS | D3D11_BIND_SHADER_RESOURCE | D3D11_BIND_RENDER_TARGET; gtDesc.CPUAccessFlags = 0; gtDesc.MiscFlags = 0; hr = d3d11Device->CreateTexture2D(&amp;gtDesc, NULL, &amp;gaussTexture); if (FAILED(hr)) return false; //create render target view rtDesc.Format = gtDesc.Format; rtDesc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2D; rtDesc.Texture2D.MipSlice = 0; hr = d3d11Device->CreateRenderTargetView(gaussTexture, &amp;rtDesc, &amp;gaussTextureRTView); if (FAILED(hr)) return false; //create shader resource view srView.Format = gtDesc.Format; srView.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D; srView.Texture2D.MostDetailedMip = 0; srView.Texture2D.MipLevels = 1; hr = d3d11Device->CreateShaderResourceView(gaussTexture, &amp;srView, &amp;gaussTextureSRView); if (FAILED(hr)) return false; //create unordered access view uaDesc.Format = gtDesc.Format; uaDesc.ViewDimension = D3D11_UAV_DIMENSION_TEXTURE2D; uaDesc.Texture2D.MipSlice = 0; hr = d3d11Device->CreateUnorderedAccessView(gaussTexture, &amp;uaDesc, &amp;gaussTextureUAView); if (FAILED(hr)) return false; Now render entire scene to the first texture: float bgTexColor[4] = {(1.0f, 0.0f, 0.0f, 1.0f)}; //default color is red! d3d11DevCon->VSSetShader(VS, 0, 0); d3d11DevCon->PSSetShader(PS, 0, 0); d3d11DevCon->RSSetViewports(1, &amp;texViewport); d3d11DevCon->OMSetRenderTargets(1, &amp;renderTargetTextureView, NULL); d3d11DevCon->ClearRenderTargetView(renderTargetTextureView, bgTexColor); d3d11DevCon->Draw(36, 0); //draw the cube Apply gaussian filter: d3d11DevCon->CSSetShader(CS, 0, 0); d3d11DevCon->CSSetShaderResources(0, 1, &amp;shaderRenderTextureView); //bind out rendered scene as shader resource view d3d11DevCon->CSSetUnorderedAccessViews(0, 1, &amp;gaussTextureUAView, NULL); //unordered access for resulting texture! UINT x = (UINT)( ceil( textureWidth / 32.0f ) ); UINT y = (UINT)( ceil( textureHeight / 32.0f ) ); d3d11DevCon->Dispatch(x, y, 1); Finally, render our final texture to the screen (in pixel shader i just use texture.Sample) : d3d11DevCon->VSSetShader(textureVS, 0, 0); d3d11DevCon->PSSetShader(texturePS, 0, 0); d3d11DevCon->RSSetViewports(1, &amp;viewport); d3d11DevCon->OMSetRenderTargets(1, &amp;renderTargetView, NULL); //back buffer now is render target d3d11DevCon->PSSetShaderResources(0, 1, &amp;gaussTextureSRView); d3d11DevCon->Draw(6, 0); Oh, by the way, here is my compute shader: //Resources Texture2D<float4> InputTex : register( t0 ); RWTexture2D<float4> OutputTex : register( u0 ); //filter kernel coefficients static const float kernel[7][7] = { 0.000904706, 0.003157733, 0.00668492, 0.008583607, 0.00668492, 0.003157733, 0.000904706, 0.003157733, 0.01102157, 0.023332663, 0.029959733, 0.023332663, 0.01102157, 0.003157733, 0.00668492, 0.023332663, 0.049395249, 0.063424755, 0.049395249, 0.023332663, 0.00668492, 0.008583607, 0.029959733, 0.063424755, 0.081438997, 0.063424755, 0.029959733, 0.008583607, 0.00668492, 0.023332663, 0.049395249, 0.063424755, 0.049395249, 0.023332663, 0.00668492, 0.003157733, 0.01102157, 0.023332663, 0.029959733, 0.023332663, 0.01102157, 0.003157733, 0.000904706, 0.003157733, 0.00668492, 0.008583607, 0.00668492, 0.003157733, 0.000904706 }; [numthreads(32, 32, 1)] void CS(uint3 DispatchThreadId : SV_DispatchThreadID) { //get coordinates of top left corner int3 textureCoords = DispatchThreadId - int3(3, 3, 0); //initialize final color float4 finalColor = (float4)0.0f; //loop through filter kernel getting final color for (int i = 0; i < 7; i++) for (int j = 0; j < 7; j++) finalColor += InputTex.Load(textureCoords + int3(i, j, 0) ) * kernel[j]; //assign new color value to the output image OutputTex[DispatchThreadId.xy] = finalColor; //OutputTex[DispatchThreadId.xy] = float4(1.0f, 1.0f, 1.0f, 1.0f); } Why I think that the problem is with Unordered Access View? I tried to clear gaussTexture with red color after the compute shader has executed: float bgTexColor[4] = {(1.0f, 0.0f, 0.0f, 1.0f)}; d3d11DevCon->ClearRenderTargetView(gaussTextureRTView, bgTexColor); And i still get the black screen. But if I comment binding the unordered access to the compute shader I get what I should get - the red screen: //d3d11DevCon->CSSetUnorderedAccessViews(0, 1, &amp;gaussTextureUAView, NULL); //unordered access for resulting texture! I'm pretty sure that compute shader itself works correctly as commenting Dispatch call without commenting CSSetUnorderedAccessViews still suffers the problem and I get only black screen. Where the problem can be? I would appreciate any help! Thanks in advance!
  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!