About Store Forum Documentation Contact



Post Reply 
Cubemap from world
Author Message
cat555 Offline
Member

Post: #1
Cubemap from world
Hi, Esenthel supports (on the fly) the creation of cubemap image, for the actual world? The idea was to at the start of the scene, create the cubemap, that will then be assigned to materials for use as reflection.

Thanks!
09-10-2014 11:27 AM
Find all posts by this user Quote this message in a reply
Rubeus Offline
Member

Post: #2
RE: Cubemap from world
For having the image in the cache:
CACHE_MODE Cache = Images.mode( CACHE_ALL_DUMMY );
ImagePtr NewImage = Images.ptrRequire( UID( ).randomize( ) );
Images.mode( Cache );

For creating a cubemap image:
NewImage->create3D( ... );

For getting/setting pixels:
NewImage->lock();
NewImage->color3D( ... );
NewImage->unLock();
For this method, I'm not entirely sure how the coordinate system works in relation to which face is being accessed. Try to call lock/unlock only once.

For setting the reflection map to a material:
Mat->reflection_map = NewImage;
Mat->validate();
(This post was last modified: 09-10-2014 02:03 PM by Rubeus.)
09-10-2014 02:03 PM
Find all posts by this user Quote this message in a reply
cat555 Offline
Member

Post: #3
RE: Cubemap from world
Hi @Rubeus, thanks for your reply!

I've already tried that but with no luck... i just got a black image...

Code:
CACHE_MODE Cache = Images.mode( CACHE_ALL_DUMMY );
      ImagePtr NewImage = Images.ptrRequire( UID( ).randomize( ) );
      Images.mode( Cache );
      
      NewImage->create3D(1024, 512, 16, IMAGE_DXT5, 0);
      
      NewImage->lock();
      NewImage->color3D(1, 1, 1);
      NewImage->unlock();

      NewImage->ExportJPG("/tmp/image.jpg", -1); // export just to check image

Any idea?
(This post was last modified: 09-10-2014 02:51 PM by cat555.)
09-10-2014 02:47 PM
Find all posts by this user Quote this message in a reply
cat555 Offline
Member

Post: #4
RE: Cubemap from world
Hmm, i was looking into this in the wrong way... my doubt here is how do i get Color values so i can edit the image with them?
09-10-2014 04:51 PM
Find all posts by this user Quote this message in a reply
Rubeus Offline
Member

Post: #5
RE: Cubemap from world
NewImage->color3D(1, 1, 1); <-- gets the color from position 1, 1, 1
NewImage->color3D(1, 1, 1, BLUE); <-- sets the color at position 1, 1, 1 to blue

You will need to loop through every pixel and set it.
09-10-2014 05:39 PM
Find all posts by this user Quote this message in a reply
cat555 Offline
Member

Post: #6
RE: Cubemap from world
(09-10-2014 05:39 PM)Rubeus Wrote:  NewImage->color3D(1, 1, 1); <-- gets the color from position 1, 1, 1
NewImage->color3D(1, 1, 1, BLUE); <-- sets the color at position 1, 1, 1 to blue

You will need to loop through every pixel and set it.

Yes i know, but how do i get the 3D world pixel color values to be set in the image?
09-10-2014 05:42 PM
Find all posts by this user Quote this message in a reply
SamerK Offline
Member

Post: #7
RE: Cubemap from world
Quote:Yes i know, but how do i get the 3D world pixel color values to be set in the image?

You can screen capture N/S/W/E/up/down directions from cam position and then apply it to the relevant 3d image cube face direction.
(This post was last modified: 09-10-2014 08:07 PM by SamerK.)
09-10-2014 08:06 PM
Find all posts by this user Quote this message in a reply
cat555 Offline
Member

Post: #8
RE: Cubemap from world
(09-10-2014 08:06 PM)SamerK Wrote:  
Quote:Yes i know, but how do i get the 3D world pixel color values to be set in the image?

You can screen capture N/S/W/E/up/down directions from cam position and then apply it to the relevant 3d image cube face direction.

Ok, i see what your point... i'm trying to use Renderer.getBackBuffer() for that, since it returns a reference to an "Image" obj, as i need in this case.

I'll post my findings here in this thread!

Thanks!
09-10-2014 10:07 PM
Find all posts by this user Quote this message in a reply
Esenthel Offline
Administrator

Post: #9
RE: Cubemap from world
Hi,

Cubemap is not Image.create3D but Image.createCube,
and for setting pixels of a cube face you specify the 'cube_face' param in the lock method
Code:
Bool     lock    (LOCK_MODE lock=LOCK_READ_WRITE, Int mip_map=0, DIR_ENUM cube_face=DIRE_RIGHT) ; //   lock image for editing specified 'mip_map', this needs to be called before manual setting/getting pixels/colors on hardware images (IMAGE_SOFT doesn't need locking), 'cube_face'=desired cube face (this is used only for IMAGE_CUBE modes)
09-11-2014 04:03 AM
Find all posts by this user Quote this message in a reply
cat555 Offline
Member

Post: #10
RE: Cubemap from world
(09-11-2014 04:03 AM)Esenthel Wrote:  Hi,

Cubemap is not Image.create3D but Image.createCube,
and for setting pixels of a cube face you specify the 'cube_face' param in the lock method
Code:
Bool     lock    (LOCK_MODE lock=LOCK_READ_WRITE, Int mip_map=0, DIR_ENUM cube_face=DIRE_RIGHT) ; //   lock image for editing specified 'mip_map', this needs to be called before manual setting/getting pixels/colors on hardware images (IMAGE_SOFT doesn't need locking), 'cube_face'=desired cube face (this is used only for IMAGE_CUBE modes)

Hi, thanks for the clarification!

I've made progress by creating each image (and exporting it) for each cube face... they're fine, since i've imported to Esenthel editor image (as cube texture), and it looks Ok smile

But for creating the cubemap, instead of using the pixel color set, is it possible to copy each image for each face of the cubemap?

I was able to test:

Code:
someimg.copy(cubemap, -1, -1, -1, -1, IMAGE_CUBE);

It works like expected, setting /copyingthe same image (someimg) for each cube face. Is there any method that allows this, but allows also specifying for which cubeface we want to copy the image?

Thanks!
09-11-2014 12:52 PM
Find all posts by this user Quote this message in a reply
para Offline
Member

Post: #11
RE: Cubemap from world
You should use a smaller render target for rendering each cube side, something like 256x256 or 512, also make sure to set the camera fov to 90° and disable any advanced effects like DOF etc. (See the render to texture tutorial on how to render to a custom buffer).

Just an idea, maybe make a 6 by 1 sized buffer (image) as your render target, then by manipulating the viewRect render all the sides onto it, and then use buffer.toCube() to convert it to a cubemap in one go..

..but the right solution would be to:
@Esenthel, could you add the option of setting a cubemap face as the render target? This way we could render realtime cubemaps more efficiently and with less hassle.
09-11-2014 03:02 PM
Visit this user's website Find all posts by this user Quote this message in a reply
cat555 Offline
Member

Post: #12
RE: Cubemap from world
Hi, finally i managed to do it... for each image (each cube face) i have something like this (this is for DIR_UP cubemap image):

Code:
Image tmp, up, cubemap;
...

cubemap.createCube(some_size, IMAGE_R8G8B8);

D.viewFov(DegToRad(90));
Cam.setSpherical(Vec(0, 0, 0), DegToRad(0), DegToRad(90), DegToRad(0), 0).updateVelocities().set();

Renderer(Render);

up = Renderer.getBackBuffer();
tmp.create2D(up.size().y, up.size().y, IMAGE_R8G8B8);
up.crop(tmp, front.size().x / 2 - front.size().y / 2, 0, 0, front.size().y, front.size().y, 1);

if(cubemap.lock(LOCK_READ_WRITE, 0, DIRE_UP)) // in order to edit the texture we must first lock it
{
    if(tmp.lock(LOCK_READ))
    {
      FREPD(y, tmp.h()) // iterate through all y's
      FREPD(x, tmp.w()) // iterate through all x's
      {
         cubemap.color(x, y, tmp.color(x, y)); // this wasn't working before, till i realize that i was trying it without locking "tmp" image :(
      }
      tmp.unlock();
    }
cubemap.unlock(); // unlock
}

<use_cubemap>

...

Thanks to all of your input guys smile
09-11-2014 04:49 PM
Find all posts by this user Quote this message in a reply
Esenthel Offline
Administrator

Post: #13
RE: Cubemap from world
(09-11-2014 12:52 PM)cvieira Wrote:  Is there any method that allows this, but allows also specifying for which cubeface we want to copy the image?

Hi,

I think you can use Image.injectMipMap for that

para Wrote:@Esenthel, could you add the option of setting a cubemap face as the render target? This way we could render realtime cubemaps more efficiently and with less hassle
Added to the roadmap.
09-12-2014 03:14 AM
Find all posts by this user Quote this message in a reply
Post Reply