hlsl irrlicht

You are an experienced programmer and have a problem with the engine, shaders, or advanced effects? Here you'll get answers.
No questions about C++ programming or topics which are answered in the tutorials!
Post Reply
Revan1985
Posts: 89
Joined: Tue May 08, 2007 4:11 pm
Location: Italy

hlsl irrlicht

Post by Revan1985 »

hi all.
I'm developing a game for ittlicht, using the Chield example located here http://irrlicht.sourceforge.net/phpBB2/ ... hp?t=38544

Now, i've a little problem.
Seen that my game will be in direct3d9/11 when i'll finish my d3d11driver,
i'm converting the shader glsl in hlsl.
It's not hard, i've already done this, but i've a strange problem now.

When i'm going to set the hlsl variable, irrlicht say me "i can't found the variable to set".

Now, here is the shader

Code: Select all

float Time;
float Radius;
float Intensity;

float4x4 View;
float4x4 World;
float4x4 Projection;

float3 HitPoint;
float3 Position;

texture ModelTexture;
texture GradientTexture;

sampler2D ModelSampler : register(s0);

sampler2D GradientSampler : register(s1);

struct VertexShaderInput
{
	float4 Position : POSITION0;
	float3 Normal : NORMAL0;
	float2 TexCoord : TEXCOORD0;
};

struct VertexShaderOutput
{
	float4 Position : POSITION0;
	float3 Normal : TEXCOORD0;
	float2 TexCoord : TEXCOORD1;
};

struct PixelShaderOutput
{
	float4 RGBAColor : COLOR0;
};

VertexShaderOutput VertexMain(VertexShaderInput Input)
{
	VertexShaderOutput Output = (VertexShaderOutput)0;
	float4 worldPos = mul(Input.Position, World);
	float4 viewPos = mul(worldPos, View);
	Output.Position = mul(viewPos, Projection);
	
	Output.Normal = mul(Input.Normal, World);
	Output.TexCoord = Input.TexCoord;
	
	return Output;
}

PixelShaderOutput PixelMain(VertexShaderOutput Input)
{
	Input.TexCoord.x += cos(Time);
	Input.TexCoord.y += sin(Time);
	
	float4 ColorModel = tex2D(ModelSampler, Input.TexCoord);
	float Factor = 0.0f;
	float Distance = length(Position - HitPoint);
	Factor = max( Intensity / (Distance * Distance), 0.0f);
	ColorModel.w *= Factor;
	
	PixelShaderOutput Output;
	Output.RGBAColor = ColorModel;
	return Output;
}
and here where i set the variables

Code: Select all

video::IVideoDriver* driver = services->getVideoDriver();

			
			core::matrix4 world = driver->getTransform(video::ETS_WORLD);
			core::matrix4 view = driver->getTransform(video::ETS_VIEW);
			core::matrix4 projection = driver->getTransform(video::ETS_PROJECTION);
			
			services->setVertexShaderConstant("Time", /*(f32*)*/&TimeMs, 1);
			services->setVertexShaderConstant("Radius", /*(f32*)*/&Radius, 1);
			/*services->setVertexShaderConstant("ModelTexture", (f32*)&texture0, 1);
			services->setVertexShaderConstant("GradientTexture", (f32*)&texture1, 1);*/

			services->setVertexShaderConstant("Intensity", /*(f32*)*/&Intensity, 1);
			services->setVertexShaderConstant("HitPoint", /*(f32*)*/&HitPoint.X, 3);

			services->setVertexShaderConstant("World", world.pointer(), 16);
			services->setVertexShaderConstant("View", view.pointer(), 16);
			services->setVertexShaderConstant("Projection", projection.pointer(), 16);
now, can i know what i'm doing wrong?
the error sent by irrlicht is this :

Code: Select all

HLSL Variable to set not found: 'HitPoint'. Available variables are:
  'Projection' Registers:[begin:8, count:4]
  'View' Registers:[begin:0, count:4]
  'World' Registers:[begin:4, count:4]
this is repeated for all the varibles different from World, View and Projection.

Thanks for any help, and sorry for my bad english ^^
CPU: AMD PHENOMII X6 1090T BE 3,2GHZ
RAM : OCZ 8GB 2*4GB DDR3 LOW VOLTAGE 1333
VGA: GeForce GTX680 2GB
HD : 500GB + 500GB + 2x1TB Raid Edition + 500GB External
Motherboard: ASUS CROSSHAIR FORMULA 4 890FX AM3
PSU: Corsair 750W
CPU Cooling: Katana 2
Bate
Posts: 364
Joined: Sun Nov 01, 2009 11:39 pm
Location: Germany

Post by Bate »

HitPoint, Time, Intensity are used in the pixel shader.

So, use "setPixelShaderConstant" for these.

btw "radius" is never used, so remove it, use it or comment it out.
Never take advice from someone who likes to give advice, so take my advice and don't take it.
slavik262
Posts: 753
Joined: Sun Nov 22, 2009 9:25 pm
Location: Wisconsin, USA

Post by slavik262 »

Bate wrote:btw "radius" is never used, so remove it, use it or comment it out.
The shader compiler should automatically strip out any unused variables itself.
Bate
Posts: 364
Joined: Sun Nov 01, 2009 11:39 pm
Location: Germany

Post by Bate »

...and that's why an error will occur by trying to set it.
Never take advice from someone who likes to give advice, so take my advice and don't take it.
Post Reply