diff --git a/and_proj/app/src/main/assets/shaders/texture_loading/glsl/bg.vert b/and_proj/app/src/main/assets/shaders/texture_loading/glsl/bg.vert index 0769410..5ff8f1b 100644 --- a/and_proj/app/src/main/assets/shaders/texture_loading/glsl/bg.vert +++ b/and_proj/app/src/main/assets/shaders/texture_loading/glsl/bg.vert @@ -25,20 +25,6 @@ const vec2 positions[6] = vec2[6]( ); -//const float offset = (640-480)/(640.0*2); // 假设宽高比为4:3 -// const float offset = 0; - -// const vec2 positions[6] = vec2[6]( -// vec2( -1.0 - offset, 1.0), // 右上 -> 左上 -// vec2(-1.0 - offset, -1.0), // 左上 - 左下 -// vec2(1.0 + offset, -1.0), // 左下 - 右下 - -// vec2(1.0 + offset, -1.0), // 左下 - 右下 -// vec2( 1.0 + offset, 1.0), // 右下 - 右上 -// vec2( -1.0 - offset, 1.0) // 右上 - 左上 -// ); - - const vec2 texCoords[6] = vec2[6]( vec2(1.0, 1.0), // 右上 @@ -50,12 +36,19 @@ const vec2 texCoords[6] = vec2[6]( vec2(1.0, 1.0) // 右上 ); +// 定义 Push Constant,只有一个 float +layout(push_constant) uniform PushConstants { + float myValue; +} pushConstants; + + // 输出变量 layout(location = 0) out vec2 outTexCoord; void main() { // 获取顶点位置 vec2 position = positions[gl_VertexIndex]; + position = position * pushConstants.myValue; // 设置输出位置(Vulkan使用不同的坐标系) gl_Position = vec4(position, 0.0, 1.0); diff --git a/and_proj/app/src/main/assets/shaders/texture_loading/glsl/bg.vert.spv b/and_proj/app/src/main/assets/shaders/texture_loading/glsl/bg.vert.spv index 1d843ff..9569f0b 100644 Binary files a/and_proj/app/src/main/assets/shaders/texture_loading/glsl/bg.vert.spv and b/and_proj/app/src/main/assets/shaders/texture_loading/glsl/bg.vert.spv differ diff --git a/and_proj/app/src/main/assets/shaders/texture_loading/glsl/point_line.frag b/and_proj/app/src/main/assets/shaders/texture_loading/glsl/point_line.frag index 1c8908e..63eec64 100644 --- a/and_proj/app/src/main/assets/shaders/texture_loading/glsl/point_line.frag +++ b/and_proj/app/src/main/assets/shaders/texture_loading/glsl/point_line.frag @@ -6,6 +6,20 @@ layout(location = 2) in vec3 fragLineEnd; layout(location = 0) out vec4 outColor; +layout(binding = 0) uniform UniformBufferObject { + mat4 proj; + mat4 model; + mat4 view; +} ubo; + +layout(binding = 1) uniform DashParameters { + float dashSize; + float gapSize; + float dashOffset; + float uAASize; + int useWorldSpace; +} dashParams; + void main() { vec2 fragPos = gl_FragCoord.xy; diff --git a/and_proj/app/src/main/assets/shaders/texture_loading/glsl/point_line.frag.spv b/and_proj/app/src/main/assets/shaders/texture_loading/glsl/point_line.frag.spv index 982d99e..9893ce9 100644 Binary files a/and_proj/app/src/main/assets/shaders/texture_loading/glsl/point_line.frag.spv and b/and_proj/app/src/main/assets/shaders/texture_loading/glsl/point_line.frag.spv differ diff --git a/and_proj/app/src/main/assets/shaders/texture_loading/glsl/point_line.vert b/and_proj/app/src/main/assets/shaders/texture_loading/glsl/point_line.vert index cc00794..9837258 100644 --- a/and_proj/app/src/main/assets/shaders/texture_loading/glsl/point_line.vert +++ b/and_proj/app/src/main/assets/shaders/texture_loading/glsl/point_line.vert @@ -16,9 +16,18 @@ layout(binding = 0) uniform UniformBufferObject { mat4 view; } ubo; +layout(push_constant) uniform PushConstants { + float myValue; +} pushConstants; + void main() { mat4 worldviewproj = ubo.proj * ubo.view * ubo.model; - gl_Position = worldviewproj * vec4(inPosition, 1.0); + //gl_Position = worldviewproj * vec4(inPosition, 1.0); + + vec2 position = vec2(inPosition.xy*2 -1); + //gl_Position = vec4(inPosition.xy*2 -1, 0.5, 1.0); + position = position * pushConstants.myValue; + gl_Position = vec4(position, 0.5, 1.0); fragColor = inColor; diff --git a/and_proj/app/src/main/assets/shaders/texture_loading/glsl/point_line.vert.spv b/and_proj/app/src/main/assets/shaders/texture_loading/glsl/point_line.vert.spv index eb72c72..a54c81c 100644 Binary files a/and_proj/app/src/main/assets/shaders/texture_loading/glsl/point_line.vert.spv and b/and_proj/app/src/main/assets/shaders/texture_loading/glsl/point_line.vert.spv differ diff --git a/and_proj/app/src/main/assets/shaders/texture_loading/glsl/pointcloud.vert b/and_proj/app/src/main/assets/shaders/texture_loading/glsl/pointcloud.vert index 97ea1cf..fa11d28 100644 --- a/and_proj/app/src/main/assets/shaders/texture_loading/glsl/pointcloud.vert +++ b/and_proj/app/src/main/assets/shaders/texture_loading/glsl/pointcloud.vert @@ -11,11 +11,21 @@ layout(binding = 0) uniform UniformBufferObject { mat4 view; } ubo; +layout(push_constant) uniform PushConstants { + float myValue; +} pushConstants; + void main() { // 预计算MVP矩阵以减少乘法次数 - mat4 mvp = ubo.proj * ubo.view * ubo.model; + //mat4 mvp = ubo.proj * ubo.view * ubo.model; //vec3 pos = vec3(2.0, inPosition.y, inPosition.z); - gl_Position = mvp * vec4(inPosition, 1.0); + //gl_Position = mvp * vec4(inPosition, 1.0); + + vec2 position = vec2(inPosition.xy*2 -1); + //gl_Position = vec4(inPosition.xy*2 -1, 0.5, 1.0); + position = position * pushConstants.myValue; + gl_Position = vec4(position, 0.5, 1.0); + fragColor = inColor; gl_PointSize = 2.0; } \ No newline at end of file diff --git a/and_proj/app/src/main/assets/shaders/texture_loading/glsl/pointcloud.vert.spv b/and_proj/app/src/main/assets/shaders/texture_loading/glsl/pointcloud.vert.spv index 239970f..3c9232a 100644 Binary files a/and_proj/app/src/main/assets/shaders/texture_loading/glsl/pointcloud.vert.spv and b/and_proj/app/src/main/assets/shaders/texture_loading/glsl/pointcloud.vert.spv differ diff --git a/and_proj/app/src/main/assets/shaders/texture_loading/glsl/texture.frag b/and_proj/app/src/main/assets/shaders/texture_loading/glsl/texture.frag index ccdb2fd..6943e81 100644 --- a/and_proj/app/src/main/assets/shaders/texture_loading/glsl/texture.frag +++ b/and_proj/app/src/main/assets/shaders/texture_loading/glsl/texture.frag @@ -1,41 +1,26 @@ #version 450 -/* Copyright (c) 2019-2024, Sascha Willems - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed under the Apache License, Version 2.0 the "License"; - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ layout (binding = 1) uniform sampler2D samplerColor; layout (location = 0) in vec2 inUV; -layout (location = 1) in float inLodBias; -layout (location = 2) in vec3 inNormal; -layout (location = 3) in vec3 inViewVec; -layout (location = 4) in vec3 inLightVec; +layout (location = 1) in vec3 inNormal; + layout (location = 0) out vec4 outFragColor; void main() { - vec4 color = texture(samplerColor, inUV, inLodBias); + vec4 color = texture(samplerColor, inUV); vec3 N = normalize(inNormal); - vec3 L = normalize(inLightVec); - vec3 V = normalize(inViewVec); - vec3 R = reflect(-L, N); - vec3 diffuse = max(dot(N, L), 0.0) * vec3(1.0); - float specular = pow(max(dot(R, V), 0.0), 16.0) * color.a; - outFragColor = vec4(diffuse * color.rgb + specular, 1.0); + vec4 textureColor = color; + if (textureColor.a < 0.1) { + //textureColor = vec4(0.2, 0.2, 0.2, 0.5); + discard; + } + + outFragColor = textureColor; + +// outFragColor = vec4(1, 0, 0, 1); } \ No newline at end of file diff --git a/and_proj/app/src/main/assets/shaders/texture_loading/glsl/texture.frag.spv b/and_proj/app/src/main/assets/shaders/texture_loading/glsl/texture.frag.spv index e0bc54e..dfcd420 100644 Binary files a/and_proj/app/src/main/assets/shaders/texture_loading/glsl/texture.frag.spv and b/and_proj/app/src/main/assets/shaders/texture_loading/glsl/texture.frag.spv differ diff --git a/and_proj/app/src/main/assets/shaders/texture_loading/glsl/texture.vert b/and_proj/app/src/main/assets/shaders/texture_loading/glsl/texture.vert index a836f8d..183bc7b 100644 --- a/and_proj/app/src/main/assets/shaders/texture_loading/glsl/texture.vert +++ b/and_proj/app/src/main/assets/shaders/texture_loading/glsl/texture.vert @@ -1,20 +1,5 @@ #version 450 -/* Copyright (c) 2019-2024, Sascha Willems - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed under the Apache License, Version 2.0 the "License"; - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ + layout (location = 0) in vec3 inPos; layout (location = 1) in vec2 inUV; @@ -29,10 +14,11 @@ layout (binding = 0) uniform UBO } ubo; layout (location = 0) out vec2 outUV; -layout (location = 1) out float outLodBias; -layout (location = 2) out vec3 outNormal; -layout (location = 3) out vec3 outViewVec; -layout (location = 4) out vec3 outLightVec; +layout (location = 1) out vec3 outNormal; + +layout(push_constant) uniform PushConstants { + float myValue; +} pushConstants; out gl_PerVertex { @@ -42,16 +28,12 @@ out gl_PerVertex void main() { outUV = inUV; - outLodBias = ubo.lodBias; - vec3 worldPos = vec3(ubo.model * vec4(inPos, 1.0)); - - gl_Position = ubo.projection * ubo.model * vec4(inPos.xyz, 1.0); + vec2 position = vec2(inPos.xy*2 -1); + position = position * pushConstants.myValue; + gl_Position = vec4(position, 0.5, 1.0); vec4 pos = ubo.model * vec4(inPos, 1.0); outNormal = mat3(inverse(transpose(ubo.model))) * inNormal; - vec3 lightPos = vec3(0.0); - vec3 lPos = mat3(ubo.model) * lightPos.xyz; - outLightVec = lPos - pos.xyz; - outViewVec = ubo.viewPos.xyz - pos.xyz; + } diff --git a/and_proj/app/src/main/assets/shaders/texture_loading/glsl/texture.vert.spv b/and_proj/app/src/main/assets/shaders/texture_loading/glsl/texture.vert.spv index 4938ff8..edeb674 100644 Binary files a/and_proj/app/src/main/assets/shaders/texture_loading/glsl/texture.vert.spv and b/and_proj/app/src/main/assets/shaders/texture_loading/glsl/texture.vert.spv differ