From 097cd0350cc6583cc59695064d98ea0926c875d7 Mon Sep 17 00:00:00 2001 From: J3oss Date: Fri, 25 Jun 2021 21:23:22 +0200 Subject: [PATCH] added textures to shaders --- res/project/res/scenes/MainScene.evsc | 6 +++++- res/project/res/scenes/SideScene.evsc | 4 ++++ res/project/res/scenes/TestScene.evsc | 6 +++++- res/project/res/shaders/default.frag | 25 +++++++++++++++++++-- res/project/res/shaders/default.vert | 31 ++++++++++++++++++++------- 5 files changed, 60 insertions(+), 12 deletions(-) diff --git a/res/project/res/scenes/MainScene.evsc b/res/project/res/scenes/MainScene.evsc index f73ebf8..120fde6 100644 --- a/res/project/res/scenes/MainScene.evsc +++ b/res/project/res/scenes/MainScene.evsc @@ -127,7 +127,7 @@ }, { "type": "RenderComponent", - "mesh": "project://Avocado.mesh", + "mesh": "project://Cube.mesh", "material": "WhiteMaterial" } ] @@ -263,21 +263,25 @@ "id": "GreenMaterial", "pipeline": "DefaultPipeline", "baseColor": [0.0, 1.0, 0.0, 1.0] + "albedoTexture": "project://lost.tx", }, { "id": "RedMaterial", "pipeline": "DefaultPipeline", "baseColor": [1.0, 0.0, 0.0, 1.0] + "albedoTexture": "project://lost.tx", }, { "id": "BlueMaterial", "pipeline": "DefaultPipeline", "baseColor": [0.0, 0.0, 1.0, 1.0] + "albedoTexture": "project://lost.tx", }, { "id": "WhiteMaterial", "pipeline": "DefaultPipeline", "baseColor": [1.0, 1.0, 0.0, 1.0] + "albedoTexture": "project://lost.tx", }, ], diff --git a/res/project/res/scenes/SideScene.evsc b/res/project/res/scenes/SideScene.evsc index bd5cdac..b8e2e36 100644 --- a/res/project/res/scenes/SideScene.evsc +++ b/res/project/res/scenes/SideScene.evsc @@ -133,21 +133,25 @@ "id": "GreenMaterial", "pipeline": "DefaultPipeline", "baseColor": [0.0, 1.0, 0.0, 1.0] + "albedoTexture": "project://lost.tx", }, { "id": "RedMaterial", "pipeline": "DefaultPipeline", "baseColor": [1.0, 0.0, 0.0, 1.0] + "albedoTexture": "project://lost.tx", }, { "id": "BlueMaterial", "pipeline": "DefaultPipeline", "baseColor": [0.0, 0.0, 1.0, 1.0] + "albedoTexture": "project://lost.tx", }, { "id": "WhiteMaterial", "pipeline": "DefaultPipeline", "baseColor": [1.0, 1.0, 0.0, 1.0] + "albedoTexture": "project://lost.tx", }, ], diff --git a/res/project/res/scenes/TestScene.evsc b/res/project/res/scenes/TestScene.evsc index a6ed9b2..62e6fd1 100644 --- a/res/project/res/scenes/TestScene.evsc +++ b/res/project/res/scenes/TestScene.evsc @@ -122,7 +122,7 @@ }, { "type": "RenderComponent", - "mesh": "project://Avocado.mesh", + "mesh": "project://Cube.mesh", "material": "GreenMaterial" } ] @@ -1759,21 +1759,25 @@ "id": "GreenMaterial", "pipeline": "DefaultPipeline", "baseColor": [0.0, 1.0, 0.0, 1.0] + "albedoTexture": "project://lost.tx", }, { "id": "RedMaterial", "pipeline": "DefaultPipeline", "baseColor": [1.0, 0.0, 0.0, 1.0] + "albedoTexture": "project://lost.tx", }, { "id": "BlueMaterial", "pipeline": "DefaultPipeline", "baseColor": [0.0, 0.0, 1.0, 1.0] + "albedoTexture": "project://lost.tx", }, { "id": "WhiteMaterial", "pipeline": "DefaultPipeline", "baseColor": [1.0, 1.0, 0.0, 1.0] + "albedoTexture": "project://lost.tx", }, ], diff --git a/res/project/res/shaders/default.frag b/res/project/res/shaders/default.frag index 1a80a3a..d7837bb 100644 --- a/res/project/res/shaders/default.frag +++ b/res/project/res/shaders/default.frag @@ -3,17 +3,38 @@ struct Material { vec3 baseColor; + uint index; +}; + +struct Light { + vec3 color; + uint intensity; +}; + +struct Scene { + uint lightsCount; }; vec3 directional_light = vec3(-1.0,-1.0,-1.0); +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 = 2, binding = 4) uniform sampler2D texSampler[]; + layout(location = 0) in vec3 normal; -layout(location = 1) in Material material; +layout(location = 1) in vec3 color; +layout(location = 2) flat in Material material; layout(location = 0) out vec4 outColor; void main() { float intensity = ((dot(normalize(normal), normalize(directional_light)) +1)/2.0)+0.05; - outColor = vec4(material.baseColor * intensity, 1.0); + outColor = vec4(color * intensity, 1.0); } diff --git a/res/project/res/shaders/default.vert b/res/project/res/shaders/default.vert index 21c2b57..be17c40 100644 --- a/res/project/res/shaders/default.vert +++ b/res/project/res/shaders/default.vert @@ -1,6 +1,11 @@ #version 450 #extension GL_EXT_nonuniform_qualifier : require +struct Material { + vec3 baseColor; + uint index; +}; + struct Vertex { vec4 position; vec4 normal; @@ -8,8 +13,13 @@ struct Vertex { vec2 uv[2]; }; -struct Material { - vec3 baseColor; +struct Light { + vec3 color; + uint intensity; +}; + +struct Scene { + uint lightsCount; }; struct Mesh { @@ -24,29 +34,32 @@ layout( push_constant ) uniform constants uint materialBufferIndex; } PushConstants; -layout(set = 0, binding = 0) uniform CameraParam { +layout(set = 1, binding = 0) uniform CameraParam { mat4 projection; mat4 view; } Camera; -layout(set = 1, binding = 0) buffer MeshBuffer { +layout(set = 2, binding = 0) buffer MeshBuffer { layout(align = 16) Mesh mesh; } MeshBuffers[]; -layout(set = 1, binding = 1) buffer VertexBuffer { +layout(set = 2, binding = 1) buffer VertexBuffer { layout(align = 16) Vertex vertices[]; } VertexBuffers[]; -layout(set = 1, binding = 2) buffer IndexBuffer { +layout(set = 2, binding = 2) buffer IndexBuffer { uint indices[]; } IndexBuffers[]; -layout(set = 1, binding = 3) buffer MaterialBuffer { +layout(set = 2, binding = 3) buffer MaterialBuffer { layout(align = 16) Material materials[]; } MaterialBuffers; +layout(set = 2, binding = 4) uniform sampler2D texSampler[]; + layout(location = 0) out vec3 normal; -layout(location = 1) out Material material; +layout(location = 1) out vec3 color; +layout(location = 2) out Material material; void main() { @@ -55,6 +68,8 @@ void main() uint index = IndexBuffers[ PushConstants.indexBufferIndex ].indices[gl_VertexIndex]; Vertex vertex = VertexBuffers[ PushConstants.vertexBufferIndex ].vertices[ index ]; + color = texture(texSampler[0],vertex.uv[0]).xyz; + normal = vertex.normal.xyz; gl_Position = Camera.projection * Camera.view * PushConstants.render_matrix * vec4(vertex.position.xyz, 1.0); }