Cameras, materials and effects

Everything on this page draws: it runs on the players' games, where the world is rendered. The server renders nothing and refuses these calls: mark these scripts [ClientOnly].

Materials

A Material is a material of your world: a field set from the scene, or renderer.sharedMaterial. Changing it changes every renderer that uses it.

csharp
using NodeWorld.Flux;

namespace MyWorld
{
    [ClientOnly]
    public class Glow : FluxScript
    {
        public Material neon;

        protected override void Update()
        {
            var pulse = 0.5f + 0.5f * Mathf.Sin(Time.time * 4f);
            neon.SetColor("_EmissionColor", Color.cyan * (2f * pulse));
        }
    }
}
Materialcolor (its main color), SetFloat, SetColor, SetVector, SetTexture, GetFloat, GetColor, GetVector, HasProperty, shader (give it the shader of another material of your world), renderQueue, shaderKeywords
RenderersharedMaterial, sharedMaterials, SetSharedMaterial(index, material), materialCount, enabled, bounds
Renderer.SetFloat, SetColor, SetVector, SetMatrix, SetTextureA value for this renderer alone (a property block): the shared material does not change. The last argument is the material index (0 by default).
Shader.SetGlobalFloat, SetGlobalVector, SetGlobalColor, SetGlobalTextureA value every shader of your world reads (a clock, a wind). Names starting with unity_ or _NW are Unity's and NodeWorld's: A world cannot set the global shader property '_NWTime' (reserved by Unity or NodeWorld).

Textures come from fields (Texture, Sprite), from images loaded from the web, from render textures and from data textures.

Cameras and render textures

A camera of your scene keeps its settings, but the game turns it off: the player's view is the game's. To render something else (a mirror, a security screen, a portal view), a script makes its own camera and renders it into a texture:

csharp
[ClientOnly]
public class SecurityCamera : FluxScript
{
    public Renderer screen;
    private Camera _camera;
    private RenderTexture _texture;

    protected override void Start()
    {
        _texture = RenderTexture.Create(512, 512);
        _camera = Camera.Create();
        _camera.targetTexture = _texture;
        _camera.transform.SetPositionAndRotation(transform.position, transform.rotation);
        screen.SetTexture("_BaseMap", _texture);
    }

    protected override void LateUpdate() => _camera.Render();
}
  • Camera.Create() makes a camera of your world, off: it renders only when the script calls Render(), into its targetTexture. Turning it on is refused (A camera created by a script only renders when the script calls Render.).
  • Its settings: cullingMask, clearFlags and backgroundColor, fieldOfView, aspect, nearClipPlane, farClipPlane, worldToCameraMatrix, projectionMatrix, CalculateObliqueMatrix, useOcclusionCulling, and showLocalPlayerHead (the local player's head, hidden from their own eyes, shows in a mirror).
  • Camera.main is the player's camera (the eyes in VR): read its pose, stereoEnabled, GetStereoViewMatrix(eye) and GetStereoProjectionMatrix(eye) to render one image per eye.
  • RenderTexture.Create(width, height, depthBits, hdr) and Release(). A render texture goes to a renderer (SetTexture) or to every shader (Shader.SetGlobalTexture).

The mirror of the example world is a complete camera script.

Data textures

DataTexture.Create(width, height) (1 to 1024 texels a side) is a small texture of floats your script writes: SetPixels(rgba) takes width × height × 4 floats (r, g, b, a), row by row from y = 0. Give it to your shaders with Shader.SetGlobalTexture: Pulse hands the music to shaders this way. Release() frees it.

Lights, particles, animation

ComponentWhat a script uses
Lightenabled, intensity, color, range, spotAngle
ParticleSystemPlay, Stop, Pause, Clear, Emit(count), Simulate, isPlaying, isEmitting, particleCount; main: startColor, startSize, startSpeed, startLifetime, simulationSpeed, gravityModifier, loop, maxParticles; emission: enabled, rateOverTime, rateOverTimeMultiplier
AnimatorSetBool, SetFloat, SetInteger, SetTrigger, ResetTrigger, their Get…, Play(state, layer, normalizedTime), speed, Rebind, Update(deltaTime), enabled
LineRenderer, TrailRendererpositionCount, SetPosition, GetPosition, SetPositions, useWorldSpace, startWidth, endWidth, startColor, endColor
Volume (post-processing)weight, enabled
ReflectionProbeintensity, enabled
LODGroupenabled
ParentConstraintsourceCount, GetSourceTransform, GetSourceWeight, SetSourceWeight, enabled

For many objects at once, see object batches and drawing by instances; for meshes, meshes made by scripts.