Shader
Extends:
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 |
glPrimitive: * |
|
| public |
glslVersion: number |
|
| public |
ignoreMissingUniforms: boolean |
|
| public |
lastCompile: number |
|
| public |
offScreenPass: boolean |
|
| public |
opId: * |
|
| public |
popTexture: * pop last texture |
|
| public |
popTextures: * pop all textures |
|
| public |
precision: * |
|
| 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 |
_attributes: *[] |
|
| private |
|
|
| private |
_cgl: * |
|
| private |
_compileReason: string |
|
| private |
_countMissingUniforms: number |
|
| private |
_drawBuffers: boolean[] |
|
| private |
_extensions: *[] |
|
| private |
_feedBackNames: *[] |
|
| private |
_fromUserInteraction: boolean |
|
| private |
_hasErrors: boolean |
|
| private |
|
|
| private |
|
|
| private |
|
|
| private |
|
|
| private |
_isValid: boolean |
|
| private |
_libs: *[] |
|
| private |
_log: * |
|
| private |
|
|
| private |
_materialId: * |
|
| private |
|
|
| private |
_modGroupCount: number |
|
| private |
|
|
| private |
_name: * |
|
| private |
_needsRecompile: boolean |
|
| private |
|
|
| private |
|
|
| private |
|
|
| private |
_program: * |
|
| private |
|
|
| private |
_structNames: *[] |
|
| private |
_structUniformNames: *[] |
|
| private |
|
|
| private |
|
|
| private |
|
|
| private |
|
|
| private |
|
|
| private |
|
|
| private |
_textureStackTex: *[] |
|
| private |
_textureStackTexCgl: *[] |
|
| private |
_textureStackType: *[] |
|
| private |
_textureStackUni: *[] |
|
| private |
_uniDeclarationsFrag: *[] |
|
| private |
_uniDeclarationsVert: *[] |
|
| private |
_uniforms: *[] |
|
| private |
|
|
| private |
|
|
Method Summary
| Public Methods | ||
| 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 |
compile() |
|
| public |
copy(): * copy current shader |
|
| public |
copyUniformValues(origShader: *) copy all uniform values from another shader |
|
| public |
createStructUniforms(): undefined[] |
|
| public |
dispose() |
|
| public |
enableExtension(name: *) enable an extension for the shader |
|
| public |
getAttrVertexPos(): * |
|
| public |
getCgl(): * |
|
| public |
getInfo(): * |
|
| public |
getMaterialId(): * |
|
| public |
getName(): * |
|
| public |
getProgram(): * |
|
| public |
getUniform(name: *): * |
|
| public |
getUniforms(): * |
|
| public |
hasChanged(): * |
|
| public |
hasErrors(): * |
|
| public |
hasTextureUniforms(): boolean |
|
| public |
hasUniform(name: *): boolean |
|
| public |
isValid(): * |
|
| public |
needsRecompile(): * |
|
| public |
|
|
| public |
removeUniform(name: *) |
|
| public |
setDrawBuffers(arr: *) |
|
| public |
setFeedbackNames(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 |
_moduleNames: *[] |
|
| private |
_moduleNumId: number |
|
| private |
_modules: *[] |
|
| private |
_needsRecompile: boolean |
|
| public |
addModule(mod: shaderModule, sibling: shaderModule): * add a module |
|
| public |
define(name: String, value: Any) add a define to a shader, e.g. |
|
| public |
getAttributeSrc(mod: *, srcHeadVert: *, srcVert: *): {"srcHeadVert": *, "srcVert": *} |
|
| public |
getCurrentModules(): * |
|
| public |
getDefine(name: *): * |
|
| public |
getDefines(): * |
|
| public |
getNumModules(): * |
|
| public |
hasDefine(name: String): Boolean return true if shader has define |
|
| public |
hasModule(modId: *): boolean |
|
| public |
removeDefine(name: name) remove a define from a shader |
|
| public |
removeModule(mod: shaderModule) remove a module from shader |
|
| public |
|
|
| public |
setModules(names: *) |
|
| public |
toggleDefine(name: name, enabled: any) easily enable/disable a define without a value |
|
Public Constructors
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 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 _libs: *[] source
private _log: * source
private _mMatrixUniform: * source
private _materialId: * source
private _materialIdUniform: * source
private _modGroupCount: number source
private _mvMatrixUniform: * source
private _name: * source
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 addUniformBoth(type: String, name: String, valueOrPort: any, p2: *, p3: *, p4: *): CGL.Uniform source
add a uniform to both shaders
Params:
| Name | Type | Attribute | Description |
| 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:
| Name | Type | Attribute | Description |
| 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:
| Name | Type | Attribute | Description |
| 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:
| Name | Type | Attribute | Description |
| 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:
| Name | Type | Attribute | Description |
| 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:
| Name | Type | Attribute | Description |
| type | String | ['f','t', etc] |
|
| name | String | ||
| valueOrPort | any | value or port |
|
| p2 | * | ||
| p3 | * | ||
| p4 | * |
Return:
| CGL.Uniform |
public bindTextures() source
public compile() source
public copyUniformValues(origShader: *) source
copy all uniform values from another shader
Params:
| Name | Type | Attribute | Description |
| origShader | * | uniform values will be copied from this shader |
public dispose() source
public enableExtension(name: *) source
enable an extension for the shader
Params:
| Name | Type | Attribute | Description |
| name | * | extension name |
public hasUniform(name: *): boolean source
Params:
| Name | Type | Attribute | Description |
| name | * |
Return:
| boolean |
public removeAllUniforms() source
public removeUniform(name: *) source
Params:
| Name | Type | Attribute | Description |
| name | * |
public setDrawBuffers(arr: *) source
Params:
| Name | Type | Attribute | Description |
| arr | * |
public setFeedbackNames(names: *) source
Params:
| Name | Type | Attribute | Description |
| names | * |
public setSource(srcVert: String, srcFrag: String, fromUserInteraction: Bool) source
set shader source code
Params:
| Name | Type | Attribute | Description |
| srcVert | String | ||
| srcFrag | String | ||
| fromUserInteraction | Bool |
public setWhyCompile(why: *) source
Params:
| Name | Type | Attribute | Description |
| why | * |
public unBind() source
Private Methods
private _addUniform(uni: *) source
Params:
| Name | Type | Attribute | Description |
| uni | * |
private _bindTextures() source
private _createProgram(vstr: *, fstr: *): * source
Params:
| Name | Type | Attribute | Description |
| vstr | * | ||
| fstr | * |
Return:
| * |
private _getAttrSrc(attr: *, firstLevel: *): * source
Params:
| Name | Type | Attribute | Description |
| attr | * | ||
| firstLevel | * |
Return:
| * |
private _linkProgram(program: *, vstr: *, fstr: *) source
Params:
| Name | Type | Attribute | Description |
| program | * | ||
| vstr | * | ||
| fstr | * |