• Advertisement
Sign in to follow this  

Does my HLSL Shader work right?

This topic is 3385 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Well I've been having a problem once I tried to do rag dolls in my engine, things are just not moving right. I need to remove a few possibilities and the way it works right now I would have to do a complete over hall on it to run the tests I need to. I'm going to post my default shader and I hope someone can look over it and tell me if anything is wrong with it.
Texture2D txDiffuse
< 
string UIName = "Base Texture";
>;
SamplerState samLinear
{
    Filter = MIN_MAG_MIP_LINEAR;
    AddressU = Wrap;
    AddressV = Wrap;
};

TextureCube txEnvironment
<
string UIName = "Environment Map";
>;
SamplerState envSampler
{
	Filter = MIN_MAG_MIP_LINEAR;
	AddressU = Clamp;
	AddressV = Clamp;
	AddressW = Clamp;
};

float Environment_map_intensity
<
	string UIName = "Intensity";
	float UIMin = 0.000000;
	float UIMax = 1.000000;
	float UIStep = 0.01;
	string UIWidget = "slider";
> = 1.000000;

float4 Ambient  <
	string UIName = "Ambient";
> = float4( 0.47f, 0.47f, 0.47f, 1.0f );
	
float4 Diffuse  <
	string UIName = "Diffuse";
> = float4( 0.47f, 0.47f, 0.47f, 1.0f );

float4 lightPos : Position <  string UIName = "Light Position"; string Object = "PointLight";> ={0.0f, 0.0f, -10.0f, 0.0f};

float4x4 World				: WORLD;
float4x4 View				: WORLDVIEW;
float4x4 Projection			: PROJECTION;
float4x4 WorldMatrixArray[256]		: WORLDMATRIXARRAY;

struct VS_INPUT
{
	float4 pos			: POSITION;
	float3 norm			: NORMAL;
	float2 tex			: TEXCOORD0;
	float4 bw			: TEXCOORD1;
	float4 bi			: TEXCOORD2;
};

struct PS_INPUT
{
	float4 pos			: SV_POSITION;
	float4 pos2			: POSITION;
	float2 tex			: TEXCOORD0;
	float3 norm			: NORMAL;
};


PS_INPUT VS( VS_INPUT In )
{

	PS_INPUT Out = (PS_INPUT)0;
	Out.pos = In.pos;
	Out.norm = In.norm;
	Out.pos += mul(In.pos, WorldMatrixArray[In.bi[0]]) * In.bw[0];
	Out.norm += mul(In.norm, (float3x3)WorldMatrixArray[In.bi[0]]) * In.bw[0];
	Out.pos += mul(In.pos, WorldMatrixArray[In.bi[1]]) * In.bw[1];
	Out.norm += mul(In.norm, (float3x3)WorldMatrixArray[In.bi[1]]) * In.bw[1];
	Out.pos += mul(In.pos, WorldMatrixArray[In.bi[2]]) * In.bw[2];
	Out.norm += mul(In.norm, (float3x3)WorldMatrixArray[In.bi[2]]) * In.bw[2];
	Out.pos += mul(In.pos, WorldMatrixArray[In.bi[3]]) * In.bw[3];
	Out.norm += mul(In.norm, (float3x3)WorldMatrixArray[In.bi[3]]) * In.bw[3];
	Out.pos2 = Out.pos;
	Out.pos = mul( Out.pos, mul( Projection, View ) );
	Out.tex = In.tex;
	return Out;
}

float4 PS( PS_INPUT input) : SV_Target
{
float4 color = txDiffuse.Sample( samLinear, input.tex );
float a = color.w;
color = (color * (dot(input.norm,normalize(input.pos2-lightPos)))) + ( Environment_map_intensity * txEnvironment.Sample( envSampler, -reflect( normalize( input.pos2 - View[3] ).xyz, input.norm.xyz )));
color.w = a;
return color;
}

technique10 Render
{
	pass P0
	{
		SetVertexShader( CompileShader( vs_4_0, VS() ) );
		SetGeometryShader( NULL );
		SetPixelShader( CompileShader( ps_4_0, PS() ) );
	}
}




I know this is a far fetch but I can't figure out whats wrong...

Share this post


Link to post
Share on other sites
Advertisement
Quote:
Original post by the_edd
If you're unsure but suspect your shader code, why not go back to a fixed-function pipeline until you fix the problem?


Well one reason is that there is no fixed function in DirectX 10 but anyways I fixed the shader and it was only partly the reason for the problem and I believe it's in the way I'm creating the matrices to send to the shader for more information go to this thread.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement