Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 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
0
Question by Nostr0 · Mar 27, 2020 at 12:24 PM · shader3drenderingshader programmingshader writing

Image effect shader not running

I created an image effect shader for the camera that is supposed to pixelate the screen but no matter what I do it's not running / working.

I am using Unity version 2019.3.6f1 with URP installed.

I noticed that the shader (and other similar ones) are not working anymore after installing URP

Does OnRenderImage() work with URP?

 Shader "Hidden/Pixelated"
 {
     Properties
     {
         _MainTex("Texture", 2D) = "white" {}
         _ScreenWidth("screen width", float) = 320.0
         _ScreenHeight("screen height", float) = 240.0
         _CellSizeX("size of x cell", float) = 4.0
         _CellSizeY("size of y cell", float) = 4.0
     }
         SubShader
         {
             // No culling or depth
             Cull Off ZWrite Off ZTest Always
 
             Pass
             {
                 CGPROGRAM
                 #pragma vertex vert
                 #pragma fragment frag
 
                 #include "UnityCG.cginc"
 
                 struct appdata
                 {
                     float4 vertex : POSITION;
                     float2 uv : TEXCOORD0;
                 };
 
                 struct v2f
                 {
                     float2 uv : TEXCOORD0;
                     float4 vertex : SV_POSITION;
                 };
 
                 v2f vert(appdata v)
                 {
                     v2f o;
                     o.vertex = UnityObjectToClipPos(v.vertex);
                     o.uv = v.uv;
                     return o;
                 }
 
                 sampler2D _MainTex;
                 float _ScreenWidth;
                 float _ScreenHeight;
                 float _CellSizeX;
                 float _CellSizeY;
 
                 fixed4 frag(v2f i) : SV_Target
                 {
                     float2 uv = i.uv;
 
                     float pixelX = _ScreenWidth / _CellSizeX;
                     float pixelY = _ScreenHeight / _CellSizeY;
 
                     return tex2D(_MainTex, float2(floor(pixelX * uv.x) / pixelX, floor(pixelY * uv.y) / pixelY));
                 }
                 ENDCG
             }
         }
 }



And this is the script that's attached to the main camera using UnityEngine;

 [ExecuteInEditMode]
 public class PostProcess : MonoBehaviour
 {
     [SerializeField]
     private Vector2 cellSize = new Vector2(4, 4);
 
     private Material material;
 
     private void Awake()
     {
         material = new Material(Shader.Find("Hidden/Pixelated"));
     }
 
     private void OnRenderImage(RenderTexture source, RenderTexture destination)
     {
         material.SetFloat("_ScreenWidth", Screen.width);
         material.SetFloat("_ScreenHeight", Screen.height);
         material.SetFloat("_CellSizeX", cellSize.x);
         material.SetFloat("_CellSizeY", cellSize.y);
         Graphics.Blit(source, destination, material);
     }
 }

The result is always as if no shader was applied even when changing the fragment function return to return fixed4(1, 0, 0, 1); which should return a red screen if I am not wrong.

Adding the shader in the "Always included shaders" list did not solve the problem (Edit->Project Settings->Graphics)

Comment
Add comment · Show 1
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
avatar image Pangamini · Mar 27, 2020 at 10:01 PM 0
Share

Is your OnRenderImage method being called?

1 Reply

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

Answer by Namey5 · Mar 28, 2020 at 03:04 AM

Image effects need to be drawn at a specific part of the rendering process. OnRenderImage was called by the built-in pipeline as a way of injecting custom post-processing at the correct point, but because SRP's handle all rendering manually, they would also need to manually call the method. In theory you can do this, however Unity's SRPs use their own post-processing stacks that are called directly by the rendering pipeline. HDRP has support for custom effect injection, but as of now URP does not. If you wanted to use custom post-processing in URP, you would need to modify the internal renderer to also draw your custom effects. Here are some links to the files that handle post-processing, so you can probably copy and modify some of the built-in effects to do what you need.

https://github.com/Unity-Technologies/ScriptableRenderPipeline/tree/master/com.unity.render-pipelines.universal/Runtime/Overrides

https://github.com/Unity-Technologies/ScriptableRenderPipeline/blob/master/com.unity.render-pipelines.universal/Runtime/Data/PostProcessData.cs

https://github.com/Unity-Technologies/ScriptableRenderPipeline/blob/master/com.unity.render-pipelines.universal/Runtime/Passes/PostProcessPass.cs

Another thing to keep in mind is that the shader-side approach to writing image effects has changed a bit. Here's the Unity guide to writing post-processing for the stack (and for future pipelines);

https://docs.unity3d.com/Packages/com.unity.postprocessing@2.1/manual/Writing-Custom-Effects.html

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

227 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 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

cartoon lit shader with transparency? 0 Answers

someone knows how to create an anisotropic shader? HELP!!! 0 Answers

Convert Code Shaders to Shader Graph 0 Answers

tex2D(_texture, float2(col/(width-1), row/(height-1))) is not returning correct values 1 Answer

Stretching when using world coordinates 2 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