for my game I use a fixed camera position and there is a skybox. Assume there is e.g. a house painted on the skybox and I want that the ball’s visibility depends on its relative depth with respect to the face (which represents the house position). The blue ball should be invisible, the red one should be visible. In xith I solved this problem, by using the skybox texture also for the face but then I need a customized texture projection. How can this be solved in jme3? I did not find a custom texture projection possibility, or can my concern be done with another trick?
Thanks for your help.
So if i got it right, like fake objects that are further away than the house?
My approach would be 6 low res viewports that render to cubemap sides, and then have a complelty independent scene for the skybox, eg similar to source engine.
(not i have never tested if that works, but that would be my first idea)
I would use 3 viewports : 2 pre viewports and the main viewport
one pre viewport for the skybox
one pre viewport for the face(s). Faces have a material that only render depth
and the main viewport for the spheres.
the 2 pre viewports must be set to not clear depth nor color.
this way your skybox will be drawn first, all over the screen (with depth = 1, that’s what the sky bucket does). Then your faces will be rendered over it, but since they don’t write color there will be no visual changes. But their depth will be rendered in the depth buffer.
Finally, the spheres will be rendered, but the one behind the face will fail the depth test and won’t be rendered
You’ll have a bit of overdraw, because the skybox is usually rendered at the end, but that’s no big deal.
Why not move the skybox further back and have the house actually in the scene? Separate the house texture and put it on a billboard if you don’t need a full 3d model (fixed camera is why that works I guess).
Then z buffer etc handles it all for you…
Not that I begin to understand what your trying to accomplish, but you mentioned projected textures. If you’re really looking for this, there is a plugin you can download (projective textures) under… well… tools > plugins! (I believe) in the IDE. It does just that… but after reading the responses here, I’m not totally sure that is what you are looking for. Anyways, cheers!
Thank you for your replies. My favorite solution would be to have a 3d-object of the house. And this house is then textured in such a way that you cannot see it because it is not distinguished from the skybox. Thus, ths solution of nehon would work, but when I have a more compicated object, e.g. a tree, I’d like to use an alpha channel to decide when an other object behind the scene is visible.
Thus, as far as i understand it, the projected textures would be a solution. The suggestion of t0neg0d seem to point in this direction, but - sorry - I cannot find the mentioned plugin. Further hint are very appreciated.
Thank you and merry christmas
You don’t need projected textures. Just use a billboard for each object in the 3d scene and put the texture on them. Then other objects can move around the scene and the z buffer/sorting/etc will automatically sort out what is behind what for you.
Trying to use projection/put stuff on the skybox/etc really is throwing away all the really useful stuff in the engine and then trying to recreate it yourself.
Skybox should be behind everything in the scene.
I forget to tell you, that the 3d-objects then shall also be collision objects. Thus, billboards were not accurate enough, since their shape does not fit well enough to the real geometry. BTW: The reason for the use of askybox is that I want to use real panorama photos, so that also the texture projection has to be accurate.
So, lets start simple, you have apanormaa photo, that you wnat to use as skybox, and it should be behind everything?, So far all is fine then.
Now you have different bojects that should be behin each other like normally. So why not just use normal objects i the scene and you are done? (Actually i dont really understand where the problem is i fear)
Everything you said, is correct, but: When I use real 3d-object I do not want that the player can see that it is something different than the skybox image. When there is a house in the skybox, the 3d-hose shoul look identical. Therefore I have to put the texture (with the correct projection) onto the shapes of the house.
So, to summarize, you want a real 3D object, that has exactly the same texture as the skybox. Some kind of Camera-Mapping in blender ?
For this to succeed, your object sould be put at the very right place… Otherwise, your object will not have the “right” texture… (a house with parts of sky for example).
So kinda like the background houses here? If i get it right? If the 3d version of the house is placed correctly, it is not really visible what is in the skybox and what is not.
It sounds like the OP wants something like WoW did. Where the skybox looks like the surrounding game area, and as you move around the world, the actual 3d objects are slowly melded into the sceen.
This is something that I was going to look into at some point myself.
Ah, i see, then do what i suggested first, have a secondary scene with like 1/100scale, and render that to your realscenes skybox.
Eg all those mountains are not really in the ingamescene, but in the 3d skybox. (actually you have that with almost all source engine games, everything where you cannot walk is in the skybox usually)
I have here an example (with xith3d). Look at Time 1:11. Here you see a that the fence is in the skybox, but it is additionally a 3d-object with the correct texture. Using the alpha channel, the heli is only visible behind the fence:
Ok i might understand what you mean now,
you have a pixture of tht sourrungind (grass, car ect) now you have the helicopter in the 3d scene, and you have additionally the fence wich is not there in reallife,but injected by you?
Well but wouldnt a normal quad(not billboard) with a fence texture in transparent bucked work for that? (and appropiate alpha channel of course)
That fence looks like a standard 3d object to me, what makes you think it is in the skybox?
I still think the billboard will be the simplest solution. Don’t forget that your physics collision shapes are different from your rendering. You can attach whatever model you like to the physics at that point and just attach the billboard to the display.
Normally its used the other way around (i.e. physics model is much less detailed than the one being rendered) but no reason it can’t work the other way too…
Do you think that it would be possible to build some kind of UV-coordinates, based on raycasting for example?
I mean, we know that we have thinks like :
- getting screen coordinates of 3D point
- getting ray intersection with mesh
- building texture coordinates for custom meshes.
I can imagine some kind of offline algorithm that would :
- cast a ray to each vertex of the mesh you want to texture (the house, the fence, …)
- get the corresponding skybox texture coordinate (raycasting to the skybox?)
- build a new texture coordinate mapping with these
- save it for later use
I have no experience with texturing in JME. But I know that some gurus here have… Does it seem feasible to you ?
I can imagine some kind of offline algorithm that would :
1) cast a ray to each vertex of the mesh you want to texture (the house, the fence, …)
2) get the corresponding skybox texture coordinate (raycasting to the skybox?)
3) build a new texture coordinate mapping with these
4) save it for later use
That is exactly what i imagine to do. The problem now is that you cannot use a usual texture mapping, then the picture on the face would be distorted. I have to use then a texture projection, which could look as
0 0 -1 0
0 1 0 -heightOfEyes
1 0 0 0
1 0 0 0
Why does usual texture mapping would result on distorted picture?
It does work properly on the skybox; it should on any surface… I think.
All the trouble is finding the right texture coordinates… and apply them to your mesh.