Jump to content

  • Log In with Google      Sign In   
  • Create Account

steven166

Member Since 22 Nov 2011
Offline Last Active Mar 30 2016 07:11 AM

Topics I've Started

How to enable supersampling in DirectX 11?

19 February 2016 - 03:56 AM

I have googled about enabling supersampling in GPU and I have found that it can be done by using SV_SampleIndex as an pixel shader input. There is no difference after inserting the SV_SampleIndex as an input of the pixel shader. Is there anyway to check that the supersampling is enable or not in DirectX 11 and HLSL?


How find sample positions in mulisampling rendering?

01 February 2016 - 11:34 PM

We all know that pixel shader is executed at pixel frequency in MSAA rendering and a given position (with SV_POSITION semantic) is a random position inside a pixel. However, I do not know how to position of each sample using HLSL and DirectX 11. Is there anyway to get position of each sample inside pixel shader when using multisampling?


A problem about implementing stochastic rasterization for rendering motion blur

01 February 2016 - 09:22 PM

I have read "Real-Time Stochastic Rasterization on Conventional GPU Architectures" paper. Now I am trying to implement this algorithm using DirectX 11 and HLSL instead of OpenGL and glsl (can be downloaded at http://graphics.cs.williams.edu/papers/StochasticHPG10/stochastic-shaders-reference.zip), but there is something that I do not understand:

 

First, I generate random time and store in a 128 x 128 2D texture. In pixel shader, the author calculates fragment (sample) position using

// In 4xMSAA case, MSAA_SAMPLES_CONSUMED_X = MSAA_SAMPLES_CONSUMED_Y = 2

ivec2 iFragCoordBase = ivec2(gl_FragCoord.xy) * ivec2(MSAA_SAMPLES_CONSUMED_X, MSAA_SAMPLES_CONSUMED_Y) + ivec2(samplePatternShift & 2, samplePatternShift >> 1) * 64;

for (int iy = 0; iy < MSAA_SAMPLES_CONSUMED_Y; ++iy) {
        for (int ix = 0; ix < MSAA_SAMPLES_CONSUMED_X; ++ix) {
            int index = ix + iy * MSAA_SAMPLES_CONSUMED_X;

            ....
           
        } // for ix
    } // for iy

I do not know that iFragCoordBase means, since the authour have already specified sample positions. In DirectX and HLSL if I use NvAPI to specify sample positions, do I need to compute iFragCoordBase variable?

 

Is there anybody experienced this problem?

 


Check each mipmap of a texture2D?

07 October 2015 - 06:55 PM

I follow the book "Introduction to 3D Game Programming with DIRECTX 11" to load several textures and its mipmaps, then copy into a texture array. But there is a problem with mipmaps. I am not sure the reason so now I want to check each mipmap of each loaded texture 2D by saving each mipmap to a file, but I do not know how to do that.

 

The following source code is used to load 2D textures and its mipmap (automatically generated by GPU):

        D3DX11_IMAGE_LOAD_INFO loadInfo;
	loadInfo.Width = 1024;
	loadInfo.Height = 1024;
	loadInfo.Depth = 0;
	loadInfo.FirstMipLevel = 0;
	loadInfo.MipLevels = 0;
	loadInfo.Usage = D3D11_USAGE_STAGING;
	loadInfo.BindFlags = 0;
	loadInfo.CpuAccessFlags = D3D10_CPU_ACCESS_WRITE | D3D10_CPU_ACCESS_READ;
	loadInfo.MiscFlags = D3D11_RESOURCE_MISC_GENERATE_MIPS;
	loadInfo.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
	loadInfo.Filter = D3DX11_FILTER_NONE;
	loadInfo.MipFilter = D3DX11_FILTER_NONE;
	loadInfo.pSrcInfo = 0;

	vector<string> m_sTextureNames;

	m_sTextureNames.push_back("MovingBox/metalcrate-L.jpg");

	UINT iNumOfMaterials = (UINT)m_sTextureNames.size();
	g_pTexture2Ds.resize(iNumOfMaterials);

	for (UINT i = 0; i<iNumOfMaterials; i++)
	{
		if (m_sTextureNames[i].compare("") != 0)
		{
			V(D3DX11CreateTextureFromFileA(pd3dDevice, m_sTextureNames[i].c_str(),
				&loadInfo, 0, (ID3D11Resource**)&g_pTexture2Ds[i], 0));
		}
	}

Is there anyone know to save a mipmap of a 2D texture to a file?


Output triangle strips in the geometry shader

15 August 2015 - 10:59 AM

I am implementing the "Real-time stochastic rasterization on conventional GPU". But I only use HLSL, so I do not understand how the GS in GLSL output triangle strips.

 

First is output vertices' attributes

flat out vec4 pack0, pack1, pack2, pack3, pack4, pack5;

flat out vec3 wsTanZA; // normal vector
flat out vec3 wsTanZB;
flat out vec3 wsTanZC;

The source  code means that each output vertex will have 9 attributes (pack0 -> pack5 and 3 vector normals). Is that right?

 

 

And source code to output triangle strips is:

 layout(triangle_strip, max_vertices = 9) out;

....

void emitConvexHull(in vec3 v0, in vec3 v1, in vec3 v2, in vec3 v3, in vec3 v4, in vec3 v5, const in float zmin) {

    // Swap the lowest y vertex to position 0.
    // In the case of ties, resolve to the lower x
    // (the latter is specified by Graham, but does it matter?)
    // 5 comparisons
    xysort(v0.xy, v1.xy);
    xysort(v0.xy, v2.xy);
    xysort(v0.xy, v3.xy);
    xysort(v0.xy, v4.xy);
    xysort(v0.xy, v5.xy);

    // Compute sort keys relative to v0.  Store them in the z component.
    computeSortKey(v0, v1);
    computeSortKey(v0, v2);
    computeSortKey(v0, v3);
    computeSortKey(v0, v4);
    computeSortKey(v0, v5);

    // Sort by keys in increasing (CCW) order-- 10 comparisons in a sorting network.
    zsort(v1, v2);    zsort(v1, v3);    zsort(v1, v4);    zsort(v1, v5);
    zsort(v2, v3);    zsort(v2, v4);    zsort(v2, v5);    
    zsort(v3, v4);    zsort(v3, v5);
    zsort(v4, v5);

    // The first two vertices and the last must be on the convex hull.
    // Use v5 as the apex of the fan; we'll keep coming back to it.
    chEmit(v0);
    chEmit(v5);
    chEmit(v1);
    // Last known "good" vertex on the CH, constantly updated
    vec2 G = v1.xy;

    // Now we must determine which of points [2,3,4], if any, are on the hull.

    // Vertex 2: check corners 123, 124, 125
    vec2 toNext = v2.xy - G;
    if (isRightTurn(toNext, v3.xy - G) &&
        isRightTurn(toNext, v4.xy - G) &&
        isRightTurn(toNext, v5.xy - G)) {
        chEmit(v5);  chEmit(v2);  G = v2.xy;
    }

    // Vertex 3: check corners G34, G35
    toNext = v3.xy - G;
    if (isRightTurn(toNext, v4.xy - G) &&
        isRightTurn(toNext, v4.xy - G)) {
        chEmit(v5);  chEmit(v3);  G = v3.xy;
    }

    // Vertex 4: check corner G45
    if (isRightTurn(v4.xy - G, v5.xy - G)) {
        chEmit(v5);  chEmit(v4);
    }

    EndPrimitive();
}

Follow the GLSL code that if all conditions are true then the output vertices will be 0 5 1 5 2 5 3 5 4. It means that the finally generated triangles are 051, 515, 152, 525, 253, 535, 354. Is that right?


PARTNERS