Skip to content
Stian Jensen edited this page Apr 15, 2017 · 2 revisions

Every project has its own shader folder, inside the src folder of the project. This folder has a folder for each shader. These shaders will be compiled into the global object SHADERS which is available to all layers. To use the shader example, simply write SHADERS.example.

Shaders may be used as a separate node in nin, by creating a node which inherits from NIN.ShaderNode with a shader object (or the name of a shader in the shaders folder) as a parameter in options, or they may also be used for materials, by using ShaderMaterial.

If your shader only needs for instance a vertex shader but not a fragment shader, NIN will fall back to a default set of shaders. The only rules you need to oblige is that:

  • The uniform file needs to include tDiffuse
  • The vertex shader needs to pass on vUv (uv)

Live reloading

When a shader is changed on disk using an external editor, nin can reload node which depend on the shader. To let nin know which node to reload, register the shader in graph.json, like this:

{
  "id": "ExampleLayer",
  "type": "ExampleLayer",
  ...
  "options": {
    "shader": "example"
  }
}

Now, every time example is edited, ExampleLayer will be reloaded instantly.

Clone this wiki locally