Horde3D

Next-Generation Graphics Engine
It is currently 22.11.2024, 12:59

All times are UTC + 1 hour




Post new topic Reply to topic  [ 4 posts ] 
Author Message
PostPosted: 01.10.2009, 00:52 
Offline

Joined: 09.09.2009, 00:13
Posts: 12
I am trying to create a floating point image, upload it as a texture and use it inside a Material and would like to know if this is the fastest/only way to do it.

Code:
   
    H3DRes samplerTexture = h3dCreateTexture("samplers", 16, 2, H3DFormats::TEX_RGBA32F, H3DResFlags::NoTexMipmaps);

    float* data = static_cast<float*>(h3dMapResStream(samplerTexture, H3DTexRes::ImageElem, 0, H3DTexRes::ImgPixelStream, true, true ));

    data[0] = 0.355512; data[1] = -0.709318; data[2] = -0.102371; data[3] = 0.0; //and all the other values....

    h3dUnmapResStream(samplerTexture);


Btw, If I would like to use a TEX_RGBA16F do you have any suggestion other than the OPENEXR library to use?. (it would also be great to add support to .exr. .hdr is pretty old :) )

Then I have to find the resource material and find a sampler element defined beforehand (with the map attribute empty) in the xml to assign the new sampler. Wouldn't be nice to be able to create a new sampler on the fly :D?

Code:
    //Point the texture to the material
    H3DRes material =  h3dFindResource( H3DResTypes::Material, "models/building/volumetric.material.xml" );
    h3dSetResParamI(material, H3DMatRes::SamplerElem, 0, H3DMatRes::SampTexResI, samplerTexture);


Best regards

return true;

_________________
r3D^rgba


Top
 Profile  
Reply with quote  
PostPosted: 01.10.2009, 20:40 
Offline
Engine Developer

Joined: 10.09.2006, 15:52
Posts: 1217
That's the right way to do it. If you don't have to read out the texture you can map it with the read flag set to false. This will be more efficient since the pixel data will not be transfered from VRAM to RAM.

DDS supports Float16 formats. Another solution is to use your own encoding, something like RGBM. However, from my experience HDR textures are usually not required so often except for some cube maps (image based lighting). Most of the HDR is usually coming directly from the lighting math in the shader.

r3d wrote:
Wouldn't be nice to be able to create a new sampler on the fly :D?

The current philosophy is that the resource structure is immutable after creation. So you can only change values but nothing that would require a memory allocation. This is close to the direction that D3D10 started to take.


Top
 Profile  
Reply with quote  
PostPosted: 08.07.2010, 12:22 
Offline

Joined: 21.10.2009, 16:25
Posts: 7
I've taken the liberty to add this information to the howto section in the wiki. Maybe someone more knowledgeable should check it for correctness... I had the problem that texture creation would fail because I called h3dutLoadResorcesFromDisk before. Took me a little while to figure this out!


Top
 Profile  
Reply with quote  
PostPosted: 19.07.2010, 21:35 
Offline
Engine Developer

Joined: 10.09.2006, 15:52
Posts: 1217
Thanks for updating the wiki.

The second part, the creation of a custom sampler in the shader, is optional and probably not necessary in most cases, especially if you want to use your texture as diffuse or normal map (the corresponding samplers are already defined in the model.shader).

karstux wrote:
I had the problem that texture creation would fail because I called h3dutLoadResorcesFromDisk before. Took me a little while to figure this out!

I agree that this is a pitfall. To solve that, h3dCreateTexture could be modified to be successful if it is called for an existing texture resource which is still unloaded.


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 71 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group