tag:blogger.com,1999:blog-5181746871086541575.post4690931074607525215..comments2024-03-22T09:36:46.384+00:00Comments on chilliant: RGB/HSV in HLSL 5Ian Taylorhttp://www.blogger.com/profile/06869762490434824010noreply@blogger.comBlogger4125tag:blogger.com,1999:blog-5181746871086541575.post-48705775154995431152018-01-06T23:49:54.177+00:002018-01-06T23:49:54.177+00:00This comment has been removed by the author.Anonymoushttps://www.blogger.com/profile/05034693075541968883noreply@blogger.comtag:blogger.com,1999:blog-5181746871086541575.post-73211375813508233892014-09-06T19:01:39.760+00:002014-09-06T19:01:39.760+00:00Having said all that, actually setting all values ...Having said all that, actually setting all values of 'V' throughout an image to a fixed value is a strange thing to do. If you want to change the "brightness" then linear scaling the RGB channels by an amount makes sense. Of course, if you want to increase the brightness (i.e. the scaling factor is > 1) just make sure you clamp the result.<br /><br />Alternatively, you may be wanting to set the 'V' without changing the 'H' or the 'S'. This can be a little bit more tricky. I'll add another entry for that topic.Ian Taylorhttps://www.blogger.com/profile/06869762490434824010noreply@blogger.comtag:blogger.com,1999:blog-5181746871086541575.post-19354618627566927902014-09-06T17:22:07.485+00:002014-09-06T17:22:07.485+00:00Hi Anonymous,
Yes, you can do that ... though the...Hi Anonymous,<br /><br />Yes, you can do that ... though there's a caveat. I'm assuming you're talking about the 'V' channel in HSV space; in which case, V = max(R,G,B). So to modify the RGB components you simply have to scale R, G and B by a common amount. Supposing your input float3 is "rgb_in" and your required 'V' is "v_out", then:<br /><br />float v_in = max(max(rgb_in.r, rgb_in.g), rgb_in.b);<br />float scale = v_out / v_in;<br />float3 rgb_out = rgb_in * scale;<br /><br />The problem comes when the input is fully black, i.e. "v_in" is zero. One solution could be to produce an appropriately-bright grey value based on "v_out" under those circumstances:<br /><br />float v_in = max(max(rgb_in.r, rgb_in.g), rgb_in.b);<br />float3 rgb_out;<br />if (v_in < 1e-10) {<br /> rgb_out = float3(v_out, v_out, v_out);<br />} else {<br /> float scale = v_out / v_in;<br /> rgb_out = rgb_in * scale;<br />}<br /><br />I hope this helps.Ian Taylorhttps://www.blogger.com/profile/06869762490434824010noreply@blogger.comtag:blogger.com,1999:blog-5181746871086541575.post-56498172624432609622014-09-04T23:01:29.869+00:002014-09-04T23:01:29.869+00:00Great work!
I have a query for you. I am looking ...Great work!<br /><br />I have a query for you. I am looking to manipulate only the v channel of an image and do not need to touch the h and s channels. So I only need the h and s to get back to RGB after modifying the v. Is there a way in this case to save computation by not fully computing h and s and instead only compute enough information which can be combined with the updated v value to get back to RGB?Anonymousnoreply@blogger.com