Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 /
avatar image
1
Question by GeraldOBBI · Apr 08, 2013 at 10:40 PM · camerarenderingshadersimage effects

Disabling AA Changes how SS Effects Work

Hello unity answers community!

I'm currently trying to figure out why, when I disable Anti-aliasing in my quality settings the way in which my screen space effect works changes.

The intent of my screen space effect is to apply an additive colour after rendering is done as an overlay. Depending on what is happening during the game this colour shifts and changes. The screen space effect uses Graphics.Blit() in a script attached to the main game camera using in the OnRenderImage(RenderTexture source, RenderTexture destination) function as prescribed in the unity documentation.

I've managed to isolate the issue such that it is reproducible in a separate scene using just a cube, a camera and the screen space effect. Here is the shader code:

 Shader "my screenspace shader" {
 Properties {
     _Color ("Main Color", Color) = (1,1,1,1)
 }
 
 SubShader {
     Tags {"Queue"="Geometry" "IgnoreProjector"="True" "RenderType"="Transparent"}
 
     pass {
         ZTest Off
         Blend DstColor Zero, SrcAlpha Zero
         Cull Off Lighting Off ZWrite Off
 
 CGPROGRAM
 #pragma vertex vert
 #pragma fragment frag
 #pragma fragmentoption ARB_precision_hint_fastest
 #include "UnityCG.cginc"
 
     half4 _Color;
 
     struct v2f {
         float4 vertex : POSITION;
         float2 texcoord : TEXCOORD0;
     };
 
     v2f vert(appdata_base i)
     {
         v2f vout;
         vout.vertex = mul(UNITY_MATRIX_MVP, i.vertex);
         vout.texcoord = i.texcoord;
         return vout;
     }
 
     half4 frag(v2f vout) : COLOR
     {
         half4 ret = _Color + half4(1 - _Color.a, 1 - _Color.a, 1 - _Color.a, 1 - _Color.a);
         return ret;
     }
 
 ENDCG
     }
     }
 }

When I have AA enabled, the effect overlays the colour additively as expected. However, when I disabled AA in the quality settings the screen becomes whichever colour is set as _Color in the shader. In addition to this, if I have any other screen space effect after this shader, things become really strange (black screens) even with AA on.

The shader is incredibly simple, and I am pulling my hair out over how disabling AA can cause it to behave so much differently. If someone out there has any knowledge which could explain the issue or to solve it, I'd be very happy to hear it.

Thanks!

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

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by GeraldOBBI · May 13, 2013 at 04:39 PM

Well, I finally figured it out. Turns out that there's a bug in Unity's rendering engine where this shader combines its output with the render texture when AA is on. It's true behaviour comes out when AA is disabled, causing a solid colour to be drawn. I had forgotten to add the _MainTex property so that Graphics.Blit() can set the camera's render texture to its _MainTex property. The correct shader can be found below:

 Shader "my screenspace shader"
 {
     Properties
     {
         _Color ("Main Color", Color) = (1,1,1,1)
         _MainTex ("Render Texture", 2D) = "white" {}
     }
     
     SubShader
     {
         Tags {"Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent"}
     
         pass
         {
             ZTest Off
             Cull Off Lighting Off ZWrite Off
 
 CGPROGRAM
 #pragma vertex vert
 #pragma fragment frag
 #pragma fragmentoption ARB_precision_hint_fastest
 #include "UnityCG.cginc"
 
             half4 _Color;
             sampler2D _MainTex;
     
             struct v2f {
                 float4 vertex : SV_POSITION;
                 float2 texcoord : TEXCOORD0;
             };
     
             v2f vert(appdata_base i)
             {
                 v2f vout;
                 vout.vertex = mul(UNITY_MATRIX_MVP, i.vertex);
                 vout.vertex.z = 0;
                 vout.texcoord = i.texcoord.xy;
                 return vout;
             }
     
             half4 frag(v2f vout) : COLOR
             {
                 half4 renderColour = tex2D(_MainTex, vout.texcoord);
                 half4 ret =  lerp(renderColour, renderColour * (_Color + fixed4(1 - _Color.a, 1 - _Color.a, 1 - _Color.a, 1 - _Color.a)), _Color.a);
                 return ret;
             }
 
 ENDCG
         }
     }
 }
Comment
Add comment · Share
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

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

10 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

Related Questions

Applying full screen image effects to UI only 2 Answers

How to Partially Blur an Object 0 Answers

Rendering an Object only inside of a certain area 2 Answers

How to render Camera's view on the flat mesh (plane/etc) 2 Answers

Best way to access RenderTexture immediately after camera render 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