mirror of
https://github.com/w23/xash3d-fwgs
synced 2024-12-17 06:30:44 +01:00
rtx: add broken sun sampling
i cant into math. sun direction is completely incorrect
This commit is contained in:
parent
f8b0b8c672
commit
100ba22f0e
@ -40,6 +40,7 @@ struct EmissiveKusok {
|
||||
layout (set = 0, binding = 7/*, align=4*/) uniform Lights {
|
||||
uint num_kusochki;
|
||||
uint num_point_lights;
|
||||
vec3 sun_dir, sun_color;
|
||||
EmissiveKusok kusochki[MAX_EMISSIVE_KUSOCHKI];
|
||||
PointLight point_lights[MAX_POINT_LIGHTS];
|
||||
} lights;
|
||||
@ -125,6 +126,17 @@ vec3 sampleSurfaceTriangle(vec3 view_dir, MaterialProperties material, mat4x3 em
|
||||
return evalCombinedBRDF(payload.normal, light_dir, view_dir, material) / pdf;
|
||||
}
|
||||
|
||||
vec3 sampleSun(vec3 view_dir, MaterialProperties material) {
|
||||
const float light_dot = dot(lights.sun_dir, payload.normal);
|
||||
if (light_dot <= 1e-5)
|
||||
return vec3(0.);
|
||||
|
||||
if (shadowed(payload.hit_pos_t.xyz, lights.sun_dir, 1e5))
|
||||
return vec3(0.);
|
||||
|
||||
return lights.sun_color * light_dot * evalCombinedBRDF(payload.normal, lights.sun_dir, view_dir, material);
|
||||
}
|
||||
|
||||
vec3 computeLighting(vec3 view_dir, MaterialProperties material) {
|
||||
vec3 C = vec3(0.);
|
||||
const ivec3 light_cell = ivec3(floor(payload.hit_pos_t.xyz / LIGHT_GRID_CELL_SIZE)) - light_grid.grid_min;
|
||||
@ -208,6 +220,8 @@ vec3 computeLighting(vec3 view_dir, MaterialProperties material) {
|
||||
} // for all lights
|
||||
}
|
||||
|
||||
C += sampleSun(view_dir, material);
|
||||
|
||||
return C;
|
||||
}
|
||||
|
||||
|
@ -1,14 +1,34 @@
|
||||
#version 460 core
|
||||
#extension GL_GOOGLE_include_directive : require
|
||||
#include "ray_common.glsl"
|
||||
#include "ray_kusochki.glsl"
|
||||
|
||||
layout (constant_id = 0) const uint MAX_POINT_LIGHTS = 32;
|
||||
layout (constant_id = 1) const uint MAX_EMISSIVE_KUSOCHKI = 256;
|
||||
|
||||
// TODO #include, use from here and regular shader
|
||||
struct EmissiveKusok {
|
||||
uint kusok_index;
|
||||
vec4 tx_row_x, tx_row_y, tx_row_z;
|
||||
};
|
||||
|
||||
layout (set = 0, binding = 7/*, align=4*/) uniform Lights {
|
||||
uint num_kusochki;
|
||||
uint num_point_lights;
|
||||
vec3 sun_dir, sun_color;
|
||||
EmissiveKusok kusochki[MAX_EMISSIVE_KUSOCHKI];
|
||||
PointLight point_lights[MAX_POINT_LIGHTS];
|
||||
} lights;
|
||||
|
||||
layout(location = 0) rayPayloadInEXT RayPayload payload;
|
||||
|
||||
void main() {
|
||||
const float sun_dot = max(0., dot(gl_WorldRayDirectionEXT, lights.sun_dir));
|
||||
payload.hit_pos_t = vec4(-1.);
|
||||
payload.geometry_normal = payload.normal = vec3(0., 1., 0.);
|
||||
payload.reflection = 0.;
|
||||
payload.roughness = 0.;
|
||||
payload.base_color = vec3(1., 0., 1.);
|
||||
payload.base_color = vec3(0.);//mix(vec3(.1, .2, .7), lights.sun_color, pow(sun_dot, 100.));
|
||||
//vec3(1., 0., 1.);
|
||||
payload.kusok_index = -1;
|
||||
}
|
||||
|
@ -383,7 +383,7 @@ static qboolean renderableSurface( const msurface_t *surf, int i ) {
|
||||
}
|
||||
|
||||
if( FBitSet( surf->flags, SURF_DRAWSKY )) {
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
if( FBitSet( surf->flags, SURF_DRAWTILED )) {
|
||||
@ -398,7 +398,7 @@ typedef struct {
|
||||
int num_surfaces, num_vertices, num_indices;
|
||||
int max_texture_id;
|
||||
int water_surfaces;
|
||||
int sky_surfaces;
|
||||
//int sky_surfaces;
|
||||
} model_sizes_t;
|
||||
|
||||
static model_sizes_t computeSizes( const model_t *mod ) {
|
||||
@ -409,7 +409,7 @@ static model_sizes_t computeSizes( const model_t *mod ) {
|
||||
const msurface_t *surf = mod->surfaces + mod->firstmodelsurface + i;
|
||||
|
||||
sizes.water_surfaces += !!(surf->flags & (SURF_DRAWTURB | SURF_DRAWTURB_QUADS));
|
||||
sizes.sky_surfaces += !!(surf->flags & SURF_DRAWSKY);
|
||||
//sizes.sky_surfaces += !!(surf->flags & SURF_DRAWSKY);
|
||||
|
||||
if (!renderableSurface(surf, i))
|
||||
continue;
|
||||
|
@ -156,6 +156,7 @@ static void loadRadData( const model_t *map, const char *fmt, ... ) {
|
||||
X(2, float, pitch, Float) \
|
||||
X(3, vec3_t, _light, Rgbav) \
|
||||
X(4, class_name_e, classname, Classname) \
|
||||
X(5, float, angle, Float) \
|
||||
|
||||
typedef enum {
|
||||
Unknown = 0,
|
||||
@ -224,6 +225,8 @@ static unsigned parseEntPropClassname(const string value, class_name_e *out, uns
|
||||
|
||||
static void parseStaticLightEntities( void ) {
|
||||
g_light_entities.num_lights = 0;
|
||||
VectorSet(g_lights.map.sun_dir, 0, 0, 0);
|
||||
VectorSet(g_lights.map.sun_color, 0, 0, 0);
|
||||
|
||||
const model_t* const world = gEngine.pfnGetModelByIndex( 1 );
|
||||
char *pos;
|
||||
@ -269,6 +272,48 @@ static void parseStaticLightEntities( void ) {
|
||||
case LightSpot:
|
||||
// TODO
|
||||
break;
|
||||
|
||||
case LightEnvironment:
|
||||
{
|
||||
float angle = values.angle;
|
||||
vec3_t dir = {0};
|
||||
|
||||
const unsigned need_fields = Field__light;
|
||||
if (have_fields & need_fields != need_fields) {
|
||||
gEngine.Con_Printf(S_ERROR "Missing _light prop for light_environment\n");
|
||||
continue;
|
||||
}
|
||||
|
||||
if (angle == -1) { // UP
|
||||
dir[0] = dir[1] = 0;
|
||||
dir[2] = 1;
|
||||
} else if (angle == -2) { // DOWN
|
||||
dir[0] = dir[1] = 0;
|
||||
dir[2] = -1;
|
||||
} else {
|
||||
if (angle == 0) {
|
||||
angle = values.angles[1];
|
||||
}
|
||||
|
||||
angle *= M_PI / 180.f;
|
||||
|
||||
dir[2] = 0;
|
||||
dir[0] = cosf(angle);
|
||||
dir[1] = sinf(angle);
|
||||
}
|
||||
|
||||
angle = values.pitch ? values.pitch : values.angles[0];
|
||||
|
||||
angle *= M_PI / 180.f;
|
||||
dir[2] = sinf(angle);
|
||||
dir[0] *= cosf(angle);
|
||||
dir[1] *= cosf(angle);
|
||||
|
||||
VectorScale(dir, -1.f, g_lights.map.sun_dir);
|
||||
//VectorCopy(dir, g_lights.map.sun_dir);
|
||||
VectorCopy(values._light, g_lights.map.sun_color);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
continue;
|
||||
|
@ -38,6 +38,9 @@ typedef struct {
|
||||
int grid_cells;
|
||||
|
||||
vk_emissive_texture_t emissive_textures[MAX_TEXTURES];
|
||||
|
||||
vec3_t sun_color;
|
||||
vec3_t sun_dir;
|
||||
} map;
|
||||
|
||||
int num_emissive_surfaces;
|
||||
|
@ -31,7 +31,11 @@ typedef struct Kusok vk_kusok_data_t;
|
||||
typedef struct {
|
||||
uint32_t num_kusochki;
|
||||
uint32_t num_point_lights;
|
||||
uint32_t padding__[2];
|
||||
uint32_t padding__1[2];
|
||||
vec3_t sun_dir;
|
||||
uint32_t padding__2[1];
|
||||
vec3_t sun_color;
|
||||
uint32_t padding__3[1];
|
||||
struct {
|
||||
uint32_t kusok_index;
|
||||
uint32_t padding__[3];
|
||||
|
@ -671,6 +671,10 @@ static void updateLights( void )
|
||||
Vector4Copy(g_lights.point_lights[i].origin, ek->point_lights[i].position);
|
||||
Vector4Copy(g_lights.point_lights[i].color, ek->point_lights[i].color);
|
||||
}
|
||||
|
||||
//VectorCopy(g_lights.map.sun_color, ek->sun_color);
|
||||
VectorScale(g_lights.map.sun_color, 50, ek->sun_color);
|
||||
VectorCopy(g_lights.map.sun_dir, ek->sun_dir);
|
||||
}
|
||||
}
|
||||
|
||||
@ -918,7 +922,7 @@ static void createLayouts( void ) {
|
||||
.binding = RayDescBinding_Lights,
|
||||
.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
|
||||
.descriptorCount = 1,
|
||||
.stageFlags = VK_SHADER_STAGE_RAYGEN_BIT_KHR,
|
||||
.stageFlags = VK_SHADER_STAGE_RAYGEN_BIT_KHR | VK_SHADER_STAGE_MISS_BIT_KHR,
|
||||
};
|
||||
|
||||
g_rtx.desc_bindings[RayDescBinding_LightClusters] = (VkDescriptorSetLayoutBinding){
|
||||
|
Loading…
Reference in New Issue
Block a user