Hology
Hology 文檔
Hology 文檔
  • 👋歡迎來到Hology文檔
  • Getting started
    • Hology Engine簡介
    • 第一步指南
    • 編輯器基礎指南
      • 在場景中飛行
      • 放置物件
      • 選擇物件
      • 變換
      • 分組物件
      • 複製
    • 入門遊戲模板 - 第三人稱射擊遊戲
  • Tutorials
    • 滾球 - 遊戲玩法編程
    • 角色動畫程式設計
    • Character AI behavior
  • Release
    • 遊戲發行
      • Discord Activities
      • 臉書即時遊戲
      • 上傳至 Itch.io
      • 使用 GitHub Pages
      • 發布到Steam
      • iOS 和 Android
  • Assets
    • 3D模型
      • 客製化碰撞形狀
      • 材質自訂分配
    • 材質
    • 紋理
    • 預製體
  • Gameplay
    • 演員(Actors)
      • 創建演員類
      • 演員參數
      • Actor 元件
      • Actor 的生命週期
      • 生成 Actors
      • 移動 Actors
    • 服務
      • 載入資產
    • 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
    • 世界
    • Navigation
  • Shaders
    • 著色器介紹
    • Creating shaders
    • 著色器參數
    • Typescript shaders
      • Types
      • Math functions
      • Attributes
      • Varying
      • Uniforms
      • Textures
      • Arrays
      • Select
      • Lighting
    • Painted materials
    • Water shader tutorial
  • Level design
    • 地形雕刻
    • 地形繪製
    • Grass
  • User Interfaces
    • 創建用戶界面UI
    • 使用 React
    • VR
  • Visual Effects
    • 視覺效果簡介
    • 視覺特效資產
  • Integrations
    • Arcweave
由 GitBook 提供支持
在本页
  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
上一页Math functions下一页Varying

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