Setting shader constants

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
Nyxojaele
Posts: 98
Joined: Mon Sep 18, 2006 4:06 am

Setting shader constants

Post by Nyxojaele »

In my IShaderConstantSetCallBack::OnSetConstants function, I should be using setPixelShaderConstant and setVertexShaderConstant for setting my constants, but there's 2 overloads, each of which has a description stating that they can be used on an ASM or high level shader, but do they have to be?

What I mean is this:
I am assuming that an ASM shader wouldn't recognize a name in the overload with this param set: (const c8 *name, const f32 *floats, int count).

But could I use the other overload with this param set: (const f32 *data, s32 startRegister, s32 constantAmount = 1), for both a high level AND an ASM shader file?

The reason I ask is because my code will accept both ASM and high level shader files, and they currently all use the same callback, so they use the userData parameter. But now when they want to set constants, I'm not sure exactly how I should go about it, because if I have to use only a certain overload depending on which function was used to load the file, I'll have to pass some more values into the callback (I can do that part, that's fine- I just want to know if I have to do so!)

<EDIT>Alternatively, could I just blindly call BOTH overloads and they won't interfere with each other or crash the application?</EDIT>
Halifax
Posts: 1424
Joined: Sun Apr 29, 2007 10:40 pm
Location: $9D95

Post by Halifax »

Hmm, I don't know exactly what you question is. But I am sure that tutorial 10 will help you in your quest.
TheQuestion = 2B || !2B
Nyxojaele
Posts: 98
Joined: Mon Sep 18, 2006 4:06 am

Post by Nyxojaele »

Okay, I'll elaborate a bit.

Here is the API docs on the pixel shader functions I'm referring to. The same question applies to the vertex shaders, but I'll only refer to the pixel ones for simplicity's sake

Code: Select all

virtual void irr::video::IMaterialRendererServices::setPixelShaderConstant  	(   	const f32 *   	 data,
		s32  	startRegister,
		s32  	constantAmount = 1
	)  	[pure virtual]

Sets a pixel shader constant. Can be used if you created a shader using pixel/vertex shader assembler or ARB_fragment_program or ARB_vertex_program.
and

Code: Select all

virtual bool irr::video::IMaterialRendererServices::setPixelShaderConstant  	(   	const c8 *   	 name,
		const f32 *  	floats,
		int  	count
	)  	[pure virtual]

Sets a constant for the pixel shader based on a name. This can be used if you used a high level shader language like GLSL or HLSL to create a shader. See setVertexShaderConstant() for an example on how to use this.
So as you can see, the docs say that the 2nd override can be used if I used a high level shader language, which is to say that I used IGPUProgrammingServices::addHighLevelShaderMaterial to add the shader, and the 1st override can be used if I used an ASM shader language, which is to say that I used IGPUProgrammingServices::addShaderMaterial to add the shader.

What I want to know, is since the docs only say "can" be used, does that mean "have to" be used? ie. If I used IGPUProgrammingServices::addShaderMaterial to add a shader, could I use setPixelShaderConstant(const c8 *name, const f32 *floats, int count) to set the constants for it? Alternatively, if I used IGPUProgrammingServices::addHighLevelShaderMaterial to add a shader, could I use setPixelShaderConstant(const f32 *data, s32 startRegister, s32 constantAmount = 1) to set the constants for it?
Halifax
Posts: 1424
Joined: Sun Apr 29, 2007 10:40 pm
Location: $9D95

Post by Halifax »

The answer is no. The simply used 'can' because that is the word of choice I guess. I would not take 'can' to implicitly suggest that it could be used with another type.

If you think about it, how could use the overidden method, in which you provide a name, with an assembly shader? It's not possible in short. And how could you use the one, in which you provide the register offset, in a high-level shader? The compiler handles all the register allocation, etc., and you don't have any idea on where your data will end up.
TheQuestion = 2B || !2B
RenoRosco
Posts: 11
Joined: Sat Sep 15, 2007 7:26 am

Post by RenoRosco »

Look at tutorial 10 they do exatly what you want. checking for highl level shaders and use the corresponding function to set the constants.
Halifax
Posts: 1424
Joined: Sun Apr 29, 2007 10:40 pm
Location: $9D95

Post by Halifax »

RenoRosco wrote:Look at tutorial 10 they do exatly what you want. checking for highl level shaders and use the corresponding function to set the constants.
Yeah, I am pretty sure he knew that. He just wanted to inquire as to whether they could be used interchangably, based off the documentation.
TheQuestion = 2B || !2B
Post Reply