Hology
Hology
Hology
  • 👋Welcome to Hology Docs
  • Getting started
    • Introduction to Hology
    • The first steps
    • Editor basics
      • Flying in scenes
      • Placing objects
      • Select objects
      • Transform
      • Grouping objects
      • Duplicate
    • Starter project - Third person shooter
  • Tutorials
    • Rolling ball - Gameplay programming
    • Character movement programming
    • Character AI behavior
  • Release
    • Distribution
      • Discord Activities
      • Facebook Instant Games
      • Upload to Itch.io
      • Host with GitHub Pages
      • Publishing to Steam
      • iOS and Android
  • Assets
    • 3D Models
      • Custom collision shapes
      • Material slots
    • Materials
    • Textures
    • Prefabs
  • Gameplay
    • Actors
      • Creating actor classes
      • Actor parameters
      • Actor components
      • Actor lifecycle
      • Spawning actors
      • Moving actors
    • Services
      • Load assets
    • Player input
    • Collision detection
    • Physics
      • Physics body types
      • Applying forces
      • Ray casting
    • Trigger volumes
    • Character movement
    • Pointer events
    • Animation
      • Animation system
      • Character Animation
      • Animation State Machine
    • Sound
      • Audio parameter
    • World
    • Navigation
  • Shaders
    • Introduction to shaders
    • Creating shaders
    • Shader parameters
    • Typescript shaders
      • Types
      • Math functions
      • Attributes
      • Varying
      • Uniforms
      • Textures
      • Arrays
      • Select
      • Lighting
    • Painted materials
    • Water shader tutorial
  • Level design
    • Landscape sculpting
    • Landscape painting
    • Grass
  • User Interfaces
    • Creating user interfaces
    • Using React
    • VR
  • Visual Effects
    • Introduction to VFX
    • VFX Assets
  • Integrations
    • Arcweave
Powered by GitBook
On this page
  1. Shaders
  2. Typescript shaders

Varying

In order to use information in each fragment of a triangle that exists on the vertex level, this information needs to be interpolated between the vertices. The variable referred to at a specific fragment needs to be interpolated for that fragment's position based on the the value at each of the triangle's vertices and the fragment's offset from those vertices. In order for this information to be available, they need to be passed in as "varying" variables to the fragment shader. This is done by wrapping the value in call to a special function defined for each type as illustrated below.

import { float, varyingVec2, attributes } from "@hology/core/shader-nodes"

const coord: Vec2Node = varyingVec2(attributes.uv)

// coord can now be used to lookup a color from a texture on each fragment

Functions

varyingFloat(n: FloatNode): FloatNode
varyingVec2(n: Vec2Node): Vec2Node
varyingVec3(n: Vec3Node): Vec3Node
varyingVec4(n: Vec4Node): Vec4Node
varyingMat2(n: Mat2Node): Mat2Node
varyingMat3(n: Mat3Node): Mat3Node
varyingMat4(n: Mat4Node): Mat4Node

When you must use varyings

If you try to use a value that only exists in the vertex shader, you will get an error that you are referring to something undefined. This is easily fixed by wrapping it in a varying call but it is useful to know when this would happen. These are the scenarios in which you have to define a varying:

  • You are referring to attributes such as position, uv, normal as this information only exist per vertex and has to be interpolated for each fragment in order to affect the color calculation.

  • You have defined a value which is used both in a vertex transformation and the color.

PreviousAttributesNextUniforms

Last updated 1 year ago