Jump to content

  • Log In with Google      Sign In   
  • Create Account

Banner advertising on our site currently available from just $5!


1. Learn about the promo. 2. Sign up for GDNet+. 3. Set up your advert!


_undex

Member Since 18 Oct 2012
Offline Last Active Dec 24 2014 05:58 PM

Topics I've Started

Geometry shader with stream output

16 February 2013 - 04:36 PM

Hello folks,

I tried to generate a stream output with a geometry shader.
But when I "draw" it, the window turns black.
Could someone show me some sample code on geometry shader with stream out or could someone correct my existing code?

Draw call:

 

bool GeometrySh::Render(ID3D11DeviceContext* deviceContext, int count)
{
	HRESULT result;
	D3D11_MAPPED_SUBRESOURCE mappedResource;
	unsigned int bufferNumber;
	BufferType* dataPtr;

	result = deviceContext->Map(m_cBuffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedResource);
	if(FAILED(result))
	{
		return false;
	}

	dataPtr = (BufferType*)mappedResource.pData;
	dataPtr->lightdir = D3DXVECTOR4(4.0f, 5.0f, 10.0f, 1.0f);
	deviceContext->Unmap(m_cBuffer, 0);

	bufferNumber = 0;

	deviceContext->GSSetConstantBuffers(bufferNumber, 1, &m_cBuffer);

	unsigned int stride;
	unsigned int offset;

	stride = sizeof(VertexType); 
	offset = 0;

	deviceContext->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST);

	deviceContext->IASetInputLayout(m_gslayout);

	deviceContext->SOSetTargets(1, &m_outBuffer, &offset);
	deviceContext->GSSetShader(gsshader, NULL, 0);
	deviceContext->PSSetShader(NULL, NULL, 0);
	deviceContext->VSSetShader(NULL, NULL, 0);
	
	deviceContext->DrawIndexed(count, 0, 0); // If I disable this line that bug dosen't occur
	
	deviceContext->GSSetShader(NULL, NULL, 0);
	ID3D11Buffer* pBuffer[1];
	pBuffer[0] = NULL;
	deviceContext->SOSetTargets(1, pBuffer, &offset);

	return true;
}

Shader code:
 

cbuffer BufferConType
{
	float4 lightdir;
}

struct GIN
{
	float4 pos : POSITION;
    float2 tex : TEXCOORD0;
    float3 normal : NORMAL;
};

struct GOUT
{
	float4 pos : POSITION;
};

[maxvertexcount(3)]
void GS(triangleadj GIN input[6], inout TriangleStream<GOUT> OutputStream)
{
        //Test geometry shader
	GOUT p;
	p.pos = input[0].pos;
	p.pos.w = 1.0f;
	OutputStream.Append(p);
	p.pos = input[2].pos;
	p.pos.w = 1.0f;
	OutputStream.Append(p);
	p.pos = input[4].pos;
	p.pos.w = 1.0f;
	OutputStream.Append(p);
	OutputStream.RestartStrip();
}

 


CreatePixelShader access violation

14 February 2013 - 05:06 AM

hello folks,

I keep getting an access violation exception when I create a pixelshader.

Here's the code:
 

        HRESULT result;
	ID3D10Blob* errorMessage;
	ID3D10Blob* vertexShaderBuffer;
	ID3D10Blob* pixelShaderBuffer;
	D3D11_INPUT_ELEMENT_DESC polygonLayout[2];
	unsigned int numElements;
	D3D11_BUFFER_DESC matrixBufferDesc;

	// Initialize the pointers this function will use to null.
	errorMessage = 0;
	vertexShaderBuffer = 0;
	pixelShaderBuffer = 0;

	result = D3DX11CompileFromFile(vsFilename, NULL, NULL, "VSTex", "vs_5_0", D3D10_SHADER_ENABLE_STRICTNESS, 0, NULL, 
				       &vertexShaderBuffer, &errorMessage, NULL);  

	if(FAILED(result))
	{
		// If the shader failed to compile it should have writen something to the error message.
		if(errorMessage)
		{
			OutputShaderErrorMessage(errorMessage, hwnd, vsFilename);
		}
		// If there was nothing in the error message then it simply could not find the shader file itself.
		else
		{
			MessageBox(hwnd, vsFilename, L"Missing Shader File", MB_OK);
		}

		return false;
	}

	// Compile the pixel shader code.
	result = D3DX11CompileFromFile(psFilename, NULL, NULL, "PSTex", "ps_5_0", D3D10_SHADER_ENABLE_STRICTNESS, 0, NULL, 
				       &pixelShaderBuffer, &errorMessage, NULL);
	if(FAILED(result))
	{
		// If the shader failed to compile it should have writen something to the error message.
		if(errorMessage)
		{
			OutputShaderErrorMessage(errorMessage, hwnd, psFilename);
		}
		// If there was nothing in the error message then it simply could not find the file itself.
		else
		{
			MessageBox(hwnd, psFilename, L"Missing Shader File", MB_OK);
		}

		return false;
	}
	// Create the vertex shader from the buffer.
	result = device->CreateVertexShader(vertexShaderBuffer->GetBufferPointer(), vertexShaderBuffer->GetBufferSize(), NULL, &m_vertexShader); // No access violation here
	if(FAILED(result))
	{
		return false;
	}
	// Create the pixel shader from the buffer.
	result = device->CreatePixelShader(pixelShaderBuffer->GetBufferPointer(), pixelShaderBuffer->GetBufferSize(), NULL, &m_pixelShader);  // Here it comes
	if(FAILED(result))
	{
		return false;
	}

I also checked if pixelShaderBuffer is still a nullpointer but it isn't and the buffersize is a non zero value.
I hope someone can help me. I also wish you a great valentine's day.


Geometry shader with stream output

11 February 2013 - 03:55 AM

Hi folks,

 

I've been trying to generate shadow volumes with the gpu.
But can't get the geometry shader to produce output.
So how can I create a shader with stream output in slimdx? Can you give me an example with code in hlsl and slimdx?


Problem by creating texture3d out of a texture2d array

12 December 2012 - 09:46 AM

Hello folks

I use SlimDx and I'm trying to create a texture3d object out of a texture2d array.
Each texture2d object has a height and a width of the variable "scale" and there are "scale" texture2d objects in the array.
But there is a problem. I can't get the data out of that array to write it into that texture3d object. So the texture3d object is always black when I draw it.
Here's my code:


[source lang="csharp"] byte[] data = new byte[textures.Length * scale * scale * 16]; for (int i = 0; i < textures.Length; i++) { System.IO.Stream stream = System.IO.Stream.Null; Texture2D.ToStream(device.ImmediateContext, textures[i], ImageFileFormat.Png, stream); stream.Read(data, i * (int)stream.Length, (int)stream.Length); } DataBox b = new DataBox(16 * scale, 16 * scale * scale, new DataStream(data, true, true)); volume = new Texture3D(device, new Texture3DDescription() { Width = scale, Height = scale, Depth = scale, MipLevels = 1, Format = SlimDX.DXGI.Format.R32G32B32A32_Float, BindFlags = BindFlags.ShaderResource, CpuAccessFlags = CpuAccessFlags.None, OptionFlags = ResourceOptionFlags.None, Usage = ResourceUsage.Default }, b);[/source]

I hope someone can help me.

HLSL Shadow Shader Issue

18 October 2012 - 09:34 AM

Hi folks,

I try to implement a simple shadow shader in my project. The shadow map and the basic shader works fine.
When I get to the shadow shader itself, i get a weird issue. When I want to transform the position in the vertex shader with the light view-projection matrix, i get only x and y values. The z and w values are always 1. But when I transform the position with the camera view-projection I get some z and w values. This is my test code for my issue. The output color is always white, which however must be gray, as the values in the shadow map are also gray:

[source lang="hlsl"]float4x4 View;float4x4 Projection;float4x4 ProjectionLight;float4x4 ViewLight;texture2D tex;SamplerState textureSampler{ Filter = MIN_MAG_MIP_LINEAR; AddressU = Wrap; AddressV = Wrap;};struct VS_IN{float4 pos : POSITION;float2 texpos : TEXCOORD;float3 normal : NORMAL;}; struct PS_IN{float4 pos : SV_POSITION;float4 Light : POSITION;float2 texpos : TEXCOORD0;float3 normal : NORMAL;float4 pos3D : TEXCOORD1;};void VShader(in VS_IN input, out PS_IN output){ float4 p = input.pos; output.pos = mul(p, mul(View, Projection)); output.texpos = input.texpos; output.normal = input.normal; output.Light = mul(p, mul(ViewLight,ProjectionLight)); output.pos3D = p;}float4 PShader(PS_IN input) : SV_Target{ float4 l = input.Light; return l.z / l.w;}technique10 Simple{ pass Main { SetGeometryShader(0); SetVertexShader(CompileShader(vs_5_0, VShader())); SetPixelShader(CompileShader(ps_5_0, PShader())); }}[/source]

I tried everything to get this work. I hope someone can help me.

Sorry for my perhaps bad english

PARTNERS