Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 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 Parksters · Aug 18, 2020 at 12:26 PM · shadershaderspost processingpost-process-effect

Curved Screen Post Processing Effect

I am working on a 2D side scroller, and I want it to appear as though the screen is wrapped around a cylinder (meaning the closer things are to the sides of the screen, the thinner they get). Is there a post processing effect or shader that could accomplish this effect?

Comment
Add comment · Show 2
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 Llama_w_2Ls · Aug 18, 2020 at 04:40 PM 0
Share

I mean, the lens distortion effect on the post processing stack does give nice results, but i dont think its reeeeaaly what youre looking for. I may be wrong but try it out.

avatar image Parksters Llama_w_2Ls · Aug 18, 2020 at 09:06 PM 0
Share

Thanks; I may be able to make that work.

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by BastianUrbach · Aug 19, 2020 at 02:57 PM

This as an image effect should work.

 Shader "CylinderImageEffect" {
     Properties {
         _MainTex ("Texture", 2D) = "white" {}
     }
 
     SubShader {
         Cull Off ZWrite Off ZTest Always
 
         Pass {
             CGPROGRAM
             #pragma vertex vert
             #pragma fragment frag
 
             #include "UnityCG.cginc"
 
             struct v2f {
                 float4 vertex : SV_POSITION;
                 float2 uv : TEXCOORD0;
             };
 
             v2f vert (float4 p : POSITION, float2 t : TEXCOORD0) {
                 v2f o;
                 o.vertex = UnityObjectToClipPos(p);
                 o.uv = t;
                 return o;
             }
 
             sampler2D _MainTex;
 
             fixed4 frag (v2f i) : SV_Target {
                 i.uv.x = 1 - acos(i.uv.x * 2 - 1) / 3.14159265;
                 return tex2D(_MainTex, i.uv);
             }
             ENDCG
         }
     }
 }
Comment
Add comment · Show 3 · 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
avatar image RishabP · May 03, 2021 at 08:17 PM 0
Share

@BastianUrbach I copied this code and pasted it into an image shader file. If I want to apply this to a canvas Image, how should I proceed from here?

avatar image BastianUrbach RishabP · May 03, 2021 at 08:51 PM 1
Share

Well, image effects are always applied to an entire camera. I'm not sure if there is an easy way to apply it just to a canvas. If you apply it to a camera, it will affect the canvas if it is set to either Render Mode: Screen Space - Camera or Render Mode: World Space. Do it like this:

  1. Write an image effect script using the shader (example below) by implementing the OnRenderImage method

  2. Put the script on the camera

  3. On the canvas, select "Screen Space - Camera" or "World Space" as the render mode

  4. Assign the correct camera to the canvas


Simple image effect script (assign a material with the right shader in the inspector):

 using UnityEngine;
 
 [ExecuteAlways]
 public class BasicImageEffect : MonoBehaviour {
     public Material material;
 
     void OnRenderImage(RenderTexture src, RenderTexture dst) {
         Graphics.Blit(src, dst, material);
     }
 }



Note that you might run into issues with the render resolution. The effect wraps the image rendered at screen resolution around the visible half of a cylinder, which means that it's compressed at the left and right edge of the screen but stretched in the middle by a factor of pi/2. In theory you would have to render at pi/2 times the screen width. Not sure what the easiest way to do that is. I suppose you'd have to render into a render texture of that size and then draw that to another camera with the image effect.

avatar image RishabP RishabP · May 04, 2021 at 03:30 PM 0
Share

@BastianUrbach thanks mate, will look into this.

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

210 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

Related Questions

HLSL Post Process Shader Fixing UV/Texcoord 1 Answer

Why doesn't this shader work when using it with as a custom effect on the post processing stack 1 Answer

What is the meaning of a vertex shader for a post-processing shader? 1 Answer

How do you use a shader file once written? 1 Answer

HDRP Edge Detection FullScreen Custom Pass 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