Jump to content

  • Log In with Google      Sign In   
  • Create Account

Zosimas

Member Since 14 Mar 2009
Offline Last Active Feb 03 2012 08:42 AM

Topics I've Started

DirectX bounding sphere weird results

03 February 2012 - 06:52 AM

I made a simple box in 3Dstudio max and exported it with KW X-port plugin in .X format. Now I'm loading this mesh in my Direct3D project and calculating the bounding sphere of it like this:

m = Mesh.FromFile(My.Application.Info.DirectoryPath & "\Data\Models\Box.X", MeshFlags.Managed, DEV)
Using vb As VertexBuffer = m.VertexBuffer
	Dim vertexData As GraphicsStream = vb.Lock(0, 0, LockFlags.None)
	objectRadius = Geometry.ComputeBoundingSphere(vertexData, m.NumberVertices, m.VertexFormat, objectCenter)
	vb.Unlock()
End Using

Now the problem is that I'm getting some weird results as center and radius:

objectCenter.X : -944.5798
objectCenter.Y : 0
objectCenter.Z : 944.5798
objectRadius : 0.007336923

although box's width, height and length are about 50, and box's position is 0. What could be going wrong here?

HLSL - Multiple World Matrices

30 December 2011 - 03:08 PM

I'm using VB.NET and DirectX9 to animate a mesh. The following code is the Draw function:

p = FX.Begin(Direct3D.FX.None)
For k = 0 To p - 1
	FX.BeginPass(k)
	For iattrib As Integer = 0 To mesh.NumberAttributes - 1
		Dim boneCombo As BoneCombination = mesh.BoneTable(iattrib)
		For i As Integer = 0 To mesh.NumberInfluences - 1
			Dim matrixIndex As Integer = boneCombo.BoneId(i)
			If matrixIndex <> -1 Then
				Dim tempMatrix As Matrix = offsetMatrices(matrixIndex) * frameMatrices(matrixIndex).Combined
				'DXDEV.Transform.SetWorldMatrixByIndex(i, tempMatrix)
				'''''''''''''''''''''
			End If
		Next
		DXDEV.RenderState.VertexBlend = DirectCast(boneCombo.BoneId.Length, VertexBlend) - 1
		mesh.MeshData.Mesh.DrawSubset(iattrib)
	Next
	FX.EndPass()
Next k
FX.End()

As you can see there are multiple world matrices that are passed in different indexes in device. The thing is that I use an HLSL effect file to render the mesh and I don't know how to pass and use multiple world matrices in my effect. I want to replace the commented line:

DXDEV.Transform.SetWorldMatrixByIndex(i, tempMatrix)

with a line that passes those world matrices in my effect and then some HLSL code to use those world matrices in my vertex shader.

Any help will be appreciated.

(HLSL) Spot light calculations

16 October 2010 - 07:07 AM

As you can see in the image below, I made a spot light shader
that looks pretty good.

Now, I have an interesting question. In real life when the
atmosphere is foggy, the space inside the red lines in the image
becomes brighter. I want to find a way to calculate (in my pixel
shader) if a pixel is in this area, to make a more realistic spot light.

Of course I have all the necessary vectors that can help:
WorldView
WorldNormal
LightPosition
LightDirection
EyePosition

Any suggestions?

Spot light shader

Cannot retrieve LightVector in Pixel Shader

13 October 2010 - 09:02 AM

Why when I use this in my HLSL shader, everything work fine:


struct vertexOutput {
float4 HPosition : POSITION;
float2 UV : TEXCOORD0;
float3 LightVec : TEXCOORD1;
float3 WorldNormal : TEXCOORD2;
float3 WorldTangent : TEXCOORD3;
float3 WorldBinormal : TEXCOORD4;
float3 WorldView : TEXCOORD5;
};

/*Pixel Shader*/
float4 depthMap_PS(vertexOutput IN) : COLOR
{
float3 Ln = normalize(IN.LightVec);
float c = length(Ln);
return float4(c,0,0,1);
}



but when I use this I get an "E_FAIL" error: ?


struct vertexOutput {
float4 HPosition : POSITION;
float2 UV : TEXCOORD0;
float3 LightVec : TEXCOORD1;
float3 WorldNormal : TEXCOORD2;
float3 WorldTangent : TEXCOORD3;
float3 WorldBinormal : TEXCOORD4;
float3 WorldView : TEXCOORD5;
};

/*Pixel Shader*/
float4 depthMap_PS(vertexOutput IN) : COLOR
{
float c = length(IN.lightVec);
return float4(c,0,0,1);
}



Why can't I get IN.LightVec in Pixel Shader?

3D camera vectors

09 October 2010 - 02:45 PM

I made a 3d camera class like the one in: toymaker.info

and I read that thread too: Understanding 3D camera better

Now, the question is how am I going to extract the real Look, Up, and Right vectors from the final viewMatrix?

And I say real because the only vector that is set by the user is the Position vector and the other three vectors (Look, Up, Right) are calculated programmatically as unit vectors and not at the real world space[attention]

PARTNERS