Skip to content

Commit d8ea99b

Browse files
committed
implement basic rendering of standard on webgpu
1 parent 718f983 commit d8ea99b

File tree

4 files changed

+115
-19
lines changed

4 files changed

+115
-19
lines changed

debug/gl/vt-extrusion.html

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<meta charset='UTF-8' />
4+
<meta name='viewport' content='width=device-width, initial-scale=1' />
5+
<title>vt-fill</title>
6+
<style type='text/css'>
7+
html,
8+
body {
9+
width: 100%;
10+
height: 100%;
11+
margin: 0px;
12+
}
13+
14+
.container {
15+
width: 100%;
16+
height: 100%;
17+
}
18+
</style>
19+
<link rel="stylesheet" href="/maptalks/dist/maptalks.css">
20+
<script type="text/javascript" src="/maptalks/dist/maptalks.js"></script>
21+
<script type="text/javascript" src="/maptalks-work/packages/gl/dist/maptalksgl.js"></script>
22+
<script type="text/javascript" src="/maptalks-work/packages/vt/dist/maptalks.vt.js"></script>
23+
24+
<body>
25+
<canvas id="DEBUG" width="1" height="1"></canvas>
26+
<div id="map" class="container"></div>
27+
28+
<script>
29+
const map = new maptalks.Map("map", {
30+
center: [-73.98795379493208, 40.72100197835064],
31+
zoom: 19,
32+
bearing: -69,
33+
renderer: 'gpu'
34+
});
35+
36+
/**start**/
37+
const vt = new maptalks.VectorTileLayer("vt", {
38+
features: true,
39+
urlTemplate: "http://tile.maptalks.com/test/planet-single/{z}/{x}/{y}.mvt",
40+
});
41+
42+
const style = {
43+
style: [
44+
{
45+
filter: ["all", ["==", "$layer", "building"],
46+
["==", "$type", "Polygon"]
47+
],
48+
renderPlugin: {
49+
type: "lit",
50+
dataConfig: {
51+
type: "3d-extrusion",
52+
altitudeProperty: "height",
53+
minHeightProperty: "min_height",
54+
altitudeScale: 1,
55+
defaultAltitude: 10,
56+
topThickness: 0,
57+
top: true,
58+
side: true
59+
},
60+
sceneConfig: {}
61+
},
62+
symbol: {
63+
material: {
64+
baseColorFactor: [1, 1, 1, 1],
65+
roughnessFactor: 1,
66+
metallicFactor: 1
67+
}
68+
}
69+
}
70+
],
71+
};
72+
vt.setStyle(style);
73+
/**end**/
74+
75+
// const groupLayer = new maptalks.GroupGLLayer("group", [vt]);
76+
// groupLayer.addTo(map);
77+
vt.addTo(map);
78+
79+
map.on('click', e => {
80+
const hits = vt.identify(e.coordinate);
81+
if (hits.length) {
82+
console.log(hits[0].data.feature.properties);
83+
}
84+
});
85+
</script>
86+
</body>
87+
88+
</html>

packages/reshader.gl/src/pbr/wgsl/standard_frag.wgsl

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@ struct SceneUniforms {
3636
metallicFactor: f32,
3737
normalMapFactor: f32,
3838
specularF0: f32,
39-
emitMultiplicative: i32,
40-
normalMapFlipY: i32,
41-
outputSRGB: i32,
39+
emitMultiplicative: f32,
40+
normalMapFlipY: f32,
41+
outputSRGB: f32,
4242
contrast: f32,
4343

4444
hsv: vec3f,
@@ -414,9 +414,9 @@ fn initMaterial(vertexOutput: VertexOutput) -> MaterialUniforms {
414414
let patternWidth = ceil(uvSize.x * vertexOutput.vPatternHeight / uvSize.y);
415415
let plusGapWidth = patternWidth * (1.0 + myGap);
416416
let animSpeed = myAnimSpeed / uniforms.animSpeedScale;
417-
linesofar += mod(uniforms.currentTime * -animSpeed * 0.2, plusGapWidth);
418-
let patternx = mod(linesofar / plusGapWidth, 1.0);
419-
let patterny = mod(uniforms.flipY * vertexOutput.vNormalY, 1.0);
417+
linesofar += (uniforms.currentTime * -animSpeed * 0.2) % plusGapWidth;
418+
let patternx = (linesofar / plusGapWidth) % 1.0;
419+
let patterny = (uniforms.flipY * vertexOutput.vNormalY) % 1.0;
420420
uv = computeUV(vec2(patternx * (1.0 + myGap) * uniforms.uvScale[0], patterny * uniforms.uvScale[1]));
421421
let patternColor = textureSample(linePatternFile, linePatternFileSampler, uv);
422422
let inGap = clamp(sign(1.0 / (1.0 + myGap) - patternx) + 0.000001, 0.0, 1.0);
@@ -476,7 +476,7 @@ fn initMaterial(vertexOutput: VertexOutput) -> MaterialUniforms {
476476

477477
materialUniforms.emit = uniforms.emissiveFactor;
478478
#if HAS_EMISSIVE_MAP
479-
if (uniforms.emitMultiplicative == 1) {
479+
if (uniforms.emitMultiplicative == 1.0) {
480480
materialUniforms.emit *= sRGBToLinear(textureSample(emissiveTexture, emissiveTextureSampler, uv).rgb);
481481
} else {
482482
materialUniforms.emit += sRGBToLinear(textureSample(emissiveTexture, emissiveTextureSampler, uv).rgb);
@@ -494,15 +494,15 @@ fn initMaterial(vertexOutput: VertexOutput) -> MaterialUniforms {
494494

495495
#if HAS_NORMAL_MAP && HAS_TANGENT
496496
var nmap = textureSample(normalTexture, normalTextureSampler, uv).xyz * 2.0 - 1.0;
497-
nmap.y = uniforms.normalMapFlipY == 1 ? -nmap.y : nmap.y;
497+
nmap.y = select(nmap.y, -namp.y, uniforms.normalMapFlipY == 1.0);
498498
materialUniforms.normal = nmap;
499499
#else
500500
materialUniforms.normal = normalize(vertexOutput.vModelNormal);
501501
#endif
502502

503503
#if HAS_TERRAIN_NORMAL && HAS_TANGENT
504504
var nmap = convertTerrainHeightToNormalMap(uv);
505-
nmap.y = uniforms.normalMapFlipY == 1 ? -nmap.y : nmap.y;
505+
nmap.y = select(nmap.y, -namp.y, uniforms.normalMapFlipY == 1.0);
506506
materialUniforms.normal = nmap;
507507
#endif
508508

@@ -620,8 +620,8 @@ fn normalFiltering(roughness: f32, worldNormal: vec3f) -> f32 {
620620
let z = fetchDepth(sampleUV.xy);
621621
let depth = linearizeDepth(z);
622622
let sampleDepth = -1.0 / sampleUV.z;
623-
*startSteps = depth > sampleDepth ? *startSteps : steps;
624-
*endSteps = depth > sampleDepth ? steps : *endSteps;
623+
*startSteps = select(steps, *startSteps, depth > sampleDepth);
624+
*endSteps = select(*endSteps, steps, depth > sampleDepth);
625625
return steps;
626626
}
627627

@@ -654,7 +654,7 @@ fn normalFiltering(roughness: f32, worldNormal: vec3f) -> f32 {
654654
depthDiff *= clamp(sign(abs(depthDiff) - rayLen * invNumSteps * invNumSteps), 0.0, 1.0);
655655
hit = abs(depthDiff + depthTolerance) < depthTolerance;
656656
let timeLerp = clamp(diffSampleW.x / (diffSampleW.x - depthDiff), 0.0, 1.0);
657-
let hitTime = hit ? (diffSampleW.y + timeLerp * invNumSteps - invNumSteps) : 1.0;
657+
let hitTime = select(1.0, (diffSampleW.y + timeLerp * invNumSteps - invNumSteps), hit);
658658
diffSampleW.z = min(diffSampleW.z, hitTime);
659659
diffSampleW.x = depthDiff;
660660
if (hit) {
@@ -701,7 +701,7 @@ fn normalFiltering(roughness: f32, worldNormal: vec3f) -> f32 {
701701
var result = vec4f(0.0);
702702
var rough4 = roughness * roughness;
703703
rough4 = rough4 * rough4;
704-
let upVector = abs(normal.z) < 0.999 ? vec3f(0.0, 0.0, 1.0) : vec3f(1.0, 0.0, 0.0);
704+
let upVector = select(vec3f(1.0, 0.0, 0.0), vec3f(0.0, 0.0, 1.0), abs(normal.z) < 0.999);
705705
let tangentX = normalize(cross(upVector, normal));
706706
let tangentY = cross(normal, tangentX);
707707
var maskSsr = shaderUniforms.ssrFactor * clamp(-4.0 * dot(eyeVector, normal) + 3.8, 0.0, 1.0);
@@ -719,7 +719,7 @@ fn normalFiltering(roughness: f32, worldNormal: vec3f) -> f32 {
719719
result += fetchColorInRay(resRay, maskSsr, specularEnvironment, specularColor, roughness);
720720
}
721721
}
722-
return result.w > 0.0 ? result.rgb / result.w : specularEnvironment;
722+
return select(specularEnvironment, result.rgb / result.w, result.w > 0.0);
723723
}
724724
#endif
725725

@@ -829,7 +829,7 @@ fn main(vertexOutput: VertexOutput) -> @location(0) vec4f {
829829
diffuse += materialEmit;
830830

831831
var frag = specular + diffuse;
832-
if (uniforms.outputSRGB == 1) {
832+
if (uniforms.outputSRGB == 1.0) {
833833
frag = linearTosRGB(frag);
834834
}
835835

packages/reshader.gl/src/pbr/wgsl/standard_vert.wgsl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,15 +166,15 @@ fn transformTexcoord(uv: vec2f) -> vec2f {
166166
#ifdef HAS_RANDOM_TEX
167167
let origin = uniforms.uvOrigin;
168168
let texCoord = decodedTexCoord * uniforms.uvScale + uniforms.uvOffset;
169-
return mod(origin, 1.0) + texCoord;
169+
return (origin % 1.0) + texCoord;
170170
#else
171171
let origin = uniforms.uvOrigin;
172172
let texCoord = decodedTexCoord * uniforms.uvScale;
173173
if (uniforms.uvRotation != 0.0) {
174174
origin = rotateUV(origin, uniforms.uvRotation);
175175
texCoord = rotateUV(texCoord, uniforms.uvRotation);
176176
}
177-
return mod(origin, 1.0) + texCoord + uniforms.uvOffset;
177+
return (origin % 1.0) + texCoord + uniforms.uvOffset;
178178
#endif
179179
}
180180
#endif
Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
vec3 linearTosRGB(const in vec3 color) {
2-
return vec3( color.r < 0.0031308 ? color.r * 12.92 : 1.055 * pow(color.r, 1.0/2.4) - 0.055, color.g < 0.0031308 ? color.g * 12.92 : 1.055 * pow(color.g, 1.0/2.4) - 0.055, color.b < 0.0031308 ? color.b * 12.92 : 1.055 * pow(color.b, 1.0/2.4) - 0.055);
2+
return vec3(
3+
color.r < 0.0031308 ? color.r * 12.92 : 1.055 * pow(color.r, 1.0/2.4) - 0.055,
4+
color.g < 0.0031308 ? color.g * 12.92 : 1.055 * pow(color.g, 1.0/2.4) - 0.055,
5+
color.b < 0.0031308 ? color.b * 12.92 : 1.055 * pow(color.b, 1.0/2.4) - 0.055
6+
);
37
}
48
vec3 sRGBToLinear(const in vec3 color) {
5-
return vec3( color.r < 0.04045 ? color.r * (1.0 / 12.92) : pow((color.r + 0.055) * (1.0 / 1.055), 2.4), color.g < 0.04045 ? color.g * (1.0 / 12.92) : pow((color.g + 0.055) * (1.0 / 1.055), 2.4), color.b < 0.04045 ? color.b * (1.0 / 12.92) : pow((color.b + 0.055) * (1.0 / 1.055), 2.4));
9+
return vec3(
10+
color.r < 0.04045 ? color.r * (1.0 / 12.92) : pow((color.r + 0.055) * (1.0 / 1.055), 2.4),
11+
color.g < 0.04045 ? color.g * (1.0 / 12.92) : pow((color.g + 0.055) * (1.0 / 1.055), 2.4),
12+
color.b < 0.04045 ? color.b * (1.0 / 12.92) : pow((color.b + 0.055) * (1.0 / 1.055), 2.4)
13+
);
614
}

0 commit comments

Comments
 (0)