Jump to content

Material: Brightness is not saved in material files


klepto2
 Share

Recommended Posts

It's not supposed to be. Brightness is just a hack to make up for the fact that the Win32 color picker only allows colors in the range 0-1.

The color is converted to 0-1 color and brightness for display in the editor interface, but it's really stored as a Vec4.

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

thats what i thought as well, but when you choose another brightness than 100, the colors are safed normalized and after reloading it, the editor shows again 100 instead of the original value.

  • Windows 10 Pro 64-Bit-Version
  • NVIDIA Geforce 1080 TI
Link to comment
Share on other sites

It depends. If any color channel is less than or equal to 1.0, then the brightness will be reset to 1.0. If any color channel is greater than 1.0, then brightness is used to multiply the values.

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

  • 5 weeks later...

I tested a little bit, and it was working as expected. Please let me know if you think there is any problem.

Here is the code I use for extracting the brightness value, for colors that have one channel value greater than 1.0:

Vec4 c = material->GetColor();
c.a = Clamp(c.a, 0.0f, 1.0f);
float brightness = 1.0f;
if ((c.x > 1.0f) or (c.y > 1.0f) or (c.z > 1.0f))
{
	for (int n = 0; n < 3; ++n)
	{
		brightness = Max(brightness, c[n]);
	}
	for (int n = 0; n < 3; ++n)
	{
		c[n] /= brightness;
	}
}

 

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

On 10/12/2024 at 3:59 PM, Josh said:

Is emission greater than 1.0 really something that will realistically be used?

it is more realistically than the brightness > 1.0 of the diffuse channel. In addition to what Dreikblack said, you can use the emission for much more: glowing signs, monitors with text on it and much more. Another benefit of having a brightness value (adjustable from the MaterialClass) is an easy way to implement flickering materials or ways to turn glow on/off.

On 10/11/2024 at 8:07 PM, Josh said:

I tested a little bit, and it was working as expected. Please let me know if you think there is any problem.

Here is the code I use for extracting the brightness value, for colors that have one channel value greater than 1.0:

Vec4 c = material->GetColor();
c.a = Clamp(c.a, 0.0f, 1.0f);
float brightness = 1.0f;
if ((c.x > 1.0f) or (c.y > 1.0f) or (c.z > 1.0f))
{
	for (int n = 0; n < 3; ++n)
	{
		brightness = Max(brightness, c[n]);
	}
	for (int n = 0; n < 3; ++n)
	{
		c[n] /= brightness;
	}
}

 

This looks right, but it has a major downside (at least in my opinion): Once you set the brightness to 0.0 you lose the color information. In my opinion you should always store the color and brightness independently in the material file. How it is then used in the engine doesn't matter, but it will prevent users from accidentally delete the color information.  

  • Like 1
  • Windows 10 Pro 64-Bit-Version
  • NVIDIA Geforce 1080 TI
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...