Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Mask render texture

Discussion in 'General Graphics' started by raycosantana, Nov 27, 2015.

  1. raycosantana

    raycosantana

    Joined:
    Dec 23, 2012
    Posts:
    319
    Hi

    I just started to work a on project where I need to make a working phone with camera in game, I already did this once on my game "R-eLink" but people complained the screen was hard on the eyes because the screen of the phone displayed the full render texture instead of just the portion of the screen the phone screen covers.

    Maybe I can explain this better with an image
    Sin título.png


    how can I do this?
     
  2. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,248
    Is the render texture camera from the same view as the main camera? If that's the case why even do a render texture for this, why not just have the phone's screen be transparent? If you want to do screen effects you can use a grab pass.
     
  3. raycosantana

    raycosantana

    Joined:
    Dec 23, 2012
    Posts:
    319
    No its not the same view, its a second camera that renders different things but its align with the main camera.
     
  4. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,248
    Okay, in that case you can use a similar shader to what you would use for a grab pass to get the UV coordinates for the render texture.

    Use
    o.screenPos = ComputeScreenPos(v.vertex);
    in the vertex shader or add screenPos to your input struct in a surf shader and then do
    float2 renderTexUvs = screenPos.xy / screenPos.w;