Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
0
Question by Reahreic · Aug 14, 2017 at 12:41 PM · shadervrrendertextureoutlinerender texture

PostProcess Outline Shader GVR alignment

Cross post from my Friday forum post as to date there's been 30+ views but no responses yet and time is running out for me. (Thank you for your consideration)

(https://forum.unity3d.com/threads/postprocess-outline-shader-gvr-alignment.487815/)

I've been working on implementing a post processing outline shader that i can use on the Google Daydream (GVR) Platform (among others) and have run into a problem that i can't seem to resolve.

My outlined objects display correctly in the editor, however once deployed to a daydream compatible phone, the outline is rendered offset along the z axis about halfway between the camera and target object.

Project Settings:

  • Multi Pass Stereo Rendering

  • Forward Rendering

Shader

 Shader "Hidden/Test"
     {
          Properties
         {
             _MainTex ("Main Texture",2D) = "black"{}
             _SceneTex("Scene Texture",2D) = "black"{}
         }
         SubShader
         {
             // No culling or depth
             //Cull Off ZWrite Off ZTest Always
             Blend SrcAlpha OneMinusSrcAlpha
             Pass
             {
                 CGPROGRAM
                 #pragma vertex vert
                 #pragma fragment frag
                
                 #include "UnityCG.cginc"
      
                 sampler2D _MainTex ;
                 sampler2D _SceneTex;
      
                 float2 _MainTex_TexelSize;
      
                 struct v2f{
                     float4 pos : POSITION;
                     float2 uv : TEXCOORD0;
                 };
      
                 v2f vert (appdata_base v){
                     v2f o;
                     o.pos = UnityObjectToClipPos(v.vertex);
                     o.uv = o.pos.xy / 2 + 0.5;
                     return o;
                 }
      
                 half4 frag (v2f i) : COLOR{
      
                     if(tex2D(_MainTex , i.uv.xy).r > 0){
                         return tex2D(_SceneTex , i.uv.xy);
                     }
      
                     float colorInt = 0;
                     int thickness = 8;
      
                     for(int k = 0; k < thickness; k++){
                         for(int j = 0; j < thickness; j++){
                             colorInt += tex2D( _MainTex , i.uv.xy + float2(( k - thickness / 2) * _MainTex_TexelSize.x, (j - thickness / 2) * _MainTex_TexelSize.y)).r;
                         }
                     }
                     return colorInt * half4(0,1,1,1) + tex2D(_SceneTex , i.uv.xy);
                 }
                 ENDCG
             }
         }
     }

OutlinePostEffect

 using UnityEngine;
 using System.Collections.Generic;
 using UnityEngine.Rendering;
 using UnityEngine.VR;
  
 public class OutlinePostEffect :MonoBehaviour {
  
     public AppManager appManager;
     public Camera bufferCamera;
  
     [Space(20)]
     public Shader outlineShader;
     public Shader outlineBufferShader;
     public LayerMask layerMask;
  
     private Material outlineMaterial;
     private RenderTexture renderTexture;
  
    
  
     private bool isReady = false;
  
     void Start() {
         //Configure bufferCam rendering path on outline camera
         bufferCamera.cullingMask = layerMask.value;
         bufferCamera.renderingPath = RenderingPath.Forward;
  
         MakeRT();
  
         outlineMaterial = new Material(outlineShader);
  
         isReady = true;
     }
  
     private void MakeRT() {
         if(VRSettings.eyeTextureWidth <= 0) {
             renderTexture = new RenderTexture(Screen.width, Screen.height, 0, RenderTextureFormat.R8);
         } else {
             renderTexture = new RenderTexture(VRSettings.eyeTextureWidth, VRSettings.eyeTextureHeight, 0, RenderTextureFormat.R8);
         }
         renderTexture.antiAliasing = 2;
         renderTexture.anisoLevel = 0;
         renderTexture.depth = 0;
         renderTexture.useMipMap = false;
         renderTexture.filterMode = FilterMode.Bilinear;
  
         //put it to video memory
         renderTexture.Create();
     }
  
     void OnRenderImage(RenderTexture source, RenderTexture destination) {
         if(!isReady) { return; }
        
         //set the camera's target texture when rendering
         bufferCamera.targetTexture = renderTexture;
  
         outlineMaterial.SetTexture("_SceneTex", source);
  
         //render all objects this camera can render, but with our custom shader.
         bufferCamera.RenderWithShader(outlineBufferShader, "");
  
         //copy the RT to the final image
         Graphics.Blit(renderTexture, destination, outlineMaterial);
  
         //release the temporary RT
         //renderTexture.Release();
  
     }
 }




Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

148 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Render on top 1 Answer

PC blackscreens when "Failed to create RenderTexture",PC screen goes black when "Failed to create rendertexture" 0 Answers

(HDRP) Camera.Render() renders black, but only if Scene View is not visible 0 Answers

Unity 5.3.1p3 - Viewports on Render Textures are warped when Virtual Reality Supported is enabled. 0 Answers

Shader for creating AR in VR.. sort of.. 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges