Jump to content

  • Log In with Google      Sign In   
  • Create Account

Interested in a FREE copy of HTML5 game maker Construct 2?

We'll be giving away three Personal Edition licences in next Tuesday's GDNet Direct email newsletter!

Sign up from the right-hand sidebar on our homepage and read Tuesday's newsletter for details!


We're also offering banner ads on our site from just $5! 1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


#ActualWaaayoff

Posted 05 July 2013 - 08:06 AM

I wrote a simple test code that creates a 3D texture and fills it with red pixels. All i get is the same colour i'm setting the render target to. Here's the shader code: (The problem is probably here)

struct GS_OUT_LAYER
{
	float4 posH	: SV_POSITION;
	uint layer	: SV_RenderTargetArrayIndex;
};

float4 VShader(float4 pos : POSITION) : SV_POSITION
{
	return pos;
}

[maxvertexcount(3)]
void GShader(triangle float4 input[3] : POSITION, inout TriangleStream<GS_OUT_LAYER> triStream)
{
	GS_OUT_LAYER output;

	output.posH  = input[0];
	output.layer = 0; 
	triStream.Append(output);
	
	output.posH  = input[1];
	output.layer = 0; 
	triStream.Append(output);
	
	output.posH  = input[2];
	output.layer = 0; 
	triStream.Append(output);
}

float4 PShader(GS_OUT_LAYER input) : SV_TARGET
{
	return float4(1, 0, 0, 1);
}

And this is how i create the texture and render target:

RenderEffect Test3DEffect;
	
	Test3DEffect.pVertexShader = mRenderer->LoadShader(VERTEX_SHADER, "Shaders/Test3D.hlsl", "VShader", "vs_4_0");
	Test3DEffect.pGeometryShader = mRenderer->LoadShader(GEOMETRY_SHADER, "Shaders/Test3D.hlsl", "GShader", "gs_4_0");
	Test3DEffect.pPixelShader = mRenderer->LoadShader(PIXEL_SHADER, "Shaders/Test3D.hlsl", "PShader", "ps_4_0");

	Texture3D* Test3DTexture;
	TConfig3d.Width = 256;
	TConfig3d.Height = 64;
	TConfig3d.Depth = 32;
	TConfig3d.Format = DXGI_FORMAT_R16G16B16A16_FLOAT;
	TConfig3d.BindFlags = D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE;
	Test3DTexture = mRenderer->CreateTexture3D(TConfig3d, NULL);

	int TestTarget;
	RTConfig.Format = TConfig3d.Format;
	RTConfig.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE3D;
	RTConfig.Texture3D.MipSlice = 0;
	RTConfig.Texture3D.FirstWSlice = 0;
	RTConfig.Texture3D.WSize = 32;
	TestTarget = mRenderer->CreateRenderTargetView(Test3DTexture, &RTConfig);

	mPipeline->SetRenderTargets(1, &TestTarget, &mZBuffer);
	mPipeline->ClearRenderTarget(0, D3DXCOLOR(0.2f, 0.3f, 0.6f, 1.0f));
	mPipeline->ClearDepthStencilView();
	mPipeline->SetViewport(TransmittanceViewport);

	pQuad->SetRenderEffect( &Test3DEffect );
	cmd = pQuad->GetRenderCommand();
	
	mPipeline->Draw(cmd);

	mRenderer->Present();

	mPipeline->SaveTextureToFile(Test3DTexture->GetResource(), D3DX11_IFF_DDS, "Test3D.dds"); 

#1Waaayoff

Posted 05 July 2013 - 08:04 AM

I wrote a simple test code that creates a 3D texture and fills it with red pixels. All i get is the same colour i'm setting the render target to. Here's the shader code: (The problem is probably here)

struct GS_OUT_LAYER
{
	float4 posH	: SV_POSITION;
	uint layer	: SV_RenderTargetArrayIndex;
};

float4 VShader(float4 pos : POSITION) : SV_POSITION
{
	return pos;
}

[maxvertexcount(3)]
void GShader(triangle float4 input[3] : POSITION, inout TriangleStream<GS_OUT_LAYER> triStream)
{
	GS_OUT_LAYER output;

	output.posH  = input[0];
	output.layer = 0; 
	triStream.Append(output);
	
	output.posH  = input[1];
	output.layer = 0; 
	triStream.Append(output);
	
	output.posH  = input[2];
	output.layer = 0; 
	triStream.Append(output);
}

float4 PShader(GS_OUT_LAYER input) : SV_TARGET
{
	return float4(1, 0, 0, 1);
}

And this is how i create the texture and render target:

RenderEffect Test3DEffect;
	
	Test3DEffect.pVertexShader = mRenderer->LoadShader(VERTEX_SHADER, "Shaders/Test3D.hlsl", "VShader", "vs_4_0");
	Test3DEffect.pGeometryShader = mRenderer->LoadShader(GEOMETRY_SHADER, "Shaders/Test3D.hlsl", "GShader", "gs_4_0");
	Test3DEffect.pPixelShader = mRenderer->LoadShader(PIXEL_SHADER, "Shaders/Test3D.hlsl", "PShader", "ps_4_0");

	Texture3D* Test3DTexture;
	TConfig3d.Width = 256;
	TConfig3d.Height = 64;
	TConfig3d.Depth = 32;
	TConfig3d.Format = DXGI_FORMAT_R16G16B16A16_FLOAT;
	TConfig3d.BindFlags = D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE;
	Test3DTexture = mRenderer->CreateTexture3D(TConfig3d, NULL);

	int TestTarget;
	RTConfig.Format = TConfig3d.Format;
	RTConfig.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE3D;
	RTConfig.Texture3D.MipSlice = 0;
	RTConfig.Texture3D.FirstWSlice = 0;
	RTConfig.Texture3D.WSize = 1;
	TestTarget = mRenderer->CreateRenderTargetView(Test3DTexture, &RTConfig);

	mPipeline->SetRenderTargets(1, &TestTarget, &mZBuffer);
	mPipeline->ClearRenderTarget(0, D3DXCOLOR(0.2f, 0.3f, 0.6f, 1.0f));
	mPipeline->ClearDepthStencilView();
	mPipeline->SetViewport(TransmittanceViewport);

	pQuad->SetRenderEffect( &Test3DEffect );
	cmd = pQuad->GetRenderCommand();
	
	mPipeline->Draw(cmd);

	mRenderer->Present();

	mPipeline->SaveTextureToFile(Test3DTexture->GetResource(), D3DX11_IFF_DDS, "Test3D.dds"); 

PARTNERS