feat(polygon-layer): 支持多个平行光源配置

This commit is contained in:
yuqi.pyq 2019-06-21 16:50:51 +08:00
parent f8269ee35b
commit 32cdcf83f3
5 changed files with 35 additions and 51 deletions

View File

@ -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();

View File

@ -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;

View File

@ -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;

View File

@ -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];

View File

@ -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