aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--api-test/main.cpp6
-rw-r--r--api-test/vk-device.cpp17
-rw-r--r--shaders/transmittance_lut.comp35
3 files changed, 40 insertions, 18 deletions
diff --git a/api-test/main.cpp b/api-test/main.cpp
index 12deac1..2137ffb 100644
--- a/api-test/main.cpp
+++ b/api-test/main.cpp
@@ -68,6 +68,8 @@ RENDERDOC_API_1_6_0 *rdoc_api = nullptr;
static constexpr size_t Kb = 1024U;
static constexpr size_t Mb = 1024U * Kb;
+static uintptr_t transmittance_LUT_tex_id = 0U;
+
void ui(uint64_t frame_time) {
static float max_fps = 0.f;
static uint64_t max_frame_time = 1000U;
@@ -79,14 +81,13 @@ void ui(uint64_t frame_time) {
max_frame_time = frame_time;
}
ImGui::NewFrame();
- bool open = true;
ImGui::Text("FPS : %f\n", fps);
ImGui::Text("Max FPS : %f\n", max_fps);
ImGui::Text("frame_time : %f ms\n", frame_time / 1000.f);
ImGui::Text("max frame_time : %f ms\n", max_frame_time / 1000.f);
ImGui::Text("LUT");
- ImGui::Image(45, ImVec2(128, 128));
+ ImGui::Image(transmittance_LUT_tex_id, ImVec2(128, 128));
ImGui::EndFrame();
ImGui::Render();
}
@@ -394,6 +395,7 @@ int main() {
.name = "transmittance_lut",
});
device_texture transmittance_lut = device.get_texture(transmittance_lut_handle);
+ transmittance_LUT_tex_id = transmittance_lut.get_sampled_index();
std::vector<uint8_t> transmittance_lut_code = read_file("shaders/transmittance_lut.comp.spv");
handle<device_pipeline> transmittance_lut_compute = device.create_compute_pipeline({
diff --git a/api-test/vk-device.cpp b/api-test/vk-device.cpp
index 71f4618..1e7b385 100644
--- a/api-test/vk-device.cpp
+++ b/api-test/vk-device.cpp
@@ -977,6 +977,23 @@ void vkdevice::pick_physical_device() {
}
bool vkdevice::device_support_features(VkPhysicalDevice physical_dev) {
+ // limits
+ {
+ VkPhysicalDeviceProperties2 props{
+ .sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROPERTIES_2,
+ .pNext = nullptr,
+ };
+ vkGetPhysicalDeviceProperties2(physical_dev, &props);
+
+ VkPhysicalDeviceLimits* limits = &props.properties.limits;
+ if (limits->maxPerStageDescriptorSampledImages < 0x10000 ||
+ limits->maxPerStageDescriptorStorageImages < 0x10000 ||
+ limits->maxDescriptorSetSampledImages < 0x10000 ||
+ limits->maxDescriptorSetStorageImages < 0x10000) {
+ return false;
+ }
+ }
+
// Vulkan 1.2 physical device features support
{
VkPhysicalDeviceVulkan12Features vulkan_12_features{
diff --git a/shaders/transmittance_lut.comp b/shaders/transmittance_lut.comp
index d9e3f4a..34adbae 100644
--- a/shaders/transmittance_lut.comp
+++ b/shaders/transmittance_lut.comp
@@ -13,21 +13,21 @@ layout(push_constant) uniform buffers {
uint padding;
} params;
-vec2 sphere_intersect( in vec3 pos, in vec3 dir, float radius )
+vec2 sphere_intersection ( in vec3 pos, in vec3 dir, float radius )
{
- float b = dot( pos, rd );
- float c = dot( pos, pos ) - radius * radius;
+ float b = dot(pos, vec3(radius));
+ float c = dot(pos, pos) - radius * radius;
float h = b * b - c;
- if( h<0.0 ) return vec2(-1.0); // no intersection
+ if (h < 0.f) return vec2(-1.f); // no intersection
h = sqrt( h );
return vec2( -b - h, -b + h );
}
-vec3 rayleigh_scattering = vec3(5.8f, 13.5f, 33.1f);
-vec3 rayleigh_extinction = -rayleigh_scattering;
+vec3 rayleigh_scattering = vec3(5.802f, 13.558f, 33.1f);
+vec3 rayleigh_absorption = vec3(0.f);
-vec3 mie_scattering = vec3(0.f);
-vec3 mie_extinction = vec3(0.f);
+vec3 mie_scattering = vec3(3.996f);
+vec3 mie_absorption = vec3(4.40f);
void main() {
ivec2 coords = ivec2(gl_GlobalInvocationID.xy);
@@ -53,31 +53,34 @@ void main() {
float height = atmosphere_radius * uvs.x;
vec2 pos = vec2(0.f, ground_radius + height);
- vec2 dir vec2(mu, sin(theta));
- vec3 transmittance = vec3(0);
+ vec2 dir = vec2(mu, sin(theta));
+ vec3 transmittance = vec3(0.f);
// find ground hit
float t = 0.f;
- vec2 ground_intersection = sphere_intersection(pos, dir, ground_radius);
+ vec2 ground_intersection = sphere_intersection(vec3(pos, 0.f), vec3(dir, 0.f), ground_radius);
t = ground_intersection.x;
// find atmosphere hit
if (ground_intersection.y < 0.f) {
- vec2 top_intersection = sphere_intersection(pos, dir, top_radius);
+ vec2 top_intersection = sphere_intersection(vec3(pos, 0.f), vec3(dir, 0.f), top_radius);
t = top_intersection.y;
}
vec2 hit = pos + dir * t;
+ vec3 extinction = rayleigh_scattering + rayleigh_absorption + mie_scattering + mie_absorption;
+ vec3 total_extinction = vec3(0.f);
// raymarching
float step = t / raymarching_steps;
- float dist = 0.f
- for (dist < t) {
+ for (float dist = 0.f; dist < t; dist += step) {
vec2 cur = pos + dir * dist;
dist += step;
-
+ total_extinction += extinction * step;
}
- imageStore(images[nonuniformEXT(params.output_image_index)], vec2(mu, height), vec4(out_color, 1.0));
+ vec4 color = vec4(exp(-total_extinction), 1.f);
+
+ imageStore(images[nonuniformEXT(params.output_image_index)], coords, color);
}