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.
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));
}
}
}Material | color (its main color), SetFloat, SetColor, SetVector, SetTexture, GetFloat, GetColor, GetVector, HasProperty, shader (give it the shader of another material of your world), renderQueue, shaderKeywords |
Renderer | sharedMaterial, sharedMaterials, SetSharedMaterial(index, material), materialCount, enabled, bounds |
Renderer.SetFloat, SetColor, SetVector, SetMatrix, SetTexture | A 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, SetGlobalTexture | A 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:
[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 callsRender(), into itstargetTexture. Turning it on is refused (A camera created by a script only renders when the script calls Render.).- Its settings:
cullingMask,clearFlagsandbackgroundColor,fieldOfView,aspect,nearClipPlane,farClipPlane,worldToCameraMatrix,projectionMatrix,CalculateObliqueMatrix,useOcclusionCulling, andshowLocalPlayerHead(the local player's head, hidden from their own eyes, shows in a mirror). Camera.mainis the player's camera (the eyes in VR): read its pose,stereoEnabled,GetStereoViewMatrix(eye)andGetStereoProjectionMatrix(eye)to render one image per eye.RenderTexture.Create(width, height, depthBits, hdr)andRelease(). 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
| Component | What a script uses |
|---|---|
Light | enabled, intensity, color, range, spotAngle |
ParticleSystem | Play, Stop, Pause, Clear, Emit(count), Simulate, isPlaying, isEmitting, particleCount; main: startColor, startSize, startSpeed, startLifetime, simulationSpeed, gravityModifier, loop, maxParticles; emission: enabled, rateOverTime, rateOverTimeMultiplier |
Animator | SetBool, SetFloat, SetInteger, SetTrigger, ResetTrigger, their Get…, Play(state, layer, normalizedTime), speed, Rebind, Update(deltaTime), enabled |
LineRenderer, TrailRenderer | positionCount, SetPosition, GetPosition, SetPositions, useWorldSpace, startWidth, endWidth, startColor, endColor |
Volume (post-processing) | weight, enabled |
ReflectionProbe | intensity, enabled |
LODGroup | enabled |
ParentConstraint | sourceCount, GetSourceTransform, GetSourceWeight, SetSourceWeight, enabled |
For many objects at once, see object batches and drawing by instances; for meshes, meshes made by scripts.
