Using procedural texture for a skybox. Possible?

Here’s the thing:



My goal is to generate a procedural skybox using cubemapping. I’ve looked for some time and couldn’t find a way to do this from a shader point of view, but I think I might have found something, but (there’s always a but) I need to retrieve a texture that is on a face of a cube.



Using my procedural noise shader I’m making a tiling texture on a box. What I need is to be able to retrieve the texture for each side. Is that possible? I think I might have to use a Framebuffer somehow.



Input or idea anyone?

cough



Anything?

Getting the material obviously is easy. I don’t see a “get texture” method on the material either but it might be worth looking at the source to see if there is one.



A work around though would be to keep a record of what textures you’ve applied where (i.e. a hashmap - maybe use weak references to avoid memory leaks) and get the texture from that? Depending on what you are doing you might be able to do something more simple than that.

The issue is its in the gpu/opengl, basically just a memory range… I think you’d have to render it or something to get it back to the software side… But I might be wrong.

@zarch said:
keep a record of what textures you've applied where (i.e. a hashmap - maybe use weak references to avoid memory leaks) and get the texture from that? Depending on what you are doing you might be able to do something more simple than that.


Can't do that. It's procedural, made directly from a shader and applied to the box's sides.

@normen said:
The issue is its in the gpu/opengl, basically just a memory range.. I think you'd have to render it or something to get it back to the software side.. But I might be wrong.


Yeah my thoughts exactly. The only way I see how it can be done is by using a viewport and rendering each side to a texture, making sure they are perfectly sized to the pixel to a framebuffer, then passing those textures to the SkyFactory...

We’re way out of my depth here but can’t you apply the procedural texture directly to the skybox instead of via the intermediate steps?

@zarch said:
We're way out of my depth here but can't you apply the procedural texture directly to the skybox instead of via the intermediate steps?

I've looked everywhere and couldn't find anything to help me. This was Plan A actually, but lacking the resources to do it that way I had to find another way. I'm sure there's a way to do it directly from a shader, bu I couldn't figure out how.

you want to render a skybox on the fly right?



you would have to setup 6 different viewport rendering into 6 framebuffers to generate 6 textures, no need of an intermediate cube.Each of your viewport’s camera has to point in a different direction. Then sets the textures to north, south, etc textures of the skybox.

But if you can generate all of those different views then I think it might be easier to just make a shader to render a full screen quad in the background… rather than go through the cubemap generation trouble. Though I guess it depends on how often those cube maps change.



I didn’t read what the sky map is supposed to be so I may be talking out of my…

Hmm…



I know that using a geometry with a 4d noise function will make a seamless texture, but doing it this way… Not sure if it’ll do that. Besides, where am I supposed to generate the textures to? 6 individual quads? The shader still needs a texture coordinate, matrix etc. Right?

@pspeed said:
But if you can generate all of those different views then I think it might be easier to just make a shader to render a full screen quad ...

You mean "full viewport size" right? Cubemap textures have to be square and ^2 iirc.

And again, I need 6 textures for a skybox/cubemap and those textures have to be seamless.


... in the background... rather than go through the cubemap generation trouble. Though I guess it depends on how often those cube maps change.

Cubemaps might only change when switching from the galaxy scene to a solar system scene or to an Arena scene (for a battle). I'm not sure at this point if I want to generate a new cubemap each and every time.

It's possible I'm misunderstanding what you guys are suggesting though.

I’m suggesting that you abandon cube maps altogether and just write a custom shader. But I don’t know why that is harder than going the long way of having a custom shader generate a cube map which will then be rendered by another shader.

@pspeed said:
I'm suggesting that you abandon cube maps altogether and just write a custom shader. But I don't know why that is harder than going the long way of having a custom shader generate a cube map which will then be rendered by another shader.

I know. I've looked high and low, but couldn't find a resource that was clear on the subject.

I was actually successful on generating a colored noise map on the inside of a sphere but for some reason I wasn't able to have it act exactly as a skybox. The drawing was fine as everything was drawn above it, but moving around I would eventually go out of the "sky".

I still have the shader around, but couldn't piece the last parts together. :cry:

A JME sky is always centered around the camera not matter where it goes. If you were able to go out of your sky then it seems like that wasn’t true in your case.



Having some mesh to render to is definitely easier than trying to do it with a full screen quad, though. (my original suggestion) And is probably faster and less fragile.

@pspeed said:
A JME sky is always centered around the camera not matter where it goes. If you were able to go out of your sky then it seems like that wasn't true in your case.

Yeah, Exactly. It was mostly acting as a skybox... Not good enough. ;)


Having some mesh to render to is definitely easier than trying to do it with a full screen quad, though. (my original suggestion) And is probably faster and less fragile.

Definitively and that's why I wanted to switch to using a a cube or a sphere. Either way I wouldn't have access to the texture itself since it resides only in the GPU's memory...

I'll revisit the sky generation. If I'm lucky it'll be only a small thing I am missing. If not... I guess I'll just :cry: myself to sleep from now on. ;)

I meant that a custom shader on a sky sphere is faster than trying to spherically map a full screen quad. Either is going to be better than generating cube maps at runtime… especially if they need to change often.

Hence why I tried that in the first place. I’ll be going back to this in a bit. Finishing moon texturing and I’ll jump on it.



Although… I have a brand new WD Caviar Black 1.5 TB 64 MB cache SATA3 that is looking at me with an “You’re gonna leave me on the desk moron!?” air… :smiley:

@madjack said:
Although... I have a brand new WD Caviar Black 1.5 TB 64 MB cache SATA3 that is looking at me with an "You're gonna leave me on the desk moron!?" air... :D

Fanboy ;P

And it’s still in its antistatic bag. He’s looking at me. In a bad way. 8O

Well… It seems that avenue is not the best way.



I’m actually back where I was with a sphere textured w/o being projected “far away”, but then it hit me. I lose about 250 FPS with nothing else on the screen, just generating the sphere’s texture. So that’s not a workable solution.



Given that texture lookup is by far a lot faster than noise generation I’ll have to make texture a cube and snapshot each face’s texture to a Texture and generate a cubemap with that using the SkyFactory.



I don’t think there’s a choice here. Makes me a bit sad but it should still look good and novel.