Skip to content
A shader for Unity that generates moving grating patterns
ShaderLab C#
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
UnityGratingShader
docs
.gitignore
LICENSE
README.md

README.md

UnityGratingShader

A shader for Unity that generates moving grating patterns.

screenshot

Requirements

Useage

This repository includes a Unity project in the UnityGratingShader folder, however to make use of the shader you only need the GratingShader.shader file from the Assets folder.

  • Start a Unity project or open an existing one

  • Copy the GratingShader.shader file into the Assets folder

  • Right click in the Assets directory, select: Create > Material new_material

  • Select the material and in the Inspector set the Shader to Custom/GratingPattern custom_shader

GameObject mode

You can apply this material to any GameObject that has a Mesh Renderer component.

Full screen mode

To render a grating pattern such that it covers the whole screen:

  • Download the FullScreenMaterial.cs script
  • Put it in your Assets forlder
  • Select the Main Camera of your scene and drag the script onto the inspector
  • Choose a material you want to render as the Material property of the script

Customization

You can customize how the grating pattern looks by selecting a Material that uses the GratingShader and changing its values in the inspector.

customization

  • Direction controls which way the lines of the pattern are aligned (in degrees). 0 is completely horizontal with the lines moving from top to bottom. Increasing the value rotates the pattern clockwise.
  • Speed controls how fast the animation is playing. Note: The animation only plays while you are in play mode.
  • Density controls how many lines are drawn
  • Modulation can be toggled between Sine and Square. The former results in smooth edges, the latter in sharp ones.
  • Tint Color as the name implies tints the pattern with the selected color.
  • Starting Phase sets an offset in degrees. This is proportional to the frequency so an offset of 360 looks exactly the same as 0.
  • Texture can be optionally set to any image that you imported as an asset by dragging it onto the texture property. The image will be overlayed to the pattern. Tip: For a smooth circular cutoff you can use the Default-Particle texture built into Unity (press the Select button).
You can’t perform that action at this time.