Posts

Showing posts with the label sin

sin vertex displacement shader

 The following vertex-surface shader moves vertices up and down based on some sine waves and the time variable. Combining lots of waves is a cool way to generate funky displacements. Things to note - we calculate a new normal in the vert function to prevent weird shading issues.  Shader "Dave/Unlit/waves" {     Properties     {         _MainTex ("Texture", 2D) = "white" {}         _Tint("Colour Tint",color)=(1,1,1,1)         _Freq("Frequency",Range(0,5))=3         _Speed("Speed",Range(0,100))=10         _Amp("Amplitude",Range(0,1))=0.5     }     SubShader     {        CGPROGRAM     #pragma surface surf Lambert vertex:vert        struct Input {         ...

fragment/vertex shader - distorting UVs and the Grabpass

Two things shown here, with a bit of fiddling needed to make it actually work, which shouldn't be a problem if you've looked at all the other bits. In the appdata struct we're including the UVs now, with TEXCOORD0 attribute. In the v2f function, we use TRANSFORM_TEX(v.uv, _MainTex) to get our uv coordinates into screenspace. Once we have these values, we use the sin function to distort both the X&Y, or U & V!, multiplying the input by some properties we defined earlier. This is passed to the Frag shader, which displays "a" texture..  What I've not mentioned is the GrabPass -it essentially takes a snapshot of the framebuffer and stores it as a texture. The Transparent Queue tag stops it from going crazy & rendering into infinity (think of when you record a tv and feed the recording into the tv.. The GrabPass is defined as a sampler2D, which must be labelled as _GrabTexture- after that it can be used in a tex2D function as usual.  Shader "Dave/U...