1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162 |
- import { Effect, ProceduralTexture, Texture, Scene, serializeAsTexture, SerializationHelper } from "babylonjs";
- Effect.ShadersStore["normalMapProceduralTexturePixelShader"] = require("./normalMapProceduralTexture.fragment.fx");
- export class NormalMapProceduralTexture extends ProceduralTexture {
- private _baseTexture: Texture;
- constructor(name: string, size: number, scene: Scene, fallbackTexture?: Texture, generateMipMaps?: boolean) {
- super(name, size, "normalMapProceduralTexture", scene, fallbackTexture, generateMipMaps);
- this.updateShaderUniforms();
- }
- public updateShaderUniforms() {
- this.setTexture("baseSampler", this._baseTexture);
- this.setFloat("size", this.getRenderSize());
- }
- public render(useCameraPostProcess?: boolean) {
- super.render(useCameraPostProcess);
- }
- public resize(size: any, generateMipMaps: any): void {
- super.resize(size, generateMipMaps);
- // We need to update the "size" uniform
- this.updateShaderUniforms();
- }
- @serializeAsTexture()
- public get baseTexture(): Texture {
- return this._baseTexture;
- }
- public set baseTexture(texture: Texture) {
- this._baseTexture = texture;
- this.updateShaderUniforms();
- }
- /**
- * Serializes this normal map procedural texture
- * @returns a serialized normal map procedural texture object
- */
- public serialize(): any {
- var serializationObject = SerializationHelper.Serialize(this, super.serialize());
- serializationObject.customType = "BABYLON.NormalMapProceduralTexture";
- return serializationObject;
- }
- /**
- * Creates a Normal Map Procedural Texture from parsed normal map procedural texture data
- * @param parsedTexture defines parsed texture data
- * @param scene defines the current scene
- * @param rootUrl defines the root URL containing normal map procedural texture information
- * @returns a parsed Normal Map Procedural Texture
- */
- public static Parse(parsedTexture: any, scene: Scene, rootUrl: string): NormalMapProceduralTexture {
- var texture = SerializationHelper.Parse(() => new NormalMapProceduralTexture(parsedTexture.name, parsedTexture._size, scene, undefined, parsedTexture._generateMipMaps), parsedTexture, scene, rootUrl);
- return texture;
- }
- }
|