Page 3 of 3

Re: How to make a false floor in 3D?

Posted: Tue Dec 24, 2013 1:39 am
by retrotails
OP, would this not work? It's incredibly difficult to add hills, not only for the shader code but also for the game code.
Arrow keys to move, + and - to rotate (call it '= and -' if you prefer...) 0.9.0, requires shader support but not canvas support.
This code is mine and you're free to use it, I am however too busy dabbling in true 3D games to help much.

Re: How to make a false floor in 3D?

Posted: Tue Dec 24, 2013 1:53 am
by Ref
Jasoco wrote:
1. You ran setMode after loading the library? Because if you only setMode before loading the library (require 'Perspective') then it works fine until you try to change the window mode again. Are you on 0.8.0 or 0.9.0? Because it has failed for me on both.

2. Not sure what you mean by this because the way I use it is for my 3D project where everything is going to be changing every frame. So caching imagery for later isn't going to help when the whole screen changes. Don't really see how a canvas would apply here.

I'd like to see someone figure out proper perspective warping using Mesh's though.
I would also like to see warping with Meshes.

1. I'm on Windows 7 Love 0.9 and haven't experienced any problems with setMode though that is not something I usually reset. (Re-ran a simple test with setMode in different of positions and encountered no problems but test may not be valid.)

2. As I said, I didn't think this approach would meet your requirements but to create a 'false floor in 3D' it should do just fine since I wouldn't expect a floor would be changed too often.

3. The use of a canvas would limit the area over which the effect of the shader would be active to the canvas. Texturing a single small object every frame shouldn't be too much of a problem. Multiple objects - big problem as you point out.

Here's hoping someone gets the Mesh approach going.

Re: How to make a false floor in 3D?

Posted: Tue Dec 24, 2013 2:38 am
by ncarlson
Here's a few tech demos I whipped up. All source is MIT. But you must respect the Ol' Barry, his Whiteness.


1. 3D Box
3d-cube-and-xyY-colorspace.love
Real 3D using Model View Projection
(18.26 KiB) Downloaded 454 times

2. Steam Effect (very sexy)
extra-steamy.love
Faux clouds by fiddling with perspective matricies
(604.85 KiB) Downloaded 442 times

Re: How to make a false floor in 3D?

Posted: Tue Dec 24, 2013 8:30 am
by Jasoco
The 3D Box intrigues me. I'll have to take a closer look at the code.

And the steam one is pretty realistic looking. Makes me want to figure out some place to use that effect. (Almost looks like you're flying over some clouds)

Re: How to make a false floor in 3D?

Posted: Tue Dec 24, 2013 9:53 am
by ncarlson
The Steam demo was just eyeballed on my part. Basically,

1. Place a quarter-scale cloud sprite in back
2. Chose random movement vector (left or right, mostly)
3. Move sprite along vector while also
3.a Increasing sprite scale
3.b decreasing alpha

The whole thing was a failed attempt to port this WebGL demo: http://www.mrdoob.com/#/131/clouds


As for the cube demo, the interesting part was trying to cram 3d-Position, 4d-Color, and 2d-Texture coords into the mesh. If you stick to just flat color, or just UV texture cords, the current Mesh api opens a world possibilities.

Re: How to make a false floor in 3D?

Posted: Tue Dec 24, 2013 9:58 am
by slime
If you only care about texture coordinates in the range of [0, 1] with a <= 256 texel resolution and don't need alpha for colors (but still want the RGB colorspace), you could use the 'u' texture coordinate component for the Z component of the position, and the 'a' color component to replace the 'u' texture coordinate component.

Re: How to make a false floor in 3D?

Posted: Tue Dec 24, 2013 2:43 pm
by Ref
This is my 'best effort' with mesh.
Not too sure I got it right but will try to refine later.
Triangulation apparent on surfaces and am recreating meshes every frame (bound to be slow.)
Arrow keys to rotate
WSAD to change FOV and scale
Esc to exit
Edit: ncarson ,took a peek at your code! Wow! Seems a bit of an overkill. My little cube took only 80 lines of code - total.

Re: How to make a false floor in 3D?

Posted: Tue Dec 24, 2013 7:14 pm
by slime
Ref wrote:Edit: ncarson ,took a peek at your code! Wow! Seems a bit of an overkill. My little cube took only 80 lines of code - total.
His shader-based method is closest to how the 'real' 3D pipeline works, and is likely the most efficient out of anything here as well.

Also, using [wiki]Mesh:setVertices[/wiki] will usually be more efficient than re-creating the entire mesh.

The shader-based approach allows the GPU to do the work it's designed to do (transforming vertices in parallel, using a perspective projection matrix, the perspective divide / perspective-correct interpolation, etc.) and it also provides a built-in way to know if a face is front- or back-facing so you can act accordingly.

My recommendation if you want to experiment with 3D: learn vertex and pixel shaders. :)

Re: How to make a false floor in 3D?

Posted: Thu Dec 26, 2013 7:26 pm
by alberto_lara
Thanks everybody.