Jump to content
  • Advertisement

Daganar

Member
  • Content count

    7
  • Joined

  • Last visited

Community Reputation

264 Neutral

About Daganar

  • Rank
    Newbie

Personal Information

  • Role
    Programmer
  • Interests
    Programming

Recent Profile Visitors

The recent visitors block is disabled and is not being shown to other users.

  1. Just as an update: I've narrowed it down exactly to the phase function, if I use the isotropic phase function: 1.0 / 4.0 * PI  I get correct scattering. After a bit of shader debugging with the Henyey-Greenstein phase function it turns out that the dot product I am doing is causing the phase function to produce NaN results: float d = dot( ( currentPosition ), normalize( rayDirection ) ); Is producing NaN results.. does any one know the correct vectors I should be using here? I can't find much info on this, thanks.   EDIT: Here is my latest Henyey-Greenstein phase function: float result = ( 1.0f - g2 ) / pow( 4.0f * M_PI * 1.0f + g2 - 2.0f * g * fCos, 1.5f );
  2. Hi guys, So I'm working on some volumetric lighting effects using the ray marching method. I seem to have it nearly nailed, the way this works is I render my entire scene, then I render a fullscreen quad which takes the scene render target as an input as well as shadow maps which then ray marches for N samples for each pixel and accumulates the scattering along that ray, lastly it adds it on top of the scene render. My issue is however I get some bad acne/aliasing issues.. I've narrowed it down to the scattering equation inputs, I believe I'm incorrectly computing the angle needed for the scattering phase function. Here is the issue I'm seeing (enjoy the hot pink):  Here is my HLSL code for this: float ComputeScattering( float fCos ) { float g = -0.94f; float g2 = g*g; float fCos2 = fCos * fCos; float result = 1.5f * ( ( 1.0f - g2 ) / ( 2.0f + g2 ) ) * ( 1.0f * fCos2 ) / pow( abs( 1.0f + g2 - 2.0f * g * fCos ), 1.5f ); return result; } float3 CalculatePosition( float depth, float2 uv ) { float x = uv.x * 2 - 1; float y = ( 1 - uv.y ) * 2 - 1; float4 vProjectedPos = float4( x, y, depth, 1.0f ); float4 vPositionVS = mul( vProjectedPos, matInvViewProj ); return vPositionVS.xyz / vPositionVS.w; } float4 PSMain( PSInput input ) : SV_TARGET { // Sample scene colour. float4 diffuseColour = diffuseTexture.Sample(diffuseSampler, input.uv); // Reconstruct world position from depth. float worldDepth = depthTexture.Sample( diffuseSampler, input.uv ); float shadowTex = shadowTexture.Sample( diffuseSampler, input.uv ); float3 worldPos = CalculatePosition( worldDepth, input.uv ); // Calculate ray from world pos -> eye float3 rayVector = eyePos.xyz - worldPos.xyz; float rayLength = length( rayVector ); float3 rayDirection = rayVector / rayLength; // Calculate step float stepLength = rayLength / NUM_SAMPLES; float3 step = rayDirection * stepLength; float3 lightVec = float3( 0.1f, 1.0f, 0.0f ); float4 lightCol = float4( 1.0f, 0.0f, 1.0f, 1.0f ); float3 accumFog = float3( 0.0f, 0.0f, 0.0f ); float3 currentPosition = worldPos.xyz; // Ray March [loop] for( int i = 0; i < NUM_SAMPLES; i++ ) { // Advance. currentPosition += step; // Shadow mapping test. float4 shadowPos = mul( float4( currentPosition.xyz, 1.0f ), matShadow ); float2 shadowCoord; shadowCoord.x = shadowPos.x / shadowPos.w / 2.0f + 0.5f; shadowCoord.y = -shadowPos.y / shadowPos.w / 2.0f + 0.5f; float bias = 0.002f; float shadowDepth = ( shadowPos.z / shadowPos.w ) - bias; float shadow = shadowTexture.Sample( diffuseSampler, shadowCoord.xy ); // Check if in shadow. if( shadow > shadowDepth ) { // Calculate scattering. float d = dot( ( currentPosition ), normalize( rayDirection ) ); float3 scattering = lightCol * ComputeScattering( d ); // Accumulate accumFog += scattering; } } accumFog /= NUM_SAMPLES; // Combine. return( diffuseColour + float4( accumFog, 1.0f ) ); } At first this seemed very familiar to shadow acne, but removing the shadow map test produces the same results, I believe it's down to this line: float d = dot( ( currentPosition ), normalize( rayDirection ) ); Any advice would be greatly appreciated, thanks.  
  3. Daganar

    Any good A* tutorial?

    A recent one I came across that visually explains it quite well is on the Computerphile YouTube channel: (Dijkstra's) - Fundamental A* algorithm. (A*)
  4. Daganar

    D3D12 Enabling Multi-Sampling.

    Also worth mentioning to retrieve the number of quality levels supported can be done like so: D3D12_FEATURE_DATA_MULTISAMPLE_QUALITY_LEVELS msLevels; msLevels.Format = DXGI_FORMAT_R8G8B8A8_UNORM; // Replace with your render target format. msLevels.SampleCount = 4; // Replace with your sample count. msLevels.Flags = D3D12_MULTISAMPLE_QUALITY_LEVELS_FLAG_NONE; m_Device->CheckFeatureSupport(D3D12_FEATURE_MULTISAMPLE_QUALITY_LEVELS, &msLevels, sizeof(msLevels)); Doing this will store the quality level for the sample count in D3D12_FEATURE_DATA_MULTISAMPLE_QUALITY_LEVELS::NumQualityLevels
  5. Daganar

    D3D12 Enabling Multi-Sampling.

    I was reading a bit in Introduction to 3D Game Programming with DirectX 12 by Frank Luna and he talks briefly about enabling MSAA via the SwapChain, which is apparently completely incorrect... For anyone wanting to know my solution (as there seems to be little info on this) I had to do the following; Create as usual SwapChain with SampleDesc.Count = 1 and SampleDesc.Quality = 0. Create SwapChain RTV's as usual. Create another RenderTarget texture + view with the required sample count and quality. Create PipelineStateObject with the SAME count and quality (this also applies to depth-stencil buffer) Use the non-SwapChain render targets to render your scene to. When you are ready to display contents on the screen, transition the non-SwapChain render target to "D3D12_RESOURCE_STATE_RESOLVE_SOURCE" state and the actual SwapChain render target to "D3D12_RESOURCE_STATE_RESOLVE_DEST" Call ResolveSubresource on your command list with the correct source/destination. Transition the SwapChain render target to D3D12_RESOURCE_STATE_PRESENT and you are done.
  6. Daganar

    D3D12 Enabling Multi-Sampling.

    Ah of course, thanks for the quick reply.
  7. Hi all, I was hoping somebody could point me in the right direction for enabling multi-sampling for a render target in D3D12.. Everywhere I've read states that I should enable it via the DXGI_SAMPLE_DESC in the swapchain and the pipeline state object. I am having two issues with this, first of changing the count/quality on the swapchain always fails with the error: "IDXGIFactory::CreateSwapChain: Flip model swapchains (DXGI_SWAP_EFFECT_FLIP_SEQUENTIAL and DXGI_SWAP_EFFECT_FLIP_DISCARD) do not support multisampling" Okay.. So I swap to a non-flip mode and then I just get the next error: "IDXGIFactory::CreateSwapChain: This D3D API version requires the swap effect to be one of DXGI_SWAP_EFFECT_FLIP_*. [ MISCELLANEOUS ERROR #273: ]" I'm unable to find any documentation on this, but to me it sounds like I'm completely unable to enable multi-sampling? Thanks.
  8. Looks to me that the position you are placing it is at the top left corner of the sprite, if that's the case try offsetting the positions by the width and height of your sprite.   Assuming that +X is to the right and +Y is going up:   X = X + ( width * 0.5f ) Y = Y - ( height * 0.5f )
  9. Daganar

    Including headers from Windows 10 SDK

    I had this issue, you have to install Visual Studio 2015 and on the install make sure you got to "custom install" and include all the C++ tools and the Windows SDK bundled with it... For some reason DX12 isn't shipped with the Windows SDK off the Microsoft website.   EDIT:    On mine the d3d12 headers are located at "C:\Program Files (x86)\Windows Kits\10\Include\10.0.10240.0\um"   Also the DX12 samples use the D3DX12.h which isn't included in any Windows SDK, you have to get that header from the samples on GitHub https://github.com/Microsoft/DirectX-Graphics-Samples
  • Advertisement
×

Important Information

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

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!