From 63e70a36796667c90987e8f522a125f32e5071d0 Mon Sep 17 00:00:00 2001 From: xiaoiver Date: Fri, 21 Jun 2019 16:50:51 +0800 Subject: [PATCH] =?UTF-8?q?feat(polygon-layer):=20=E6=94=AF=E6=8C=81?= =?UTF-8?q?=E5=A4=9A=E4=B8=AA=E5=B9=B3=E8=A1=8C=E5=85=89=E6=BA=90=E9=85=8D?= =?UTF-8?q?=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- demos/07_city.html | 36 +++++++++++----------- src/geom/material/polygonMaterial.js | 30 ++++-------------- src/geom/shader/polygon_frag.glsl | 14 ++++----- src/geom/shader/polygon_vert.glsl | 2 +- src/geom/shader/shaderChunks/lighting.glsl | 4 ++- 5 files changed, 35 insertions(+), 51 deletions(-) diff --git a/demos/07_city.html b/demos/07_city.html index 51efa39bf3..0b5acd860f 100644 --- a/demos/07_city.html +++ b/demos/07_city.html @@ -69,24 +69,24 @@ scene.on('loaded', () => { .source(data) .shape('extrude') .active({fill:'red'}) - // .style({ - // lights: [ - // { - // type: 'directional', - // direction: [ 1, -10.5, 12 ], - // ambient: [ 0.2, 0.2, 0.2 ], - // diffuse: 'red', - // specular: [ 0.1, 0.1, 0.1 ] - // }, - // { - // type: 'directional', - // direction: [ 1, 10.5, 12 ], - // ambient: [ 0.2, 0.2, 0.2 ], - // diffuse: 'green', - // specular: [ 0.1, 0.1, 0.1 ] - // }, - // ] - // }) + .style({ + lights: [ + { + type: 'directional', + direction: [ 1, 10.5, 12 ], + ambient: [ 0.2, 0.2, 0.2 ], + diffuse: 'red', + specular: [ 0.1, 0.1, 0.1 ] + }, + { + type: 'directional', + direction: [ 1, -10.5, 12 ], + ambient: [ 0.2, 0.2, 0.2 ], + diffuse: 'green', + specular: [ 0.1, 0.1, 0.1 ] + }, + ] + }) .size('floor',[10,2000]) .color('rgba(242,246,250,0.96)') .render(); diff --git a/src/geom/material/polygonMaterial.js b/src/geom/material/polygonMaterial.js index 5de4c72acc..d77069e5fa 100644 --- a/src/geom/material/polygonMaterial.js +++ b/src/geom/material/polygonMaterial.js @@ -1,33 +1,15 @@ import Material from './material'; -import { getModule } from '../../util/shaderModule'; -export default class PolygonMaterial extends Material { - getDefaultParameters() { - return { - uniforms: { - u_opacity: { value: 1.0 }, - u_time: { value: 0 }, - u_zoom: { value: 0 }, - u_baseColor: { value: [ 1.0, 0, 0, 1.0 ] }, - u_brightColor: { value: [ 1.0, 0, 0, 1.0 ] }, - u_windowColor: { value: [ 1.0, 0, 0, 1.0 ] }, - u_near: { value: 0.0 }, - u_far: { value: 1.0 }, - u_activeId: { value: 0 }, - u_activeColor: { value: [ 1.0, 0, 0, 1.0 ] } - }, - defines: { +import { getModule, wrapUniforms } from '../../util/shaderModule'; +import merge from '@antv/util/lib/deep-mix'; - } - }; - } +export default class PolygonMaterial extends Material { constructor(_uniforms, _defines, parameters) { super(parameters); - const { uniforms, defines } = this.getDefaultParameters(); - this.uniforms = Object.assign(uniforms, this.setUniform(_uniforms)); + const { vs, fs, uniforms } = getModule('polygon'); + this.uniforms = wrapUniforms(merge(uniforms, _uniforms)); this.type = 'PolygonMaterial'; - this.defines = Object.assign(defines, _defines); + this.defines = _defines; - const { vs, fs } = getModule('polygon'); this.vertexShader = vs; this.fragmentShader = fs; this.transparent = true; diff --git a/src/geom/shader/polygon_frag.glsl b/src/geom/shader/polygon_frag.glsl index 331e8cef59..0bc49f7142 100644 --- a/src/geom/shader/polygon_frag.glsl +++ b/src/geom/shader/polygon_frag.glsl @@ -1,12 +1,12 @@ precision highp float; -uniform vec4 u_baseColor; -uniform vec4 u_brightColor; -uniform vec4 u_windowColor; -uniform float u_zoom; -uniform float u_time; -uniform float u_near; -uniform float u_far; +uniform vec4 u_baseColor : [ 1.0, 0, 0, 1.0 ]; +uniform vec4 u_brightColor : [ 1.0, 0, 0, 1.0 ]; +uniform vec4 u_windowColor : [ 1.0, 0, 0, 1.0 ]; +uniform float u_zoom : 0; +uniform float u_time : 0; +uniform float u_near : 0; +uniform float u_far : 1; #ifdef ANIMATE varying vec2 v_texCoord; diff --git a/src/geom/shader/polygon_vert.glsl b/src/geom/shader/polygon_vert.glsl index 47b6634176..ad811a1c7b 100644 --- a/src/geom/shader/polygon_vert.glsl +++ b/src/geom/shader/polygon_vert.glsl @@ -14,7 +14,7 @@ varying vec2 v_texCoord; varying vec4 v_color; -uniform float u_zoom; +uniform float u_zoom : 0; uniform float u_opacity : 1.0; uniform float u_activeId : 0; uniform vec4 u_activeColor : [1.0, 0.0, 0.0, 1.0]; diff --git a/src/geom/shader/shaderChunks/lighting.glsl b/src/geom/shader/shaderChunks/lighting.glsl index aa3eefba13..330e8b5525 100644 --- a/src/geom/shader/shaderChunks/lighting.glsl +++ b/src/geom/shader/shaderChunks/lighting.glsl @@ -12,6 +12,8 @@ uniform int u_num_of_spot_lights : 0; #define MAX_NUM_OF_DIRECTIONAL_LIGHTS 3 #define MAX_NUM_OF_SPOT_LIGHTS 3 +#pragma include "common" + struct DirectionalLight { vec3 direction; vec3 ambient; @@ -37,7 +39,7 @@ uniform DirectionalLight u_directional_lights[MAX_NUM_OF_DIRECTIONAL_LIGHTS]; uniform SpotLight u_spot_lights[MAX_NUM_OF_SPOT_LIGHTS]; vec3 calc_directional_light(DirectionalLight light, vec3 normal, vec3 viewDir) { - vec3 lightDir = normalize(-light.direction); + vec3 lightDir = normalize(light.direction); // diffuse shading float diff = max(dot(normal, lightDir), 0.0); // Blinn-Phong specular shading