Ramp texture

User avatar
clintonman
Captain
Posts: 5422
Joined: 21 May 2009, 21:08
Type the number ten into the box: 0
Location: California
Contact:

Re: Ramp texture

Post by clintonman »

Found the problem. The reason for the error was because the MapRange function was trying to divide by zero. This happens when 2 keys have the exact same position. Added a check so it bypasses the division when the start and end of the range are the same value. The function is somewhere around line 500 of the RampDataNode.

Code: Select all

// https://rosettacode.org/wiki/Map_range
function MapRange(val,a1,a2,b1,b2)
{
	if(Math.abs(a2 - a1) < Number.MIN_VALUE) return b1;
	var val2 = Math.min(val,a2);
	s = Math.max(val2, a1);
	return b1 + (s-a1)*(b2-b1)/(a2-a1)
}
It's funny I searched the internet and everyone is giving the same function for mapping a range and no one is checking for the divide by zero error case.

Edit:
side note, if you add a color picker it should be a normal color picker, not the abstract art version of a color picker.
Clinton Reese

http://clintons3d.com
User avatar
clintonman
Captain
Posts: 5422
Joined: 21 May 2009, 21:08
Type the number ten into the box: 0
Location: California
Contact:

Re: Ramp texture

Post by clintonman »

ramp2.jpg
Here the ramp is used to add a blue tint to the lower part of the night sky.
RampCompressionOff.jpg
RampCompressionOff.jpg (46.92 KiB) Viewed 2727 times
The Compression in the material bitmap had to be turned off to get a smooth ramp texture. When on it gave a stair step like change of color.
Clinton Reese

http://clintons3d.com
User avatar
trueBlue
Captain
Posts: 5208
Joined: 06 Jul 2009, 22:50
Type the number ten into the box: 10

Re: Ramp texture

Post by trueBlue »

clintonman wrote: 12 Feb 2020, 04:45 Found the problem. The reason for the error was because the MapRange function was trying to divide by zero. This happens when 2 keys have the exact same position. Added a check so it bypasses the division when the start and end of the range are the same value. The function is somewhere around line 500 of the RampDataNode.

Code: Select all

// https://rosettacode.org/wiki/Map_range
function MapRange(val,a1,a2,b1,b2)
{
	if(Math.abs(a2 - a1) < Number.MIN_VALUE) return b1;
	var val2 = Math.min(val,a2);
	s = Math.max(val2, a1);
	return b1 + (s-a1)*(b2-b1)/(a2-a1)
}
It's funny I searched the internet and everyone is giving the same function for mapping a range and no one is checking for the divide by zero error case.

Edit:
side note, if you add a color picker it should be a normal color picker, not the abstract art version of a color picker.
Working great!
Is there anyway you can export out the Texture slots to a Texture aspect, and add a Add/Remove button script?
Edit: I notice that you can add unlimited Textures as it is now. Remove Texture is not working when in this state..
TextureAspect.PNG
User avatar
trueBlue
Captain
Posts: 5208
Joined: 06 Jul 2009, 22:50
Type the number ten into the box: 10

Re: Ramp texture

Post by trueBlue »

Here is my attempt for a Texture UI for your V Ramp as a D3D material

D3D V Ramp material
Add
Luminosity Color Picker
V Ramp.PNG
V Ramp.PNG (16.51 KiB) Viewed 2697 times
init script
Add
Node.ConReset(System.ThisOwner(), "Red");
Node.ConReset(System.ThisOwner(), "Green");
Node.ConReset(System.ThisOwner(), "Blue");
Node.ConReset(System.ThisOwner(), "lum");


RampDataNode
Add
params.ConValue("Current_Key") = CurrentKey;

add texture script
Comment
//Node.ExportConnector(System.ThisOwner() + "/RampDataNode", "Texture" + curkey, "", 1, 1);

remove texture script
Not in use

Texture aspect
D3D V Ramp.PNG
RampBitmap / Clickable Bitmap Control
Add
Activity.Run("%THIS_NAME%" + "/add texture")

Use:
First 8 Keys can be textures
LMB click in Ramp Bitmap control to add texture
Ctrl + LMB select Bitmap to change texture
RMB select Reset - Texture @ Key # to remove texture
Attachments
D3D V Ramp.zip
(391.7 KiB) Downloaded 204 times
User avatar
trueBlue
Captain
Posts: 5208
Joined: 06 Jul 2009, 22:50
Type the number ten into the box: 10

Re: Ramp texture

Post by trueBlue »

If you remove the 0 key, you will get several errors and you can not continue adding keys.
Remove Key 0.PNG
Remove Key 0.PNG (10.59 KiB) Viewed 2682 times
Second errorRemove Key 0.PNG
Second errorRemove Key 0.PNG (10.95 KiB) Viewed 2682 times
Adding:

Code: Select all

if(key == 0) return;
to the remove key script seems to work.
User avatar
clintonman
Captain
Posts: 5422
Joined: 21 May 2009, 21:08
Type the number ten into the box: 0
Location: California
Contact:

Re: Ramp texture

Post by clintonman »

Added the ramp textures to my site. It has my original ugly texture and the ramp textures extracted from the ramp materials of the Unofficial Update.

http://clintons3d.com/plugins/truespace ... rials.html
Clinton Reese

http://clintons3d.com
Post Reply