init
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
/* Copyright (c) 2023, 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 vec3 inNormal;
|
||||
layout (location = 1) in vec3 inColor;
|
||||
layout (location = 2) in vec3 inViewVec;
|
||||
layout (location = 3) in vec3 inLightVec;
|
||||
|
||||
layout (location = 0) out vec4 outFragColor;
|
||||
|
||||
void main()
|
||||
{
|
||||
float ambientStrength = 0.2f;
|
||||
vec3 ambient = ambientStrength * vec3(1.0f, 1.0f, 1.0f);
|
||||
|
||||
vec3 N = normalize(inNormal);
|
||||
vec3 L = normalize(inLightVec);
|
||||
vec3 V = normalize(inViewVec);
|
||||
vec3 R = reflect(-L, N);
|
||||
|
||||
vec3 diffuse = max(dot(N,L),0.0f) * vec3(1.0f);
|
||||
|
||||
vec3 specular = pow(max(dot(R, V), 0.0f), 64.0f) * vec3(0.65f);
|
||||
|
||||
vec3 result = (ambient + diffuse) * inColor + specular;
|
||||
outFragColor = vec4(result, 1.0f);
|
||||
}
|
||||
Binary file not shown.
@@ -0,0 +1,49 @@
|
||||
/* Copyright (c) 2023, 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 (triangles) in;
|
||||
layout (line_strip, max_vertices = 2) out;
|
||||
|
||||
layout (binding = 1) uniform UniformBufferObject {
|
||||
mat4 model;
|
||||
mat4 view;
|
||||
mat4 proj;
|
||||
} ubo;
|
||||
|
||||
layout (location = 0) in vec3 inNormal[];
|
||||
layout (location = 0) out vec3 outColor;
|
||||
|
||||
void main(void)
|
||||
{
|
||||
float normalLength = 0.1f;
|
||||
|
||||
//middle point of triangle
|
||||
vec3 pos = (gl_in[0].gl_Position.xyz + gl_in[1].gl_Position.xyz + gl_in[2].gl_Position.xyz)/3.0f;
|
||||
vec3 normal = inNormal[0].xyz;
|
||||
|
||||
//line vertices
|
||||
gl_Position = ubo.proj * ubo.view * ubo.model * vec4(pos, 1.0f);
|
||||
outColor = vec3(1.0f, 0.0f, 0.0f);
|
||||
EmitVertex();
|
||||
|
||||
gl_Position = ubo.proj * ubo.view * ubo.model * vec4(pos + normal * normalLength, 1.0f);
|
||||
outColor = vec3(0.0f, 0.0f, 1.0f);
|
||||
EmitVertex();
|
||||
|
||||
EndPrimitive();
|
||||
}
|
||||
Binary file not shown.
@@ -0,0 +1,108 @@
|
||||
/* Copyright (c) 2023, 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
|
||||
#extension GL_EXT_mesh_shader : require
|
||||
|
||||
layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;
|
||||
layout(lines, max_vertices = 64, max_primitives = 126) out;
|
||||
|
||||
layout(std140, binding = 2) uniform UniformBufferObject
|
||||
{
|
||||
mat4 model;
|
||||
mat4 view;
|
||||
mat4 proj;
|
||||
} ubo;
|
||||
|
||||
|
||||
struct s_vertex
|
||||
{
|
||||
vec4 position;
|
||||
vec4 normal;
|
||||
};
|
||||
|
||||
layout (std430, binding = 4) buffer _vertices
|
||||
{
|
||||
s_vertex vertices[];
|
||||
} vb;
|
||||
|
||||
|
||||
struct s_meshlet
|
||||
{
|
||||
uint vertices[64];
|
||||
uint indices[126];
|
||||
uint vertex_count;
|
||||
uint index_count;
|
||||
};
|
||||
|
||||
layout (std430, binding = 3) buffer _meshlets
|
||||
{
|
||||
s_meshlet meshlets[];
|
||||
} mbuf;
|
||||
|
||||
|
||||
layout (location = 0) out PerVertexData
|
||||
{
|
||||
vec4 color;
|
||||
} v_out[];
|
||||
|
||||
|
||||
void main(void)
|
||||
{
|
||||
uint meshlet_index = gl_WorkGroupID.x;
|
||||
uint thread_id = gl_LocalInvocationID.x;
|
||||
uint vertex_count = mbuf.meshlets[meshlet_index].vertex_count;
|
||||
uint index_count = mbuf.meshlets[meshlet_index].index_count;
|
||||
uint primitive_count = index_count/3;
|
||||
SetMeshOutputsEXT( primitive_count * 2, primitive_count);
|
||||
|
||||
float normalLength = 0.1f;
|
||||
|
||||
mat4 MVP = ubo.proj * ubo.view * ubo.model;
|
||||
|
||||
uint j = 0;
|
||||
uint k = 0;
|
||||
for (uint i = 0; i < primitive_count; ++i)
|
||||
{
|
||||
//triangle indices
|
||||
uint vi1 = mbuf.meshlets[meshlet_index].indices[j];
|
||||
uint vi2 = mbuf.meshlets[meshlet_index].indices[j + 1];
|
||||
uint vi3 = mbuf.meshlets[meshlet_index].indices[j + 2];
|
||||
|
||||
//middle point of triangle
|
||||
vec3 pos = (vb.vertices[vi1].position.xyz + vb.vertices[vi2].position.xyz + vb.vertices[vi3].position.xyz)/3.0f;
|
||||
vec3 normal = vb.vertices[vi1].normal.xyz;
|
||||
|
||||
//line vertices
|
||||
gl_MeshVerticesEXT[k].gl_Position = MVP * vec4(pos ,1.0f);
|
||||
v_out[k].color = vec4(0.0f, 0.0f, 1.0f, 1.0f);
|
||||
|
||||
gl_MeshVerticesEXT[k + 1].gl_Position = MVP * vec4(pos + normal * normalLength, 1.0f);
|
||||
v_out[k + 1].color = vec4(1.0f, 0.0f, 0.0f, 1.0f);
|
||||
|
||||
k = k + 2;
|
||||
j= j + 3;
|
||||
}
|
||||
|
||||
//indices for line vertices
|
||||
k = 0;
|
||||
for (uint i = 0; i < primitive_count; i++)
|
||||
{
|
||||
gl_PrimitiveLineIndicesEXT[i] = uvec2(k,k+1);
|
||||
k = k + 2;
|
||||
}
|
||||
|
||||
}
|
||||
Binary file not shown.
@@ -0,0 +1,45 @@
|
||||
/* Copyright (c) 2023, 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(set = 0, binding = 0) uniform UniformBufferObject {
|
||||
mat4 model;
|
||||
mat4 view;
|
||||
mat4 proj;
|
||||
} ubo;
|
||||
|
||||
layout(location = 0) in vec3 inPosition;
|
||||
layout(location = 1) in vec3 inNormal;
|
||||
|
||||
layout (location = 0) out vec3 outNormal;
|
||||
layout (location = 1) out vec3 outColor;
|
||||
layout (location = 2) out vec3 outViewVec;
|
||||
layout (location = 3) out vec3 outLightVec;
|
||||
|
||||
void main()
|
||||
{
|
||||
outColor = vec3(0.0f, 1.0f, 1.0f);
|
||||
gl_Position = ubo.proj * ubo.view * ubo.model * vec4(inPosition, 1.0f);
|
||||
|
||||
vec4 FragPos = ubo.model * vec4(inPosition, 1.0f);
|
||||
vec3 lightPos = vec3(-20.0f, 5.0f, 5.0f);
|
||||
vec3 lPos = mat3(ubo.model) * lightPos.xyz;
|
||||
outNormal = mat3(transpose(inverse( ubo.view *ubo.model))) * inNormal;
|
||||
|
||||
outLightVec = lPos.xyz - FragPos.xyz;
|
||||
outViewVec = - (ubo.view * ubo.model * vec4(inPosition, 1.0f)).xyz;
|
||||
}
|
||||
Binary file not shown.
@@ -0,0 +1,26 @@
|
||||
/* Copyright (c) 2023, 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 vec3 inColor;
|
||||
|
||||
layout (location = 0) out vec4 outFragColor;
|
||||
|
||||
void main(void)
|
||||
{
|
||||
outFragColor = vec4(inColor, 1.0f);
|
||||
}
|
||||
Binary file not shown.
@@ -0,0 +1,28 @@
|
||||
/* Copyright (c) 2023, 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 vec3 inPos;
|
||||
layout (location = 1) in vec3 inNormal;
|
||||
|
||||
layout (location = 0) out vec3 outNormal;
|
||||
|
||||
void main(void)
|
||||
{
|
||||
outNormal = inNormal;
|
||||
gl_Position = vec4(inPos.xyz, 1.0f);
|
||||
}
|
||||
Binary file not shown.
@@ -0,0 +1,25 @@
|
||||
/* Copyright (c) 2023, 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 color;
|
||||
|
||||
void main()
|
||||
{
|
||||
color = inColor;
|
||||
}
|
||||
Binary file not shown.
Reference in New Issue
Block a user