Jump to content
  • Advertisement


  • Content Count

  • Joined

  • Last visited

Community Reputation

100 Neutral

About Cachinnus

  • Rank
  1. Thanks alot invalidPointer, that certainly clears up alot of confusion for me.
  2. I figured out my problems I think. My problems originated from the fact that I used MSAA on all my render textures, even though I didn't need it in most of them. Now, I have defined every render texture without MSAA, except for the one I render my main scene to. The second problem I had was with the ZBuffer. For anyone else having problems using a mixed set of render textures with and without MSAA, make sure the ZBuffer you are using matches your current render target in MSAA settings. I have now defined two ZBuffers, one for rendering with MSAA and one for everything else. Also make sure MSAA is disabled on your backbuffer, if you are rendering non-MSAA textures to it. As InvalidPointer pointed out, I also had to copy my main scene render texture to another texture without MSAA using ResolveSubresource(). Then I can draw the new texture using a full-screen quad to my backbuffer. I have one question though. Is there a way to render my MSAA-texture directly to my backbuffer? Or do I have to do convert it to a non-MSAA texture and then draw it as a full-screen quad as I do currently? Edit: Okay I can answer my own question again You can draw the MSAA texture directly to the backbuffer just fine. Just make sure you don't use linear filter or something if you are resizing the texture.
  3. Thanks for the reply. I'm not really sure about the correct method to apply msaa when dealing with textures etc. So basically, what I'd like to do is this: 1. Render the main scene to a full-resolution DXGI_FORMAT_R16G16B16A16_FLOAT-texture (with msaa enabled). 2. Render the volumetric light (that you see in my first post) to a small-resolution texture. MSAA is not really needed here. 3. Render the main scene to the backbuffer (maybe using a HDR/bloom effect later on), by rendering a full-screen quad and texture from step 1. 4. Render the small-resolution texture from step 2 to the backbuffer with a full-screen quad I've tried to extract what I think is the most relevant code here. Setting up the swap chain: // Get data on GPU's support of multisampling UINT qual_levels[ D3D11_MAX_MULTISAMPLE_SAMPLE_COUNT ] = {0}; for(int i = 1; i < D3D11_MAX_MULTISAMPLE_SAMPLE_COUNT; i++) { hr = dev->CheckMultisampleQualityLevels(DXGI_FORMAT_R8G8B8A8_UNORM, i, &qual_levels); if(!FAILED(hr) && qual_levels > 0) { settings.msaa_count = i; settings.msaa_quality = qual_levels-1; } } settings.msaa_count = 4; settings.msaa_quality = qual_levels[settings.msaa_count]-1; // create a struct to hold information about the swap chain DXGI_SWAP_CHAIN_DESC scd; ZeroMemory(&scd, sizeof(DXGI_SWAP_CHAIN_DESC)); scd.BufferCount = 1; // one back buffer scd.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM; // use 32-bit color scd.BufferDesc.Width = sys.screen_width; // set the back buffer width scd.BufferDesc.Height = sys.screen_height; // set the back buffer height scd.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT; // how swap chain is to be used scd.OutputWindow = hWnd; // the window to be used scd.SampleDesc.Count = settings.msaa_count; // how many multisamples scd.SampleDesc.Quality = settings.msaa_quality; scd.Windowed = TRUE; // windowed/full-screen mode scd.Flags = DXGI_SWAP_CHAIN_FLAG_ALLOW_MODE_SWITCH; // allow full-screen switching Setting up a rasterizer: // Apply custom rasterizer so we can be sure to get anti-aliasing D3D11_RASTERIZER_DESC rd; ZeroMemory(&rd, sizeof(D3D11_RASTERIZER_DESC)); rd.MultisampleEnable = ( settings.msaa_count > 1 ); rd.AntialiasedLineEnable = ( settings.msaa_count > 1 ); rd.FillMode = D3D11_FILL_SOLID; rd.CullMode = D3D11_CULL_BACK; rd.DepthClipEnable = true; hr = dev->CreateRasterizerState(&rd, &pRS); if( SUCCEEDED(hr)) devcon->RSSetState(pRS); Depth stencil texture: // create the depth stencil texture D3D11_TEXTURE2D_DESC texd; ZeroMemory(&texd, sizeof(texd)); texd.Width = sys.screen_width; texd.Height = sys.screen_height; texd.ArraySize = 1; texd.MipLevels = 1; texd.SampleDesc.Count = settings.msaa_count; texd.SampleDesc.Quality = settings.msaa_quality; texd.Format = DXGI_FORMAT_D24_UNORM_S8_UINT; texd.BindFlags = D3D11_BIND_DEPTH_STENCIL; ID3D11Texture2D *pDepthBuffer; hr = dev->CreateTexture2D(&texd, NULL, &pDepthBuffer); if(FAILED(hr)) return false; // create the depth stencil buffer D3D11_DEPTH_STENCIL_VIEW_DESC dsvd; ZeroMemory(&dsvd, sizeof(dsvd)); dsvd.Format = DXGI_FORMAT_D24_UNORM_S8_UINT; dsvd.ViewDimension = settings.msaa_count == 1 ? D3D11_DSV_DIMENSION_TEXTURE2D : D3D11_DSV_DIMENSION_TEXTURE2DMS; //D3D11_DSV_DIMENSION_TEXTURE2DMS; dsvd.Texture2D.MipSlice = 0; dev->CreateDepthStencilView(pDepthBuffer, &dsvd, &zbuffer); pDepthBuffer->Release(); // set the render target as the back buffer devcon->OMSetRenderTargets(1, &backbuffer, zbuffer); Here is the code used to setup all my render textures: I've tried turning off multi-sampling here, but then my game crashes on startup. So I guess there is something I should be doing differently to turn off msaa on individual textures. D3D11_TEXTURE2D_DESC textureDesc; HRESULT result; D3D11_RENDER_TARGET_VIEW_DESC renderTargetViewDesc; D3D11_SHADER_RESOURCE_VIEW_DESC shaderResourceViewDesc; // Initialize the render target texture description. ZeroMemory(&textureDesc, sizeof(textureDesc)); // Setup the render target texture description. textureDesc.Width = textureWidth; textureDesc.Height = textureHeight; textureDesc.MipLevels = 1; textureDesc.ArraySize = 1; textureDesc.Format = format; textureDesc.SampleDesc.Count = sys.device->settings.msaa_count; textureDesc.SampleDesc.Quality = sys.device->settings.msaa_quality; textureDesc.Usage = D3D11_USAGE_DEFAULT; textureDesc.BindFlags = D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE; textureDesc.CPUAccessFlags = 0; textureDesc.MiscFlags = 0; // Create the render target texture. result = sys.device->dev->CreateTexture2D(&textureDesc, NULL, &pRenderTargetTexture); if(FAILED(result)) { return false; } // Setup the description of the render target view. renderTargetViewDesc.Format = textureDesc.Format; renderTargetViewDesc.ViewDimension = sys.device->settings.msaa_count == 1 ? D3D11_RTV_DIMENSION_TEXTURE2D : D3D11_RTV_DIMENSION_TEXTURE2DMS; //D3D11_RTV_DIMENSION_TEXTURE2DMS; renderTargetViewDesc.Texture2D.MipSlice = 0; // Create the render target view. result = sys.device->dev->CreateRenderTargetView(pRenderTargetTexture, &renderTargetViewDesc, &pRenderTargetView); if(FAILED(result)) { return false; } // Setup the description of the shader resource view. shaderResourceViewDesc.Format = textureDesc.Format; shaderResourceViewDesc.ViewDimension = sys.device->settings.msaa_count == 1 ? D3D11_SRV_DIMENSION_TEXTURE2D : D3D11_SRV_DIMENSION_TEXTURE2DMS;// D3D11_SRV_DIMENSION_TEXTURE2DMS; shaderResourceViewDesc.Texture2D.MostDetailedMip = 0; shaderResourceViewDesc.Texture2D.MipLevels = 1; // Create the shader resource view. result = sys.device->dev->CreateShaderResourceView(pRenderTargetTexture, &shaderResourceViewDesc, &pShaderResourceView); if(FAILED(result)) { return false; } Here is an extract of my main graphics-draw loop. rt_xxxx are my render textures. // Render main 3d scene to texture rt_scene->SetRenderTarget(); rt_scene->ClearRenderTarget(0,0,0,0); setShader( SHADER_TYPE_MAIN ); shader_main->updateCbLightSource( matView, matProj ); ID3D11ShaderResourceView *srv = rt_light_shadowmap->GetShaderResourceView(); sys.device->devcon->PSSetShaderResources(1, 1, &srv); sys.renderScene(true); // Render volumetric light to small-resolution render texture rt_small_2->SetRenderTarget(); rt_small_2->ClearRenderTarget(0,0,0,0); setShader( SHADER_TYPE_VOL_LIGHTING ); sprite_light->Render(0, 0, 0 ); // The model of the light frustum shader_vol_lighting->render( 18, rt_light_shadowmap->GetShaderResourceView(), rt_depth_map->GetShaderResourceView()); // The shadow-map and depth-map are also just render textures, previously generated // Render full-screen quads to backbuffer sys.device->setBackBufferRenderTarget(); sys.device->turnOffAlphaBlending(); sys.device->changeZbufferState(false); setShader( SHADER_TYPE_TEXTURE ); updateTextureCB( sys.screen_width , sys.screen_height ); full_window->Render(0, 0, rt_scene->GetShaderResourceView() ); shader_texture->render( sizeof(WORD)*6); // Vol. light sys.device->turnOffAlphaBlending(); full_window->Render(0, 0, rt_small_2->GetShaderResourceView() ); shader_texture->render( sizeof(WORD)*6); // Present swapchain->Present(0, 0); If I understand it correctly, I should define my rt_scene render texture with msaa and just draw it like I do currently. On the other hand, my volumetric light render texture (here called rt_small2) should be defined without msaa. Then, I can resize it and hopefully not get the pixelation. Is it generally bad to resize textures with msaa?
  4. Hi. So I am trying to upsample a texture to a full-screen quad. By turning on MSAA, the texture becomes pixelated, while everything seems perfect with no anti-aliasing. This sample image sums up my problem pretty well I think: I am using DirectX 11 with pixel/vertex shader 4.0, if it matters. I have tried searching for a solution, but the only relevant things I could find was about the half-pixel offset needed on DirectX 9, which shouldn't be a problem on DirectX 10+. So my question is, does anyone recognise this problem? Any form of help is appreciated. Thanks in advance.
  5. Cachinnus

    2d car with simple suspension physics

    Thanks for the answer, it's been very helpful.
  6. Cachinnus

    2d car with simple suspension physics

    Thanks for the help. You are probably right that I'm not obeying Newton's third law. So if I understand you correct, I should not add a collision force/impulse to keep the car from the ground. Rather, I should just compress the spring. Next, this will result in the two masses connected to the spring each getting a force directed from each other, which should be equal in magnitude. Hmm, or perhaps not? The spring can store potential energy (like gravity) so it doesn't completely obey newton's third law. At least on some level of abstraction, if I understand it correct. Some questions: The wheel will get the most acceleration because it is the lightest of the two bodies, so it will probably collide again. I suspect this will result in jittery motion. Maybe I should do the same calculations several times each frame to reduce this?With the springs having only one freedom of movement, the spring length will in some cases have to become infinitely long to get out of the ground. That is when the car is colliding with a surface perpendicular to the spring axis. What is the best way to deal with this? I am thinking in the lines of having an angular spring as well.When compressing the spring, this will add energy to it. And since this energy is not based on the mechanical energy of the car, isn't there a danger for unstable and somewhat random motions? Proposed solution: Take the desired absorbed energy of the car, and use the spring constant to calculate the distance based on this energy. Artificially move rest of the car out of the collision area. Bonus: This will also avoid the problem with the infinite spring length. What do you think about this solution? Thanks for that demo h4tt3n, I had fun with it I will take a deeper look at that code.
  7. Cachinnus

    2d car with simple suspension physics

    That was a very good tip, my code is definitely cleaner and more intuitive now. I still have one weird behaviour though. The spring force acting on the car body creates a torque as expected, but because there is no opposite directed force, this force creates a linear acceleration as well. This makes the car accelerate to the right or left if it has a rotation and only one wheel is connected to the ground. The suspension feels perfect if I just cheat and add another force such that I only get a net torque and zero net force, and add a small force normal to the ground such that it counteracts the fall. But I would like to understand what I'm doing wrong. Thanks again.
  8. Hi. My first post here I have recently started writing a simple game engine from scratch, mainly for the learning experience. The most difficult I've had yet is with the physics, and I feel I need some help from more experienced people. The physics in question is for a side-scrolling 2d car game. The collisions seems to work out pretty good, but now I'm trying to implement suspension on the wheels of the car which has proven to be difficult. The suspension is very simple. On each wheel (of the two) there is a spring-damper-mass with one degree of freedom in the direction as seen as the red arrow in the illustration. Take a look at the illustration. Without the suspension, things are pretty simple because we just apply the impulse normal to the collision surface, and get some new linear and angular velocities. But with the suspension, I imagine some of this impulse is just added as spring/wheel velocity. And here I'm getting confused on how this changes the impulse on the car body. Here is what I currently do when a collision is detected: Calculate the normal impulse as if the suspension was not there (unelastic collision)Set new spring velocity such that it is the same as the velocity in the collision point (in the direction of it's freedom)Subtract some of the spring's added velocity from the normal impulseApply normal impulse (from 1 & 3) to car bodyUpdate spring velocity and position, add reverse directed impulse on the car body (done every frame regardless of collision) This does work to a certain degree, but has some shortcomings, and it's not all theoretically founded. If somebody could explain to me how the collision in my illustration will behave I will be eternally happy And I'm sure there is a more efficient way than how I resolve collisions. Any ideas and suggestions in this regard is also very welcome. Thanks for reading!
  • 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!