CustomMaterial ============== ### CustomMaterial is a StandardMaterial with some customizable Options 1- manage part of current shader > CustomMaterial put some part of shader in special part of current shader and make new shader in ShaderStore > shaders struct : > > [ Begin ] > > . // includes extensions varyng uniforms attributes special functions > > [ Definations ] > > void main(){ > > [ Main Begin ] > > . > . > . > > [ ] > > } method : SelectVersion(ver:string) > Custom material for now Supported just ver 3.0.0 of BabylonJs and this is default of currentVersion for now > Add other old version in Progress % method : AddUniform(name:string,kind:string,param:any):CustomMaterial > for append dynamic setting and manage
> this method Add Unforn in bouth of shaders(Fragment and Vertex)
> usage : new CustomMaterial(...).AddUniform('time','float')
> : new CustomMaterial(...).AddUniform('direction','vec3',new BABYLON.Vector3(0.,0.,0.))
> : new CustomMaterial(...).AddUniform('txt1','sampler2D', new BABYLON.Texture("path",scene)) method : Fragment_Begin(shaderPart:string):CustomMaterial > shaderPart is Shader Structure append in start of main function in fragment shader
> usage : new CustomMaterial(...).Fragment_Begin('vec3 direction = vec3(0.);') method : Fragment_Definations(shaderPart:string):CustomMaterial > shaderPart is Shader Structure append in befor of the main function in fragment shader
> you can define your varyng and functions from this
> usage : new CustomMaterial(...).Fragment_Definations('float func1(vec4 param1){ return param1.x;}')
> * dont try use uniform with this function because uniforms need to add buffers method : Fragment_MainBegin(shaderPart:string):CustomMaterial > shaderPart is Shader Structure append in start place of the main function in fragment shader method : Fragment_Custom_Diffuse(shaderPart:string):CustomMaterial > shaderPart is Shader Structure append after diffuseColor is defined of the main function in fragment shader
> usage : new CustomMaterial(...).Fragment_Custom_Diffuse('diffuseColor = vec3(sin(vPositionW.x));')
> : new CustomMaterial(...).Fragment_Custom_Diffuse('result = vec3(sin(vPositionW.x));')
> * diffuseColor is vec3 variable
> * you can use result (vec3) too that replaced by diffuseColor method : Fragment_Custom_Alpha(shaderPart:string):CustomMaterial > shaderPart is Shader Structure append when material need a alpha parameter in fragment shader
method : Fragment_Before_FragColor(shaderPart:string):CustomMaterial > shaderPart is Shader Structure append before gl_FragColor wanna be set in fragment shader
> * color is vec4 parameter be set in last part to gl_fragcolor > * you can use result (vec4) too > * this part your last chance for change the frag color method : Vertex_Begin(shaderPart:string):CustomMaterial > shaderPart is Shader Structure append in start of main function in vertex shader
> usage : new CustomMaterial(...).Vertex_Begin('vec3 direction = vec3(0.);') method : Vertex_Definations(shaderPart:string):CustomMaterial > shaderPart is Shader Structure append in befor of the main function in vertex shader
> you can define your varyng and functions from this
> usage : new CustomMaterial(...).Vertex_Definations('float func1(vec4 param1){ return param1.x;}')
> * dont try use uniform with this function because uniforms need to add buffers
> * for connect any information between vertex and fragment part in shader you can define varying you need make that in both of definition part method : Vertex_MainBegin(shaderPart:string):CustomMaterial > shaderPart is Shader Structure append in start place of the main function in vertex shader method : Vertex_Befor_PositionUpdated(shaderPart:string):CustomMaterial{ > shaderPart is Shader Structure append after positionUpdated is defined of the main function in vertex shader
> usage : new CustomMaterial(...).Vertex_Befor_PositionUpdated('positionUpdated = positionUpdated;')
> : new CustomMaterial(...).Vertex_Befor_PositionUpdated('result = positionUpdated * 1.5 ;')
> * positionUpdated is vec3 variable
> * you can use result (vec3) too that replaced by positionUpdated > * you can use 'normal' attribute in this part too method : Vertex_Befor_NormalUpdated(shaderPart:string):CustomMaterial > shaderPart is Shader Structure append after normalUpdated is defined of the main function in vertex shader
> usage : new CustomMaterial(...).Vertex_Befor_NormalUpdated('normalUpdated = normalUpdated;')
> : new CustomMaterial(...).Vertex_Befor_NormalUpdated('result = normalUpdated ;')
> * normalUpdated is vec3 variable
> * you can use result (vec3) too that replaced by normalUpdated > * you can use positionUpdated too in this part