POV-Ray : Newsgroups : povray.advanced-users : 24 and 32 bit heightfields : 24 and 32 bit heightfields Server Time
1 Jul 2024 05:40:04 EDT (-0400)
  24 and 32 bit heightfields  
From: SharkD
Date: 19 Oct 2009 12:35:57
Message: <4adc956d$1@news.povray.org>
A few months ago I posted an idea for creating 24 bit heightfields using 
existing image formats. The idea is that each channel is used to encode 
height data at different levels of precision. I was wondering if this 
could be implemented as an export format in POV-Ray? I think the 
Leveller program also uses this format, and the images it outputs seem 
to already work OK when used in POV-Ray.

Here's some sample code:

//BEGIN
camera
{
	orthographic
	location	-z * 10
	direction	+z
	up		+y * 2
	right		+x * 2 * image_width/image_height
	rotate		+x * 90
}

#local hf_pigment_function_pow = function {y * pow(256,3)}
#local hf_pigment_function_b = function 
{mod(hf_pigment_function_pow(x,y,z), pow(256,1))}
#local hf_pigment_function_g = function 
{mod(hf_pigment_function_pow(x,y,z) - hf_pigment_function_b(x,y,z), 
pow(256,2))}
#local hf_pigment_function_r = function 
{mod(hf_pigment_function_pow(x,y,z) - hf_pigment_function_b(x,y,z) - 
hf_pigment_function_g(x,y,z), pow(256,3))}

#local hf_pigment_b = pigment
{
	function {hf_pigment_function_b(x,y,z) / pow(256,1)}
	color_map {[0 rgb 0][1 rgb z * 3]}
}
#local hf_pigment_g = pigment
{
	function {hf_pigment_function_g(x,y,z) / pow(256,2)}
	color_map {[0 rgb 0][1 rgb y * 3]}
}
#local hf_pigment_r = pigment
{
	function {hf_pigment_function_r(x,y,z) / pow(256,3)}
	color_map {[0 rgb 0][1 rgb x * 3]}
}

// This is the one you want
#local hf_pigment_rgb = pigment
{
	average
	pigment_map {[hf_pigment_b][hf_pigment_g][hf_pigment_r]}
}

cone
{
	0, 1, y, 0
	texture
	{
		pigment	{hf_pigment_rgb}
		finish {ambient 1}
	}
}
//END







The technique could also be extended to 32 bits. For example:

//BEGIN
camera
{
	orthographic
	location	-z * 10
	direction	+z
	up		+y * 2
	right		+x * 2 * image_width/image_height
	rotate		+x * 90
}

#local hf_pigment_function_pow = function {y * pow(256,4)}
#local hf_pigment_function_t = function 
{mod(hf_pigment_function_pow(x,y,z), pow(256,1))}
#local hf_pigment_function_b = function 
{mod(hf_pigment_function_pow(x,y,z) - hf_pigment_function_t(x,y,z), 
pow(256,2))}
#local hf_pigment_function_g = function 
{mod(hf_pigment_function_pow(x,y,z) - hf_pigment_function_t(x,y,z) - 
hf_pigment_function_b(x,y,z), pow(256,3))}
#local hf_pigment_function_r = function 
{mod(hf_pigment_function_pow(x,y,z) - hf_pigment_function_t(x,y,z) - 
hf_pigment_function_b(x,y,z) - hf_pigment_function_g(x,y,z), pow(256,4))}

#local hf_pigment_t = pigment
{
	function {hf_pigment_function_t(x,y,z) / pow(256,1)}
	color_map {[0 rgbt 0][1 rgbt <0,0,0,4,>]}
}
#local hf_pigment_b = pigment
{
	function {hf_pigment_function_b(x,y,z) / pow(256,2)}
	color_map {[0 rgbt 0][1 rgbt <0,0,4,0,>]}
}
#local hf_pigment_g = pigment
{
	function {hf_pigment_function_g(x,y,z) / pow(256,3)}
	color_map {[0 rgbt 0][1 rgbt <0,4,0,0,>]}
}
#local hf_pigment_r = pigment
{
	function {hf_pigment_function_r(x,y,z) / pow(256,4)}
	color_map {[0 rgbt 0][1 rgbt <4,0,0,0,>]}
}


// This is the one you want
#local hf_pigment_rgbt = pigment
{
	average
	pigment_map {[hf_pigment_t][hf_pigment_b][hf_pigment_g][hf_pigment_r]}
}

cone
{
	0, 1, y, 0
	open
	texture
	{
		pigment	{hf_pigment_rgbt}
		finish {ambient 1}
	}
}
//END






Mike


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.