Home Reference Source
import {Shader} from './core/cgl/cgl_shader.js'
public class | source

Shader

Extends:

EventTargetCgShader → Shader

Example:

var shader=new CGL.Shader(cgl,'MinimalMaterial');
shader.setSource(attachments.shader_vert,attachments.shader_frag);

Constructor Summary

Public Constructor
public

Member Summary

Public Members
public

addAttribute(attr: Object): Object: *

adds attribute definition to shader header without colliding with other shader modules...

public
public
public

fshader: *

public
public
public
public

glslVersion: number

public
public

lastCompile: number

public

offScreenPass: boolean

public

opId: *

public

pop last texture

public

pop all textures

public
public

pushTexture(uniform: uniform, t: texture, type: type): *

push a texture on the stack.

public
public

srcFrag: *

public

srcVert: *

public

vshader: *

Private Members
private
private
private
private

_cgl: *

private

_compileReason: string

private
private

_drawBuffers: boolean[]

private
private
private
private

_hasErrors: boolean

private
private
private
private
private

_isValid: boolean

private

_libs: *[]

private

_log: *

private
private
private
private

_modGroupCount: number

private
private

_moduleNumId: number

private

_modules: *[]

private
private

_name: *

private

_needsRecompile: boolean

private
private
private
private
private
private
private
private
private
private
private
private
private
private
private
private
private
private
private
private

_uniforms: *[]

private
private

Method Summary

Public Methods
public

addModule(mod: shaderModule, sibling: shaderModule): *

add a module

public

addUniformBoth(type: String, name: String, valueOrPort: any, p2: *, p3: *, p4: *): CGL.Uniform

add a uniform to both shaders

public

addUniformFrag(type: String, name: String, valueOrPort: any, p2: *, p3: *, p4: *): CGL.Uniform

add a uniform to the fragment shader

public

addUniformStructBoth(structName: String, uniformName: String, members: Array): Object

add a struct & its uniforms to the both shaders.

public

addUniformStructFrag(structName: String, uniformName: String, members: Array): Object

add a struct & its uniforms to the fragment shader

public

addUniformStructVert(structName: String, uniformName: String, members: Array): CGL.Uniform

add a struct & its uniforms to the vertex shader

public

addUniformVert(type: String, name: String, valueOrPort: any, p2: *, p3: *, p4: *): CGL.Uniform

add a uniform to the vertex shader

public

bind(): *

public
public
public

copy(): *

copy current shader

public

copyUniformValues(origShader: *)

copy all uniform values from another shader

public

createStructUniforms(): undefined[]

public
public

enableExtension(name: *)

enable an extension for the shader

public
public

getCgl(): *

public
public

getInfo(): *

public
public

getName(): *

public
public

getProgram(): *

public

getUniform(name: *): *

public
public

hasChanged(): *

public

hasErrors(): *

public

hasModule(modId: *): boolean

public

hasTextureUniforms(): boolean

public

hasUniform(name: *): boolean

public

isValid(): *

public
public
public

removeModule(mod: shaderModule)

remove a module from shader

public

removeUniform(name: *)

public

setDrawBuffers(arr: *)

public

setFeedbackNames(names: *)

public

setModules(names: *)

public

setSource(srcVert: String, srcFrag: String, fromUserInteraction: Bool)

set shader source code

public

setWhyCompile(why: *)

public

unBind()

Private Methods
private

_addLibs(src: *): *

private

_addUniform(uni: *)

private
private

_createProgram(vstr: *, fstr: *): *

private

_getAttrSrc(attr: *, firstLevel: *): *

private

_linkProgram(program: *, vstr: *, fstr: *)

Inherited Summary

From class CgShader
public

id: *

private

_defines: *[]

private

_isValid: boolean

private

_needsRecompile: boolean

public

define(name: String, value: Any)

add a define to a shader, e.g.

public

getDefine(name: *): *

public

getDefines(): *

public

hasDefine(name: String): Boolean

return true if shader has define

public

remove a define from a shader

public

toggleDefine(name: name, enabled: any)

easily enable/disable a define without a value

Public Constructors

public constructor() source

Override:

CgShader#constructor

Public Members

public addAttribute(attr: Object): Object: * source

adds attribute definition to shader header without colliding with other shader modules... when attrFrag is defined, vertex shader will output this attribute to the fragment shader

Return:

Object

public finalShaderFrag: * source

public finalShaderVert: * source

public fshader: * source

public getDefaultFragmentShader: * source

public getDefaultVertexShader: * source

public glPrimitive: * source

public glslVersion: number source

public ignoreMissingUniforms: boolean source

public lastCompile: number source

public offScreenPass: boolean source

public opId: * source

public popTexture: * source

pop last texture

public popTextures: * source

pop all textures

public precision: * source

public pushTexture(uniform: uniform, t: texture, type: type): * source

push a texture on the stack. those textures will be bound when binding the shader. texture slots are automatically set

public setUniformTexture: * source

public srcFrag: * source

public srcVert: * source

public vshader: * source

Private Members

private _attrVertexPos: * source

private _attributes: *[] source

private _camPosUniform: * source

private _cgl: * source

private _compileReason: string source

private _countMissingUniforms: number source

private _drawBuffers: boolean[] source

private _extensions: *[] source

private _feedBackNames: *[] source

private _fromUserInteraction: boolean source

private _hasErrors: boolean source

private _injectedStringsFrag: {} source

private _injectedStringsVert: {} source

private _inverseProjMatrixUniform: * source

private _inverseViewMatrixUniform: * source

private _isValid: boolean source

Override:

CgShader#_isValid

private _libs: *[] source

private _log: * source

private _mMatrixUniform: * source

private _materialId: * source

private _materialIdUniform: * source

private _modGroupCount: number source

private _moduleNames: *[] source

private _moduleNumId: number source

private _modules: *[] source

private _mvMatrixUniform: * source

private _name: * source

private _needsRecompile: boolean source

Override:

CgShader#_needsRecompile

private _normalMatrixUniform: * source

private _objectIdUniform: * source

private _pMatrixState: * source

private _program: * source

private _projMatrixUniform: * source

private _structNames: *[] source

private _structUniformNames: *[] source

private _structUniformNamesIndicesFrag: *[] source

private _structUniformNamesIndicesVert: *[] source

private _tempCamPosMatrix: * source

private _tempInverseProjMatrix: * source

private _tempInverseViewMatrix: * source

private _tempNormalMatrix: * source

private _textureStackTex: *[] source

private _textureStackTexCgl: *[] source

private _textureStackType: *[] source

private _textureStackUni: *[] source

private _uniDeclarationsFrag: *[] source

private _uniDeclarationsVert: *[] source

private _uniforms: *[] source

private _vMatrixState: * source

private _vMatrixUniform: * source

Public Methods

public addModule(mod: shaderModule, sibling: shaderModule): * source

add a module

Params:

NameTypeAttributeDescription
mod shaderModule

the module to be added

sibling shaderModule
  • optional

sibling module, new module will share the same group

Return:

*

public addUniformBoth(type: String, name: String, valueOrPort: any, p2: *, p3: *, p4: *): CGL.Uniform source

add a uniform to both shaders

Params:

NameTypeAttributeDescription
type String

['f','t', etc]

name String
valueOrPort any

value or port

p2 *
p3 *
p4 *

Return:

CGL.Uniform

public addUniformFrag(type: String, name: String, valueOrPort: any, p2: *, p3: *, p4: *): CGL.Uniform source

add a uniform to the fragment shader

Params:

NameTypeAttributeDescription
type String

['f','t', etc]

name String
valueOrPort any

value or port

p2 *
p3 *
p4 *

Return:

CGL.Uniform

public addUniformStructBoth(structName: String, uniformName: String, members: Array): Object source

add a struct & its uniforms to the both shaders. PLEASE NOTE: it is not possible to add the same struct to both shaders when it contains ANY integer members.

Params:

NameTypeAttributeDescription
structName String

name of the struct, i.e.: LightStruct

uniformName String

name of the struct uniform in the shader, i.e.: lightUni

members Array

array of objects containing the struct members. see example for structure

Return:

Object

Example:

const shader = new CGL.Shader(cgl, 'MinimalMaterial');
shader.setSource(attachments.shader_vert, attachments.shader_frag);
shader.addUniformStructBoth("Light", "uniformLight", [
{ "type": "3f", "name": "position", "v1": null },
{ "type": "4f", "name": "color", "v1": inR, v2: inG, v3: inB, v4: inAlpha }
]);

public addUniformStructFrag(structName: String, uniformName: String, members: Array): Object source

add a struct & its uniforms to the fragment shader

Params:

NameTypeAttributeDescription
structName String

name of the struct, i.e.: LightStruct

uniformName String

name of the struct uniform in the shader, i.e.: lightUni

members Array

array of objects containing the struct members. see example for structure

Return:

Object

Example:

const shader = new CGL.Shader(cgl, 'MinimalMaterial');
shader.setSource(attachments.shader_vert, attachments.shader_frag);
shader.addUniformStructFrag("Light", "uniformLight", [
{ "type": "3f", "name": "position", "v1": null },
{ "type": "4f", "name": "color", "v1": inR, v2: inG, v3: inB, v4: inAlpha }
]);

public addUniformStructVert(structName: String, uniformName: String, members: Array): CGL.Uniform source

add a struct & its uniforms to the vertex shader

Params:

NameTypeAttributeDescription
structName String

name of the struct, i.e.: LightStruct

uniformName String

name of the struct uniform in the shader, i.e.: lightUni

members Array

array of objects containing the struct members. see example for structure

Return:

CGL.Uniform

Example:

const shader = new CGL.Shader(cgl, 'MinimalMaterial');
shader.setSource(attachments.shader_vert, attachments.shader_frag);
shader.addUniformStructVert("Light", "uniformLight", [
{ "type": "3f", "name": "position", "v1": null },
{ "type": "4f", "name": "color", "v1": inR, v2: inG, v3: inB, v4: inAlpha }
]);

public addUniformVert(type: String, name: String, valueOrPort: any, p2: *, p3: *, p4: *): CGL.Uniform source

add a uniform to the vertex shader

Params:

NameTypeAttributeDescription
type String

['f','t', etc]

name String
valueOrPort any

value or port

p2 *
p3 *
p4 *

Return:

CGL.Uniform

public bind(): * source

Return:

*

public bindTextures() source

public compile() source

public copy(): * source

copy current shader

Return:

*

newShader

public copyUniformValues(origShader: *) source

copy all uniform values from another shader

Params:

NameTypeAttributeDescription
origShader *

uniform values will be copied from this shader

public createStructUniforms(): undefined[] source

Return:

undefined[]

public dispose() source

public enableExtension(name: *) source

enable an extension for the shader

Params:

NameTypeAttributeDescription
name *

extension name

public getAttrVertexPos(): * source

Return:

*

public getCgl(): * source

Return:

*

public getCurrentModules(): * source

Return:

*

public getInfo(): * source

Return:

*

public getMaterialId(): * source

Return:

*

public getName(): * source

Return:

*

public getNumModules(): * source

Return:

*

public getProgram(): * source

Return:

*

public getUniform(name: *): * source

Params:

NameTypeAttributeDescription
name *

Return:

*

public getUniforms(): * source

Return:

*

public hasChanged(): * source

Return:

*

public hasErrors(): * source

Return:

*

public hasModule(modId: *): boolean source

Params:

NameTypeAttributeDescription
modId *

Return:

boolean

public hasTextureUniforms(): boolean source

Return:

boolean

public hasUniform(name: *): boolean source

Params:

NameTypeAttributeDescription
name *

Return:

boolean

public isValid(): * source

Return:

*

public needsRecompile(): * source

Return:

*

public removeAllUniforms() source

public removeModule(mod: shaderModule) source

remove a module from shader

Params:

NameTypeAttributeDescription
mod shaderModule

the module to be removed

public removeUniform(name: *) source

Params:

NameTypeAttributeDescription
name *

public setDrawBuffers(arr: *) source

Params:

NameTypeAttributeDescription
arr *

public setFeedbackNames(names: *) source

Params:

NameTypeAttributeDescription
names *

public setModules(names: *) source

Params:

NameTypeAttributeDescription
names *

public setSource(srcVert: String, srcFrag: String, fromUserInteraction: Bool) source

set shader source code

Params:

NameTypeAttributeDescription
srcVert String
srcFrag String
fromUserInteraction Bool

public setWhyCompile(why: *) source

Params:

NameTypeAttributeDescription
why *

public unBind() source

Private Methods

private _addLibs(src: *): * source

Params:

NameTypeAttributeDescription
src *

Return:

*

private _addUniform(uni: *) source

Params:

NameTypeAttributeDescription
uni *

private _bindTextures() source

private _createProgram(vstr: *, fstr: *): * source

Params:

NameTypeAttributeDescription
vstr *
fstr *

Return:

*

private _getAttrSrc(attr: *, firstLevel: *): * source

Params:

NameTypeAttributeDescription
attr *
firstLevel *

Return:

*

private _linkProgram(program: *, vstr: *, fstr: *) source

Params:

NameTypeAttributeDescription
program *
vstr *
fstr *