放到android 包里面

This commit is contained in:
xsl
2025-09-29 23:23:16 +08:00
parent 72f21a21af
commit f4665a4c9f
12 changed files with 65 additions and 72 deletions
@@ -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);
@@ -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;
@@ -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;
@@ -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;
}
@@ -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);
}
@@ -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;
}