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!


jkristia

Member Since 14 Oct 2012
Offline Last Active Jan 02 2015 02:18 PM

Topics I've Started

thick line - fixed width ?

07 October 2013 - 10:24 PM

I'm trying to create a thick line class, and I have it working to the point where the line is always facing the camera and the line width is a fixed hard coded unit width, e.g. 0.1f

 

What I'm struggling with at the moment is to

  1. have the line width fixed regardless of zoom level, e.g. I would like to have it 5 pixels wide, whether I have zoomed in or out.
  2. To have the fixed width at both ends of the thick line in perspective view.

 

For #2 I thought it was as simple as using the inverse projection matrix, but ...

 

Any suggestions of how to attack this is much appreciated.


SharpDX, how to set constant buffer when using effect / technique

29 September 2013 - 08:08 PM

I want to change to use effect, and I have it working now, but I was not able to figure out how to set the constant buffers when using effects, so the 2 update calls

 

rc.Context.UpdateSubresource<cbObjStruct>(ref m_cbObj, m_perObjcBuf);

rc.Context.UpdateSubresource<cbTransform>(ref m_cbTransform, m_transformcBuf);

 

turns into this instead (ignore the extra transpose). Is there an easier way to update the constant buffer than setting it per variable? (obviously I will optimize it to per frame and per obj Update)

		void Update(RenderContext rc)
		{
			Matrix m1 = m_cbTransform.gWorld;
			m1.Transpose();
			EffectMatrixVariable m = m_effect.GetVariableByName("gWorld").AsMatrix();
			m.SetMatrix(m1);

			m1 = m_cbTransform.gView;
			m1.Transpose();
			m = m_effect.GetVariableByName("gView").AsMatrix();
			m.SetMatrix(m1);

			m1 = m_cbTransform.gViewProj;
			m1.Transpose();
			m = m_effect.GetVariableByName("gViewProj").AsMatrix();
			m.SetMatrix(m1);

			EffectVectorVariable v = m_effect.GetVariableByName("objColor").AsVector();
			v.Set(m_cbObj.ObjColor);

			m1 = m_cbObj.ObjWorld;
			m1.Transpose();
			m = m_effect.GetVariableByName("objWorld").AsMatrix();
			m.SetMatrix(m1);

			EffectPass renderpass = m_currentRender.GetPassByIndex(0);
			renderpass.Apply(rc.Context);
		}

problem with basinc light

29 September 2013 - 08:04 AM

Hi, I have been working on getting basinc light working for the last several evenings, but I'm not able to get the correct behavior, and I would like some help understanding what I'm doing wrong.

 

The objects vertices are transformed to world space at the time of creating the geometry, so positions are in world space. The normal are calculated from the positions, which I think should be correct.

 

Here is my simple shader code



cbuffer cbTransform : register(b0)
{
	float4x4 gWorld;
	float4x4 gView;
	float4x4 gViewProj;
	float3 gEyePos;
	float filler;
}

cbuffer cbObjColor : register(b1)
{
	float4 objColor;
	float4x4 objInvTransform;
}

struct VS_IN
{
	float4 pos : POSITION;
	float4 normal : NORMAL;
};

struct PS_IN
{
	float4 posH : SV_POSITION;
	float4 posWorld : POSITION;
	float4 col : COLOR;
	float4 normal : NORMAL;
};

PS_IN VS( VS_IN input )
{
	PS_IN output = (PS_IN)0;
	output.posWorld = input.pos;
	output.posH = mul(input.pos, gViewProj);
	input.normal.w = 0;
	output.normal = input.normal;
	output.normal.w = 0;
	output.col = objColor;
	return output;
}

float4 PS( PS_IN input ) : SV_Target
{
	float3 gDirectionalLightPos = float3(1,1,-1);
	float4 gAmbColor = input.col; // ambient color
	float  gAmbIntensity = 0.0;

	float4 inputnormal = input.normal;
	float4 inputpos = input.posWorld;
	float4 inputcolor = input.col;
	float4 lightpos = float4(gDirectionalLightPos,0);

	float4 n = normalize(inputnormal);
	float4 L = normalize(lightpos);

	// ambient
	float4 cAmb = saturate(gAmbColor * gAmbIntensity);
	// diffuse component
	float4 sDiff = float4(1,1,1,1); // color of diffuse light
	float4 mDiff = inputcolor;		// color of the object
	float4 cDiffuse = saturate((sDiff * mDiff) * clamp(dot(n, L), 0, 1));

	return saturate(cAmb + cDiffuse);
	//return input.col;
}

The problem is that when the camera is at 1,1,-1 the cylinder is not lit

 

Attached File  img1.png   33.32KB   3 downloads

 

but when moved to -1,1-1 the cylinder is lit, but it is lit 'almost' evenly from all sides

 

Attached File  img2.png   29.19KB   3 downloads

 

Anyone can spot my mistake, because I can't.

Any help is very much appreciated.

 

 


problem defining the VS input struct

19 September 2013 - 11:02 PM

I have run into a problem when I tried to add the third property to my input struct, and I cannot see what I'm doing wrong, but I'm sure it is something obvious.

I have defined my C# struct, the shader struct and the layout. Checking the vertex buffer I see the POS at the right position, and 1,2,3,4 for the 'normal' vector4 and 11,22,33,44 for the last property.

When I debug the shader code with the graphical editor (can't figure out how to debug the code using the AMD PerfStudio) then I see the input struct contains 1,2,3,4 for the POS property, and the other 2 shows 'cannot display'.

 

If I remove Test from the Vertex struct without changing anything else, then it works.

 

Any idea what I'm missing?

C# SharpDX definition

 [Serializable, StructLayout(LayoutKind.Sequential, Pack=4)]
 public struct Vertex
 {
  public Vector4 Pos;
  public Vector4 Normal;
  public Vector4 Test;
  public Vertex(Vector4 pos)
  {
   Pos = pos;
   Normal = new Vector4(1,2,3,4);
   Test = new Vector4(11,22,33,44);
  }
 }

 

Layout definition

 

    rc.InputLayout = new InputLayout(rc.Device, ShaderSignature.GetInputSignature(vertexShaderByteCode), new[]
     {
  new InputElement("POSITION", 0, SharpDX.DXGI.Format.R32G32B32A32_Float,  0, 0),
  new InputElement("NORMAL"  , 0, SharpDX.DXGI.Format.R32G32B32A32_Float, 16, 0),
  new InputElement("TEXCOORD", 0, SharpDX.DXGI.Format.R32G32B32A32_Float, 32, 0)
     });

fx definition
 struct VS_IN
 {
  float4 pos : POSITION;
  float4 normal : NORMAL;
  float4 test : TEXCOORD;
 };

vertex buffer
0 [0x00000000-0x00000003] |           -0.625
1 [0x00000004-0x00000007] |           -0.625
2 [0x00000008-0x0000000b] |           -0.625
3 [0x0000000c-0x0000000f] |               +1
4 [0x00000010-0x00000013] |               +1
5 [0x00000014-0x00000017] |               +2
6 [0x00000018-0x0000001b] |               +3
7 [0x0000001c-0x0000001f] |               +4
8 [0x00000020-0x00000023] |              +11
9 [0x00000024-0x00000027] |              +22
10 [0x00000028-0x0000002b] |              +33
11 [0x0000002c-0x0000002f] |              +44
12 [0x00000030-0x00000033] |           -0.625  <-- new vertex
13 [0x00000034-0x00000037] |           +0.625


VS2012 debugging DirectX

17 September 2013 - 07:34 PM

I see people refer to PIX if you need to debug your shader code, but it seems like it is no longer available, and instead you have to use the debugger integrated in VS2012.

 

So - I tried to run the graphics debugger from VS2012, but all I see is an empty view with the frame count and elapsed time.

 

Attached File  emptyview.png   4.83KB   3 downloads

 

If I take some snapshots, then I do see the correct events, and I do the see mesh in the pipeline preview.

But, when I attempt to debug the shader code I only see assembly code, not the C code. I have the debug mode set to mixed mode, but only difference is that I now get a warning that no symbols could be found at startup.

 

Any idea if I'm missing some setting ?

 

Edit: Is there any other tool to use if I want to debug the shader code?


PARTNERS