diff --git a/assets/meshes/lightSphere_Sphere.mesh b/assets/meshes/lightSphere_Sphere.mesh new file mode 100644 index 0000000..82aeaa2 Binary files /dev/null and b/assets/meshes/lightSphere_Sphere.mesh differ diff --git a/assets/shaders/lightObject.frag b/assets/shaders/lightObject.frag new file mode 100644 index 0000000..b3a5464 --- /dev/null +++ b/assets/shaders/lightObject.frag @@ -0,0 +1,78 @@ +#version 450 +#extension GL_EXT_nonuniform_qualifier : require + +#include "shaders://_builtins/constants.glsl" +#include "shaders://_builtins/srgb_ops.glsl" +#include "shaders://_builtins/PBR.glsl" + +struct Material { + vec4 baseColor; + uint albedoTexture; + + uint normalTexture; + + float metallicFactor; + float roughnessFactor; + uint metallicRoughnessTexture; +}; + +struct Light { + vec3 color; + uint intensity; +}; + +struct Scene { + uint lightsCount; +}; + +vec3 directional_light = vec3(1.0); + +layout( push_constant ) uniform constants +{ + mat4 render_matrix; + uint indexBufferIndex; + uint vertexBufferIndex; + uint materialBufferIndex; +} PushConstants; + +layout(set = 0, binding = 0) uniform SceneData { + layout(align = 16) Scene mesh; +} SceneBuffers[]; + +layout(set = 0, binding = 1) uniform LightBuffer { + layout(align = 16) Light lights[]; +} LightsBuffers; + +layout (set = 0, binding = 2) uniform samplerCube skybox; + +layout(set = 2, binding = 3) buffer MaterialBuffer { + layout(align = 16) Material materials[]; +} MaterialBuffers; + +layout(set = 2, binding = 4) uniform sampler2D texSampler[]; + +layout(location = 0) in vec2 uv; +layout(location = 1) smooth in mat3 TBN; +layout(location = 4) in vec4 outpos; +layout(location = 5) in vec3 cameraPos; + +layout (location = 0) out vec4 gPosition; +layout (location = 1) out vec4 gNormal; +layout (location = 2) out vec4 gAlbedo; +layout (location = 3) out vec4 gSpecular; + +float near = 0.001; +float far = 50.0; + +float LinearizeDepth(float depth) +{ + float z = depth * 2.0 - 1.0; // back to NDC + return (2.0 * near * far) / (far + near - z * (far - near)); +} + +void main() { + gNormal = vec4(1.0); + gSpecular = vec4(1.0); + gPosition = outpos; + gAlbedo = vec4(1.0); +} diff --git a/assets/shaders/lightObject.vert b/assets/shaders/lightObject.vert new file mode 100644 index 0000000..235caee --- /dev/null +++ b/assets/shaders/lightObject.vert @@ -0,0 +1,76 @@ +#version 450 +#extension GL_EXT_nonuniform_qualifier : require + +struct Material { + vec4 baseColor; + uint albedoTexture; + + uint normalTexture; + + float metallicFactor; + float roughnessFactor; + uint metallicRoughnessTexture; +}; + +struct Vertex { + vec4 position; + vec4 normal; + vec2 uv[2]; + vec4 tangent; + vec4 bitangent; // No longer needed. // TODO remove +}; + +struct Light { + vec3 color; + uint intensity; +}; + +struct Scene { + uint lightsCount; +}; + +struct Mesh { + uint asd; +}; + +layout( push_constant ) uniform constants +{ + mat4 tranformMatrix; + uint indexBufferIndex; + uint vertexBufferIndex; + uint materialBufferIndex; +} PushConstants; + +layout(set = 1, binding = 0) uniform CameraParam { + mat4 projection; + mat4 view; +} Camera; + +layout(set = 2, binding = 0) buffer MeshBuffer { + layout(align = 16) Mesh mesh; +} MeshBuffers[]; + +layout(set = 2, binding = 1) buffer VertexBuffer { + layout(align = 16) Vertex vertices[]; +} VertexBuffers[]; + +layout(set = 2, binding = 2) buffer IndexBuffer { + uint indices[]; +} IndexBuffers[]; + +layout(set = 2, binding = 4) uniform sampler2D texSampler[]; + +layout(location = 0) out vec2 uv; +layout(location = 1) smooth out mat3 TBN; + +layout(location = 4) out vec4 outpos; +layout(location = 5) out vec3 cameraPos; + +void main() +{ + uint index = IndexBuffers[ PushConstants.indexBufferIndex ].indices[gl_VertexIndex]; + Vertex vertex = VertexBuffers[ PushConstants.vertexBufferIndex ].vertices[ index ]; + + gl_Position = Camera.projection * Camera.view * PushConstants.tranformMatrix * vec4(vertex.position.xyz, 1.0); + outpos = PushConstants.tranformMatrix * vec4(vertex.position.xyz, 1.0); +} diff --git a/scenes/DamagedHelmet.evsc b/scenes/DamagedHelmet.evsc index 20d22c9..492709f 100644 --- a/scenes/DamagedHelmet.evsc +++ b/scenes/DamagedHelmet.evsc @@ -20,6 +20,14 @@ "metallicFactor": 1, "pipeline": "DefferedPipeline", "roughnessFactor": 1 + }, + { + "baseColor":[1.0,1.0,1.0,1.0], + "emissiveFactor":[1.0,1.0,1.0], + "id":"LightMaterial", + "metallicFactor":1.0, + "pipeline":"LightSpherePipeline", + "roughnessFactor":1.0 } ], "nodes": [ @@ -59,11 +67,16 @@ { "components": [ { - "position": [ -2, 1, 2], - "rotation": [-180, 0, 0], + "position": [ 0, 1, 0], + "rotation": [0, 0, 0], "scale": [ 1, 1, 1], "type": "TransformComponent" }, + { + "material":"LightMaterial", + "mesh":"assets://meshes/lightSphere_Sphere.mesh", + "type":"RenderComponent" + }, { "color": [1.0, 1.0, 1.0, 1.0], "intensity": 200, @@ -79,6 +92,11 @@ "scale": [ 1, 1, 1], "type": "TransformComponent" }, + { + "material":"LightMaterial", + "mesh":"assets://meshes/lightSphere_Sphere.mesh", + "type":"RenderComponent" + }, { "color": [1.0, 1.0, 1.0, 1.0], "intensity": 200, @@ -94,6 +112,11 @@ "scale": [ 1, 1, 1], "type": "TransformComponent" }, + { + "material":"LightMaterial", + "mesh":"assets://meshes/lightSphere_Sphere.mesh", + "type":"RenderComponent" + }, { "color": [1.0, 1.0, 1.0, 1.0], "intensity": 200, @@ -109,6 +132,11 @@ "scale": [ 1, 1, 1], "type": "TransformComponent" }, + { + "material":"LightMaterial", + "mesh":"assets://meshes/lightSphere_Sphere.mesh", + "type":"RenderComponent" + }, { "color": [1.0, 1.0, 1.0, 1.0], "intensity": 200, diff --git a/scenes/MainScene.evsc b/scenes/MainScene.evsc index 06bcb96..1da1440 100755 --- a/scenes/MainScene.evsc +++ b/scenes/MainScene.evsc @@ -273,6 +273,19 @@ } ] }, + { + "id": "LightSpherePipeline", + "shaderStages": [ + { + "type": "Vertex", + "shaderPath": "shaders://lightObject.vert" + }, + { + "type": "Fragment", + "shaderPath": "shaders://lightObject.frag" + } + ] + }, { "id": "DefferedPipeline", "shaderStages": [