Jump to content

  • Log In with Google      Sign In   
  • Create Account

Awesome job so far everyone! Please give us your feedback on how our article efforts are going. We still need more finished articles for our May contest theme: Remake the Classics

directx user

Member Since 03 Jun 2012
Offline Last Active Mar 28 2013 10:11 AM
-----

Topics I've Started

adress mode issues

23 December 2012 - 10:10 AM

hi,

iam currently having some issues with my sample texture to wrap proper on my geodesic sphere, actually it seems like the address mode of my sampler doesnt works. I need the texture to repeat on the other side of the sphere, so i assigned a wrap samplerstate:
D3D11_SAMPLER_DESC samplerdesc = D3D11_SAMPLER_DESC();ZeroMemory( &samplerdesc, sizeof(samplerdesc) );samplerdesc.AddressU = D3D11_TEXTURE_ADDRESS_MODE::D3D11_TEXTURE_ADDRESS_WRAP;samplerdesc.AddressV = D3D11_TEXTURE_ADDRESS_MODE::D3D11_TEXTURE_ADDRESS_WRAP;samplerdesc.Filter = D3D11_FILTER::D3D11_FILTER_ANISOTROPIC;device->CreateSamplerState(&samplerdesc,&sampstate);////////////////////////////////immediatecontext->PSSetSamplers(0,1,&sampstate);immediatecontext->VSSetSamplers(0,1,&sampstate);
Shadercode:
Texture2D<float4> Textur : register(t0);sampler sampler1 : register(s0);cbuffer Matrix : register( b0 ){	row_major matrix World;	row_major matrix View;	row_major matrix Projection;};struct VS_INPUT{    float4 Pos : POSITION;    float2 texcoord : TEXCOORD;};struct PS_INPUT{    float4 Pos : SV_POSITION;    float2 texcoord : TEXCOORD;};//--------------------------------------------------------------------------------------// Vertex Shader//--------------------------------------------------------------------------------------PS_INPUT VS( VS_INPUT input ){    PS_INPUT output = (PS_INPUT)0;    output.Pos = mul(input.Pos,World);    output.Pos = mul(output.Pos,View);    output.Pos = mul(output.Pos,Projection);    output.texcoord = input.texcoord;    return output;}//--------------------------------------------------------------------------------------// Pixel Shader//--------------------------------------------------------------------------------------float4 PS( PS_INPUT input) : SV_Target{	float4 ret = Textur.Sample(sampler1,input.texcoord);	return ret;}
Is there a problem with the shader itself?


The resolution of the image is 512X512, so there shouldnt be a problem with it?Attached File  merkurfail.PNG   238.36K   20 downloads

the u coordinate ranges from 0 to 2, and the white strip has nothing to do with the texture, will replace it soon

edit:




Its working now, i missed to set the addressmode w parameter in the samplerstate, but i have another question anyway.
While searching in the internet i saw this code snippet:
Texture2D Textur : register(t0);
SamplerState sampler1 : register(s0);


while i used this one:
Texture2D<float4> Textur : register(t0);
sampler sampler1 : register(s0);

both is working but where is the difference, besides the float4 telling hlsl the format.

multiple objects performance issue

19 June 2012 - 10:04 AM

Hello, its me again.
After i sucessfully initialised my shader code i experienced some performance issues with drawing my scene which contains spherical geometrie. The issue seems to be the seperate drawing calls which tookes about 0,3ms. first i thought my graphics card would be too slow to give me the necessary performance to render 1800 spheres but then i increased the vertex-count of my "sphere" and the rendering tooked the same time.

Now i know that the Issue has to be the cpu-gpu-communication, but everything at all i cant imagine how a single draw call can cost that much time?... if i look at modern games having hundreds of models displayed at the same time.

A solution would be to use instancing but iam not really sure how i can use it at dx11, basicly all that should be done is telling the gpu to loop my indexbuffer content n times insteat of calling the drawing such often. The problem is i have absolutly no idea how to do that? Creating the whole indesbuffer containing 1800 times the same index-sequence seams to be very messy and unnecessary.

And if you use different models at the same time i guess a drawing call which takes 200 ms for 1000 different object buffers isnt really aceptable so how do YOU manage it?

problems with shader matrices

03 June 2012 - 06:59 AM

Hello Forum,

I have currently some issues with my shader code:

cbuffer matrizen : register( b0 )
{
	row_major matrix World;
	row_major matrix View;
	row_major matrix Projection;

};


struct VS_INPUT
{
	float4 Pos : POSITION;
};

struct PS_INPUT
{
	float4 Pos : SV_POSITION;
};


//--------------------------------------------------------------------------------------
// Vertex Shader
//--------------------------------------------------------------------------------------
PS_INPUT VS( VS_INPUT input )
{
	PS_INPUT output = (PS_INPUT)0;

	output.Pos = mul(input.Pos,World);
	output.Pos = mul(output.Pos,View);
	output.Pos = mul(output.Pos,Projection);

	return output;
}


//--------------------------------------------------------------------------------------
// Pixel Shader
//--------------------------------------------------------------------------------------
float4 PS( PS_INPUT input) : SV_Target
{
	return float4(1.0f,0.0f,0.0f,1.0f);
}

actually this code is mostly copied from the directx sample browser and should work as it also works in the sample project. The Problem is, it doesnt displays anything if i apply the matrix transformations inside the vertex shader. The Matrices are assigned over this code.

struct Mats
{
	XMMATRIX World;
	XMMATRIX View;
	XMMATRIX Projection;
};
........................
Mats mat;
mat.World = XMMatrixIdentity(); //no geometry transformations
XMVECTOR Eye = XMVectorSet( 0.0f, 0.0f, 5.0f, 0.0f );
XMVECTOR At = XMVectorSet( 0.0f, 0.0f, 0.0f, 0.0f );
XMVECTOR Up = XMVectorSet( 0.0f, 1.0f, 0.0f, 0.0f );
mat.View = XMMatrixLookAtLH( Eye, At, Up ); //looking on the triangle
mat.Projection =  XMMatrixPerspectiveFovLH( XM_PIDIV4, (FLOAT)width / (FLOAT)height, 0.01f, 100.0f ); //calculating perspective matrix


immediatecontext->UpdateSubresource( Matrixbuffer 0, NULL, &mat, 0, 0 ); //updating matrices

drawing the content:

immediatecontext->VSSetShader( vertexshader, NULL, 0 ); //using the vertexshader
	immediatecontext->VSSetConstantBuffers( 0, 1, &Matrixbuffer ); //assign matrices to the vertexshader
	immediatecontext->PSSetShader( pixelshader, NULL, 0 ); //using the pixelshader
	immediatecontext->Draw( 3, 0 ); //drawing three vertices (one single triangle)
	swapchain->Present( 0, 0 );


I guess there is a really easy solution to this problem but currently i dont know how i could fix that.

EDIT: Leaving the matrices Identity matrices doesnt solves the problem so the problem has to be inside the matrix assignment (without doing the matrix transformations it display the triangle)

PARTNERS