Advertisement

HLSL DirectX9 - Really odd behaviour (I am stupid)

Started by August 14, 2024 02:06 AM
0 comments, last by teles1h 3 months, 1 week ago

Hi guys,

I've been sort of debugging this code for about two weeks at this point and I cannot for the life of me figure out what's wrong with it. This is my first ever shader and besides the fact that if statements DO not work and there aren't any warnings about it I think I wasted a total of 40 hours on this thus far with lots more to come.

I am setting my VS20mp using the following call:

if (FAILED(effect->SetMatrixArray(handle, buffer, count)))

Custom vertex:

struct CustomVertex
{
	enum { Format = (D3DFVF_XYZ | D3DFVF_DIFFUSE| D3DFVF_TEX1 | D3DFVF_TEXCOORDSIZE4(0) )};
	float3 position;
	unsigned int indexes; // I'm packing the weights in here using bitshifts and it works well.
	float weights[MAX_BONE_INFLUENCE];
};

Here is my Vertex/pixel shader:

float4x4 World : World;
float4x4 InvView : INVERSEVIEW;
float4x4 WorldViewProjection : WORLDVIEWPROJECTION;
int renderingPass = 85;
int renderingSorting = 0;
// Matrix
float4x4 View : VIEW;
float4x4 Projection : PROJECTION;
float4x4 InvWorld : INVERSEWORLD;
float4x4 WorldView : WORLDVIEW;

static const int VS20_MaxMatrices = 80;
float4x4 VS20mp[VS20_MaxMatrices];

struct VS_OUTPUT
{
	float4 position : POSITION;
	float4 color : COLOR;
};

VS_OUTPUT Skinning_VS20(float3 position : POSITION, float4 color : COLOR, float4 weights : TEXCOORD)
{
	VS_OUTPUT output = (VS_OUTPUT)0;

	int4 bone_index = D3DCOLORtoUBYTE4(color);
	output.color[0] = bone_index[0] * weights[0];
	output.color[1] = bone_index[1] * weights[1];
	output.color[2] = bone_index[2] * weights[2];
	output.color[3] = bone_index[3] * weights[3];
	// The line bellow is where my problems begin.
	// If I comment out the line bellow and change the last line before the return to:
	// output.position = mul(float4(position,1), WorldViewProjection);
	// I can see the colors being modified properly based on weights and the projection works perfectly fine
	output.position = mul(VS20mp[bone_index[0]], float4(position, 1));
	//  pos += mul(VS20mp[bone_index[1]], float4(position, 1)).xyz * weights[1];
	//  pos += mul(VS20mp[bone_index[2]], float4(position, 1)).xyz * weights[2];
	//  pos += mul(VS20mp[bone_index[3]], float4(position, 1)).xyz * weights[3];

	output.position = mul(output.position, WorldViewProjection);
	return output;
}

float Alpha = 0.5;
float3 Color = float3(0.5, 0.5, 0.5);
float4 Normal_PS20(in VS_OUTPUT input) : COLOR0
{
	return input.color;
}

technique Shader2
{
	pass Silhouette < string RenderingPath = "LOD_CharacterSilhouette";
	>
	{
		VertexShader = compile vs_3_0 Skinning_VS20();
		PixelShader = compile ps_2_0 Normal_PS20();
	}
}

This topic is closed to new replies.

Advertisement