Added Vulkan examples sources!

This commit is contained in:
saschawillems 2016-02-16 15:07:25 +01:00
parent 367fda186b
commit c91341813c
868 changed files with 514080 additions and 5584 deletions

View file

@ -0,0 +1,25 @@
#version 450
#extension GL_ARB_separate_shader_objects : enable
#extension GL_ARB_shading_language_420pack : enable
layout (binding = 1) uniform sampler2D samplerPosition;
layout (binding = 2) uniform sampler2D samplerNormal;
layout (binding = 3) uniform sampler2D samplerAlbedo;
layout (location = 0) in vec3 inUV;
layout (location = 0) out vec4 outFragColor;
void main()
{
vec3 components[3];
components[0] = texture(samplerPosition, inUV.st).rgb;
components[1] = texture(samplerNormal, inUV.st).rgb;
components[2] = texture(samplerAlbedo, inUV.st).rgb;
//components[2] = vec3(texture(samplerAlbedo, inUV.st).a);
// Select component depending on z coordinate of quad
highp int index = int(inUV.z);
outFragColor.rgb = components[index];
}

Binary file not shown.

View file

@ -0,0 +1,22 @@
#version 450
#extension GL_ARB_separate_shader_objects : enable
#extension GL_ARB_shading_language_420pack : enable
layout (location = 0) in vec3 inPos;
layout (location = 1) in vec2 inUV;
layout (location = 3) in vec3 inNormal;
layout (binding = 0) uniform UBO
{
mat4 projection;
mat4 model;
} ubo;
layout (location = 0) out vec3 outUV;
void main()
{
outUV = vec3(inUV.st, inNormal.z);
gl_Position = ubo.projection * ubo.model * vec4(inPos.xyz, 1.0);
}

Binary file not shown.

View file

@ -0,0 +1,68 @@
#version 450
#extension GL_ARB_separate_shader_objects : enable
#extension GL_ARB_shading_language_420pack : enable
layout (binding = 1) uniform sampler2D samplerposition;
layout (binding = 2) uniform sampler2D samplerNormal;
layout (binding = 3) uniform sampler2D samplerAlbedo;
layout (location = 0) in vec2 inUV;
layout (location = 0) out vec4 outFragcolor;
struct Light {
vec4 position;
vec4 color;
float radius;
float quadraticFalloff;
float linearFalloff;
float _pad;
};
layout (binding = 4) uniform UBO
{
Light lights[6];
vec4 viewPos;
} ubo;
void main()
{
// Get G-Buffer values
vec3 fragPos = texture(samplerposition, inUV).rgb;
vec3 normal = texture(samplerNormal, inUV).rgb;
vec4 albedo = texture(samplerAlbedo, inUV);
#define lightCount 5
#define ambient 0.05
#define specularStrength 0.15
// Ambient part
vec3 fragcolor = albedo.rgb * ambient;
vec3 viewVec = normalize(ubo.viewPos.xyz - fragPos);
for(int i = 0; i < lightCount; ++i)
{
// Distance from light to fragment position
float dist = length(ubo.lights[i].position.xyz - fragPos);
if(dist < ubo.lights[i].radius)
{
// Get vector from current light source to fragment position
vec3 lightVec = normalize(ubo.lights[i].position.xyz - fragPos);
// Diffuse part
vec3 diffuse = max(dot(normal, lightVec), 0.0) * albedo.rgb * ubo.lights[i].color.rgb;
// Specular part (specular texture part stored in albedo alpha channel)
vec3 halfVec = normalize(lightVec + viewVec);
vec3 specular = ubo.lights[i].color.rgb * pow(max(dot(normal, halfVec), 0.0), 16.0) * albedo.a * specularStrength;
// Attenuation with linearFalloff and quadraticFalloff falloff
float attenuation = 1.0 / (1.0 + ubo.lights[i].linearFalloff * dist + ubo.lights[i].quadraticFalloff * dist * dist);
fragcolor += (diffuse + specular) * attenuation;
}
}
outFragcolor = vec4(fragcolor, 1.0);
}

Binary file not shown.

View file

@ -0,0 +1,21 @@
#version 450
#extension GL_ARB_separate_shader_objects : enable
#extension GL_ARB_shading_language_420pack : enable
layout (location = 0) in vec3 inPos;
layout (location = 1) in vec2 inUV;
layout (binding = 0) uniform UBO
{
mat4 projection;
mat4 model;
} ubo;
layout (location = 0) out vec2 outUV;
void main()
{
outUV = inUV;
gl_Position = ubo.projection * ubo.model * vec4(inPos.xyz, 1.0);
}

Binary file not shown.

View file

@ -0,0 +1,7 @@
glslangvalidator -V debug.vert -o debug.vert.spv
glslangvalidator -V debug.frag -o debug.frag.spv
glslangvalidator -V deferred.vert -o deferred.vert.spv
glslangvalidator -V deferred.frag -o deferred.frag.spv
glslangvalidator -V mrt.vert -o mrt.vert.spv
glslangvalidator -V mrt.frag -o mrt.frag.spv

View file

@ -0,0 +1,22 @@
#version 450
#extension GL_ARB_separate_shader_objects : enable
#extension GL_ARB_shading_language_420pack : enable
layout (binding = 1) uniform sampler2D samplerColor;
layout (location = 0) in vec3 inNormal;
layout (location = 1) in vec2 inUV;
layout (location = 2) in vec3 inColor;
layout (location = 3) in vec3 inWorldPos;
layout (location = 0) out vec4 outPosition;
layout (location = 1) out vec4 outNormal;
layout (location = 2) out vec4 outAlbedo;
void main()
{
outPosition = vec4(inWorldPos, 1.0);
outNormal = vec4(inNormal, 1.0);
outAlbedo = texture(samplerColor, inUV);
}

Binary file not shown.

View file

@ -0,0 +1,42 @@
#version 450
#extension GL_ARB_separate_shader_objects : enable
#extension GL_ARB_shading_language_420pack : enable
layout (location = 0) in vec4 inPos;
layout (location = 1) in vec2 inUV;
layout (location = 2) in vec3 inColor;
layout (location = 3) in vec3 inNormal;
layout (binding = 0) uniform UBO
{
mat4 projection;
mat4 model;
mat4 view;
} ubo;
layout (location = 0) out vec3 outNormal;
layout (location = 1) out vec2 outUV;
layout (location = 2) out vec3 outColor;
layout (location = 3) out vec3 outWorldPos;
void main()
{
gl_Position = ubo.projection * ubo.view * ubo.model * inPos;
outUV = inUV;
outUV.t = 1.0 - outUV.t;
// Vertex position in world space
vec4 tmpPos = inPos;
outWorldPos = vec3(ubo.model * tmpPos);
// GL to Vulkan coord space
outWorldPos.y = -outWorldPos.y;
// Normal in world space
mat3 mNormal = transpose(inverse(mat3(ubo.model)));
outNormal = mNormal * normalize(inNormal);
// Currently just vertex color
outColor = inColor;
}

Binary file not shown.