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

Attributes

Attributes contain information for each vertex.

In order to use attribute information for calculating the color, they have to first be made varying. See the the guide on Varying for how to do this.

Predefined

ThreeJS provides data for each vertex for position, uv, and normal. These can be accessed from the common attributes object.

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

const uv: Vec2Node = attributes.uv
const position: Vec3Node = attributes.position
const normal: Vec3Node = attributes.normal

Transformed value helpers

If a vertex transformation is included in the material, then the attributes passed in to the shaders for each vertex are often less useful. Use these values to refer to the position and normal after vertex transformations. Usually you always want to use these to calculate the amount of light reflected from a surface.

import { transformed } from "@hology/core/shader-nodes"

const position: Vec4Node = transformed.position // After applying vertex transform
const mvPosition: Vec4Node = transformed.mvPosition // After applying vertex transform and the model view matrix
const normal: Vec3Node = transformed.normal // Recalculated normal after applying the vertex transform

Custom attributes

You can also define your own attributes with attribute node classes.

import { AttributeVec3Node, Vec3Node } from "@hology/core/shader-nodes"
import { BoxGeometry } from 'three'


const customAttribute: Vec3Node = new AttributeVec3Node('myCustomAttribute')

const customAttributeValues = new Float32Array([
   1, 1, 1,
   1, 1, 1,
   ...
])

const geometry = new BoxGeometry(1,1,1)
geometry.setAttribute('myCustomAttribute', new THREE.BufferAttribute(customAttributeValues, 3));
AttributeFloatNode
AttributeVec2Node
AttributeVec3Node
AttributeVec4Node
AttributeMat2Node
AttributeMat3Node
AttributeMat4Node
AttributeRgbNode
AttributeRgbaNode
PreviousMath functionsNextVarying

Last updated 6 months ago

The following classes exist to define your own attributes and the only constructor argument is the name of the attribute as it is defined when calling setAttribute on a .

THREE.BufferGeometry