Skip to content

Commit

Permalink
add support of function-type polygonFill and topPolygonFill and botto…
Browse files Browse the repository at this point in the history
…mPolygonFill for phong, maptalks/issues#826
  • Loading branch information
fuzhenn committed Mar 4, 2025
1 parent bd39419 commit 693791d
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 4 deletions.
3 changes: 3 additions & 0 deletions packages/reshader.gl/src/PhongMaterial.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ class PhongMaterial extends Material {
defines['HAS_COLOR0'] = 1;
defines['COLOR0_SIZE'] = geometry.getColor0Size();
}
if (geometry.data['aVertexColorType']) {
defines['HAS_VERTEX_COLOR'] = 1;
}
if (geometry.data[geometry.desc.tangentAttribute]) {
defines['HAS_TANGENT'] = 1;
} else if (geometry.data[geometry.desc.normalAttribute]) {
Expand Down
15 changes: 12 additions & 3 deletions packages/reshader.gl/src/picking/FBORayPicking.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ const depthFrag = `

export default class FBORayPicking {

constructor(renderer, { vert, uniforms, defines, extraCommandProps }, fbo, map) {
constructor(renderer, { vert, uniforms, defines, extraCommandProps, enableStencil }, fbo, map) {
this._renderer = renderer;
this._fbo = fbo;
this._map = map;
Expand All @@ -140,7 +140,16 @@ export default class FBORayPicking {
this._defines = defines;
this._extraCommandProps = extend({}, extraCommandProps);
delete this._extraCommandProps.blend;
delete this._extraCommandProps.stencil;
if (enableStencil) {
this._extraCommandProps.stencil = {
enable: enableStencil,
mask: 0xff,
func: { cmp: '<', ref: 1, mask: 0xff },
op: { fail:'keep', zfail:'keep', zpass:'replace' }
};
} else {
delete this._extraCommandProps.stencil;
}
this._currentMeshes = [];
this._init();
}
Expand Down Expand Up @@ -550,7 +559,7 @@ export default class FBORayPicking {
this._renderer.regl.clear({
color: [1, 1, 1, 1],
depth: 1,
stencil: 0,
stencil: 255,
framebuffer
});
}
Expand Down
6 changes: 6 additions & 0 deletions packages/reshader.gl/src/shader/glsl/phong.frag
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ varying vec3 vFragPos;

#include <highlight_frag>
#include <mask_frag>
#include <vertex_color_frag>
vec3 transformNormal() {
#if defined(HAS_NORMAL_MAP)
vec3 n = normalize(vNormal);
Expand Down Expand Up @@ -213,6 +214,11 @@ void main() {
discard;
}
// glFragColor = vec4(shadowCoeff, shadowCoeff, shadowCoeff, 1.0);

#ifdef HAS_VERTEX_COLOR
glFragColor *= vertexColor_get();
#endif

#ifdef HAS_HEATMAP
glFragColor = heatmap_getColor(glFragColor);
#endif
Expand Down
7 changes: 6 additions & 1 deletion packages/reshader.gl/src/shader/glsl/phong.vert
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ attribute vec3 aPosition;
#endif
#if defined(HAS_COLOR)
attribute vec4 aColor;

varying vec4 vColor;
#elif defined(HAS_COLOR0)
#if COLOR0_SIZE == 3
attribute vec3 aColor0;
Expand Down Expand Up @@ -78,6 +78,7 @@ void toTangentFrame(const highp vec4 q, out highp vec3 n, out highp vec3 t) {
vec3(-2.0, 2.0, 2.0) * q.z * q.zwx;
}

#include <vertex_color_vert>

void main()
{
Expand Down Expand Up @@ -145,4 +146,8 @@ void main()
#endif

highlight_setVarying();

#ifdef HAS_VERTEX_COLOR
vertexColor_update();
#endif
}
1 change: 1 addition & 0 deletions packages/reshader.gl/src/shaderlib/glsl/vertex_color.vert
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ void vertexColor_update() {
vertexColor_color = vertexColorsOfType[int(aVertexColorType)];
}
#endif
//用于识别顶点颜色类型: topPolygonFill 还是 bottomPolygonFill

0 comments on commit 693791d

Please sign in to comment.