added textures to shaders

This commit is contained in:
J3oss
2021-06-25 21:23:22 +02:00
parent ad14d671e6
commit 097cd0350c
5 changed files with 60 additions and 12 deletions

View File

@@ -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",
},
],

View File

@@ -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",
},
],

View File

@@ -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",
},
],

View File

@@ -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);
}

View File

@@ -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);
}