mirror of
https://github.com/w23/xash3d-fwgs
synced 2024-12-16 14:10:11 +01:00
rtx: add textures
This commit is contained in:
parent
5b7eaa8e1c
commit
e522acf8b3
@ -1,13 +1,9 @@
|
||||
## 2021-04-22
|
||||
- [x] rtx: fix backlight glitch
|
||||
|
||||
# Next
|
||||
- [ ] rtx: restore studio models
|
||||
- [ ] rtx: dynamic surface lights / dynamic light clusters
|
||||
- [ ] rtx: better light culling: normal, bsp visibility, light volumes and intensity, ...
|
||||
- [ ] rtx: live rad file reloading (or other solution for tuning lights)
|
||||
- [ ] rtx: restore studio models
|
||||
- [ ] rtx: restore dynamic stuff like particles, beams, etc
|
||||
- [ ] rtx: textures
|
||||
- [ ] rtx: emissive particles
|
||||
- [ ] rtx: better random
|
||||
- [ ] rtx: some studio models have glitchy geometry
|
||||
@ -21,6 +17,7 @@
|
||||
Split into 2 buffers:
|
||||
struct LightCluster { uint16 offset, length; }
|
||||
uint8_t data[];
|
||||
- [ ] rtx: alpha test/blending
|
||||
|
||||
# Planned
|
||||
- [ ] rtx: denoise
|
||||
@ -211,3 +208,7 @@
|
||||
- [x] rtx: light intensity-based light clusters visibility
|
||||
- [x] rtx: check multiple variants of texture name (wad and non-wad)
|
||||
- [x] rtx: rad liquids/xeno/... textures
|
||||
|
||||
## 2021-04-22
|
||||
- [x] rtx: fix backlight glitch
|
||||
- [x] rtx: textures
|
||||
|
@ -70,6 +70,7 @@ struct Kusok {
|
||||
uint vertex_offset;
|
||||
uint triangles;
|
||||
uint is_emissive;
|
||||
uint texture;
|
||||
//vec4 emissive;
|
||||
};
|
||||
|
||||
@ -137,6 +138,9 @@ layout (set = 0, binding = 9, align = 1) readonly buffer UBOLightClusters {
|
||||
LightCluster clusters[MAX_LIGHT_CLUSTERS];
|
||||
} light_grid;
|
||||
|
||||
layout (constant_id = 6) const uint MAX_TEXTURES = 4096;
|
||||
layout (set = 0, binding = 10) uniform sampler2D textures[MAX_TEXTURES];
|
||||
|
||||
layout (push_constant) uniform PC {
|
||||
float t;
|
||||
int bounces;
|
||||
@ -314,8 +318,8 @@ void main() {
|
||||
|
||||
//C = normal * .5 + .5; break;
|
||||
|
||||
// TODO read from texture
|
||||
const vec3 baseColor = vec3(1.);
|
||||
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 vec3 baseColor = pow(texture(textures[kusochki[kusok_index].texture], texture_uv).rgb, vec3(2.));
|
||||
|
||||
const ivec3 light_cell = ivec3(floor(pos / LIGHT_GRID_CELL_SIZE)) - light_grid.grid_min;
|
||||
const uint cluster_index = uint(dot(light_cell, ivec3(1, light_grid.grid_size.x, light_grid.grid_size.x * light_grid.grid_size.y)));
|
||||
@ -447,7 +451,7 @@ void main() {
|
||||
|
||||
kc *= .9;
|
||||
//const float rough = .4;
|
||||
const float rough = .3 * hash(.01 * dot(floor((inverse(mat4(transform)) * vec4(pos, 1.))/10.).xyz, vec3(1.)));
|
||||
const float rough = .3;// * hash(.01 * dot(floor((inverse(mat4(transform)) * vec4(pos, 1.))/10.).xyz, vec3(1.)));
|
||||
O = pos + .01 * normal;
|
||||
// TODO this is totally not correct
|
||||
D = normalize(mix(
|
||||
|
@ -42,6 +42,7 @@ typedef struct {
|
||||
uint32_t vertex_offset;
|
||||
uint32_t triangles;
|
||||
uint32_t debug_is_emissive;
|
||||
uint32_t texture;
|
||||
//float sad_padding_[1];
|
||||
} vk_kusok_data_t;
|
||||
|
||||
@ -488,6 +489,7 @@ void VK_RayFrameEnd(const vk_ray_frame_render_args_t* args)
|
||||
.offset = 0,
|
||||
.range = VK_WHOLE_SIZE,
|
||||
};
|
||||
VkDescriptorImageInfo dii_all_textures[MAX_TEXTURES];
|
||||
const VkWriteDescriptorSet wds[] = {
|
||||
{
|
||||
.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET,
|
||||
@ -579,8 +581,26 @@ void VK_RayFrameEnd(const vk_ray_frame_render_args_t* args)
|
||||
.dstArrayElement = 0,
|
||||
.pBufferInfo = &dbi_light_leaves,
|
||||
},
|
||||
{
|
||||
.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET,
|
||||
.dstBinding = 10,
|
||||
.dstArrayElement = 0,
|
||||
.descriptorCount = ARRAYSIZE(dii_all_textures),
|
||||
.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER,
|
||||
.dstSet = g_rtx.desc_set,
|
||||
.pImageInfo = dii_all_textures,
|
||||
},
|
||||
};
|
||||
|
||||
for (int i = 0; i < MAX_TEXTURES; ++i) {
|
||||
const vk_texture_t *texture = findTexture(i);
|
||||
const qboolean exists = texture->vk.image_view != VK_NULL_HANDLE;
|
||||
dii_all_textures[i].sampler = VK_NULL_HANDLE;
|
||||
dii_all_textures[i].imageView = exists ? texture->vk.image_view : findTexture(tglob.defaultTexture)->vk.image_view;
|
||||
ASSERT(dii_all_textures[i].imageView != VK_NULL_HANDLE);
|
||||
dii_all_textures[i].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
|
||||
}
|
||||
|
||||
vkUpdateDescriptorSets(vk_core.device, ARRAYSIZE(wds), wds, 0, NULL);
|
||||
}
|
||||
}
|
||||
@ -686,7 +706,9 @@ void VK_RayFrameEnd(const vk_ray_frame_render_args_t* args)
|
||||
}
|
||||
|
||||
static void createLayouts( void ) {
|
||||
VkDescriptorSetLayoutBinding bindings[] = {{
|
||||
VkSampler samplers[MAX_TEXTURES];
|
||||
|
||||
VkDescriptorSetLayoutBinding bindings[] = {{
|
||||
.binding = 0,
|
||||
.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE,
|
||||
.descriptorCount = 1,
|
||||
@ -736,15 +758,25 @@ static void createLayouts( void ) {
|
||||
.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER,
|
||||
.descriptorCount = 1,
|
||||
.stageFlags = VK_SHADER_STAGE_COMPUTE_BIT,
|
||||
}, {
|
||||
.binding = 10,
|
||||
.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER,
|
||||
.descriptorCount = MAX_TEXTURES,
|
||||
.stageFlags = VK_SHADER_STAGE_COMPUTE_BIT,
|
||||
.pImmutableSamplers = samplers,
|
||||
},
|
||||
};
|
||||
|
||||
VkDescriptorSetLayoutCreateInfo dslci = {.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, .bindingCount = ARRAYSIZE(bindings), .pBindings = bindings, };
|
||||
|
||||
VkPushConstantRange push_const = {0};
|
||||
push_const.offset = 0;
|
||||
push_const.size = sizeof(vk_rtx_push_constants_t);
|
||||
push_const.stageFlags = VK_SHADER_STAGE_COMPUTE_BIT;
|
||||
VkPushConstantRange push_const = {
|
||||
.offset = 0,
|
||||
.size = sizeof(vk_rtx_push_constants_t),
|
||||
.stageFlags = VK_SHADER_STAGE_COMPUTE_BIT,
|
||||
};
|
||||
|
||||
for (int i = 0; i < ARRAYSIZE(samplers); ++i)
|
||||
samplers[i] = vk_core.default_sampler;
|
||||
|
||||
XVK_CHECK(vkCreateDescriptorSetLayout(vk_core.device, &dslci, NULL, &g_rtx.desc_layout));
|
||||
|
||||
@ -983,6 +1015,9 @@ qboolean VK_RayModelInit( vk_ray_model_init_t args ) {
|
||||
kusochki[i].triangles = prim_count;
|
||||
kusochki[i].debug_is_emissive = is_emissive;
|
||||
|
||||
// TODO animated textures
|
||||
kusochki[i].texture = mg->texture;
|
||||
|
||||
// TODO this is bad. there should be another way to tie kusochki index to emissive surface index
|
||||
if (is_emissive && mg->surface_index >= 0) {
|
||||
vk_emissive_kusochki_t *ek = g_rtx.emissive_kusochki_buffer.mapped;
|
||||
|
Loading…
Reference in New Issue
Block a user