12 #include <boost/math/constants/constants.hpp> 13 #include <vulkan/vulkan.h> 14 #include <Euclid/Render/RenderCore.h> 40 RasCamera(
const Eigen::Vector3f& position,
41 const Eigen::Vector3f& focus,
42 const Eigen::Vector3f& up,
51 Eigen::Matrix4f
view()
const;
56 virtual Eigen::Matrix4f
projection()
const = 0;
87 const Eigen::Vector3f& focus,
88 const Eigen::Vector3f& up,
110 const Eigen::Vector3f& focus,
111 const Eigen::Vector3f& up,
123 void set_aspect(
float aspect);
128 void set_aspect(
unsigned width,
unsigned height);
133 void set_fov(
float vfov);
138 virtual Eigen::Matrix4f
projection()
const override;
141 float _vfov = boost::math::float_constants::half_pi;
142 float _aspect = 1.0f;
172 const Eigen::Vector3f& focus,
173 const Eigen::Vector3f& up,
184 void set_extent(
float xextent,
float yextent);
189 virtual Eigen::Matrix4f
projection()
const override;
205 SAMPLE_COUNT_1 = 0x00000001,
206 SAMPLE_COUNT_2 = 0x00000002,
207 SAMPLE_COUNT_4 = 0x00000004,
208 SAMPLE_COUNT_8 = 0x00000008,
219 uint32_t height = 256,
220 SampleCount samples = SAMPLE_COUNT_1);
234 void attach_position_buffer(
const float* positions,
size_t size);
244 void attach_normal_buffer(
const float* normals,
size_t size);
257 void attach_color_buffer(
const float* colors,
size_t size);
269 void attach_index_buffer(
const unsigned* indices,
size_t size);
274 void release_buffers();
279 void set_material(
const Material& material);
284 void set_light(
const Light& light);
289 void set_background(
const Eigen::Array3f& color);
294 void set_background(
float r,
float g,
float b);
299 void set_image(uint32_t width, uint32_t height, SampleCount samples);
312 void render_shaded(
const Eigen::Matrix4f& model,
314 std::vector<uint8_t>& pixels,
315 bool interleaved =
true);
327 void render_unlit(
const Eigen::Matrix4f& model,
329 std::vector<uint8_t>& pixels,
330 bool interleaved =
true);
345 void render_depth(
const Eigen::Matrix4f& model,
347 std::vector<uint8_t>& pixels,
348 bool interleaved =
true,
362 void render_depth(
const Eigen::Matrix4f& model,
364 std::vector<float>& values,
368 enum ShaderType :
int 370 SHADER_TYPE_SHADING = 0,
373 SHADER_TYPE_UNLIT_VCOLOR,
379 void _create_instance();
381 void _pick_physical_device();
383 uint32_t _create_logical_device();
385 void _create_command_pool(uint32_t queue_family_index);
387 void _create_descriptor_pool();
389 void _create_descriptors();
391 void _create_render_pass(VkSampleCountFlagBits samples);
393 void _create_pipeline(uint32_t width,
395 VkSampleCountFlagBits samples,
398 void _render_scene(
const Eigen::Matrix4f& model,
400 const std::vector<VkBuffer>& active_buffers,
403 void _copy_fb_to_host_buffer(VkImage src,
404 VkImageAspectFlags aspect,
407 void _transfer_data(
const void* data,
409 VkBufferUsageFlagBits usage,
411 VkDeviceMemory& buffer_memory);
413 uint32_t _find_proper_memory_type(uint32_t mem_type_bits,
414 VkMemoryPropertyFlags prop_flags);
416 void _create_buffer(VkBuffer& bufer,
417 VkDeviceMemory& buffer_memory,
419 VkBufferUsageFlags usage,
420 VkMemoryPropertyFlags props);
422 void _release_buffer(VkBuffer& buffer, VkDeviceMemory& buffer_memory);
424 void _copy_buffer(VkBuffer src, VkBuffer dst, VkDeviceSize size);
426 void _create_image(VkImage& image,
427 VkDeviceMemory& memory,
429 VkImageUsageFlags usage,
430 VkImageTiling tiling,
431 VkMemoryPropertyFlags prop_flags,
434 VkSampleCountFlagBits samples);
436 void _release_image(VkImage& buffer, VkDeviceMemory& memory);
438 void _create_image_view(VkImageView&
view,
441 VkImageAspectFlags aspect);
443 void _create_framebuffer(uint32_t width, uint32_t height);
445 VkShaderModule _load_shader(
const char* path);
447 void _update_ubo(
const VkDescriptorBufferInfo& info,
452 static const Material _default_material;
454 static const Light _default_light;
459 Eigen::Array3f _background = Eigen::Array3f::Zero();
460 size_t _num_vertices;
464 SampleCount _samples;
466 VkDebugUtilsMessengerEXT _debug_messenger;
467 VkInstance _instance;
468 VkPhysicalDevice _physical_device;
469 VkPhysicalDeviceMemoryProperties _physical_device_memory_properties;
472 VkCommandPool _command_pool;
473 VkDescriptorPool _descriptor_pool;
474 std::vector<VkDescriptorSetLayout> _descriptor_set_layouts;
475 std::vector<VkDescriptorSet> _descriptor_sets;
476 std::vector<VkPipelineLayout> _pipeline_layouts;
477 std::vector<VkPipeline> _pipelines;
478 VkFramebuffer _framebuffer = VK_NULL_HANDLE;
479 VkRenderPass _render_pass = VK_NULL_HANDLE;
480 VkBuffer _position_buffer = VK_NULL_HANDLE;
481 VkDeviceMemory _position_buffer_memory;
482 VkBuffer _normal_buffer = VK_NULL_HANDLE;
483 VkDeviceMemory _normal_buffer_memory;
484 VkBuffer _color_buffer = VK_NULL_HANDLE;
485 VkDeviceMemory _color_buffer_memory;
486 VkBuffer _index_buffer = VK_NULL_HANDLE;
487 VkDeviceMemory _index_buffer_memory;
488 VkBuffer _transform_buffer = VK_NULL_HANDLE;
489 VkDeviceMemory _transform_buffer_memory;
490 VkBuffer _material_buffer = VK_NULL_HANDLE;
491 VkDeviceMemory _material_buffer_memory;
492 VkBuffer _light_buffer = VK_NULL_HANDLE;
493 VkDeviceMemory _light_buffer_memory;
494 VkBuffer _output_color_buffer = VK_NULL_HANDLE;
495 VkDeviceMemory _output_color_buffer_memory;
496 VkBuffer _output_depth_buffer = VK_NULL_HANDLE;
497 VkDeviceMemory _output_depth_buffer_memory;
498 VkImage _color_image = VK_NULL_HANDLE;
499 VkDeviceMemory _color_image_memory;
500 VkImageView _color_image_view = VK_NULL_HANDLE;
501 VkImage _depth_image = VK_NULL_HANDLE;
502 VkDeviceMemory _depth_image_memory;
503 VkImageView _depth_image_view = VK_NULL_HANDLE;
504 VkImage _color_resolve_image = VK_NULL_HANDLE;
505 VkDeviceMemory _color_resolve_image_memory;
506 VkImageView _color_resolve_image_view = VK_NULL_HANDLE;
507 VkImage _depth_resolve_image = VK_NULL_HANDLE;
508 VkDeviceMemory _depth_resolve_image_memory;
509 VkImageView _depth_resolve_image_view = VK_NULL_HANDLE;
510 std::vector<VkShaderModule> _shader_modules;
516 #include "src/Rasterizer.cpp" virtual Eigen::Matrix4f projection() const =0
Return the projection matrix.
RasCamera()=default
Create a RasCamera.
float tnear
The near plane.
Definition: RenderCore.h:100
float tfar
The far plane.
Definition: RenderCore.h:105
A RasCamera using orthographic projection.
Definition: Rasterizer.h:150
A simple rasterizer.
Definition: Rasterizer.h:200
A camera model used for rasterization.
Definition: Rasterizer.h:24
Eigen::Matrix4f view() const
Return the view/lookat matrix.
Definition: Rasterizer.cpp:79
A simple Lambertian material model.
Definition: RenderCore.h:154
A basic positionable camera model.
Definition: RenderCore.h:17
OrthoRasCamera()
Create an OrthoRasCamera using default parameters.
Definition: Rasterizer.h:156
PerspRasCamera()
Create a PerspRasCamera using default parameters.
Definition: Rasterizer.h:70
A simple point light model.
Definition: RenderCore.h:170
A RasCamera using perspective projection.
Definition: Rasterizer.h:64