Vec4 as shader uniforms

An area for discussing new ideas and additions to Oolite.

Moderators: winston, another_commander

Post Reply
User avatar
Griff
Oolite 2 Art Director
Oolite 2 Art Director
Posts: 2483
Joined: Fri Jul 14, 2006 12:29 pm
Location: Probably hugging his Air Fryer

Vec4 as shader uniforms

Post by Griff »

If possible, could we have vec4's as shader bindings, i think Oolite uses them internally but clamps the 4th component to 1.0* and only allows you to specify 3 components of the vec 4 in shipdata.plist


* something to do with the 4th component being the alpha value in a png
User avatar
JensAyton
Grand Admiral Emeritus
Grand Admiral Emeritus
Posts: 6657
Joined: Sat Apr 02, 2005 2:43 pm
Location: Sweden
Contact:

Re: Vec4 as shader uniforms

Post by JensAyton »

Griff wrote:
If possible, could we have vec4's as shader bindings, i think Oolite uses them internally but clamps
Nah. Never touches the things.
Griff wrote:
something to do with the 4th component being the alpha value in a png
No, it’s because 1.0 is the only sane default alpha value in any context, and also because 1.0 is the standard w component for a homogeneous 4-vector converted from a Cartesian 3-vector (which Oolite uses internally). The more you know!

Seriously, though, implemented in r5009.
User avatar
Griff
Oolite 2 Art Director
Oolite 2 Art Director
Posts: 2483
Joined: Fri Jul 14, 2006 12:29 pm
Location: Probably hugging his Air Fryer

Re: Vec4 as shader uniforms

Post by Griff »

oo smashing! this'll cut down on the number of floats i'm using - always feel a bit guilty, feel like i'm hogging them all
User avatar
Griff
Oolite 2 Art Director
Oolite 2 Art Director
Posts: 2483
Joined: Fri Jul 14, 2006 12:29 pm
Location: Probably hugging his Air Fryer

Re: Vec4 as shader uniforms

Post by Griff »

I've only just got around to trying this out, I can't seem to get it working, i'm using trunk v1.77.1.5678

In my shipdata.plist shaders section i'm using a vec4 to send position.x, position.y, scale and rotation settings for a ship decal to a shader, i've written it like this

Code: Select all

Decal1_Scale_Position_Rotation = { type = vector; value = "0.72 0.765 12.0 0.5"; };
in my fragment shader I have this

Code: Select all

uniform vec4   Decal1_Scale_Position_Rotation;
but in game, oolite seems to ignore the last component in my vec4 and seems to be changing it to a 1.0, I'm probably not using the correct 'type =vector' setting in my shipdata.plist but type=vec4 doesn't seem to work at all.
User avatar
Svengali
Commander
Commander
Posts: 2370
Joined: Sat Oct 20, 2007 2:52 pm

Re: Vec4 as shader uniforms

Post by Svengali »

Try

Code: Select all

Decal1_Scale_Position_Rotation = { type = quaternion; value = "0.72 0.765 12.0 0.5"; normalized = false; asMatrix = false; };
PS: It's in w,x,y,z if I recall it right, so you may need to place the 0.5 as first one.
User avatar
Griff
Oolite 2 Art Director
Oolite 2 Art Director
Posts: 2483
Joined: Fri Jul 14, 2006 12:29 pm
Location: Probably hugging his Air Fryer

Re: Vec4 as shader uniforms

Post by Griff »

Thanks for the help Svengali, it doesn't seem to work though unfortunately, with "type = quaternion" my shader isn't able to read the values at all as it doesn't show a decal. trying it as

Code: Select all

Decal1_Scale_Position_Rotation = { type = vector; value = "0.72 0.765 12.0 0.5"; normalized = false; asMatrix = false; };
brings the decal back onto the ship but again the 4th component is overwritten to 1.0.
Post Reply