PDA

View Full Version : compiling shaders



NecroDOME
26-04-2007, 10:32 PM
I cant compile a shader, error message: error X3501: 'main': entrypoint not found

Delphi caode (Code is a valid string, I checked in the debugger)

if Failed(D3DXCompileShader(PChar(Code), SizeOf(Code)-1, nil, nil, 'main',
PChar(Profile), 0, @pCode, @pErrors, @ConstantTable)) then
begin
if LogErrors then
begin
Log('Error compiling vertex shader '+Profile);
Log(PChar(pErrors.GetBufferPointer));
end;
Errors := PChar(pErrors.GetBufferPointer);
Exit;
end;


Shader code:


float4x4 World : register(c0);
float4x4 View : register(c4);
float4x4 Proj : register(c8);

struct VS_OUTPUT
{
float4 Pos : POSITION;
float4 Diffuse : COLOR0;
float2 Tex : TEXCOORD0;
};

struct VS_INPUT
{
float3 Pos : POSITION;
float3 Normal : NORMAL;
float2 Tex : TEXCOORD0;
};

VS_OUTPUT main(const VS_INPUT Input)
{
float3 Pos = mul(float4(Input.Pos, 1), World);

Pos = mul(float4(Pos, 1), (float4x3)View);

VS_OUTPUT Out;
Out.Pos = mul(float4(Pos, 1), Proj);
Out.Diffuse = float4(1, 1, 1, 1);
Out.Tex = Input.Tex;
return Out;
}

Maybe we need to write a pascal interpeter so we can write shaders in pascal :P

LP
27-04-2007, 04:00 AM
Is Code an array of characters or a string? If it is a string, then you should use Length instead of SizeOf:

if Failed(D3DXCompileShader(PChar(Code), Length(Code), nil, nil,
PChar('main'), PChar(Profile), 0, @pCode, @pErrors,
@ConstantTable)) then ...

I am not sure about the rest of parameters though, since I am using effect files instead of writing shaders separately. :oops:

Also, is there a reason to use three separate matrix multiplications in your shader code for each vertex?

You can use only one multiplication by premultiplying all three matrices and then using something like this:


// The result of World * View * Projection matrix multiplication
float4x4 g_mWVP : register(c0);

struct VS_OUTPUT
{
float4 Pos : POSITION;
float4 Diffuse : COLOR0;
float2 Tex : TEXCOORD0;
};

struct VS_INPUT
{
float3 Pos : POSITION;
float3 Normal : NORMAL;
float2 Tex : TEXCOORD0;
};

VS_OUTPUT main(const VS_INPUT Input)
{
VS_OUTPUT Out = (VS_OUTPUT)0;

Out.Pos = mul(float4(Input.Pos, 1.0f), g_mWVP);
Out.Tex = Input.Tex;

return Out;
}

Dan
27-04-2007, 04:36 AM
everything compiled:


D3DXCompileShader(
PChar(Memo1.Text),
length(Memo1.Text),
nil, nil,
'main',
'vs_1_1',
0,
@ShaderBuffer,
@ErrorBuffer,
@ConstantTable
);

As Lifepower said it's probably SizeOf(Code)-1 that was causing the problem.

NecroDOME
27-04-2007, 07:42 AM
Thanx, it worked... i was looking elsewhere for the error... (and thx to lifepower :) )