about floatingPointImageExample

I would like to know how can I get more pictures. exr to be used as maps to create terrain. For making heightfield terrain i’m using L3DT http://www.bundysoft.com/L3DT/ but i doesn’t export to .exr format…I also have an idea that I would like to develop but has not produced many results. I wish I could dynamically create a texture to be able to draw a terrain. I developed the code, but I have no results because I did not consider that the exr format is a particular format. Does anyone have experience in this field? What image format should I use in opengl? I created a ofImage with OF_IMAGE_GRAYSCALE but it was not a good idea …

Briefly, what OpenGl image format should I use to use with ofFloatImage?
thanks

hey kalwalt – to get the .exr in the floating point image example, i used photoshop.

but in reality, most terrains don’t need much data. you could use an 8-bit format that is normalized from 0-255, and then stretch it to the range you want.

ofFloatImage uses different OpenGL formats depending on the number of channels:

  
  
int ofGetGlInternalFormat(const ofFloatPixels& pix) {  
	switch(pix.getNumChannels()) {  
		case 3: return GL_RGB32F_ARB;  
		case 4: return GL_RGBA32F_ARB;  
		default: return GL_LUMINANCE32F_ARB;  
	}  
}  
  

but if you’re asking about what filetype you should use, that depends on FreeImage. i’m pretty sure .exr is the only floating point format that FreeImage supports.

hey kalwalt – to get the .exr in the floating point image example, i used photoshop.

yes, i was able to do this .i have exported my map in .bmp format and then set to 32 bit image format and so exported to .exr.
well, basically i would like to do a terrain viewer with normal maps, diffuse tex and specular map.
now i’m try to implement the process to create tangents from normals, ( tangents needed for apply normal map), i’m trying to translate this from here http://www.ozone3d.net/tutorials/mesh-deformer-p2.php#tangent-space:

  
vec3 tangent;   
	vec3 binormal;   
	  
	vec3 c1 = cross(gl_Normal, vec3(0.0, 0.0, 1.0));   
	vec3 c2 = cross(gl_Normal, vec3(0.0, 1.0, 0.0));   
	  
	if(length(c1)>length(c2))  
	{  
		tangent = c1;	  
	}  
	else  
	{  
		tangent = c2;	  
	}  
	  
	tangent = normalize(tangent);  
	  
	binormal = cross(gl_Normal, tangent);   
	binormal = normalize(binormal);  
}  

i made this but not sure if it is correct:

  
float length(ofVec3f vector){  
  
    float result;  
    result = sqrtf((vector.x * vector.x) + (vector.y * vector.y) + (vector.z * vector.z));  
    return result;  
  
}  
void addTangent(ofVec3f normal){  
    
  
    ofVec3f tangent;  
	  
	ofVec3f c1 = normal.cross(ofVec3f(0.0, 0.0, 1.0));  
	  
	ofVec3f c2 = normal.cross(ofVec3f(0.0, 1.0, 0.0));  
  
	if(length(c1)>length(c2))  
	{  
		tangent = c1;  
	}  
	else  
	{  
		tangent = c2;  
	}  
  
	  
	tangent =tangent.normalize();  
  
  
}  

i m not interested in binormal calculation because are calculated by the frag shader . i see that you have experience with displacement mapping i ve already seen somewhere in the forum.

oh great, glad you got the .exr part figured out.

regarding the normal maps, i recommend doing it in the shader if possible. it will be much faster, unless you’re precomputing it and uploading it once.

i would add two things:

  • ofVec3f has a method called length(), so you can say c1.length() instead of writing your own length() function
  • if you’re storing the tangent in a texture before uploading it to the graphics card, you will need to use an unclamped texture. i haven’t done this before. normally what i do is i a move everything from -1/+1 to 0/1, with x/2 + .5, and then i do the reverse on the graphics card (x-.5)*2

regarding the normal maps, i recommend doing it in the shader if possible. it will be much faster, unless you’re precomputing it and uploading it once.

yes i agree with you, infact this is my idea. I have already the shader.

ofVec3f has a method called length(), so you can say c1.length() instead of writing your own length() function

I felt there was already a length function! i will use it!

if you’re storing the tangent in a texture before uploading it to the graphics card, you will need to use an unclamped texture. i haven’t done this before. normally what i do is i a move everything from -1/+1 to 0/1, with x/2 + .5, and then i do the reverse on the graphics card (x-.5)*2

thanks for the idea! but i think i will store all the tangents values by attributes.

also i found on the web these resources, this about tangent_matrix: http://www.blacksmith-studios.dk/projects/downloads/tangent-matrix-derivation.php

this tutorial about bump mapping in glsl: http://content.gpwiki.org/index.php/OpenGL:Tutorials:GLSL-Bump-Mapping and this: http://fabiensanglard.net/bumpMapping/index.php

and of course the OpenGL shading Language book…

hope that this may help someone else.
All this work should be fine integrate with physics… id est with bullet ( ofxBullet i mean…), it shouldn’t be hard to integrate in that addon, i look a bit at bullet terrain demo but i want to do before this part of the code…

hi to all, finally i get it to make my terrain with texture and normal map! look at the picture.
i have used a shader that does all the calculation for the tangent and binormal. in this way it is a bit easier since done the calculations for the tangents in the main app it isn’t so friendly. You have disadvantages like major calculation in your vertex shader , better should be done in the c++ app. I would like to release the code but i need to clean a bit all and add gloss map to the shader and maybe light map. When all will be finished i’ll put on my github repo. Basically a little tool to view terrains!

cheers! :slight_smile:

@kalwalt – nice work! look forward to seeing the code when it’s up…

hey great looking example! also looking forward to the code. maybe this can be floatingPointImageExample 2.0 :slight_smile:

wow seems great works! also thanks for the links

I finally put in my github repo, the result of my work. I used a shader that applies to the terrain a diffusion , normal and specular map. Tangents and binormali required for normal mapping are calculated by the shader. Optimal would be to calculate tangents and binormals before sending the data streams to the GPU but I found not a few difficulties in this. I’m not sure, however, that actually functions properly, especially for the light part. I wish sincerely that someone tell me your opinion. Here’s where you can download it: https://github.com/kalwalt/OFexamples you can find also other examples in my repo about light.
Best regards.
Walter
aka kalwalt

Hi,
Can I run this example on iPhone (OpenGL ES)? What must I change?

i don’t know. i’m sorry. I never worked with iPhone. but it seems that OpenGL ES doesn’t support GL_RGBA32F … sure you can with ofImage modifing a bit this example. Maybe you can find in this page an help for doing this: http://forum.openframeworks.cc/t/extremely-slow-on-windows-vs.-macbook-pro/2803/0
regards