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 YetAnotherUnityQuack · Nov 01, 2010 at 02:38 AM · shadervertexcgfragmentrefraction

Refraction Shader. Strange Artifacts

Hi! I'm trying to create a lens effect in front of a texture using vertex and fragment programs. The shader program is small and quite naive; I get some artifacts that I really can't understand why they are there or how to fix them;

Demo: http://johannes.gotlen.se/blog/2010/11/refraction/

Artifact-example:

alt text

// Per pixel refraction. // Uses a normal map and vertex normals to distort the image behind Shader "FX/Glass/RefractionMap" { Properties { _BumpAmt ("Glass Thickness", Range (-5,5)) = 0.2 _DiscRadius("Disc Radius", Float) = 1 _MainTexWidth ("Width", Float) = 512 _MainTexHeight("Height", Float) = 512 _MainTex ("Background", 2D) = "white" {} _BumpMap ("NormalInfo", 2D) = "bump" {} }

Category { // We must be transparent, so other objects are drawn before this one. Tags { "Queue"="Transparent" "RenderType"="Opaque" } SubShader {

     // This pass grabs the screen behind the object into a texture.
     // We can access the result in the next pass as _GrabTexture
     GrabPass {                          
         Name "BASE"
         Tags { "LightMode" = "Always" }
     }
     // Main pass: Take the texture grabbed above and use the bumpmap to perturb it
     // on to the screen
     Pass {
         Name "BASE"
         Tags { "LightMode" = "Always" }

CGPROGRAM #pragma exclude_renderers gles #pragma vertex vert #pragma fragment frag #pragma fragmentoption ARB_precision_hint_fastest #include "UnityCG.cginc"

struct appdata_t { half4 vertex : POSITION; half2 texcoord: TEXCOORD0; half4 normal: NORMAL; };

struct v2f { half4 vertex : POSITION; half3 normal : COLOR0; half2 uvmain : TEXCOORD0; }; const half _MainTexWidth; const half _MainTexHeight; const half _BumpAmt; const half4 _BumpMap_ST; const half4 _MainTex_ST; const half _DiscRadius; static const half2 pixelSize = 1h / half2(_MainTexWidth,_MainTexHeight);

v2f vert (appdata_t v) { v2f o; o.vertex = mul(UNITY_MATRIX_MVP, v.vertex); o.normal = mul(UNITY_MATRIX_IT_MV, v.normal); o.normal = o.normal * 0.5h + 0.5h; o.uvmain = TRANSFORM_TEX( v.texcoord, _MainTex ); return o; }

sampler2D _BumpMap; sampler2D _MainTex; static const half2 poisson[11] = { half2(-0.326212h, -0.40581h), half2(-0.840144h, -0.07358h), half2(-0.695914h, 0.457137h), half2(-0.203345h, 0.620716h), half2(0.96234h, -0.194983h), half2(0.473434h, -0.480026h), half2(0.519456h, 0.767022h), half2(0.185461h, -0.893124h), half2(0.507431h, 0.064425h), half2(0.89642h, 0.412458h), half2(-0.32194h, -0.932615h) };

half4 SiGrowablePoissonDisc12FilterRGB(sampler2D tSource, half2 texCoord, half2 pixelSize, half discRadius) {

 // Center tap
 half4 cOut = tex2D(tSource, texCoord);
 for(short tap = 0; tap </pre>

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

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

No one has followed this question yet.

Related Questions

Prevent ColorMask obscuring parts of an object's mesh 0 Answers

Unexpected behavior in Vertex/Fragment shader when using saturate method (CG) 0 Answers

Stop shader values from being clamped 1 Answer

Vertex/Fragment shaders - transparency ignoring Render Queue 3 Answers

Grabpass refraction masking 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