This commit is contained in:
xsl
2025-09-04 10:54:47 +08:00
commit 6bc8f61b18
1808 changed files with 208268 additions and 0 deletions
@@ -0,0 +1,24 @@
/* Copyright (c) 2023-2024, Mobica Limited
*
* 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.
*/
#version 450
layout(location = 0) in vec4 inColor;
layout(location = 0) out vec4 outFragColor;
void main()
{
outFragColor = inColor;
}
Binary file not shown.
+109
View File
@@ -0,0 +1,109 @@
/* Copyright (c) 2023-2024, Mobica Limited
*
* 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.
*/
#version 450
layout(binding = 0) uniform UBO
{
mat4 projection;
mat4 view;
}
ubo;
layout(binding = 1) uniform UBOTessellation
{
float tessellationFactor;
}
ubo_tessellation;
layout(vertices = 3) out;
layout(location = 0) out vec3 outColor[3];
float getTessLevel(vec4 p0, vec4 p1)
{
float tessellationLevel = 0.0f;
const float midDistance = 1.6f;
const float shortDistance = 1.0f;
// Calculate edge mid point
vec4 centerPoint = 0.5f * (p0 + p1);
// Calculate vector from camera to mid point
vec4 vCam = ubo.view * centerPoint;
// Calculate vector for camera projection
vec4 vCamView = ubo.projection * vCam;
// Calculate the vector length
float centerDistance = length(vCamView);
// Adjusting the size of the tessellation depending on the length of the vector
if (centerDistance >= midDistance)
{
tessellationLevel = 1.0f;
}
else if (centerDistance >= shortDistance && centerDistance < midDistance)
{
tessellationLevel = ubo_tessellation.tessellationFactor * 0.4f;
}
else
{
tessellationLevel = ubo_tessellation.tessellationFactor;
}
return tessellationLevel;
}
vec3 getColor(float tessellationLevel)
{
vec3 outColor;
if (tessellationLevel == 1.0f)
{
outColor = vec3(1.0f, 0.0f, 0.0f); // red color
}
else if (tessellationLevel == ubo_tessellation.tessellationFactor * 0.4f)
{
outColor = vec3(0.0f, 0.0f, 1.0f); // blue color
}
else if (tessellationLevel == ubo_tessellation.tessellationFactor)
{
outColor = vec3(0.0f, 1.0f, 0.0f); // green color
}
return outColor;
}
void main()
{
if (ubo_tessellation.tessellationFactor > 1.0)
{
gl_TessLevelOuter[0] = getTessLevel(gl_in[2].gl_Position, gl_in[0].gl_Position);
gl_TessLevelOuter[1] = getTessLevel(gl_in[0].gl_Position, gl_in[1].gl_Position);
gl_TessLevelOuter[2] = getTessLevel(gl_in[1].gl_Position, gl_in[2].gl_Position);
gl_TessLevelInner[0] = mix(gl_TessLevelOuter[0], gl_TessLevelOuter[2], 0.5);
}
else
{
gl_TessLevelOuter[0] = 1;
gl_TessLevelOuter[1] = 1;
gl_TessLevelOuter[2] = 1;
gl_TessLevelInner[0] = 1;
}
outColor[gl_InvocationID] = getColor(gl_TessLevelOuter[0]);
gl_out[gl_InvocationID].gl_Position = gl_in[gl_InvocationID].gl_Position;
}
Binary file not shown.
@@ -0,0 +1,41 @@
/* Copyright (c) 2023-2024, Mobica Limited
*
* 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.
*/
#version 450
layout(binding = 0) uniform UBO
{
mat4 projection;
mat4 view;
}
ubo;
layout(location = 0) in vec3 inColor[gl_MaxPatchVertices];
layout(location = 0) out vec4 color;
layout(triangles, equal_spacing, cw) in;
vec4 interpolate3D(vec4 v0, vec4 v1, vec4 v2)
{
return vec4(gl_TessCoord.x) * v0 + vec4(gl_TessCoord.y) * v1 + vec4(gl_TessCoord.z) * v2;
}
void main()
{
vec4 pos = interpolate3D(gl_in[0].gl_Position, gl_in[1].gl_Position, gl_in[2].gl_Position);
gl_Position = ubo.projection * ubo.view * pos;
color = vec4(inColor[0], 1.0f);
}
Binary file not shown.
@@ -0,0 +1,42 @@
/* Copyright (c) 2023-2024, Mobica Limited
*
* 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.
*/
#version 450
#define PI 3.14159
layout(location = 0) in vec3 inPos;
layout(binding = 0) uniform UBO
{
mat4 projection;
mat4 view;
}
ubo;
layout(push_constant) uniform Push_Constants
{
vec3 direction;
}
push_constants;
void main(void)
{
mat4 rotX = mat4(1.0f);
rotX[1][1] = cos(PI);
rotX[1][2] = sin(PI);
rotX[2][1] = -sin(PI);
rotX[2][2] = cos(PI);
gl_Position = rotX * vec4(inPos + push_constants.direction, 1.0f);
}
Binary file not shown.
@@ -0,0 +1,27 @@
/* Copyright (c) 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.
*/
struct DSOutput
{
float4 Pos : SV_POSITION;
[[vk::location(0)]] float3 Color : COLOR0;
};
float4 main(DSOutput input) : SV_TARGET0
{
return float4(input.Color, 1.0);
}
Binary file not shown.
@@ -0,0 +1,137 @@
/* Copyright (c) 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.
*/
struct UBO
{
float4x4 projection;
float4x4 view;
};
[[vk::binding(0, 0)]]
ConstantBuffer<UBO> ubo : register(b0);
struct UBOTessellation
{
float tessellationFactor;
};
[[vk::binding(1, 0)]]
ConstantBuffer<UBOTessellation> ubo_tessellation : register(b1);
struct VSOutput
{
float4 Pos : SV_POSITION;
};
struct HSOutput
{
float4 Pos : SV_POSITION;
[[vk::location(0)]] float3 Color : COLOR0;
};
struct ConstantsHSOutput
{
float TessLevelOuter[4] : SV_TessFactor;
float TessLevelInner[2] : SV_InsideTessFactor;
};
float getTessLevel(float4 p0, float4 p1)
{
float tessellationLevel = 0.0f;
const float midDistance = 1.6f;
const float shortDistance = 1.0f;
// Calculate edge mid point
float4 centerPoint = 0.5f * (p0 + p1);
// Calculate vector from camera to mid point
float4 vCam = mul(ubo.view, centerPoint);
// Calculate vector for camera projection
float4 vCamView = mul(ubo.projection, vCam);
// Calculate the vector length
float centerDistance = length(vCamView);
// Adjusting the size of the tessellation depending on the length of the vector
if (centerDistance >= midDistance)
{
tessellationLevel = 1.0f;
}
else if (centerDistance >= shortDistance && centerDistance < midDistance)
{
tessellationLevel = ubo_tessellation.tessellationFactor * 0.4f;
}
else
{
tessellationLevel = ubo_tessellation.tessellationFactor;
}
return tessellationLevel;
}
float3 getColor(float tessellationLevel)
{
float3 outColor;
if (tessellationLevel == 1.0f)
{
outColor = float3(1.0f, 0.0f, 0.0f); // red color
}
else if (tessellationLevel == ubo_tessellation.tessellationFactor * 0.4f)
{
outColor = float3(0.0f, 0.0f, 1.0f); // blue color
}
else if (tessellationLevel == ubo_tessellation.tessellationFactor)
{
outColor = float3(0.0f, 1.0f, 0.0f); // green color
}
return outColor;
}
ConstantsHSOutput ConstantsHS(InputPatch<VSOutput, 3> patch)
{
ConstantsHSOutput output = (ConstantsHSOutput)0;
if (ubo_tessellation.tessellationFactor > 1.0)
{
output.TessLevelOuter[0] = getTessLevel(patch[2].Pos, patch[0].Pos);
output.TessLevelOuter[1] = getTessLevel(patch[0].Pos, patch[1].Pos);
output.TessLevelOuter[2] = getTessLevel(patch[1].Pos, patch[2].Pos);
output.TessLevelInner[0] = lerp(output.TessLevelOuter[0], output.TessLevelOuter[2], 0.5);
}
else
{
output.TessLevelOuter[0] = 1;
output.TessLevelOuter[1] = 1;
output.TessLevelOuter[2] = 1;
output.TessLevelInner[0] = 1;
}
return output;
}
[domain("tri")]
[partitioning("integer")]
[outputtopology("triangle_cw")]
[outputcontrolpoints(3)]
[patchconstantfunc("ConstantsHS")]
[maxtessfactor(20.0)]
HSOutput main(InputPatch<VSOutput, 3> patch, uint InvocationID : SV_OutputControlPointID)
{
HSOutput output = (HSOutput)0;
output.Pos = patch[InvocationID].Pos;
output.Color = getColor(getTessLevel(patch[2].Pos, patch[0].Pos));
return output;
}
Binary file not shown.
@@ -0,0 +1,62 @@
/* Copyright (c) 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.
*/
struct UBO
{
float4x4 projection;
float4x4 view;
};
[[vk::binding(0, 0)]]
ConstantBuffer<UBO> ubo : register(b0);
struct HSOutput
{
float4 Pos : SV_POSITION;
[[vk::location(0)]] float3 Color : COLOR0;
};
struct ConstantsHSOutput
{
float TessLevelOuter[4] : SV_TessFactor;
float TessLevelInner[2] : SV_InsideTessFactor;
};
struct DSOutput
{
float4 Pos : SV_POSITION;
[[vk::location(0)]] float3 Color : COLOR0;
};
/// layout(triangles, equal_spacing, cw) in;
float4 interpolate3D(float4 v0, float4 v1, float4 v2, float3 TessCoord)
{
return TessCoord.x * v0 + TessCoord.y * v1 + TessCoord.z * v2;
}
[domain("tri")]
DSOutput main(ConstantsHSOutput input, float3 TessCoord : SV_DomainLocation, const OutputPatch<HSOutput, 3> patch)
{
DSOutput output = (DSOutput)0;
float4 pos = interpolate3D(patch[0].Pos, patch[1].Pos, patch[2].Pos, TessCoord);
output.Pos = mul(ubo.projection, mul(ubo.view, pos));
output.Color = patch[0].Color;
return output;
}
Binary file not shown.
@@ -0,0 +1,57 @@
/* Copyright (c) 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.
*/
struct VSInput
{
[[vk::location(0)]] float3 Pos : POSITION0;
};
struct UBO
{
float4x4 projection;
float4x4 view;
};
[[vk::binding(0, 0)]]
ConstantBuffer<UBO> ubo : register(b0);
struct PushConstants
{
float3 direction;
};
[[vk::push_constant]] PushConstants push_constants;
struct VSOutput
{
float4 Pos : SV_POSITION;
};
#define PI 3.14159
VSOutput main(VSInput input)
{
VSOutput output = (VSOutput) 0;
float4x4 rotX = float4x4(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1);
rotX[1][1] = cos(PI);
rotX[1][2] = sin(PI);
rotX[2][1] = -sin(PI);
rotX[2][2] = cos(PI);
output.Pos = mul(rotX, float4(input.Pos + push_constants.direction, 1.0f));
return output;
}
Binary file not shown.