Diagonal split screen

Blitz3D Forums/Blitz3D Programming/Diagonal split screen

Kiyoshi(Posted 2016) [#1]
Greetings all, trying to figure this out.

How would I go about creating a diagonal split-screen like this image shows? CameraViewport only seems to allow square viewports, but I'm hoping there's a way to work around that.

Many thanks,
-Kii


RemiD(Posted 2016) [#2]
I have an idea by using 2 images and 1 texture (not sure if this would be fast enough) but i will wait and see what others suggest.

Or maybe using 3 textures, 2 screenquads and a specific blendmode...

While you wait for others suggestions, you may be interested in this : http://www.blitzbasic.com/codearcs/codearcs.php?code=3256


Rick Nasher(Posted 2016) [#3]
I was (cliché) thinking something similar with alhpha/masking, but decided against it and thought I was probably off.. lol


col(Posted 2016) [#4]
'Hiya guys.
That's an interesting effect.

I'm sure you can achieve this with rendering each 'scene' to a texture thats then used over a triangle - 2 scenes 2 triangles. Would be pretty simple I'd have thought. Its been a while since I used b3d but I assume you can render to a texture with TextureBuffer ?


col(Posted 2016) [#5]
'Hiya guys.
That's an interesting effect.

I'm sure you can achieve this with rendering each 'scene' to a texture thats then used over a triangle - 2 scenes 2 triangles. Would be pretty simple I'd have thought. Its been a while since I used b3d but I assume you can render to a texture with TextureBuffer ?

Oops, I just read the docs and it says that you can't render 3d to a texture buffer :/ oh well... I'll go sit in the corner and be quiet :p


Zethrax(Posted 2016) [#6]
You might have some optimized options with a shader based approach, but with Blit3D you're probably going to be looking at some major overhead whatever approach you take. Your rendered scenes will need to be simple enough to maintain a decent frame rate to allow for the overhead.

One approach I'd try would be:-

1. Render one of the camera views with the camera rotated on its local yaw axis to accommodate the fact that you will be rotating the triangle that this scene will be displayed on. (EDIT: You probably don't need to rotate the triangle)

2. Use CopyRect to copy the contents of the backbuffer to a texture buffer. Apply the resulting texture to a triangle mesh. Align the triangle to the camera's pixel space (eg. http://www.blitzbasic.com/codearcs/codearcs.php?code=773 | http://www.blitzbasic.com/codearcs/codearcs.php?code=2860 ). Rotate the triangle to the diagonal view that you want (EDIT: You probably don't need to do this). Use EntityOrder to set the render order of the triangle so that it is rendered last (this doesn't need to be done for each update - you can do it when you first create the triangle mesh).

3. Render the other camera view with the triangle displaying the first scene overlaid on top of it.

Bear in mind that you'll need to accommodate interpolation effects on the camera if you're using render tweening. Probably have two cameras (one for each scene) and use 'CameraProjMode camera,mode' to turn each camera on and off to render each scene, rather than moving one camera between the two scenes.


RemiD(Posted 2016) [#7]
Col just gave me another idea, a simpler method (not sure if this will be fast enough) :

Have 1 premade mesh of a triangle which masks one part of the screen (black color, fullbright, zorder rendered last, positionned in front of the camera).
Have 2 images of the size of the chosen resolution

Hide the triangle
Render point of view from player1 (camera1)
Copyrect the result to image1
Show the triangle
Render point of view from player2 (camera2)
Copyrect the result to image2
Draw image1 (all pixels are drawn)
Draw image2 (the black pixels will not be drawn)

If this is not fast enough, you will have to use 2 screenmeshes with 2 textures, and the masked texels colored in black or white and use a specific blendmode to mix the texels so that some part of the textures are hidden.


@Col>>You can't render to texture but you can copyrect the rendered image (in the backbuffer) to a texture !


Kryzon(Posted 2016) [#8]
1) Hide the triangle;
2) Render one camera;
3) Copyrect to a texture;
4) Show the triangle and the black bar;
5) Render the other camera. One triangle is geometry, the other "triangle" is just the rest of the screen not covered by the triangle.

There only needs to be 1 copyrect (a slow operation) for this, since you can render the textured triangle along with a pure scene render.
The black bar can be geometry that is screen-aligned in the same way as the triangle.


RemiD(Posted 2016) [#9]
Smart Kryzon, indeed you can use 2 textured triangles meshes (one aside the other, with the same zorder) and 1 splitscreen mesh (with a zorder on top of the triangle meshes) and only need to render each point of view and copyrect the result to each texture, and since each triangle mesh will display only part of the screen, no need to play with transparent texels/pixels or blendmodes...
Once again you will need to create triangle meshes with a size and uv coords and textures to have pixel perfect precision, so this code will be useful : http://www.blitzbasic.com/codearcs/codearcs.php?code=3256
And you also may want to disable bilinear filtering of texture : http://www.blitzbasic.com/Community/posts.php?topic=103591


Kryzon(Posted 2016) [#10]
Hi, I meant using just one triangle with a texture from one of the cameras, and the other camera renders that triangle plus the rest of the scene at the same time.



Since the triangle only covers part of the screen, the other part will also be shaped like a triangle.
When camera B renders everything the user should see this:




Zethrax(Posted 2016) [#11]
This is what I've got so far. The triangle the player's backview is rendered on still needs to be sized and positioned according to pixel perfect rules. Still working on the best way to do that using a straightforward approach.

The relevant code is in the 'Create user's backview camera.', 'Render the backview scene.', and 'Render the frontview scene.' sections.




Kryzon(Posted 2016) [#12]
I wish I had thought of this sooner. Don't use textures.

Textures are always rectangular. When you allocate a screen-sized texture for that triangle you will only be using half of it (the part that will show with the triangle). The rest will not be used, and that is a lot of wasted memory.
Also, there is no guarantee that the machine running the program can create a texture big enough to cover the entire screen -- in which case you would need to use several smaller textures and more complex logic for rendering.

Instead, use stencil testing.
It's a much faster and lightweight feature where you draw geometry on the screen to establish a 'mask' (the stencil buffer), and then by setting a stencil operation, every subsequent drawing is masked to the stencil buffer in some specific way.

The steps become: you clear the stencil buffer, draw just one triangle (no texture, just geometry) to set the stencil buffer for two triangles (one is "positive" and the other is empty, as the rest of the screen). You do this once.
Then for the rest of the game you set the stencil test to render on the positive part of the stencil buffer, draw one camera. Set the stencil test to render on the empty part of the stencil buffer, draw the other camera.
Then turn off the stencil test and draw a border between the two triangles.

Blitz3D doesn't have stencil testing (even though its renderer, Direct3D 7, does). You can use BlitzMax or other game engines to access this feature. It's an old feature and should be compatible with every graphics card from the last decade.

EDIT: Alternatively, you can use one of those DX7 Dlls by Tom Speed that adds the stencil functionality to Blitz3D.
You can use the files from the "Devil Shadow System" demo for Blitz3D, it renamed that dll under a liberal license:
https://www.dropbox.com/s/vffwqw88xxyviql/Devil%20Shadow%20System%201.35%20Source.zip?dl=1

(File taken from here.)


Guy Fawkes(Posted 2016) [#13]
Speaking of Tom Speed, does anyone have every single 1 of his DLLs? I need copies & I can't find them anywhere.

Thank You!

~GF


Kiyoshi(Posted 2016) [#14]
Apologies for the late response, been busy with work. Lots of replies here, I like the idea of texturing triangles. Stencil testing is a good idea but I'd prefer to keep this all within vanilla Blitz3D. This program will be run on a higher end machine so I'm okay with using a textured triangle for now.

I'll tinker for a while, see what I can do with all this information; I think this is what I'm looking for.

I appreciate all the help, thanks much!
-Kii