@animech-public/playcanvas
Version:
PlayCanvas WebGL game engine
2 lines (1 loc) • 4.2 kB
JavaScript
import{SEMANTIC_POSITION as t,SEMANTIC_BLENDWEIGHT as e,SEMANTIC_BLENDINDICES as n,SEMANTIC_COLOR as i,SEMANTIC_TEXCOORD0 as r}from"../../../platform/graphics/constants.js";import{ShaderUtils as s}from"../../../platform/graphics/shader-utils.js";import{shaderChunks as o}from"../chunks/chunks.js";import{ShaderPass as f}from"../../shader-pass.js";import{ShaderGenerator as a}from"./shader-generator.js";const d=new class extends a{generateKey(t){let e="basic";return t.fog&&(e+="_fog"),t.alphaTest&&(e+="_atst"),t.vertexColors&&(e+="_vcol"),t.diffuseMap&&(e+="_diff"),t.skin&&(e+="_skin"),t.screenSpace&&(e+="_ss"),t.useInstancing&&(e+="_inst"),t.useMorphPosition&&(e+="_morphp"),t.useMorphNormal&&(e+="_morphn"),t.useMorphTextureBased&&(e+="_morpht"),e+=`_${t.pass}`,e}createAttributesDefinition(s,o){const f={vertex_position:t};o.skin&&(f.vertex_boneWeights=e,f.vertex_boneIndices=n),o.vertexColors&&(f.vertex_color=i),o.diffuseMap&&(f.vertex_texCoord0=r),s.attributes=f}createVertexDefinition(t,e,n,i){const r=new Map,s=new Map;r.set("shaderPassDefines",i.shaderDefines),r.set("transformDeclVS",o.transformDeclVS),r.set("transformVS",o.transformVS),r.set("skinCode",a.skinCode(t)),n.skin&&s.set("SKIN",!0),n.vertexColors&&s.set("VERTEX_COLORS",!0),n.diffuseMap&&s.set("DIFFUSE_MAP",!0),e.vertexCode='\n\n\t\t#include "shaderPassDefines"\n\t\t#include "transformDeclVS"\n\n\t\t#ifdef SKIN\n\t\t\t\t#include "skinCode"\n\t\t#endif\n\n\t\t#include "transformVS"\n\n\t\t#ifdef VERTEX_COLORS\n\t\t\t\tattribute vec4 vertex_color;\n\t\t\t\tvarying vec4 vColor;\n\t\t#endif\n\n\t\t#ifdef DIFFUSE_MAP\n\t\t\t\tattribute vec2 vertex_texCoord0;\n\t\t\t\tvarying vec2 vUv0;\n\t\t#endif\n\n\t\t#ifdef DEPTH_PASS\n\t\t\t\tvarying float vDepth;\n\t\t\t\t\n\t\t\t\t#ifndef VIEWMATRIX\n\t\t\t\t#define VIEWMATRIX\n\t\t\t\t\t\tuniform mat4 matrix_view;\n\t\t\t\t#endif\n\n\t\t\t\t#ifndef CAMERAPLANES\n\t\t\t\t#define CAMERAPLANES\n\t\t\t\t\t\tuniform vec4 camera_params;\n\t\t\t\t#endif\n\t\t#endif\n\n\t\tvoid main(void) {\n\t\t\t\tgl_Position = getPosition();\n\n\t\t\t\t#ifdef DEPTH_PASS\n\t\t\t\t\t\tvDepth = -(matrix_view * vec4(getWorldPosition(),1.0)).z * camera_params.x;\n\t\t\t\t#endif \n\n\t\t\t\t#ifdef VERTEX_COLORS\n\t\t\t\t\t\tvColor = vertex_color;\n\t\t\t\t#endif\n\n\t\t\t\t#ifdef DIFFUSE_MAP\n\t\t\t\t\t\tvUv0 = vertex_texCoord0;\n\t\t\t\t#endif\n\t\t}\n',e.vertexIncludes=r,e.vertexDefines=s}createFragmentDefinition(t,e,n){const i=new Map,r=new Map;i.set("shaderPassDefines",n.shaderDefines),i.set("fogCode",a.fogCode(e.fog)),i.set("alphaTestPS",o.alphaTestPS),i.set("packDepthPS",o.packDepthPS),e.vertexColors&&r.set("VERTEX_COLORS",!0),e.diffuseMap&&r.set("DIFFUSE_MAP",!0),e.fog&&r.set("FOG",!0),e.alphaTest&&r.set("ALPHA_TEST",!0),t.fragmentCode='\n\n\t\t#include "shaderPassDefines"\n\n\t\t#ifdef VERTEX_COLORS\n\t\t\t\tvarying vec4 vColor;\n\t\t#else\n\t\t\t\tuniform vec4 uColor;\n\t\t#endif\n\n\t\t#ifdef DIFFUSE_MAP\n\t\t\t\tvarying vec2 vUv0;\n\t\t\t\tuniform sampler2D texture_diffuseMap;\n\t\t#endif\n\n\t\t#ifdef FOG\n\t\t\t\t#include "fogCode"\n\t\t#endif\n\n\t\t#ifdef ALPHA_TEST\n\t\t\t\t#include "alphaTestPS"\n\t\t#endif\n\n\t\t#ifdef DEPTH_PASS\n\t\t\t\tvarying float vDepth;\n\t\t\t\t#include "packDepthPS"\n\t\t#endif\n\n\t\tvoid main(void) {\n\n\t\t\t\t#ifdef VERTEX_COLORS\n\t\t\t\t\t\tgl_FragColor = vColor;\n\t\t\t\t#else\n\t\t\t\t\t\tgl_FragColor = uColor;\n\t\t\t\t#endif\n\n\t\t\t\t#ifdef DIFFUSE_MAP\n\t\t\t\t\t\tgl_FragColor *= texture2D(texture_diffuseMap, vUv0);\n\t\t\t\t#endif\n\n\t\t\t\t#ifdef ALPHA_TEST\n\t\t\t\t\t\talphaTest(gl_FragColor.a);\n\t\t\t\t#endif\n\n\t\t\t\t#ifndef PICK_PASS\n\n\t\t\t\t\t\t#ifdef DEPTH_PASS\n\t\t\t\t\t\t\t\tgl_FragColor = packFloat(vDepth);\n\t\t\t\t\t\t#else\n\t\t\t\t\t\t\t\t#ifdef FOG\n\t\t\t\t\t\t\t\t\t\tglFragColor.rgb = addFog(gl_FragColor.rgb);\n\t\t\t\t\t\t\t\t#endif\n\t\t\t\t\t\t#endif\n\t\t\t\t#endif\n\t\t}\n',t.fragmentIncludes=i,t.fragmentDefines=r}createShaderDefinition(t,e){const n={name:"BasicShader"},i=f.get(t).getByIndex(e.pass);return this.createAttributesDefinition(n,e),this.createVertexDefinition(t,n,e,i),this.createFragmentDefinition(n,e,i),s.createDefinition(t,n)}};export{d as basic};