Render To Texture Security Cam
-------------------------------------------------------
-- This script should be your CCTV brush or model script
--------------------------------------------------------

--This is where security cam will render 
Script.TrackingPivot=""--entity

--This should be your main camera where you are, like your FPSCam
Script.MainCamera=""--entity

--This can be any material with any diffuse shader, paint your CCTV with this
Script.RenderToMaterial=""--path

function Script:Start()
    --Create Buffer and texture so we have a rendertarget to render to.
    camerabuffer=Buffer:Create(256,256,1,0);
    tex = Texture:Create(App.context:GetWidth(),App.context:GetHeight())
    camerabuffer:SetColorTexture(tex)
    camerabuffer:Disable();

    --Fetch CCTV material
    mat=Material:Load(self.RenderToMaterial)
    self.entity:SetMaterial(mat)
end

function Script:UpdateWorld()
    camerabuffer:Enable()
    save=self.MainCamera:GetMatrix() --save your cam matrix
    self.MainCamera:SetMatrix(self.TrackingPivot:GetMatrix())
    App.world:Render() -- render to buffer your pivots matrix
    self.MainCamera:SetMatrix(save) --restore matrix
    camerabuffer:Disable()

    --Ok now do backbuffer in mainloop (App.lua)
    Context:SetCurrent(App.context)

    --Set buffer output and send it to the shader as texture0
    buffertex = camerabuffer:GetColorTexture()
    mat:SetTexture(buffertex,0)
end
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License