Shaders take only float4?

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
dart_theg
Posts: 88
Joined: Sun Dec 29, 2024 3:13 am

Shaders take only float4?

Post by dart_theg »

I try to load parameters like just single number values etc but it seems like I can only ever load float4. Am I just doing something wrong? I’m new to shader code. I mean specifically loading and setting shader parameters in irrlicht.
Noiecity
Posts: 390
Joined: Wed Aug 23, 2023 7:22 pm
Contact:

Re: Shaders take only float4?

Post by Noiecity »

I don't know if it has anything to do with it, but I've noticed that some graphics cards support 16-bit floating-point, while others don't
Irrlicht is love, Irrlicht is life, long live to Irrlicht
CuteAlien
Admin
Posts: 10024
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: Shaders take only float4?

Post by CuteAlien »

By load you mean passing parameters from CPU to GPU? Should work for float like for other types. I just did a quick test with d3d9.hlsl and example "10.Shaders" in Irrlicht. Added a float in the global variables section.

Code: Select all

float dummy; 
Used it later in the pixelMain to see something:

Code: Select all

Output.RGBColor += dummy;
On c++ side I got the id for that shader variable in the shader callback like:

Code: Select all

DummyID = services->getPixelShaderConstantID("dummy"); // make sure you get the correct variable name here - check result for >= 0 to be sure it worked
And then setting it each frame like this:

Code: Select all

static float dummyCpu = 0.f;
dummyCpu += 0.01f; // just letting it flicker colors a bit
if ( dummyCpu> 1.0 )
	dummyCpu = 0.0;
services->setPixelShaderConstant(DummyID, &dummyCpu, 1); // that's the line that passes the cpu value to the gpu
There are certainly other things you can mess up. But generally a good idea to test if something works in principle by modifying the Irrlicht example first. If it works there - then you know you have some bug in your code. If the Irrlicht example fails at well... then we have to start really hunting what's going on.
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Post Reply