Unity VR Render Textures, Scene space rendering, and blending layers - c#

[using unity 2020.3]
I'm trying to slowly blend different layers in and out in VR, with both layers being visible while the fade between occurs. Right now, I am using two cameras, one as the main camera and one as a render texture (both only rendering their selective layers). Then I use UI to fade the render texture in and out. This looks and works great in 2D view (including builds), but UI components do not render in VR.
I am aware that rendering this in VR will require 4 sets of rendering (two for each eye), but I'd still like to know how to generate and display a render texture for each eye using unity.
This effect can be done in other ways and I'm open to suggestions. There are a lot of different types of elements I wish to fade in and out so I'm aware of one solution to add transparent shaders and fade particles but this can be tedious and requires a lot of setups (I'd like more of a permanent solution for any project). This being said, I'd still like to know how to manipulate what is being rendered out to the VR headset.
I'm fairly certain that the "Screen space effects" section of Unity doc Single Pass Stereo rendering (Double-Wide rendering) -- { https://docs.unity3d.com/Manual/SinglePassStereoRendering.html } -- is what I'm looking for, however, this still doesn't answer how to get the render texture for each eye (and I'm a little confused on how to use what they have written).
I'm happy to elaborate more and test some things out! Thank you in advance!

Related

XNA 3D blender models not keeping scale

So I am making all my models is Blender and then exporting it to .fbx format using the File ->Export and then checking off XNA Strict Options. This works just great, except that when I put my model in XNA, it has been stretched along the up-down axis and it is always the same scale. No matter how much I scale it in Blender, it is always the same size in game. Any ideas? Also, I'm not sure if this is related, but if I have a model with multiple parts, it will only show one part of it. Any help is appreciated!
I am more familiar with 3ds max than blender, but if this was happening in max I would know what's going on so I'll say it in case Blender works in a similar fashion.
When you modify something in a 3d modeling app (like scaling the model on a particular axis), it does not actually change the positions of the vertices like you may think. It only creates a transform matrix that can be applied to the original vertex positions at render time to make it appear the way you expect.
So when you import the model into Xna, you are importing the model with it's unscaled vertex positions and all the transform matrices it takes to render the model the way you would expect it to. But you have to apply those transforms in your Xna code or the model wont appear the way it did in your modeling app. (the issue you are having)
The way you apply the transforms is by calling the Xna Model.CopyAbsoluteBoneTransformsTo(Matrix[]). Make sure you do not call Model.CopyBoneTransformsTo(Matrix[]), you need the one with the word 'Absolute' in it.
Here is a tutorial that shows how to implement that method: http://msdn.microsoft.com/en-us/library/bb203933(v=xnagamestudio.40).aspx

Render target for each scene, for transitions

I'm trying to come up with a general concept for transitions, without having to include any specific code inside the actual scene. In all the samples I've seen so far the scenes handle that stuff themselves. Like a fade in/out, where the scenes have to adjust their draw method, for the correct transparency. But not only would this be annoying to have in every scene, with multiple kinds of transitions you'd get cluttered code pretty fast.
So I've been thinking. The only way I could come up with to support this, and more complicated transitions, without handling it in the scene itself, are render targets for each scene. The render target would be set from the scene manager before calling the draw method. After draw the render target would get reset to the render target of the manager, and the scene's texture would get drawn with information about the current transition. Without clearing the manager texture more scenes would follow, if more have to be drawn. This way you could do pretty much anything (transition wise), the scenes would be completely independent of each other, and you wouldn't need a single line of transition code in the actual scenes. (For reference, there are various transition types I'd like to be able to do. Not only fades, but also shader effects, moving one scene in while the current one is "pushed away", etc., involving one or multiple scenes.)
Well, that's my theory. Here comes my question: Does this sound like a viable plan? Is this the way to go? I've read about performance problems when switching rendering targets too frequently, and other problems, which is the main reason I'm hesitating to implement this. But so far I couldn't think of or find a better method. Although I think it shouldn't make a difference, for the moment I only care about 2D (mentioned just in case).
That, in general is a sound approach, but beware render target switching costs. Also, if each scene were to be animated at the time of transition, you'd be rendering two scenes at the same time into two different rendertargets and then compositing the results on screen.

is there a way to make a 3D game in winforms or WPF in C#?

I'm thinking about making a 3D point and click game, is it possible to make one in winforms or WPF? I don't need any physics or anything all I need is to make the application render 3D objects. I know that I can use XNA but if I do then I will have to relearn almost everything again. My third approach would be to make the scenes in a 3D game engine and then print the screen and then load it as a image. Any suggestion would be appreciated.
There's a big difference between a 3D game, and just letting players interact with a rendered image.
Your approach of loading a pre-rendered image is possible to do in both Winforms and WPF. You would just need to capture click events on the image and check the location against your list of active areas. Then just handle what needed to be done, ie: move to the next area, activate item, etc.
Edit from comment:
It's not so much which is friendlier. You can host an XNA viewport in Winforms/WPF. It's more about how you want your game to work. If you never have moving 3D scenes, XNA is overkill, and images will work just fine.
If you want dynamic scenes, you'll need to be able to render them on the fly. Then, XNA makes more sense. It is a lot more work though compared to just displaying images.
If you just want to show pre-rendered 3d images in your game, why not create them using a real 3d graphics tool, such as 3D Studio Max or Maya (or a free one, such as Blender)? It sounds like there's no need for actually rendering the 3d scenes in a game engine at all.

What is best way to create scrolling WORLD?

In this game im trying to create, players are going to be able to go in all directions
I added one single image(1024x768 2d texture) as background, or terrain.
Now, when player moves around I want to display some stuff.
For example, lets say a lamp, when player moves enough, he will see lamp. if he goes back, lamp will disappear because it wont be anymore in screen
If Im unclear, think about mario. when you go further, coin-boxes will appear, if you go back they will disappear. but background will always stay same
I thought if I spawn ALL my sprites at screen, but in positions like 1599, 1422 it will be invisible because screen is only 1024x768, and when player moves, I will set place of that sprite to 1599-1,1422-1 and so. Is it a good way to do this ?
Are there better ways?
There are two ways you can achieve this result.
Keep player and camera stationary, move everything else.
Keep everything stationary except the player and the camera.
It sounds like you are trying to implement the first option. This is a fine solution, but it can become complicated quickly as the number of items grows. If you use a tile system, this can become much easier to manage. I recommend you look into using a tile engine of some sort. There are a lot of great tile map editors as well.
Some resources for using Tiles:
Tiled -- Nice Map Editor
TiledLib -- XNA Library for using Tiled Maps
What you're describing there is a Viewport, which describes a portion of the 'world' that is currently visible.
You need to define the contents of your 'world' somehow. This can be done with a data structure such as a scene graph, but for the simple 2D environment you're describing, you could probably store objects in an array. You would need to bind your direction keys to change the coordinates of the viewport (and your character if you want them to stay centered).
It's a good idea to only draw objects that are currently visible. Without knowing which languages or packages you are using it's difficult to comment on that.
I would look into Parallax scrolling. Here is an example of it in action.
If this is what you require, then here is a tutorial with source code.
XNA Parallax Scrolling
After you are finished with basic scrolling, try to implement some frustum culling. That is only draw objects which are actually visible on the screen and avoid unnecessary drawing of stuff that cannot be seen anyway.
I would prefer solution number 2 (move player and camera) - It would be easier for me, but maybe its just personal preference.

Spinning a 3D model in C#

How do I take a 3D model that I created in 3D Studio Max and put it into my Winform C# program and make it spin? I'd prefer not to use DirectX if possible. I don't want anything complex. I simply want my model to rotate along the X axis. Thats it.
Thanks
You should use a 3D rendering engine for C#
Something like
http://axiom3d.net/wiki/index.php/Main_Page
http://www.codeproject.com/KB/GDI-plus/exoengine.aspx
http://irrlicht.sourceforge.net/features.html
http://freegamedev.net/wiki/Free,_cross-platform,_real-time_3D_engines
I have never used any rendering engines but for your requirements (letting the user move the object) i think a 3D engine would do. But perhaps this is over kill
If you want it to be dynamic, then the simplest option would be to render out an animation of the object rotating, but make each frame a separate file. Then you just show the correct image based on how the user is dragging the mouse. If the user drags the mouse to the right, then increment the frame and show the next image. If moving to the left, decrement the frame.
For something non interactive:
Export the animation to an AVI and embed that in your form:
Embedding Video in a WinForms app
It's not really what I'd recommend, but it's an alternative to creating an animated gif.
For something partially interactive (i.e. allowing limited movement):
I've seen QuickTime movies that you can control with the mouse. There's an example on this page. It's not 3D though.
For something fully interactive:
You need a 3D rendering engine of some sort and that does (usually) require DirectX or OpenGL. However, if you're only dealing with simple objects you might (repeat might) get away with a software renderer.

Categories

Resources