Jump to content

Script color property returns unexpected results


Recommended Posts

Playing around with a script that allows the user to pick a color from the object panel to be used with a shader. Setting the initial value of the color works as expected and fills out the property panel correctly:

Script.MyColor = Vec4(1,0,0,1)--Color "MyColor"

post-14-0-38165700-1426126023.jpg

 

But if the color property is modified via the panel, then it will return a number based on the 0-255 scale which will fail in the shader.

 

In an attempt to work around this, I changed my initial value to:

Script.MyColor = Vec4(255,0,0,255)--Color "MyColor"

which results in this:

post-14-0-54529000-1426124281.jpg

which gives weird property panel results and still would be unuseable in my shader without dividing each component by 255.

 

Since I have no viable method to determine if the color is being set by default or by the color picker, the returned color needs to be on a 0-1 scale to work properly.

 

example script:

Script.MyColor = Vec4(1,0,0,1)--Color "MyColor"

function Script:Start()
  local color = self.MyColor
  System:Print(color.r..", "..color.g..", "..color.b..", "..color.a)
  self.entity:SetColor(color)
end

Win7 64bit / Intel i7-2600 CPU @ 3.9 GHz / 16 GB DDR3 / NVIDIA GeForce GTX 590

LE / 3DWS / BMX / Hexagon

macklebee's channel

Link to comment
Share on other sites

Just pointing out that all the LE color features (SetColor, shaders, and even setting the color picker property) use the 0-1 scale except for the color picker's returned values. For consistency and to avoid problems as pointed out above, the color picker should return values scaled 0-1 instead of 0-255.

  • Upvote 3

Win7 64bit / Intel i7-2600 CPU @ 3.9 GHz / 16 GB DDR3 / NVIDIA GeForce GTX 590

LE / 3DWS / BMX / Hexagon

macklebee's channel

Link to comment
Share on other sites

Fixed for the next build. The editor will show colors as 0-255 but the engine will divide by 255 on loading.

  • Upvote 2

My job is to make tools you love, with the features you want, and performance you can't live without.

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
 Share

×
×
  • Create New...