Does anyone know the math needed to fix the perspective distortion shown at the beginning of this video?
I’m using material nodes.
Does anyone know the math needed to fix the perspective distortion shown at the beginning of this video?
I’m using material nodes.
Interestingly there is, in the BGE API both bge.texture.ImageRender() and … bge.texture.ImageMirror()
Now I haven’t used it myself, but I suspect that because it takes in the camera, the observer and the mirror object, it does all that for you.
I came up with a little hack a while ago for this exact problem!
I checked out image mirror but it has its own problems. I don’t actually want to use an object as a mirror, I’m using a tile set, so each object needs to be independent of that original plane, but use the texture generated by the render. So in that case what kind of mapping can I do? View mapping is mapped to the camera, but not the mirror plane. Global would be OK maybe if the chunks of level are smaller than the mirror, but that would mean very low resolution render.
Hmmm… that doesn’t get the result quite right. I’ll have to play around with it some more.
Did you use a render camera in the mirrored axis position/rotation of the main cam?
No, unfortunately the rendercam was just a duplicate of the main camera, with the same position/orientation/etc. (for a refraction shader). Sorry, didn’t think about this too hard when I posted it, haha
You could probably modify it and use normals to temper the influence of the effect… maybe. That’d be difficult and I’m not gonna pretend to know it’s gonna work
Ah! I got the mirror render to work. It needs to be set to “local” co-ordinates in nodes. This is like global but it follows the camera’s position (but not orientation).
Still needs to be mapped to the right size.
But the problem is that if you want to reflect bigger surfaces it has horrible resolution…is there a way to use ImageMirror() with view coordinates?, so the surface size doesn’t really matter?
You can use local co-ordinates in the nodes editor, and make sure the mirror object is attached to the camera so that it keeps the same position (which will be used for co-ordinates in the nodes). You can then make the mirror object about the same size as your viewing area, not the same size as the level.
There’s still things you need to setup, like scale of the texture co-ordinates in the nodes compositor using mapping nodes, but they will depend on your set up, like lens and such, so there’s not much i can do to help there. it’s just a case of trial and error.
You can actually make the mirror object very small, much smaller than the viewing area and mask off the texture outside that area with a radial gradient, so the reflection only shows around the focus point of the camera. That’s if you want really high res reflections without a high logic/rasterizer count.
Hmmmm, I am not sure I fully understand, say I have a big reflecting surface specifically a lake or an ocean, using UV coordinates would definitely not work cause the resolution will be horrible, I tried using local coordinates but the problem with it is the same one I get from using view coordinates, that the texture moves when you move, so if you turn to look around the texture moves with you, what do you suggest in that scenario?
If you’re doing a first person game rather than a RTS or RPG with an overhead view like mine, then you might be better off using the martinsh water shader. It was written specifically for being viewed from a human perspective, so the quality is much better than you’re likely to get from writing your own one. If you search for water shader in the resources forum you should find it.
Thnx…btw for anyone having a distortion problem in their reflection or refraction using renderToTexture methods, I used this node setup and it removed the distortion, it uses view coordinates and you can use R, G values to set the x and y scaling…I tried it on refraction with the rendercamera being a duplicate of activecamera and being at the same position too…
![/uploads/default/original/4X/9/a/0/9a0f82f2b95982b2aabce4462cdb2c3c4f82d0cb.jpgstc=1](/uploads/default/original/4X/9/a/0/9a0f82f2b95982b2aabce4462cdb2c3c4f82d0cb.jpgstc=1)
Reflection using ImageMirror():
https://drive.google.com/open?id=0B27awtGNGuMPZTNNcGlnMjZiVUU
So far as I can tell it doesn’t need correctiving for perspective distortion.
I was talking about ImageRender() not ImageMirror(), as you render from two different cameras and (if you want unlimited planar area) use view coordinates, it cause distortion around the edges of your view (specially when you’re using low FOV like 90 degrees which most first person cameras have)
Uncorrected:
Corrected:
I am pretty sure it’s true for reflections too (using ImageRender())
I managed to make my own version of it, it uses view coordinates same as martinsh so reflecting surface area could be unlimited…
I managed to make my own version of it, it uses view coordinates same as martinsh so reflecting surface area could be unlimited…
Hey, thanks, that looks great. I’ll give it a try.
EDIT: What nodes did you use for the reflection one? (Not the defraction one)?
I used same node setup that I posted before, I also wrote a small script to position the render camera at the exactly correct position and orientation…
I must have set mine up wrong then because I just got a messed up image.
Use the R and G values for scaling and try to set one of them to a negative value…this is what I used, oh and the render camera I have is not upside down so yeah you have to take that into account too…
Ah, OK. I got it now. it gives quite a nice result, though when I add a normal texture to distort the reflection it gets a bit warped around the edges of the screen.
Anyway, thanks a lot. I’ll be using that for some nice reflective floors.