 # Thread: RGB Coefficient- Limiting Range From 0-255 to Prevent Invalid Values

1. ## RGB Coefficient- Limiting Range From 0-255 to Prevent Invalid Values

I am making a pseudo-3D game with a level that involves the character standing on a conveyor belt heading into a darkened tunnel and am having trouble with programming the RGB values of objects emerging from the darkness in the distance.

RGB Problem2.jpg

I have programmed a formula to alter the RGB Coefficient value dependant on the Y-value of the desired object so that it becomes less dark as it appears to approach the camera.
This, in theory works when the calculated value is between 0 and 255.

HOWEVER, when the value is calculated at LESS than 0, the object is then displayed at what I describe as "255" value.
The inverse also happens once an object appears close to the maximum Y-value, and if the RGB value is more than 255, the object then goes black, as if at "0" value.

How can I effectively limit the max/min range of this value so that I can avoid this problem?

I have tried setting up a range condition in the same event, but it doesn't appear to do the job.

RGB Problem.jpg  Reply With Quote

2. Maybe you can do it by using min() and max() function like that :

If your result is below 0, the max function will return 0, if not it will return your result. Then min will do the same if your result is above 255 it will return 255, if not you'll keep your result

Here is an exemple of how it should normaly work :

min(max(0,-5),255) = min(0,255) = 0

min(max(0,521),255) = min(521,255) = 255

min(max(0,94),255) = min(94,255)= 94

Hope it help   Reply With Quote

But how can I incorporate this in order to program the 3 different values (R--,G--,B--) as opposed to just the one? (which tends to only alter the red?)  Reply With Quote

4. Since your calcul for R,G and B seem to be the same you can do something like this : 15.PNG
You store the result of your calcul inside a variable and use this variable in GetRGB() function

Or you can use do the calcul inside of GetRGB like you did in your exemple : 16.PNG  Reply With Quote

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•