Shaku

Shaku JS

Back To Table of Content

Effect

Classes

Effect

Effect base class. An effect = vertex shader + fragment shader + uniforms & attributes + setup code.

Functions

compileShader()

Build a shader.

Typedefs

UniformType : String

Effect

Effect base class. An effect = vertex shader + fragment shader + uniforms & attributes + setup code.

Kind: global class

new Effect()

Create the effect.

effect.uniformTypes ⇒ \*

Get a dictionary with all shaders uniforms. Key = uniform name, as appears in shader code. Value = { type: UniformTypes to represent uniform type, bind: Optional bind to one of the built-in uniforms. See Effect.UniformBinds for details. }

Kind: instance property of Effect
Returns: \* - Dictionary with uniforms descriptions.

effect.attributeTypes ⇒ \*

Get a dictionary with all shader attributes. Key = attribute name, as appears in shader code. Value = { size: size of every value in this attribute. type: attribute type. See Effect.AttributeTypes for details. normalize: if true, will normalize values. stride: optional stride. offset: optional offset. bind: Optional bind to one of the built-in attributes. See Effect.AttributeBinds for details. }

Kind: instance property of Effect
Returns: \* - Dictionary with attributes descriptions.

effect.vertexCode ⇒ String

Get this effect’s vertex shader code, as string.

Kind: instance property of Effect
Returns: String - Vertex shader code.

effect.fragmentCode ⇒ String

Get this effect’s fragment shader code, as string.

Kind: instance property of Effect
Returns: String - Fragment shader code.

effect.enableDepthTest

Should this effect enable depth test?

Kind: instance property of Effect

effect.enableFaceCulling

Should this effect enable face culling?

Kind: instance property of Effect

effect.depthFunc

Get depth func to use when rendering using this effect. Use ‘DepthFuncs’ to get options.

Kind: instance property of Effect

effect.enableStencilTest

Should this effect enable stencil test?

Kind: instance property of Effect

effect.enableDithering

Should this effect enable dithering?

Kind: instance property of Effect

effect.polygonOffset ⇒ Boolean | \*

Get polygon offset factor, to apply on depth value before checking.

Kind: instance property of Effect
Returns: Boolean | \* - Return false to disable polygon offset, or {factor, unit} to apply polygon offset.

effect.hasVertexColor ⇒ Boolean

Return if this effect have colors attribute on vertices.

Kind: instance property of Effect
Returns: Boolean - True if got vertices color attribute.

effect.setAsActive(overrideFlags)

Make this effect active.

Kind: instance method of Effect

Param Type Description
overrideFlags \* Optional flags to override in effect. May include the following: enableDepthTest, enableFaceCulling, enableStencilTest, enableDithering.

effect.getBoundUniform(bindKey) ⇒

Get a uniform method from a bind key.

Kind: instance method of Effect
Returns: Uniform set method, or null if not set.

Param Type Description
bindKey UniformBinds Uniform bind key.

effect.setTexture(texture) ⇒ Boolean

Set the main texture. Note: this will only work for effects that utilize the ‘MainTexture’ uniform.

Kind: instance method of Effect
Returns: Boolean - True if texture was changed, false if there was no need to change the texture.

Param Type Description
texture TextureAssetBase Texture to set.

effect.setColor(color)

Set the main tint color. Note: this will only work for effects that utilize the ‘Color’ uniform.

Kind: instance method of Effect

Param Type Description
color Color Color to set.

effect.setProjectionMatrix(matrix)

Set the projection matrix uniform. Note: this will only work for effects that utilize the ‘Projection’ uniform.

Kind: instance method of Effect

Param Type Description
matrix Matrix Matrix to set.

effect.setWorldMatrix(matrix)

Set the world matrix uniform. Note: this will only work for effects that utilize the ‘World’ uniform.

Kind: instance method of Effect

Param Type Description
matrix Matrix Matrix to set.

effect.setViewMatrix(matrix)

Set the view matrix uniform. Note: this will only work for effects that utilize the ‘View’ uniform.

Kind: instance method of Effect

Param Type Description
matrix Matrix Matrix to set.

effect.setOutline(weight, color)

Set outline params. Note: this will only work for effects that utilize the ‘OutlineWeight’ and ‘OutlineColor’ uniforms.

Kind: instance method of Effect

Param Type Description
weight Number Outline weight, range from 0.0 to 1.0.
color Color Outline color.

effect.setUvNormalizationFactor(factor)

Set a factor to normalize UV values to be 0-1. Note: this will only work for effects that utilize the ‘UvNormalizationFactor’ uniform.

Kind: instance method of Effect

Param Type Description
factor Vector2 Normalize UVs factor.

effect.setPositionsAttribute(buffer, forceSetBuffer)

Set the vertices position buffer. Only works if there’s an attribute type bound to ‘Position’.

Kind: instance method of Effect

Param Type Description
buffer WebGLBuffer Vertices position buffer.
forceSetBuffer Boolean If true, will always set buffer even if buffer is currently set.

effect.setTextureCoordsAttribute(buffer, forceSetBuffer)

Set the vertices texture coords buffer. Only works if there’s an attribute type bound to ‘TextureCoords’.

Kind: instance method of Effect

Param Type Description
buffer WebGLBuffer Vertices texture coords buffer.
forceSetBuffer Boolean If true, will always set buffer even if buffer is currently set.

effect.setColorsAttribute(buffer, forceSetBuffer)

Set the vertices colors buffer. Only works if there’s an attribute type bound to ‘Colors’.

Kind: instance method of Effect

Param Type Description
buffer WebGLBuffer Vertices colors buffer.
forceSetBuffer Boolean If true, will always set buffer even if buffer is currently set.

effect.setNormalsAttribute(buffer, forceSetBuffer)

Set the vertices normals buffer. Only works if there’s an attribute type bound to ‘Normals’.

Kind: instance method of Effect

Param Type Description
buffer WebGLBuffer Vertices normals buffer.
forceSetBuffer Boolean If true, will always set buffer even if buffer is currently set.

effect.setBinormalsAttribute(buffer, forceSetBuffer)

Set the vertices binormals buffer. Only works if there’s an attribute type bound to ‘Binormals’.

Kind: instance method of Effect

Param Type Description
buffer WebGLBuffer Vertices binormals buffer.
forceSetBuffer Boolean If true, will always set buffer even if buffer is currently set.

effect.setTangentsAttribute(buffer, forceSetBuffer)

Set the vertices tangents buffer. Only works if there’s an attribute type bound to ‘Tangents’.

Kind: instance method of Effect

Param Type Description
buffer WebGLBuffer Vertices tangents buffer.
forceSetBuffer Boolean If true, will always set buffer even if buffer is currently set.

Effect.DepthFuncs ⇒ \*

Get all supported depth funcs we can set.

Kind: static property of Effect
Returns: \* - Depth func options: {Never, Less, Equal, LessEqual, Greater, GreaterEqual, Always, NotEqual}.

Effect.UniformBinds

Default uniform binds. This is a set of commonly used uniforms and their names inside the shader code.

Every bind here comes with a built-in method to set and is used internally by Shaku. For example, if you want to include outline properties in your effect, you can use the ‘OutlineWeight’ and ‘OutlineColor’ binds (with matching name in the shader code). When you use the built-in binds, Shaku will know how to set them itself when relevant, for example in text rendering Shaku will use the outline binds if they exist.

If you don’t use the built-in binds you can just call your uniforms however you like, but you’ll need to set them all manually. Shaku will not know how to set them.

Kind: static property of Effect

Effect.AttributeTypes

Define attribute types.

Kind: static property of Effect

Effect.AttributeBinds

Define built-in attribute binds to connect attribute names for specific use cases like position, uvs, colors, etc. If an effect support one or more of these attributes, Shaku will know how to fill them automatically.

Kind: static property of Effect

UniformTypes : enum

Uniform types enum.

Kind: global enum
Read only: true
Properties

Name Type Default
Texture UniformType texture
Matrix UniformType uniformMatrix4fv
Color UniformType uniform4fv
Float UniformType uniform1f
FloatArray UniformType uniform1fv
Int UniformType uniform1i
IntArray UniformType uniform1iv
Float2 UniformType uniform2f
Float2Array UniformType uniform2fv
Int2 UniformType uniform2i
Int2Array UniformType uniform2iv
Float3 UniformType uniform3f
Float3Array UniformType uniform3fv
Int3 UniformType uniform3i
Int3Array UniformType uniform3iv
Float4 UniformType uniform4f
Float4Array UniformType uniform4fv
Int4 UniformType uniform4i
Int4Array UniformType uniform4iv

compileShader()

Build a shader.

Kind: global function

UniformType : String

Kind: global typedef