babylon.customMaterial.ts 1.2 KB

1234567891011121314151617181920212223242526272829303132333435
  1. /// <reference path="../../../dist/preview release/babylon.d.ts"/>
  2. module BABYLON {
  3. export class CustomShaderHelper{
  4. }
  5. export interface ICustomMaterialBuilder {
  6. (builder:CustomShaderHelper , name: string ,mainPart: string , diffusePart:string ,vertexPositionPart:string ): string;
  7. }
  8. export class CustomMaterial extends StandardMaterial {
  9. public builder: ICustomMaterialBuilder;
  10. private _mainPart = 'void main(void) {';
  11. private _diffusePart = 'vec3 diffuseColor=vDiffuseColor.rgb;';
  12. private _vertexPositionPart = 'gl_Position=viewProjection*finalWorld*vec4(position,1.0);';
  13. constructor (name: string, builder:ICustomMaterialBuilder, scene: Scene) {
  14. super(name, scene);
  15. this.builder = builder;
  16. this.customShaderNameResolve = (shaderName) => {
  17. return this.builder(
  18. new CustomShaderHelper(),
  19. shaderName,
  20. this._mainPart,
  21. this._diffusePart,
  22. this._vertexPositionPart );
  23. }
  24. }
  25. }
  26. }