import { Laya } from "Laya" ; import { Camera } from "laya/d3/core/Camera" ; import { DirectionLight } from "laya/d3/core/light/DirectionLight" ; import { BaseMaterial } from "laya/d3/core/material/BaseMaterial" ; import { MeshSprite3D } from "laya/d3/core/MeshSprite3D" ; import { Scene3D } from "laya/d3/core/scene/Scene3D" ; import { SkinnedMeshSprite3D } from "laya/d3/core/SkinnedMeshSprite3D" ; import { Sprite3D } from "laya/d3/core/Sprite3D" ; import { VertexMesh } from "laya/d3/graphics/Vertex/VertexMesh" ; import { Vector3 } from "laya/d3/math/Vector3" ; import { PrimitiveMesh } from "laya/d3/resource/models/PrimitiveMesh" ; import { Shader3D } from "laya/d3/shader/Shader3D" ; import { ShaderPass } from "laya/d3/shader/ShaderPass" ; import { SubShader } from "laya/d3/shader/SubShader" ; import { Stage } from "laya/display/Stage" ; import { Texture2D } from "laya/resource/Texture2D" ; import { Handler } from "laya/utils/Handler" ; import { Stat } from "laya/utils/Stat" ; import { Laya3D } from "Laya3D" ; import { CameraMoveScript } from "../common/CameraMoveScript" ; import { CustomMaterial } from "./customMaterials/CustomMaterial" ; import GlowingEdgeShaderFS from "./customShader/glowingEdgeShader.fs" ; import GlowingEdgeShaderVS from "./customShader/glowingEdgeShader.vs" ; import { GlowingEdgeMaterial } from "./customMaterials/GlowingEdgeMaterial" ; import { Material } from "laya/d3/core/material/Material" ; author export class Shader_GlowingEdge { private rotation : Vector3 = new Vector3 ( 0 , 0.01 , 0 ) ; constructor ( ) { Laya3D . init ( 0 , 0 ) ; Laya . stage . scaleMode = Stage . SCALE_FULL ; Laya . stage . screenMode = Stage . SCREEN_NONE ; Stat . show ( ) ; this . initShader ( ) ; var scene = ( < Scene3D > Laya . stage . addChild ( new Scene3D ( ) ) ) ; var camera = ( < Camera > ( scene . addChild ( new Camera ( 0 , 0.1 , 1000 ) ) ) ) ; camera . transform . translate ( new Vector3 ( 0 , 0.85 , 1.7 ) ) ; camera . transform . rotate ( new Vector3 ( - 15 , 0 , 0 ) , true , false ) ; camera . addComponent ( CameraMoveScript ) ; var directionLight = new DirectionLight ( ) ; scene . addChild ( directionLight ) ; directionLight . color = new Vector3 ( 1 , 1 , 1 ) ; Sprite3D . load ( "res/threeDimen/skinModel/dude/dude.lh" , Handler . create ( this , function ( dude ) : void { scene . addChild ( dude ) ; var glowingEdgeMaterial1 = new GlowingEdgeMaterial ( ) ; Texture2D . load ( "res/threeDimen/skinModel/dude/Assets/dude/head.png" , Handler . create ( this , function ( tex ) : void { glowingEdgeMaterial1 . diffuseTexture = tex ; } ) ) ; glowingEdgeMaterial1 . marginalColor = new Vector3 ( 1 , 0.7 , 0 ) ; var glowingEdgeMaterial2 = new GlowingEdgeMaterial ( ) ; Texture2D . load ( "res/threeDimen/skinModel/dude/Assets/dude/jacket.png" , Handler . create ( this , function ( tex ) : void { glowingEdgeMaterial2 . diffuseTexture = tex ; } ) ) ; glowingEdgeMaterial2 . marginalColor = new Vector3 ( 1 , 0.7 , 0 ) ; var glowingEdgeMaterial3 = new GlowingEdgeMaterial ( ) ; Texture2D . load ( "res/threeDimen/skinModel/dude/Assets/dude/pants.png" , Handler . create ( this , function ( tex ) : void { glowingEdgeMaterial3 . diffuseTexture = tex ; } ) ) ; glowingEdgeMaterial3 . marginalColor = new Vector3 ( 1 , 0.7 , 0 ) ; var glowingEdgeMaterial4 = new GlowingEdgeMaterial ( ) ; Texture2D . load ( "res/threeDimen/skinModel/dude/Assets/dude/upBodyC.png" , Handler . create ( this , function ( tex ) : void { glowingEdgeMaterial4 . diffuseTexture = tex ; } ) ) ; glowingEdgeMaterial4 . marginalColor = new Vector3 ( 1 , 0.7 , 0 ) ; var baseMaterials = [ ] ; baseMaterials [ 0 ] = glowingEdgeMaterial1 ; baseMaterials [ 1 ] = glowingEdgeMaterial2 ; baseMaterials [ 2 ] = glowingEdgeMaterial3 ; baseMaterials [ 3 ] = glowingEdgeMaterial4 ; ( < SkinnedMeshSprite3D > dude . getChildAt ( 0 ) . getChildAt ( 0 ) ) . skinnedMeshRenderer . sharedMaterials = baseMaterials ; dude . transform . position = new Vector3 ( 0 , 0.5 , 0 ) ; dude . transform . setWorldLossyScale ( new Vector3 ( 0.2 , 0.2 , 0.2 ) ) ; dude . transform . rotate ( new Vector3 ( 0 , 180 , 0 ) , false , false ) ; } ) ) ; var earth = ( < MeshSprite3D > scene . addChild ( new MeshSprite3D ( PrimitiveMesh . createSphere ( 0.5 , 128 , 128 ) ) ) ) ; var glowingEdgeMaterial = new GlowingEdgeMaterial ( ) ; Texture2D . load ( "res/threeDimen/texture/earth.png" , Handler . create ( this , function ( tex ) : void { glowingEdgeMaterial . diffuseTexture = tex ; } ) ) ; glowingEdgeMaterial . marginalColor = new Vector3 ( 0.0 , 0.3 , 1.0 ) ; earth . meshRenderer . sharedMaterial = glowingEdgeMaterial ; Laya . timer . frameLoop ( 1 , this , function ( ) : void { earth . transform . rotate ( this . rotation , true ) ; } ) ; } private initShader ( ) { var attributeMap = { 'a_Position' : VertexMesh . MESH_POSITION0 , 'a_Normal' : VertexMesh . MESH_NORMAL0 , 'a_Texcoord' : VertexMesh . MESH_TEXTURECOORDINATE0 , 'a_BoneWeights' : VertexMesh . MESH_BLENDWEIGHT0 , 'a_BoneIndices' : VertexMesh . MESH_BLENDINDICES0 } ; var uniformMap = { 'u_Bones' : Shader3D . PERIOD_CUSTOM , 'u_CameraPos' : Shader3D . PERIOD_CAMERA , 'u_MvpMatrix' : Shader3D . PERIOD_SPRITE , 'u_WorldMat' : Shader3D . PERIOD_SPRITE , 'u_texture' : Shader3D . PERIOD_MATERIAL , 'u_marginalColor' : Shader3D . PERIOD_MATERIAL , 'u_SunLight.color' : Shader3D . PERIOD_SCENE , } ; var glowingEdgeShader = Shader3D . add ( "GlowingEdgeMaterial" ) ; var subShader = new SubShader ( attributeMap , uniformMap ) ; glowingEdgeShader . addSubShader ( subShader ) ; ( < ShaderPass > subShader . addShaderPass ( GlowingEdgeShaderVS , GlowingEdgeShaderFS ) ) ; } }