diff --git a/ref_vk/shaders/additive.rahit b/ref_vk/shaders/additive.rahit index 4461d00c..ab9a7eb2 100644 --- a/ref_vk/shaders/additive.rahit +++ b/ref_vk/shaders/additive.rahit @@ -18,17 +18,17 @@ hitAttributeEXT vec2 bary; void main() { const int instance_kusochki_offset = gl_InstanceCustomIndexEXT; const int kusok_index = instance_kusochki_offset + gl_GeometryIndexEXT; - const uint first_index_offset = kusochki[kusok_index].index_offset + gl_PrimitiveID * 3; + const uint first_index_offset = getKusok(kusok_index).index_offset + gl_PrimitiveID * 3; - const uint vi1 = uint(indices[first_index_offset+0]) + kusochki[kusok_index].vertex_offset; - const uint vi2 = uint(indices[first_index_offset+1]) + kusochki[kusok_index].vertex_offset; - const uint vi3 = uint(indices[first_index_offset+2]) + kusochki[kusok_index].vertex_offset; + const uint vi1 = uint(getIndex(first_index_offset+0)) + getKusok(kusok_index).vertex_offset; + const uint vi2 = uint(getIndex(first_index_offset+1)) + getKusok(kusok_index).vertex_offset; + const uint vi3 = uint(getIndex(first_index_offset+2)) + getKusok(kusok_index).vertex_offset; - const vec2 texture_uv = vertices[vi1].gl_tc * (1. - bary.x - bary.y) + vertices[vi2].gl_tc * bary.x + vertices[vi3].gl_tc * bary.y + push_constants.time * kusochki[kusok_index].uv_speed; + const vec2 texture_uv = getVertex(vi1).gl_tc * (1. - bary.x - bary.y) + getVertex(vi2).gl_tc * bary.x + getVertex(vi3).gl_tc * bary.y + push_constants.time * getKusok(kusok_index).uv_speed; // TODO mips - const uint tex_index = kusochki[kusok_index].tex_base_color; + const uint tex_index = getKusok(kusok_index).tex_base_color; const vec4 texture_color = texture(textures[nonuniformEXT(tex_index)], texture_uv); - const vec3 color = texture_color.rgb * kusochki[kusok_index].color.rgb * texture_color.a * kusochki[kusok_index].color.a; + const vec3 color = texture_color.rgb * getKusok(kusok_index).color.rgb * texture_color.a * getKusok(kusok_index).color.a; const float overshoot = gl_HitTEXT - payload_additive.ray_distance; diff --git a/ref_vk/shaders/alphamask.rahit b/ref_vk/shaders/alphamask.rahit index 30bc2569..f2d07213 100644 --- a/ref_vk/shaders/alphamask.rahit +++ b/ref_vk/shaders/alphamask.rahit @@ -12,14 +12,14 @@ hitAttributeEXT vec2 bary; void main() { const int instance_kusochki_offset = gl_InstanceCustomIndexEXT; const int kusok_index = instance_kusochki_offset + gl_GeometryIndexEXT; - const uint first_index_offset = kusochki[kusok_index].index_offset + gl_PrimitiveID * 3; + const uint first_index_offset = getKusok(kusok_index).index_offset + gl_PrimitiveID * 3; - const uint vi1 = uint(indices[first_index_offset+0]) + kusochki[kusok_index].vertex_offset; - const uint vi2 = uint(indices[first_index_offset+1]) + kusochki[kusok_index].vertex_offset; - const uint vi3 = uint(indices[first_index_offset+2]) + kusochki[kusok_index].vertex_offset; + const uint vi1 = uint(getIndex(first_index_offset+0)) + getKusok(kusok_index).vertex_offset; + const uint vi2 = uint(getIndex(first_index_offset+1)) + getKusok(kusok_index).vertex_offset; + const uint vi3 = uint(getIndex(first_index_offset+2)) + getKusok(kusok_index).vertex_offset; - const vec2 texture_uv = vertices[vi1].gl_tc * (1. - bary.x - bary.y) + vertices[vi2].gl_tc * bary.x + vertices[vi3].gl_tc * bary.y; - const uint tex_index = kusochki[kusok_index].tex_base_color; + const vec2 texture_uv = getVertex(vi1).gl_tc * (1. - bary.x - bary.y) + getVertex(vi2).gl_tc * bary.x + getVertex(vi3).gl_tc * bary.y; + const uint tex_index = getKusok(kusok_index).tex_base_color; const vec4 texture_color = texture(textures[nonuniformEXT(tex_index)], texture_uv); if (texture_color.a < 0.1) { diff --git a/ref_vk/shaders/ray_common_alphatest.rahit b/ref_vk/shaders/ray_common_alphatest.rahit index 9279651b..a864c5e1 100644 --- a/ref_vk/shaders/ray_common_alphatest.rahit +++ b/ref_vk/shaders/ray_common_alphatest.rahit @@ -10,7 +10,7 @@ layout(set = 0, binding = 6) uniform sampler2D textures[MAX_TEXTURES]; // TODO not really needed here? // It's an artifact of readHitGeometry() computing uv_lods, which we don't really use in this shader // Split readHitGeometry into basic and advanced -layout(set = 0, binding = 2) uniform UBO { UniformBuffer ubo; }; +layout(set = 0, binding = 2) uniform UBO { UniformBuffer ubo; } ubo; hitAttributeEXT vec2 bary; @@ -20,7 +20,7 @@ const float alpha_mask_threshold = .1f; void main() { const Geometry geom = readHitGeometry(); - const uint tex_index = kusochki[geom.kusok_index].tex_base_color; + const uint tex_index = getKusok(geom.kusok_index).tex_base_color; const vec4 texture_color = texture(textures[nonuniformEXT(tex_index)], geom.uv); if (texture_color.a < alpha_mask_threshold) { diff --git a/ref_vk/shaders/ray_kusochki.glsl b/ref_vk/shaders/ray_kusochki.glsl index 157857a5..96546e66 100644 --- a/ref_vk/shaders/ray_kusochki.glsl +++ b/ref_vk/shaders/ray_kusochki.glsl @@ -17,6 +17,10 @@ struct Vertex { uint _unused_color_u8_4; }; -layout(std430, binding = 3, set = 0) readonly buffer Kusochki { Kusok kusochki[]; }; -layout(std430, binding = 4, set = 0) readonly buffer Indices { uint16_t indices[]; }; -layout(std430, binding = 5, set = 0) readonly buffer Vertices { Vertex vertices[]; }; +layout(std430, binding = 3, set = 0) readonly buffer Kusochki { Kusok a[]; } kusochki; +layout(std430, binding = 4, set = 0) readonly buffer Indices { uint16_t a[]; } indices; +layout(std430, binding = 5, set = 0) readonly buffer Vertices { Vertex a[]; } vertices; + +Kusok getKusok(uint index) { return kusochki.a[index]; } +uint16_t getIndex(uint index) { return indices.a[index]; } +Vertex getVertex(uint index) { return vertices.a[index]; } diff --git a/ref_vk/shaders/ray_light_direct.glsl b/ref_vk/shaders/ray_light_direct.glsl index 195248c2..acaa5d90 100644 --- a/ref_vk/shaders/ray_light_direct.glsl +++ b/ref_vk/shaders/ray_light_direct.glsl @@ -16,7 +16,7 @@ OUTPUTS(X) #undef X layout(set = 0, binding = 1) uniform accelerationStructureEXT tlas; -layout(set = 0, binding = 2) uniform UBO { UniformBuffer ubo; }; +layout(set = 0, binding = 2) uniform UBO { UniformBuffer ubo; } ubo; #include "ray_kusochki.glsl" @@ -43,11 +43,11 @@ void main() { const vec2 uv = (gl_LaunchIDEXT.xy + .5) / gl_LaunchSizeEXT.xy * 2. - 1.; const ivec2 pix = ivec2(gl_LaunchIDEXT.xy); - rand01_state = ubo.random_seed + gl_LaunchIDEXT.x * 1833 + gl_LaunchIDEXT.y * 31337; + rand01_state = ubo.ubo.random_seed + gl_LaunchIDEXT.x * 1833 + gl_LaunchIDEXT.y * 31337; // FIXME incorrect for reflection/refraction - const vec4 target = ubo.inv_proj * vec4(uv.x, uv.y, 1, 1); - const vec3 direction = normalize((ubo.inv_view * vec4(target.xyz, 0)).xyz); + const vec4 target = ubo.ubo.inv_proj * vec4(uv.x, uv.y, 1, 1); + const vec3 direction = normalize((ubo.ubo.inv_view * vec4(target.xyz, 0)).xyz); const vec4 material_data = imageLoad(material_rmxx, pix); diff --git a/ref_vk/shaders/ray_primary.rchit b/ref_vk/shaders/ray_primary.rchit index ac49056e..c2073d47 100644 --- a/ref_vk/shaders/ray_primary.rchit +++ b/ref_vk/shaders/ray_primary.rchit @@ -11,7 +11,7 @@ #include "color_spaces.glsl" layout(set = 0, binding = 6) uniform sampler2D textures[MAX_TEXTURES]; -layout(set = 0, binding = 2) uniform UBO { UniformBuffer ubo; }; +layout(set = 0, binding = 2) uniform UBO { UniformBuffer ubo; } ubo; layout(set = 0, binding = 7) uniform samplerCube skybox; layout(location = PAYLOAD_LOCATION_PRIMARY) rayPayloadInEXT RayPayloadPrimary payload; @@ -28,7 +28,7 @@ void main() { payload.hit_t = vec4(geom.pos, gl_HitTEXT); - const Kusok kusok = kusochki[geom.kusok_index]; + const Kusok kusok = getKusok(geom.kusok_index); const uint tex_base_color = kusok.tex_base_color; if ((tex_base_color & KUSOK_MATERIAL_FLAG_SKYBOX) != 0) { diff --git a/ref_vk/shaders/ray_primary.rgen b/ref_vk/shaders/ray_primary.rgen index 912f899e..bcdd57ef 100644 --- a/ref_vk/shaders/ray_primary.rgen +++ b/ref_vk/shaders/ray_primary.rgen @@ -8,7 +8,7 @@ RAY_PRIMARY_OUTPUTS(X) #undef X layout(set = 0, binding = 1) uniform accelerationStructureEXT tlas; -layout(set = 0, binding = 2) uniform UBO { UniformBuffer ubo; }; +layout(set = 0, binding = 2) uniform UBO { UniformBuffer ubo; } ubo; layout(location = PAYLOAD_LOCATION_PRIMARY) rayPayloadEXT RayPayloadPrimary payload; @@ -16,10 +16,9 @@ void main() { const vec2 uv = (gl_LaunchIDEXT.xy + .5) / gl_LaunchSizeEXT.xy * 2. - 1.; // FIXME start on a near plane - const vec3 origin = (ubo.inv_view * vec4(0, 0, 0, 1)).xyz; - const vec4 target = ubo.inv_proj * vec4(uv.x, uv.y, 1, 1); - //vec3 direction = (ubo.inv_view * vec4(normalize(target.xyz), 0)).xyz; - const vec3 direction = normalize((ubo.inv_view * vec4(target.xyz, 0)).xyz); + const vec3 origin = (ubo.ubo.inv_view * vec4(0, 0, 0, 1)).xyz; + const vec4 target = ubo.ubo.inv_proj * vec4(uv.x, uv.y, 1, 1); + const vec3 direction = normalize((ubo.ubo.inv_view * vec4(target.xyz, 0)).xyz); payload.hit_t = vec4(0.); payload.base_color_a = vec4(0.); diff --git a/ref_vk/shaders/ray_shadow.rchit b/ref_vk/shaders/ray_shadow.rchit index a44f422d..8823e998 100644 --- a/ref_vk/shaders/ray_shadow.rchit +++ b/ref_vk/shaders/ray_shadow.rchit @@ -9,7 +9,7 @@ layout(location = PAYLOAD_LOCATION_SHADOW) rayPayloadInEXT RayPayloadShadow payl void main() { const int instance_kusochki_offset = gl_InstanceCustomIndexEXT; const int kusok_index = instance_kusochki_offset + gl_GeometryIndexEXT; - const uint tex_base_color = kusochki[kusok_index].tex_base_color; + const uint tex_base_color = getKusok(kusok_index).tex_base_color; payload_shadow.hit_type = ((tex_base_color & KUSOK_MATERIAL_FLAG_SKYBOX) == 0) ? SHADOW_HIT : SHADOW_SKY ; } diff --git a/ref_vk/shaders/rt_geometry.glsl b/ref_vk/shaders/rt_geometry.glsl index ad2ddd2c..f232035e 100644 --- a/ref_vk/shaders/rt_geometry.glsl +++ b/ref_vk/shaders/rt_geometry.glsl @@ -56,23 +56,23 @@ Geometry readHitGeometry() { const int instance_kusochki_offset = gl_InstanceCustomIndexEXT; geom.kusok_index = instance_kusochki_offset + gl_GeometryIndexEXT; - const Kusok kusok = kusochki[geom.kusok_index]; + const Kusok kusok = getKusok(geom.kusok_index); const uint first_index_offset = kusok.index_offset + gl_PrimitiveID * 3; - const uint vi1 = uint(indices[first_index_offset+0]) + kusok.vertex_offset; - const uint vi2 = uint(indices[first_index_offset+1]) + kusok.vertex_offset; - const uint vi3 = uint(indices[first_index_offset+2]) + kusok.vertex_offset; + const uint vi1 = uint(getIndex(first_index_offset+0)) + kusok.vertex_offset; + const uint vi2 = uint(getIndex(first_index_offset+1)) + kusok.vertex_offset; + const uint vi3 = uint(getIndex(first_index_offset+2)) + kusok.vertex_offset; const vec3 pos[3] = { - gl_ObjectToWorldEXT * vec4(vertices[vi1].pos, 1.f), - gl_ObjectToWorldEXT * vec4(vertices[vi2].pos, 1.f), - gl_ObjectToWorldEXT * vec4(vertices[vi3].pos, 1.f), + gl_ObjectToWorldEXT * vec4(getVertex(vi1).pos, 1.f), + gl_ObjectToWorldEXT * vec4(getVertex(vi2).pos, 1.f), + gl_ObjectToWorldEXT * vec4(getVertex(vi3).pos, 1.f), }; const vec2 uvs[3] = { - vertices[vi1].gl_tc, - vertices[vi2].gl_tc, - vertices[vi3].gl_tc, + getVertex(vi1).gl_tc, + getVertex(vi2).gl_tc, + getVertex(vi3).gl_tc, }; geom.pos = baryMix(pos[0], pos[1], pos[2], bary); @@ -85,17 +85,17 @@ Geometry readHitGeometry() { // NOTE: only support rotations, for arbitrary transform would need to do transpose(inverse(mat3(gl_ObjectToWorldEXT))) const mat3 normalTransform = mat3(gl_ObjectToWorldEXT); geom.normal_shading = normalize(normalTransform * baryMix( - vertices[vi1].normal, - vertices[vi2].normal, - vertices[vi3].normal, + getVertex(vi1).normal, + getVertex(vi2).normal, + getVertex(vi3).normal, bary)); geom.tangent = normalize(normalTransform * baryMix( - vertices[vi1].tangent, - vertices[vi2].tangent, - vertices[vi3].tangent, + getVertex(vi1).tangent, + getVertex(vi2).tangent, + getVertex(vi3).tangent, bary)); - geom.uv_lods = computeAnisotropicEllipseAxes(geom.pos, geom.normal_geometry, gl_WorldRayDirectionEXT, ubo.ray_cone_width * gl_HitTEXT, pos, uvs, geom.uv); + geom.uv_lods = computeAnisotropicEllipseAxes(geom.pos, geom.normal_geometry, gl_WorldRayDirectionEXT, ubo.ubo.ray_cone_width * gl_HitTEXT, pos, uvs, geom.uv); return geom; } diff --git a/ref_vk/vk_core.c b/ref_vk/vk_core.c index 89d4b46f..f2b0911a 100644 --- a/ref_vk/vk_core.c +++ b/ref_vk/vk_core.c @@ -504,6 +504,7 @@ static qboolean createDevice( void ) { .sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FEATURES_2, .pNext = head, .features.samplerAnisotropy = candidate_device->features.features.samplerAnisotropy, + .features.shaderInt16 = true, }; head = &features;