Jump to content

How to MIRROR a camera rendertarget?


Russell
 Share

Go to solution Solved by SpiderPig,

Recommended Posts

Hi there team, time no see...

I'm still working on the v4.0 Update for my Steam game. And one of the addons inside this update, was the option of drive an Opel Kadett car... And here is my question about...

I have develop the mirror effect with a Camera using RenderTarget option on a Texture, and then the script:

Script.TexturaProyecta=""--string "Textura"

function Script:Start()
	local tex=Texture:Load("Materials/MisTexturas/Camaras_Texturas/"..self.TexturaProyecta..".tex")
	self.entity:SetRenderTarget(tex)
end

This works fine, but i've got a problem with the final image...

Koddy_Espejo.thumb.jpg.eaf9bc44ae50da5f400444e662ced774.jpg

Is there a way for make MIRRORED the image on the mirror?

I've tried mirroring the texture, or using 2 cameras, but nothing works for me.

 

I've got the same problem on another map:

Espejo_Museo.thumb.jpg.c1ccc636657f35ff74c5e590537a2a54.jpg

 

Many thanks in advance for your help.

Link to comment
Share on other sites

Many thanks for your answers...

3 hours ago, SpiderPig said:

I'd reverse the U coord of the entities texture coords somehow.  You might need a shader for that for a render target though.

3 hours ago, Josh said:

Cool idea. Can't you just reverse the U coord in the model?

Great idea, but i don't know how make this...
I think it would be enough to enter some command in my "tex" variable or within the "self.entity" where I put the SetRenderTarget. But I don't know what code fragment implement to invert the texture in its U coord.

1 hour ago, Canardia said:

Mirrors are a mystery, can't simply put a camera on it, since the observer moves.

1 hour ago, SpiderPig said:

You'll need to move the camera that renders the mirror based on the observing cameras position I think.

In my both cases, I don't need to control the player's perspective movement to make the mirror camera realistic.
- In the case of the car mirror, the camera is attached to the body of the car itself. If the car moves, the camera with it. And important, the player camera would not move from the driver's area view.
- In the case of the large bathroom mirrors, taking into account their position and the view triangulation, I wouldn't need to control the perspective either.

I just need to be able to invert the reflection by reversing the U coordinate of the texture in my SetRenderTarget. But I am not able to implement it.

I'm sure I can develop this idea in my script using "tex" o "self.entity":

Script.TexturaProyecta=""--string "Textura"

function Script:Start()
	local tex=Texture:Load("Materials/MisTexturas/Camaras_Texturas/"..self.TexturaProyecta..".tex")
	self.entity:SetRenderTarget(tex)
end

But no idea how to do it.

Link to comment
Share on other sites

Find the surface / mesh that uses the reflection material, and then for each vertex do this:

Vec2 coord = GetVertexTexCoord(v);
coord.x = 1.0f - coord.x;
SetVertexTexcoord(v, coord.x, coord.y);

 

  • Like 2

My job is to make tools you love, with the features you want, and performance you can't live without.

Link to comment
Share on other sites

Many thanks Josh, i'm trying your code...

At this moment i'm trying to change the TEXTURE MAPPING of the Render Texture and it looks promising for me:

CameraInvertida.thumb.jpg.c40392dda8162bc911a057eb0c5c5bd9.jpg

 

If with this I can temporarily solve my case, then it would be matter of implementing the code to improve the effect.

Love your patiente guys!!

 

  • Like 1
Link to comment
Share on other sites

Finally with the idea of @SpiderPig of invert coords of the texture i've solved/upgrade my mirror effect...

Espejo_Museo_Solved.thumb.jpg.3fee6c55362195fec690ec2449d1cb0f.jpg

Koddy_Espejo_Solved.thumb.jpg.2dea345d2e18499375d1fd5f29837117.jpg

In a future...

(Distant future probably... Because coding is hard for me) i will try to improve the mirror effect with this idea:
 

4 hours ago, SpiderPig said:

I would try something like this but in 3D.

RenderingAMirror.png.2492b0f007e3b67a924c013bdace147d.png

But at this moment this is enough for me...

Many thanks to all of you...

By the way...
For one of the 4 unlockable hidden maps of the game, I am developing a maze with the different thanks and grateful message (to the people on this forum) that I am going to put along the way. With your nicknames and avatars.

Something I mentioned in the next Thread:

https://www.ultraengine.com/community/topic/61219-question-about-an-acknowledgments-map-i-want-develop/

This is the map Icon:

Deseo1_Laberinto.thumb.png.c9617ece74f65e983909e1857026b839.png

Unlockable after our Wish to Rhexon Dragon:

4Deseos_Rhexon.thumb.jpg.ba2210cb6bb8a60fc1ad4ca8fb384040.jpg

 

Again, many thanks team!!!

 

  • Like 4
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...