Skip to content

Commit efd0bdd

Browse files
committed
rename vHeight to vExcavateHeight and improve params of getWorldHeight/getCoordinateTexcoord
1 parent d8ea99b commit efd0bdd

File tree

10 files changed

+33
-49
lines changed

10 files changed

+33
-49
lines changed

packages/reshader.gl/src/pbr/glsl/standard.vert

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -279,8 +279,8 @@ void main() {
279279
#endif
280280

281281
#ifdef HAS_EXCAVATE_ANALYSIS
282-
vCoordinateTexcoord = getCoordinateTexcoord();
283-
vHeight = getWorldHeight();
282+
vCoordinateTexcoord = getCoordinateTexcoord(position);
283+
vExcavateHeight = getWorldHeight(position);
284284
#endif
285285
//#ifdef PICKING_MODE的endif
286286
#endif

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

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -185,10 +185,6 @@ struct VertexOutput {
185185
@location($i) vTangentFragPos: vec3f,
186186
#endif
187187

188-
#ifdef HAS_EXCAVATE_ANALYSIS
189-
@location($i) vCoordinateTexcoord: vec2f,
190-
@location($i) vHeight: f32,
191-
#endif
192188
};
193189

194190
fn getMaterialAlbedo() -> vec3f {

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

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -98,11 +98,6 @@ struct VertexOutput {
9898
@location($o) vTangentViewPos: vec3f,
9999
@location($o) vTangentFragPos: vec3f,
100100
#endif
101-
102-
#ifdef HAS_EXCAVATE_ANALYSIS
103-
@location($o) vCoordinateTexcoord: vec2f,
104-
@location($o) vHeight: f32,
105-
#endif
106101
};
107102

108103
struct ShaderUniforms {
@@ -195,7 +190,7 @@ fn transposeMat3(inMat: mat3x3f) -> mat3x3f {
195190
fn main(input: VertexInput) -> VertexOutput {
196191
var output: VertexOutput;
197192

198-
let localPositionMatrix = getPositionMatrix(output, uniforms.positionMatrix);
193+
let localPositionMatrix = getPositionMatrix(input, output, uniforms.positionMatrix);
199194

200195
#ifdef IS_LINE_EXTRUSION
201196
let linePosition = getLineExtrudePosition(vec3f(input.aPosition.xyz), input);
@@ -309,8 +304,8 @@ fn main(input: VertexInput) -> VertexOutput {
309304
#endif
310305

311306
#ifdef HAS_EXCAVATE_ANALYSIS
312-
output.vCoordinateTexcoord = getCoordinateTexcoord();
313-
output.vHeight = getWorldHeight();
307+
output.vCoordinateTexcoord = getCoordinateTexcoord(position, uniforms.modelMatrix);
308+
output.vExcavateHeight = getWorldHeight(position, uniforms.modelMatrix);
314309
#endif
315310
#endif
316311

packages/reshader.gl/src/shader/wgsl/phong_vert.wgsl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ fn main(vertexInput: VertexInput) -> VertexOutput {
121121
#else
122122
let localPosition = getPosition(vec3f(vertexInput.aPosition.xyz), vertexInput);
123123
#endif
124-
let localPositionMatrix = getPositionMatrix(vertexOutput, modelUniforms.positionMatrix);
124+
let localPositionMatrix = getPositionMatrix(vertexInput, vertexOutput, modelUniforms.positionMatrix);
125125

126126
vertexOutput.vFragPos = (modelUniforms.modelMatrix * localPositionMatrix * localPosition).xyz;
127127

packages/reshader.gl/src/shaderlib/glsl/excavate.frag

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
uniform sampler2D heightmap;
33
uniform float excavateHeight;
44
varying vec2 vCoordinateTexcoord;
5-
varying float vHeight;
5+
varying float vExcavateHeight;
66
const vec2 range = vec2(-100.0, 1000.0);
77
float decodeHeight(const in vec4 pack) {
88
return pack.r + pack.g / 255.0;
@@ -14,7 +14,7 @@
1414
if(realHeight < range.x || realHeight > range.y) {
1515
realHeight = 0.0;
1616
}
17-
if(vHeight > realHeight) {
17+
if(vExcavateHeight > realHeight) {
1818
discard;
1919
}
2020
return fragColor;

packages/reshader.gl/src/shaderlib/glsl/excavate.vert

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
11
#ifdef HAS_EXCAVATE_ANALYSIS
22
uniform vec4 excavateExtent;
33
varying vec2 vCoordinateTexcoord;
4-
varying float vHeight;
4+
varying float vExcavateHeight;
55

6-
float getWorldHeight() {
7-
vec4 wPosition = modelMatrix * getPosition(aPosition);
6+
float getWorldHeight(vec4 localPosition) {
7+
vec4 wPosition = modelMatrix * localPosition;
88
return wPosition.z;
99
}
1010

11-
vec2 getCoordinateTexcoord() {
12-
mat4 localPositionMatrix = getPositionMatrix();
13-
vec4 wPosition = modelMatrix * localPositionMatrix * getPosition(aPosition);
11+
vec2 getCoordinateTexcoord(vec4 localPosition) {
12+
vec4 wPosition = modelMatrix * localPosition;
1413
float x = (wPosition.x - excavateExtent.x) / (excavateExtent.z - excavateExtent.x);
1514
float y = (wPosition.y - excavateExtent.y) / (excavateExtent.w - excavateExtent.y);
1615
return vec2(x, y);

packages/reshader.gl/src/shaderlib/glsl/output.vert

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,13 @@
3838
attribute float aTerrainAltitude;
3939
#endif
4040

41-
mat4 getPositionMatrix() {
41+
mat4 getPositionMatrix(input: VertexInput) {
4242
mat4 worldMatrix;
4343
#ifdef HAS_INSTANCE
4444
#ifdef HAS_INSTANCE_COLOR
4545
vInstanceColor = instance_getInstanceColor();
4646
#endif
47-
mat4 attributeMatrix = instance_getAttributeMatrix();
47+
mat4 attributeMatrix = instance_getAttributeMatrix(input);
4848
#ifdef HAS_SKIN
4949
if (skinAnimation == 1) {
5050
worldMatrix = attributeMatrix * positionMatrix * skin_getSkinMatrix();

packages/reshader.gl/src/shaderlib/wgsl/excavate.ts

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,24 +6,13 @@ struct ExcavateUniforms {
66
77
@group(0) @binding($b) var<uniform> excavateUniforms: ExcavateUniforms;
88
9-
struct VertexAttributes {
10-
@location(0) aPosition: vec3f
11-
};
12-
13-
struct VertexOutput {
14-
@builtin(position) position: vec4f,
15-
vCoordinateTexcoord: vec2f,
16-
vHeight: f32
17-
};
18-
19-
fn getWorldHeight(vertex: VertexInput) -> f32 {
20-
let wPosition = uniforms.modelMatrix * getPosition(vertex.aPosition);
9+
fn getWorldHeight(localPosition: vec4f, modelMatrix: mat4x4f) -> f32 {
10+
let wPosition = uniforms.modelMatrix * localPosition;
2111
return wPosition.z;
2212
}
2313
24-
fn getCoordinateTexcoord(vertex: VertexInput) -> vec2f {
25-
let localPositionMatrix = getPositionMatrix();
26-
let wPosition = uniforms.modelMatrix * localPositionMatrix * getPosition(vertex.aPosition);
14+
fn getCoordinateTexcoord(localPosition: vec4f, modelMatrix: mat4x4f) -> vec2f {
15+
let wPosition = modelMatrix * localPositionMatrix;
2716
let x = (wPosition.x - excavateUniforms.excavateExtent.x) /
2817
(excavateUniforms.excavateExtent.z - excavateUniforms.excavateExtent.x);
2918
let y = (wPosition.y - excavateUniforms.excavateExtent.y) /
@@ -60,7 +49,7 @@ fn excavateColor(fragColor: vec4f, vertexOutput: VertexOutput) -> vec4f {
6049
realHeight >= excavateUniforms.heightRange.x && realHeight <= excavateUniforms.heightRange.y
6150
);
6251
63-
if (vertexOutput.vHeight > validHeight) {
52+
if (vertexOutput.vExcavateHeight > validHeight) {
6453
discard;
6554
}
6655
return fragColor;
@@ -78,7 +67,7 @@ export default {
7867
type: 'vec2f'
7968
},
8069
{
81-
name: 'vHeight',
70+
name: 'vExcavateHeight',
8271
type: 'f32'
8372
}
8473
]

packages/reshader.gl/src/shaderlib/wgsl/instance.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,17 @@ const vert = /* wgsl */`
22
@group(0) @binding($b) var<uniform> terrainAltitudeScale: f32;
33
44
// 获取实例属性矩阵函数
5-
fn instance_getAttributeMatrix(instance_vectorA: vec4f, instance_vectorB: vec4f, instance_vectorC: vec4f) -> mat4x4f {
5+
fn instance_getAttributeMatrix(
6+
input: VertexInput
7+
) -> mat4x4f {
8+
let vectorA = input.instance_vectorA;
9+
let vectorB = input.instance_vectorB;
10+
let vectorC = input.instance_vectorC;
611
var mat = mat4x4f(
7-
instance_vectorA.x, instance_vectorB.x, instance_vectorC.x, 0.0,
8-
instance_vectorA.y, instance_vectorB.y, instance_vectorC.y, 0.0,
9-
instance_vectorA.z, instance_vectorB.z, instance_vectorC.z, 0.0,
10-
instance_vectorA.w, instance_vectorB.w, instance_vectorC.w, 1.0
12+
vectorA.x, vectorB.x, vectorC.x, 0.0,
13+
vectorA.y, vectorB.y, vectorC.y, 0.0,
14+
vectorA.z, vectorB.z, vectorC.z, 0.0,
15+
vectorA.w, vectorB.w, vectorC.w, 1.0
1116
);
1217
1318
#ifdef HAS_INSTANCE_TERRAIN_ALTITUDE

packages/reshader.gl/src/shaderlib/wgsl/output.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,10 @@ const vert = /* wgsl */`
3131
@group(0) @binding($b) var<uniform> altitudeUniforms: AltitudeUniforms;
3232
#endif
3333
34-
fn getPositionMatrix(vertexOutput: VertexOutput, positionMatrix: mat4x4f) -> mat4x4f {
34+
fn getPositionMatrix(input: VertexInput, vertexOutput: VertexOutput, positionMatrix: mat4x4f) -> mat4x4f {
3535
var worldMatrix: mat4x4f;
3636
#ifdef HAS_INSTANCE
37-
let attributeMatrix = instance_getAttributeMatrix();
37+
let attributeMatrix = instance_getAttributeMatrix(input);
3838
#ifdef HAS_INSTANCE_COLOR
3939
vertexOutput.vInstanceColor = instance_getInstanceColor();
4040
#endif

0 commit comments

Comments
 (0)