How do I invert/flip the player's screen?

No change.

I found the original code
[lua]
local MirrorRT = render.GetMorphTex0()

local FlippedVertical = CreateConVar( “r_flip_vertical”, 1, { FCVAR_ARCHIVE } )
local FlippedHorizontal = CreateConVar( “r_flip_horizontal”, 0, { FCVAR_ARCHIVE } )

local function GetBaseTransform()
return string.format( “center .5 .5 scale %i %i rotate 0 translate 0 0”, ( FlippedVertical:GetBool() and -1 or 1 ), ( FlippedHorizontal:GetBool() and -1 or 1 ) )
end

local MirroredMaterial = CreateMaterial(
“MirroredMaterial”,
“UnlitGeneric”,
{
[ ‘$basetexture’ ] = MirrorRT,
[ ‘$basetexturetransform’ ] = GetBaseTransform(),
}
)

/*
–Doesn’t work :frowning:
local function UpdateTransform()
MirroredMaterial:SetMaterialString( “$basetexturetransform”, GetBaseTransform() )
end

cvars.AddChangeCallback( “r_flip_vertical”, function( cvar, prev, new )
UpdateTransform()
end )

cvars.AddChangeCallback( “r_flip_horizontal”, function( cvar, prev, new )
UpdateTransform()
end )
*/

local view = {}

hook.Add( “RenderScene”, “Mirror.RenderScene”, function( Origin, Angles )

view.x = 0
view.y = 0
view.w = ScrW()
view.h = ScrH()
view.origin = Origin
view.angles = Angles
view.drawhud = false

// get the old rendertarget
local oldrt = render.GetRenderTarget()

// set the rendertarget
render.SetRenderTarget( MirrorRT )
 
    // clear
    render.Clear( 0, 0, 0, 255, true )
    render.ClearDepth()
    render.ClearStencil()
    render.RenderView( view )

// restore
render.SetRenderTarget( oldrt )

MirroredMaterial:SetMaterialTexture( "$basetexture", MirrorRT )
render.SetMaterial( MirroredMaterial )
render.DrawScreenQuad()

return true

end )

hook.Add( “InputMouseApply”, “flipmouse”, function( cmd, x, y, angle )

local pitchchange = y * GetConVar( "m_pitch" ):GetFloat()
local yawchange = x * -GetConVar( "m_yaw" ):GetFloat()
 
angle.p = angle.p + pitchchange * ( FlippedHorizontal:GetBool() and -1 or 1 )
angle.y = angle.y + yawchange * ( FlippedVertical:GetBool() and -1 or 1 )
 
cmd:SetViewAngles( angle )
 
return true

end )

hook.Add( “CreateMove”, “flipmove”, function( cmd ) – Override player movement

local forward = 0;
local right = 0
local maxspeed = LocalPlayer():GetMaxSpeed() * ( FlippedHorizontal:GetBool() and -1 or 1 )

if cmd:KeyDown( IN_FORWARD ) then
	forward = forward + maxspeed
end
if cmd:KeyDown( IN_BACK ) then
	forward = forward - maxspeed
end
if cmd:KeyDown( IN_MOVERIGHT ) then
	right = right - maxspeed
end
if cmd:KeyDown( IN_MOVELEFT ) then
	right = right + maxspeed
end

cmd:SetForwardMove( forward )
cmd:SetSideMove( right )

end )
[/lua]
With some minor changes to the render target get and using SetTexture instead of SetMaterialTexture it should work.

[lua]
local MirrorRT = GetRenderTarget( “MirrorTexture”, ScrW(), ScrH(), false )

local FlippedVertical = CreateConVar( “r_flip_vertical”, 1, { FCVAR_ARCHIVE } )
local FlippedHorizontal = CreateConVar( “r_flip_horizontal”, 0, { FCVAR_ARCHIVE } )

local function GetBaseTransform()
return string.format( “center .5 .5 scale %i %i rotate 0 translate 0 0”, ( FlippedVertical:GetBool() and -1 or 1 ), ( FlippedHorizontal:GetBool() and -1 or 1 ) )
end

local MirroredMaterial = CreateMaterial(
“MirroredMaterial”,
“UnlitGeneric”,
{
[ ‘$basetexture’ ] = MirrorRT,
[ ‘$basetexturetransform’ ] = GetBaseTransform(),
}
)

/*
–Doesn’t work :frowning:
local function UpdateTransform()
MirroredMaterial:SetString( “$basetexturetransform”, GetBaseTransform() )
end

cvars.AddChangeCallback( “r_flip_vertical”, function( cvar, prev, new )
UpdateTransform()
end )

cvars.AddChangeCallback( “r_flip_horizontal”, function( cvar, prev, new )
UpdateTransform()
end )
*/

local view = {}

hook.Add( “RenderScene”, “Mirror.RenderScene”, function( Origin, Angles )

view.x = 0
view.y = 0
view.w = ScrW()
view.h = ScrH()
view.origin = Origin
view.angles = Angles
view.drawhud = true

// get the old rendertarget
local oldrt = render.GetRenderTarget()

// set the rendertarget
render.SetRenderTarget( MirrorRT )
 
    // clear
    render.Clear( 0, 0, 0, 255, true )
    render.ClearDepth()
    render.ClearStencil()
    render.RenderView( view )
	

// restore
render.SetRenderTarget( oldrt )

MirroredMaterial:SetTexture( "$basetexture", MirrorRT )
render.SetMaterial( MirroredMaterial )
render.DrawScreenQuad()
render.RenderHUD(0,0,view.w,view.h)
return true

end )

hook.Add( “InputMouseApply”, “flipmouse”, function( cmd, x, y, angle )

local pitchchange = y * GetConVar( "m_pitch" ):GetFloat()
local yawchange = x * -GetConVar( "m_yaw" ):GetFloat()
 
angle.p = angle.p + pitchchange * ( FlippedHorizontal:GetBool() and -1 or 1 )
angle.y = angle.y + yawchange * ( FlippedVertical:GetBool() and -1 or 1 )
 
cmd:SetViewAngles( angle )
 
return true

end )

hook.Add( “CreateMove”, “flipmove”, function( cmd ) – Override player movement

local forward = 0;
local right = 0
local maxspeed = LocalPlayer():GetMaxSpeed() * ( FlippedHorizontal:GetBool() and -1 or 1 )

if cmd:KeyDown( IN_FORWARD ) then
	forward = forward + maxspeed
end
if cmd:KeyDown( IN_BACK ) then
	forward = forward - maxspeed
end
if cmd:KeyDown( IN_MOVERIGHT ) then
	right = right - maxspeed
end
if cmd:KeyDown( IN_MOVELEFT ) then
	right = right + maxspeed
end

cmd:SetForwardMove( forward )
cmd:SetSideMove( right )

end )
[/lua]
This one works fine, I don’t know how it handles custom huds though.

Would’t it be better to take the fb draw it in PostHUD ?

God damnit wizard, my automerge.

swag

That works fine, but the texture is dark. Mind you I didn’t copypasta the entire thing-- is there something that I missed?

[editline]3rd July 2013[/editline]

Nevermind. It works after restarting Garry’s Mod.

[editline]3rd July 2013[/editline]

The 3d works! My eyes can’t focus on my viewmodel with default values though.