Skip to content

Commit

Permalink
Create cubemap from file (#93)
Browse files Browse the repository at this point in the history
* partial implementation of cubemap support

* finish first working draft of cubemap texture support,
including example application

* in texture_cubemap example, transform left-handed cubemap coordinates to right-handed world space
and vice versa using modelView matrices instead of in shader code;
add comments explaining coordinate system transformations

* first (incomplete) draft for loading cubemap from six individual files

* adapt texture_cubemap example and load_cubemap_from_file after rebasing branch on current master

* add image_resource_t helper class for image loading library abstraction;
implement image_resource_t classes for GLI and stb_image loaders;
add factory method create_image_resource_from_file();
implement composite_cubemap_image_resource_t class for creating cubemap from individual files;
update texture_cubemap example

* partial implementation of cubemap support

* finish first working draft of cubemap texture support,
including example application

* in texture_cubemap example, transform left-handed cubemap coordinates to right-handed world space
and vice versa using modelView matrices instead of in shader code;
add comments explaining coordinate system transformations

* first (incomplete) draft for loading cubemap from six individual files

* adapt texture_cubemap example and load_cubemap_from_file after rebasing branch on current master

* add image_resource_t helper class for image loading library abstraction;
implement image_resource_t classes for GLI and stb_image loaders;
add factory method create_image_resource_from_file();
implement composite_cubemap_image_resource_t class for creating cubemap from individual files;
update texture_cubemap example

* add cubemap sample texture in ktx and dds format
add links to source

* implement image_resource as bridge pattern to facilitate caching
simplify image_resource interfaces
fix screen resizing in texture_cubemap example after update
add caching to texture_cubemap example
add loading of dds texture to texture_cubemap example

* update revision of auto_vk

* add license information about yokohama_at_night textures

* remove commented-out code

* follow naming conventions

Co-authored-by: Johannes Unterguggenberger <[email protected]>

* rename sRGB, HDR parameters

* add virtual constructor to image_resource_t
make conversion constructors of image_resource_base_t explicit
make variables and parameters const and auto if possible
prevent variable use after std::move

* delete special functions for image_resource_base_t
make conversion constructors explicit for image_resource_t classes

* follow naming conventions

Co-authored-by: Johannes Unterguggenberger <[email protected]>

* Apply suggestions from code review

follow naming conventions
use gvk::owned instead of std::move

Co-authored-by: Johannes Unterguggenberger <[email protected]>

* use avk::resource_reference for type of image_resource instead of std::unique_ptr, adapt code accordingly
add create_image_resource() helper functions
fix compilation errors in texture_cubemap example

* use avk::owning_resource for type of image_resource instead of std::unique_ptr, adapt code accordingly
add create_image_resource() helper functions
fix compilation errors in texture_cubemap example

* add explanation of memory, resource leaks for [[nodiscard]] to guidelines

* add image_resource.hpp to gvk.hpp

* don't create image_resource explicitly in cubemap example, use create_cubemap_from_file_cached instead

* rename image_resource* types and files to image_data*
remove old duplicate file

* Revert "add explanation of memory, resource leaks for [[nodiscard]] to guidelines"

* rename image_resource* types to image_data*

* code cleanup in cubemap_texture example

Co-authored-by: Johannes Unterguggenberger <[email protected]>

* remove initialization of removed mInitTime variable

* use consistent parameter names, camel case

Co-authored-by: Johannes Unterguggenberger <[email protected]>

* use consistent variable names

* use create_vertex_and_index_buffers, create_normals_buffer for model loading in texture_cubemap example

* remove owning_resource wrapper from image_data

Co-authored-by: Johannes Unterguggenberger <[email protected]>

* remove owning_resource from image_data

* use only a single descriptor cache for both pipelines

* add mirror_matrix and cancel_translation_from_matrix helper functions

* use enum to define axis in mirror_matrix
follow naming guidelines for parameters

* update auto_vk ref

* update description of texture_cubemap shaders, add newline

Co-authored-by: Johannes Unterguggenberger <[email protected]>

* don't explicitly specify image format for image view

* use enum struct instead of old style enum
fix parameter type

* - Restructured texture_cubemap example a bit by introducing `enum struct options`. This should improve readability.
- Removed useless `updater` calls and restructured the remaining code to be clearer.
- Added comments to the functions in `math_utils.hpp` that are added with this PR
- Removed default parameter value for `mirror_matrix`'s `principal_axis` parameter. There is not really a justification why any of the axes should be the default. The user must be precise anyways. Also removed the parameter's `const` declaration.

* Linked to latest Auto-Vk master which includes necessary changes for this PR.

* don't try to flip gli texture if it wasn't loaded successfully

* Fixed RELEASE-mode project config in texture_cubemap.vcxproj.user

Co-authored-by: Stefan Fiedler <[email protected]>
Co-authored-by: Johannes Unterguggenberger <[email protected]>
  • Loading branch information
3 people authored May 18, 2021
1 parent eee84d6 commit 08d4c97
Show file tree
Hide file tree
Showing 36 changed files with 1,928 additions and 391 deletions.
1 change: 1 addition & 0 deletions LICENSE.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ The following files are licensed under the Attribution 3.0 Unported (CC BY 3.0)
* all files under [`assets/3rd_party/models/cornell_box`](assets/3rd_party/models/cornell_box)
* all files under [`assets/3rd_party/models/fireplace_room`](assets/3rd_party/models/fireplace_room)
* all files under [`assets/3rd_party/models/sponza`](assets/3rd_party/models/sponza)
* all files under [`assets/3rd_party/textures/yokohama_at_night`](assets/3rd_party/textures/yokohama_at_night)

See https://creativecommons.org/licenses/by/3.0/ for full license details.

Expand Down
Binary file not shown.
13 changes: 13 additions & 0 deletions assets/3rd_party/textures/yokohama_at_night/license.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Author
======

This is the work of Emil Persson, aka Humus.
http://www.humus.name



License
=======

This work is licensed under a Creative Commons Attribution 3.0 Unported License.
http://creativecommons.org/licenses/by/3.0/
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 9 additions & 0 deletions assets/3rd_party/textures/yokohama_at_night/readme.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
The JPG files were downloaded from:

https://www.humus.name/Textures/Yokohama3.zip

The KTX and DDS files were created for gears-vk from the JPG files using ImageViewer available at:

https://github.com/kopaka1822/ImageViewer

For copyright and license information see license.txt.
Binary file not shown.
Binary file not shown.
2 changes: 1 addition & 1 deletion auto_vk
40 changes: 40 additions & 0 deletions examples/texture_cubemap/shaders/reflect.frag
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// adapted from https://github.com/SaschaWillems/Vulkan/blob/master/data/shaders/glsl/texturecubemap/reflect.frag
#version 450

layout (binding = 1) uniform samplerCube samplerColor;

layout (binding = 0) uniform UBO
{
mat4 projection;
mat4 model;
mat4 invModel;
float lodBias;
} ubo;

layout (location = 0) in vec3 inPos;
layout (location = 1) in vec3 inNormal;
layout (location = 2) in vec3 inViewVec;
layout (location = 3) in vec3 inLightVec;

layout (location = 0) out vec4 outFragColor;

void main()
{
vec3 cI = normalize (inPos);
vec3 cR = reflect (cI, normalize(inNormal));

// Convert world coordinates to cubemap coordinate space
// the inverse model-view matrix already deals with the transformation from right-handed to left-handed coordinates
cR = vec3(ubo.invModel * vec4(cR, 0.0));

vec4 color = texture(samplerColor, cR, ubo.lodBias);

vec3 N = normalize(inNormal);
vec3 L = normalize(inLightVec);
vec3 V = normalize(inViewVec);
vec3 R = reflect(-L, N);
vec3 ambient = vec3(0.5) * color.rgb;
vec3 diffuse = max(dot(N, L), 0.0) * vec3(1.0);
vec3 specular = pow(max(dot(R, V), 0.0), 16.0) * vec3(0.5);
outFragColor = vec4(ambient + diffuse * color.rgb + specular, 1.0);
}
30 changes: 30 additions & 0 deletions examples/texture_cubemap/shaders/reflect.vert
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// copied from https://github.com/SaschaWillems/Vulkan/blob/master/data/shaders/glsl/texturecubemap/reflect.vert
#version 450

layout (location = 0) in vec3 inPos;
layout (location = 1) in vec3 inNormal;

layout (binding = 0) uniform UBO
{
mat4 projection;
mat4 model;
mat4 invModel;
float lodBias;
} ubo;

layout (location = 0) out vec3 outPos;
layout (location = 1) out vec3 outNormal;
layout (location = 2) out vec3 outViewVec;
layout (location = 3) out vec3 outLightVec;

void main()
{
gl_Position = ubo.projection * ubo.model * vec4(inPos.xyz, 1.0);

outPos = vec3(ubo.model * vec4(inPos, 1.0));
outNormal = mat3(ubo.model) * inNormal;

vec3 lightPos = vec3(0.0f, -5.0f, 5.0f);
outLightVec = lightPos.xyz - outPos.xyz;
outViewVec = -outPos.xyz;
}
13 changes: 13 additions & 0 deletions examples/texture_cubemap/shaders/skybox.frag
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// copied from https://github.com/SaschaWillems/Vulkan/blob/master/data/shaders/glsl/texturecubemap/skybox.frag
#version 450

layout (binding = 1) uniform samplerCube samplerCubeMap;

layout (location = 0) in vec3 inUVW;

layout (location = 0) out vec4 outFragColor;

void main()
{
outFragColor = texture(samplerCubeMap, inUVW);
}
22 changes: 22 additions & 0 deletions examples/texture_cubemap/shaders/skybox.vert
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// adapted from https://github.com/SaschaWillems/Vulkan/blob/master/data/shaders/glsl/texturecubemap/skybox.vert
#version 450

layout (location = 0) in vec3 inPos;

layout (binding = 0) uniform UBO
{
mat4 projection;
mat4 model;
} ubo;

layout (location = 0) out vec3 outUVW;

void main()
{
// the skybox vertices are already in a left-handed coordinate system,
// so we can pass them to the fragment shader as-is for texture coordinate lookup
outUVW = inPos;

// the model matrix of the skybox takes care of transforming its vertices to right-handed world coordinates
gl_Position = ubo.projection * ubo.model * vec4(inPos.xyz, 1.0);
}
Loading

0 comments on commit 08d4c97

Please sign in to comment.