Переглянути джерело

Restored TextureFlags.Envmap and tweaked visuals.

Mark Sibly 7 роки тому
батько
коміт
0b682cf1d4

+ 1 - 1
VERSIONS.TXT

@@ -1,7 +1,7 @@
 
 ***** Monkey-v2018.05 Mx2cc-v1.1.12 Ted2go-2.10 *****
 
-Added simple support for .hdr pixmap/texture/image loading (wont work on android). Removed TextureFlags.Envmap flag!
+Added simple support for .hdr pixmap/texture/image loading (wont work on android).
 
 Added mojo3d HingeJoint. See tests/hingechain.monkey2
 

+ 83 - 30
modules/mojo/graphics/texture.monkey2

@@ -70,55 +70,94 @@ Function glType:GLenum( format:PixelFormat )
 	Return GL_UNSIGNED_BYTE
 End
 
-Function ClearTexImage2D( glTarget:GLenum,width:Int,height:Int,format:PixelFormat,color:Color )
+Function UploadTexImage2D( glTarget:GLenum,image:Pixmap,mipmap:Bool,envmap:Bool )
 	
 	glCheck()
 	
+	Local format:=image.Format
+	
 	Local gliformat:=glInternalFormat( format )
 	Local glformat:=glFormat( format )
 	Local gltype:=glType( format )
 	
-	glTexImage2D( glTarget,0,gliformat,width,height,0,glformat,gltype,Null )
+	Local mip:=0
 	
-	If Not IsDepth( format )
+	Repeat
 		
-		Local image:=New Pixmap( width,1,format )
-		image.Clear( color )
+		Local width:=image.Width,height:=image.Height
 		
-		For Local iy:=0 Until height
-			glTexSubImage2D( glTarget,0,0,iy,width,1,glformat,gltype,image.Data )
-		Next
+		If envmap
+			'write mip level into alpha channel
+			Select format
+			Case PixelFormat.RGBA8
+				For Local y:=0 until height
+					Local p:=image.PixelPtr( 0,y )
+					'write miplevel to alpha!
+					For Local x:=0 Until width
+						p[x*4+3]=mip
+					Next
+				Next
+			Case PixelFormat.RGBA32F
+				For Local y:=0 until height
+					Local p:=Cast<Float Ptr>( image.PixelPtr( 0,y ) )
+					'write miplevel to alpha!
+					For Local x:=0 Until width
+						p[x*4+3]=mip/255.0
+					Next
+				Next
+			Default
+				Assert( False )
+			End
+		Endif
+		
+		If image.Pitch=width * image.Depth
+			glTexImage2D( glTarget,mip,gliformat,width,height,0,glformat,gltype,image.Data )
+			glCheck()
+		Else
+			glTexImage2D( glTarget,mip,gliformat,width,height,0,glformat,gltype,Null )
+			glCheck()
+			For Local y:=0 Until height
+				glTexSubImage2D( glTarget,mip,0,y,width,1,glformat,gltype,image.PixelPtr( 0,y ) )
+				glCheck()
+			Next
+		Endif
 		
 		glFlush() 'macos nvidia bug!
-	
-	Endif
+		
+		If Not envmap Exit
+		
+		If image.Width=1 And image.Height=1 Exit
+		image=image.MipHalve()
+		mip+=1
+	Forever
 	
 	glCheck()
 End
 
-Function UploadTexImage2D( glTarget:GLenum,image:Pixmap )
+Function ClearTexImage2D( glTarget:GLenum,width:Int,height:Int,format:PixelFormat,color:Color )
 	
 	glCheck()
 	
-	Local width:=image.Width,height:=image.Height,format:=image.Format
-
 	Local gliformat:=glInternalFormat( format )
 	Local glformat:=glFormat( format )
 	Local gltype:=glType( format )
-
-	If image.Pitch=width * image.Depth
-		glTexImage2D( glTarget,0,gliformat,width,height,0,glformat,gltype,image.Data )
-		glCheck()
-	Else
-		glTexImage2D( glTarget,0,gliformat,width,height,0,glformat,gltype,Null )
-		glCheck()
-		For Local y:=0 Until height
-			glTexSubImage2D( glTarget,0,0,y,width,1,glformat,gltype,image.PixelPtr( 0,y ) )
-			glCheck()
+	
+	glTexImage2D( glTarget,0,gliformat,width,height,0,glformat,gltype,Null )
+	
+	If Not IsDepth( format )
+		
+		Local image:=New Pixmap( width,1,format )
+		image.Clear( color )
+		
+		For Local iy:=0 Until height
+			glTexSubImage2D( glTarget,0,0,iy,width,1,glformat,gltype,image.Data )
 		Next
+		
+		glFlush() 'macos nvidia bug!
+	
 	Endif
 	
-	glFlush() 'macos nvidia bug!
+	glCheck()
 End
 
 Public
@@ -129,7 +168,7 @@ Public
 |:--------------|:-----------
 | WrapS			| Wrap S texture coordinates
 | WrapT			| Wrap T texture coordinates
-| WrapST		| Wrap bot S and T coordinates
+| WrapST		| Wrap both S and T coordinates
 | Filter		| Enable magnification filtering
 | Mipmap		| Enable minification mipmapping, and minification filtering if Filter enabled.
 | FilterMipmap	| Enable both filterin and mipmapping.
@@ -145,6 +184,7 @@ Enum TextureFlags
 	
 	Dynamic=		$0100
 	Cubemap=		$0200
+	Envmap=			$0400
 	
 	WrapST=			WrapS|WrapT
 	FilterMipmap=	Filter|Mipmap
@@ -299,6 +339,13 @@ Class Texture Extends Resource
 	Function Load:Texture( path:String,flags:TextureFlags=TextureFlags.FilterMipmap,flipNormalY:Bool=False )
 		
 		Local format:=PixelFormat.Unknown
+		If flags & TextureFlags.Envmap
+			If ExtractExt( path )=".hdr"
+				format=PixelFormat.RGBA32F
+			Else
+				format=PixelFormat.RGBA8
+			Endif
+		Endif
 		
 		Local pixmap:=Pixmap.Load( path,format,True )
 		If Not pixmap Return Null
@@ -465,7 +512,7 @@ Class Texture Extends Resource
 					glTexParameteri( _glTarget,GL_TEXTURE_MIN_FILTER,GL_NEAREST )
 				Endif
 				
-				If _flags & TextureFlags.Mipmap And Not (_flags & TextureFlags.Cubemap)
+				If _flags & TextureFlags.Mipmap And Not (_flags & (TextureFlags.Cubemap|TextureFlags.Envmap))
 '					If glexts.GL_texture_filter_anisotropic
 						Local max:Int=0
 						glGetIntegerv( GL_MAX_TEXTURE_MAX_ANISOTROPY,Varptr max )
@@ -481,11 +528,15 @@ Class Texture Extends Resource
 		
 		If _dirty & Dirty.TexImage
 			
+			Local mipmap:=(_flags & TextureFlags.Mipmap)<>Null
+			Local envmap:=(_flags & TextureFlags.Envmap)<>Null
+			
 			Select _glTarget
 			Case GL_TEXTURE_2D
 				
 				If _managed
-					UploadTexImage2D( _glTarget,_managed )
+					UploadTexImage2D( _glTarget,_managed,mipmap,envmap )
+					If envmap mipmap=False
 				else
 					ClearTexImage2D( _glTarget,_size.x,_size.y,_format,Color.Black )
 				Endif
@@ -495,22 +546,24 @@ Class Texture Extends Resource
 				If _cubeFaces[0]._managed
 					For Local i:=0 Until 6
 						Local face:=_cubeFaces[i]
-						UploadTexImage2D( face._glTarget,face._managed )
+						UploadTexImage2D( face._glTarget,face._managed,mipmap,envmap )
 					Next
+					If envmap mipmap=False
 				Else
 					For Local i:=0 Until 6
 						Local face:=_cubeFaces[i]
 						ClearTexImage2D( face._glTarget,face._size.x,face._size.y,face._format,Color.Black )
 					Next
 				Endif
+				
 			End
 			
-			If _flags & TextureFlags.Mipmap _dirty|=Dirty.Mipmaps
+			If mipmap glGenerateMipmap( _glTarget )
+			_dirty&=~Dirty.Mipmaps
 			
 		Endif
 		
 		If _dirty & Dirty.Mipmaps
-			
 			If _flags & TextureFlags.Mipmap 
 				glGenerateMipmap( _glTarget )
 				glCheck()

+ 42 - 19
modules/mojo3d/assets/shaders/imports/std.glsl

@@ -350,36 +350,59 @@ float shadowColor( vec3 position ){
 
 #endif
 
+/*
+float mipmapLod( vec2 tc ){
+    vec2 dx=dFdx( tc );
+    vec2 dy=dFdy( tc );
+    float dsqr=max( dot( dx,dx ),dot( dy,dy ) );
+    float lod=log2( dsqr ) * 0.5;
+    return max( lod,0.0 );
+}
+
+float mipmapLodCube( vec3 tv ){
+	vec2 tc;
+	vec3 at=abs( tv );
+	if( at.x>at.y && at.x>at.z ){
+		tc=vec2( tv.y,tv.z )/tv.x;
+	}else if( at.y>at.z ){
+		tc=vec2( tv.x,tv.z )/tv.y;
+	}else{
+		tc=vec2( tv.x,tv.y )/tv.z;
+	}
+	return mipmapLod( (tc+1.0)*0.5 );
+}
+*/
+
 vec3 sampleEnv( vec3 viewVec,float roughness ){
 
 	vec3 tv=r_EnvMatrix * viewVec;
 
 	if( r_EnvCube ){
 		
-		return pow( textureCube( r_EnvTextureCube,tv,roughness*r_EnvTextureMaxLod ).rgb,vec3( 2.2 ) ) * r_EnvColor.rgb;
-		
-		/*
-		float lod=textureCube( r_EnvTextureCube,tv,r_EnvTextureMaxLod ).a * 255.0 - r_EnvTextureMaxLod;
-		if( lod>0.0 ) lod=textureCube( r_EnvTextureCube,tv ).a * 255.0;
-	
+		float r_EnvTextureMaxLod=11.0;
+
+//#ifdef GL_ES
+		float lod=textureCube( r_EnvTextureCube,tv ).a * 255.0;
+		if( lod==0 ) lod=textureCube( r_EnvTextureCube,tv,r_EnvTextureMaxLod ).a * 255.0 - r_EnvTextureMaxLod;
 		return pow( textureCube( r_EnvTextureCube,tv,max( roughness*r_EnvTextureMaxLod-lod,0.0 ) ).rgb,vec3( 2.2 ) ) * r_EnvColor.rgb;
-		*/
+//#else
+//		return pow( textureCube( r_EnvTextureCube,tv,roughness*r_EnvTextureMaxLod ).rgb,vec3( 2.2 ) ) * r_EnvColor.rgb;
+//#endif
 		
 	}else{
-
-		float p=-atan( tv.y,sqrt( tv.x*tv.x+tv.z*tv.z ) ) / (pi/2.0);
-		float y=atan( tv.x,tv.z ) / pi;
-		
-		vec2 tc=vec2( y,p ) *0.5 + 0.5;
-
-		return pow( texture2D( r_EnvTexture2D,tc,roughness*r_EnvTextureMaxLod ).rgb,vec3( 2.2 ) ) * r_EnvColor.rgb;
-
-		/*
-		float lod=texture2D( r_EnvTexture2D,tc,r_EnvTextureMaxLod ).a * 255.0 - r_EnvTextureMaxLod;
-		if( lod>0.0 ) lod=texture2D( r_EnvTexture2D,tc ).a * 255.0;
 	
+		float p=-atan( tv.y,sqrt( tv.x*tv.x+tv.z*tv.z ) ) / pi + 0.5;
+		float y=atan( tv.x,tv.z ) / pi * 0.5 + 0.5;
+		vec2 tc=vec2( y,p );
+		
+//#ifdef GL_ES
+		float lod=texture2D( r_EnvTexture2D,tc ).a * 255.0;
+		if( lod==0.0 ) lod=texture2D( r_EnvTexture2D,tc,r_EnvTextureMaxLod ).a * 255.0 - r_EnvTextureMaxLod;
 		return pow( texture2D( r_EnvTexture2D,tc,max( roughness*r_EnvTextureMaxLod-lod,0.0 ) ).rgb,vec3( 2.2 ) ) * r_EnvColor.rgb;
-		*/
+//else
+//		return pow( texture2DLod( r_EnvTexture2D,tc,max( mipmapLod( tc ),roughness*r_EnvTextureMaxLod ) ).rgb,vec3( 2.2 ) ) * r_EnvColor.rgb;
+	
+//#endif
 	}
 }
 

+ 2 - 4
modules/mojo3d/assets/shaders/misc/skybox.glsl

@@ -25,14 +25,12 @@ void main(){
 		frag=pow( textureCube( r_SkyTextureCube,tv ).rgb,vec3( 2.2 ) );
 
 	}else{
-		
-		float p=-atan( tv.y,sqrt( tv.x*tv.x+tv.z*tv.z ) ) / (pi/2.0) * 0.5 + 0.5;
+
+		float p=-atan( tv.y,sqrt( tv.x*tv.x+tv.z*tv.z ) ) / pi + 0.5;
 		
 		float y=atan( tv.x,tv.z ) / pi * 0.5 + 0.5;
 		
 		frag=pow( texture2D( r_SkyTexture2D,vec2( y,p ) ).rgb,vec3( 2.2 ) );
-		
-//		frag=vec3( p,p,p );//y,y,y );
 	}
 	
 #if MX2_DEFERREDRENDERER

+ 2 - 2
modules/mojo3d/render/renderer.monkey2

@@ -839,7 +839,7 @@ When a new renderer is created, the config setting `MOJO3D\_RENDERER` can be use
 		_gdevice.BindUniformBlock( _runiforms )
 		_gdevice.BindUniformBlock( _iuniforms )
 		
-		_defaultEnv=Texture.Load( "asset::textures/env_default.jpg",TextureFlags.FilterMipmap|TextureFlags.Cubemap )
+		_defaultEnv=Texture.Load( "asset::textures/env_default.jpg",TextureFlags.FilterMipmap|TextureFlags.Cubemap|TextureFlags.Envmap )
 		
 		_skyboxShader=Shader.Open( "misc/skybox",ShaderDefs )
 
@@ -1019,7 +1019,7 @@ When a new renderer is created, the config setting `MOJO3D\_RENDERER` can be use
 			_runiforms.SetInt( "EnvCube",0 )
 		Endif
 		
-		_runiforms.SetFloat( "EnvTextureMaxLod",Log2( env.Size.y ) )
+		_runiforms.SetFloat( "EnvTextureMaxLod",Log2( env.Size.x ) )
 		_runiforms.SetColor( "EnvColor",_scene.EnvColor )
 		
 		_runiforms.SetColor( "FogColor",_scene.FogColor )

+ 4 - 4
modules/mojo3d/scene/effects/bloomeffect.monkey2

@@ -10,7 +10,7 @@ Class BloomEffect Extends PostEffect
 	
 	#rem monkeydoc Creates a new bloom effect.
 	#end
-	Method New( passes:Int=2 )
+	Method New( passes:Int=1 )
 		
 		_shader=Shader.Open( "effects/bloom" )
 		
@@ -29,7 +29,7 @@ Class BloomEffect Extends PostEffect
 		Return _passes
 	
 	Setter( passes:Int )
-		Assert( passes>0 And (passes&1)=0,"BloomEffect passes must be even and >0" )
+		Assert( passes>0,"BloomEffect passes must be >0" )
 		
 		_passes=passes
 	End
@@ -41,7 +41,7 @@ Class BloomEffect Extends PostEffect
 		Local size:=viewport.Size
 		Local source:=target.GetColorTexture( 0 )
 		
-		If Not _target0 Or size.x>_target0.Size.x Or size.y>_target0.Size.y
+		If Not _target0 Or size.x<>_target0.Size.x Or size.y<>_target0.Size.y
 			_target0=CreateRenderTarget( size,source.Format,TextureFlags.Dynamic )
 			_target1=CreateRenderTarget( size,source.Format,TextureFlags.Dynamic )
 		Endif
@@ -51,7 +51,7 @@ Class BloomEffect Extends PostEffect
 		
 		Local rtarget:=_target0
 		
-		For Local i:=0 Until _passes
+		For Local i:=0 Until _passes*2
 			
 			Super.SetRenderTarget( rtarget,New Recti( 0,0,size ) )
 			Device.RenderPass=i ? 2-(i&1) Else 0	'0,1,2,1,2,1,2...

+ 1 - 1
modules/mojo3d/scene/posteffect.monkey2

@@ -63,7 +63,7 @@ Class PostEffect
 		Local rtarget:=_gdevice.RenderTarget
 		Local rtexture:=rtarget.GetColorTexture( 0 )
 		_runiforms.SetTexture( "SourceBuffer",rtexture )
-		_runiforms.SetVec2f( "SourceBufferSize",Cast<Vec2f>( rsize ) )
+		_runiforms.SetVec2f( "SourceBufferSize",Cast<Vec2f>( rtexture.Size ) )'rsize ) )
 		_runiforms.SetVec2f( "SourceBufferScale",Cast<Vec2f>( rsize )/Cast<Vec2f>( rtexture.Size ) )
 		
 		_gdevice.RenderTarget=target

+ 1 - 1
modules/mojo3d/tests/pbrspheres.monkey2

@@ -30,7 +30,7 @@ Class MyWindow Extends Window
 		
 		_scene=New Scene
 		
-		_scene.SkyTexture=Texture.Load( "asset::miramar-skybox.jpg",TextureFlags.FilterMipmap|TextureFlags.Cubemap )
+		_scene.SkyTexture=Texture.Load( "asset::miramar-skybox.jpg",TextureFlags.FilterMipmap|TextureFlags.Cubemap|TextureFlags.Envmap )
 		
 		'create camera
 		'

+ 1 - 1
modules/mojo3d/tests/sprites.monkey2

@@ -30,7 +30,7 @@ Class MyWindow Extends Window
 		
 		_scene=New Scene( True )
 		
-		_scene.SkyTexture=_scene.LoadTexture( "asset::miramar-skybox.jpg",TextureFlags.FilterMipmap|TextureFlags.Cubemap )
+		_scene.SkyTexture=_scene.LoadTexture( "asset::miramar-skybox.jpg",TextureFlags.FilterMipmap|TextureFlags.Cubemap|TextureFlags.Envmap )
 		_scene.FogColor=Color.Sky
 		_scene.FogNear=10
 		_scene.FogFar=30

+ 1 - 1
modules/mojo3d/tests/water.monkey2

@@ -28,7 +28,7 @@ Class MyWindow Extends Window
 		
 		_scene=New Scene
 		
-		_scene.SkyTexture=Texture.Load( "asset::miramar-skybox.jpg",TextureFlags.FilterMipmap|TextureFlags.Cubemap )
+		_scene.SkyTexture=Texture.Load( "asset::miramar-skybox.jpg",TextureFlags.FilterMipmap|TextureFlags.Cubemap|TextureFlags.Envmap )
 		
 		'create camera
 		'

+ 4 - 1
modules/std/graphics/pixelformat.monkey2

@@ -34,7 +34,9 @@ Enum PixelFormat
 	
 	RGB16F
 	RGB32F
-
+	
+	RGBE8
+	
 	'deprecated
 	IA16=IA8
 	RGB24=RGB8
@@ -80,6 +82,7 @@ Function PixelFormatDepth:Int( format:PixelFormat )
 	Case PixelFormat.Depth32 Return 4
 	Case PixelFormat.RGB16F Return 6
 	Case PixelFormat.RGB32F Return 12
+	Case PixelFormat.RGBE8 Return 4
 		
 	'deprecated
 	Case PixelFormat.IA16 Return 2

+ 89 - 48
modules/std/graphics/pixmap.monkey2

@@ -3,6 +3,34 @@ Namespace std.graphics
 
 Using std.resource
 
+Extern Private
+
+Function ldexp:Float( x:Float,exp:Int )
+	
+Function frexp:Float( arg:Float,exp:Int Ptr )
+	
+Private
+
+Function GetColorRGBE8:Color( p:UByte Ptr)
+	If Not p[3] Return Color.Black
+	Local f:=ldexp( 1.0,p[3]-136 )
+	Return New Color( p[0]*f,p[1]*f,p[2]*f )
+End
+
+Function SetColorRGBE8( p:UByte Ptr,color:Color )
+	Local v:=color.r,e:=0
+	If color.g>v v=color.g
+	If color.b>v v=color.b
+	If( v<1e-32) p[0]=0;p[1]=0;p[2]=0;p[3]=0;Return
+	v=frexp( v,Varptr e ) * 256.0/v
+	p[0]=color.r*v
+	p[1]=color.g*v
+	p[2]=color.b*v
+	p[0]=e+128
+End
+	
+Public
+
 #rem monkeydoc Pixmaps allow you to store and manipulate rectangular blocks of pixel data.
 
 A pixmap contains a block of memory used to store a rectangular array of pixels.
@@ -25,7 +53,7 @@ Class Pixmap Extends Resource
 	@param pitch The pitch of the data.
 	
 	#end
-	Method New( width:Int,height:Int,format:PixelFormat=PixelFormat.RGBA32 )
+	Method New( width:Int,height:Int,format:PixelFormat=PixelFormat.RGBA8 )
 	
 '		Print "New pixmap1, width="+width+", height="+height
 
@@ -103,7 +131,7 @@ Class Pixmap Extends Resource
 	Property HasAlpha:Bool()
 		
 		Select _format
-		Case PixelFormat.A8,PixelFormat.IA16,PixelFormat.RGBA32
+		Case PixelFormat.A8,PixelFormat.IA8,PixelFormat.RGBA8
 			Return True
 		End
 		Return False
@@ -158,36 +186,39 @@ Class Pixmap Extends Resource
 		DebugAssert( x>=0 And y>=0 And x<_width And y<_height,"Pixmap pixel coordinates out of range" )
 		
 		Local p:=PixelPtr( x,y )
+		
 		Select _format
 		Case PixelFormat.A8
 			p[0]=color.a * 255
 		Case PixelFormat.I8
 			p[0]=color.r * 255
-		Case PixelFormat.IA16
+		Case PixelFormat.IA8
 			p[0]=color.r * 255
 			p[1]=color.a * 255
-		Case PixelFormat.RGB24
+		Case PixelFormat.RGB8
 			p[0]=color.r * 255
 			p[1]=color.g * 255
 			p[2]=color.b * 255
-		Case PixelFormat.RGBA32
+		Case PixelFormat.RGBA8
 			p[0]=color.r * 255
 			p[1]=color.g * 255
 			p[2]=color.b * 255
 			p[3]=color.a * 255
 		Case PixelFormat.RGB32F
-			Local fp:=Cast<Float Ptr>( p )
-			fp[0]=color.r
-			fp[1]=color.g
-			fp[2]=color.b
+			Local f:=Cast<Float Ptr>( p )
+			f[0]=color.r
+			f[1]=color.g
+			f[2]=color.b
 		Case PixelFormat.RGBA32F
-			Local fp:=Cast<Float Ptr>( p )
-			fp[0]=color.r
-			fp[1]=color.g
-			fp[2]=color.b
-			fp[3]=color.a
-'		Default
-'			Assert( False )
+			Local f:=Cast<Float Ptr>( p )
+			f[0]=color.r
+			f[1]=color.g
+			f[2]=color.b
+			f[3]=color.a
+		Case PixelFormat.RGBE8
+			SetColorRGBE8( p,color )
+		Default
+			Assert( False )
 		End
 	End
 
@@ -208,27 +239,30 @@ Class Pixmap Extends Resource
 		DebugAssert( x>=0 And y>=0 And x<_width And y<_height,"Pixmap pixel coordinates out of range" )
 	
 		Local p:=PixelPtr( x,y )
+
 		Select _format
 		Case PixelFormat.A8 
 			Return New Color( 0,0,0,p[0]/255.0 )
 		Case PixelFormat.I8
 			Local i:=p[0]/255.0
 			Return New Color( i,i,i,1 )
-		Case PixelFormat.IA16
+		Case PixelFormat.IA8
 			Local i:=p[0]/255.0
 			Return New Color( i,i,i,p[1]/255.0 )
-		Case PixelFormat.RGB24
+		Case PixelFormat.RGB8
 			Return New Color( p[0]/255.0,p[1]/255.0,p[2]/255.0,1 )
-		Case PixelFormat.RGBA32
+		Case PixelFormat.RGBA8
 			Return New Color( p[0]/255.0,p[1]/255.0,p[2]/255.0,p[3]/255.0 )
 		Case PixelFormat.RGB32F
-			Local fp:=Cast<Float Ptr>( p )
-			Return New Color( fp[0],fp[1],fp[2] )
+			Local f:=Cast<Float Ptr>( p )
+			Return New Color( f[0],f[1],f[2] )
 		Case PixelFormat.RGBA32F
-			Local fp:=Cast<Float Ptr>( p )
-			Return New Color( fp[0],fp[1],fp[2],fp[3] )
-'		Default
-'			Assert( False )
+			Local f:=Cast<Float Ptr>( p )
+			Return New Color( f[0],f[1],f[2],f[3] )
+		Case PixelFormat.RGBE8
+			Return GetColorRGBE8( p )
+		Default
+			Assert( False )
 		End
 		Return Color.None
 	End
@@ -250,36 +284,39 @@ Class Pixmap Extends Resource
 		DebugAssert( x>=0 And y>=0 And x<_width And y<_height,"Pixmap pixel coordinates out of range" )
 	
 		Local p:=PixelPtr( x,y )
+		
 		Select _format
 		Case PixelFormat.A8
 			p[0]=color Shr 24
 		Case PixelFormat.I8
 			p[0]=color Shr 16
-		Case PixelFormat.IA16
+		Case PixelFormat.IA8
 			p[0]=color Shr 24
 			p[1]=color Shr 16
-		Case PixelFormat.RGB24
+		Case PixelFormat.RGB8
 			p[0]=color Shr 16
 			p[1]=color Shr 8
 			p[2]=color
-		Case PixelFormat.RGBA32
+		Case PixelFormat.RGBA8
 			p[0]=color Shr 16
 			p[1]=color Shr 8
 			p[2]=color
 			p[3]=color Shr 24
 		Case PixelFormat.RGB32F
-			Local fp:=Cast<Float Ptr>( p )
-			fp[0]=((color Shr 16)&255)/255.0
-			fp[1]=((color Shr 8)&255)/255.0
-			fp[2]=(color&255)/255.0
+			Local f:=Cast<Float Ptr>( p )
+			f[0]=((color Shr 16)&255)/255.0
+			f[1]=((color Shr 8)&255)/255.0
+			f[2]=(color&255)/255.0
 		Case PixelFormat.RGBA32F
-			Local fp:=Cast<Float Ptr>( p )
-			fp[0]=((color Shr 16)&255)/255.0
-			fp[1]=((color Shr 8)&255)/255.0
-			fp[2]=(color&255)/255.0
-			fp[3]=((color Shr 24)&255)/255.0
+			Local f:=Cast<Float Ptr>( p )
+			f[0]=((color Shr 16)&255)/255.0
+			f[1]=((color Shr 8)&255)/255.0
+			f[2]=(color&255)/255.0
+			f[3]=((color Shr 24)&255)/255.0
+		Case PixelFormat.RGBE8
+			SetColorRGBE8( p,New Color( ((color Shr 16)&255)/255.0,((color Shr 8)&255)/255.0,(color&255)/255.0,((color Shr 24)&255)/255.0 ) )
 		Default
-			Assert( False )
+			SetPixel( x,y,New Color( ((color Shr 16)&255)/255.0,((color Shr 8)&255)/255.0,(color&255)/255.0,((color Shr 24)&255)/255.0 ) )
 		End
 	End
 
@@ -298,27 +335,32 @@ Class Pixmap Extends Resource
 		DebugAssert( x>=0 And y>=0 And x<_width And y<_height,"Pixmap pixel coordinates out of range" )
 	
 		Local p:=PixelPtr( x,y )
+		
 		Select _format
 		Case PixelFormat.A8 
 			Return p[0] Shl 24
 		Case PixelFormat.I8 
 			Local i:=p[0]
 			Return UByte($ff) Shl 24 | i Shl 16 | i Shl 8 | i
-		Case PixelFormat.IA16
+		Case PixelFormat.IA8
 			Local i:=p[1]
 			Return p[0] Shl 24 | i Shl 16 | i Shl 8 | i
-		Case PixelFormat.RGB24
+		Case PixelFormat.RGB8
 			Return UByte($ff) Shl 24 | p[0] Shl 16 | p[1] Shl 8 | p[2]
-		Case PixelFormat.RGBA32
+		Case PixelFormat.RGBA8
 			Return p[3] Shl 24 | p[0] Shl 16 | p[1] Shl 8 | p[2]
 		Case PixelFormat.RGB32F
-			Local fp:=Cast<Float Ptr>( p )
-			Return UInt($ff000000) | UInt(p[0]*255.0) Shl 16 | UInt(fp[1]*255.0) Shl 8 | UInt(fp[2]*255.0)
+			Local f:=Cast<Float Ptr>( p )
+			Return UInt($ff) Shl 24 | UInt(f[0]*255.0) Shl 16 | UInt(f[1]*255.0) Shl 8 | UInt(f[2]*255.0)
 		Case PixelFormat.RGBA32F
-			Local fp:=Cast<Float Ptr>( p )
-			Return UInt(fp[3]*255.0) Shl 24 | UInt(p[0]*255.0) Shl 16 | UInt(fp[1]*255.0) Shl 8 | UInt(fp[2]*255.0) 
+			Local f:=Cast<Float Ptr>( p )
+			Return UInt(f[3]*255.0) Shl 24 | UInt(f[0]*255.0) Shl 16 | UInt(f[1]*255.0) Shl 8 | UInt(f[2]*255.0)
+		Case PixelFormat.RGBE8
+			Local color:=GetColorRGBE8( p )
+			Return UInt($ff) Shl 24 | UInt(color.r*255.0) Shl 16 | UInt(color.g*255.0) Shl 8 | UInt(color.b*255.0)
 		Default
-			Assert( False )
+			Local color:=GetPixel( x,y )
+			Return UInt(color.a*255.0) Shl 24 | UInt(color.r*255.0) Shl 16 | UInt(color.g*255.0) Shl 8 | UInt(color.b*255.0)
 		End
 
 		Return 0
@@ -425,7 +467,6 @@ Class Pixmap Extends Resource
 			Next
 		Endif
 		
-		
 		Return t
 	End
 	
@@ -436,7 +477,7 @@ Class Pixmap Extends Resource
 	Method PremultiplyAlpha()
 		
 		Select _format
-		Case PixelFormat.IA16,PixelFormat.RGBA32,PixelFormat.RGBA16F,PixelFormat.RGBA32F
+		Case PixelFormat.IA8,PixelFormat.RGBA8,PixelFormat.RGBA16F,PixelFormat.RGBA32F
 			
 			For Local y:=0 Until _height
 				For Local x:=0 Until _width