forked from FWGS/xash3d-fwgs
-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
173 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
#version 460 core | ||
#extension GL_GOOGLE_include_directive : require | ||
#extension GL_EXT_nonuniform_qualifier : enable | ||
#extension GL_EXT_ray_query: require | ||
|
||
#define RAY_QUERY | ||
layout(local_size_x = 8, local_size_y = 8, local_size_z = 1) in; | ||
|
||
#include "ray_primary_common.glsl" | ||
#include "ray_primary_hit.glsl" | ||
|
||
#define X(index, name, format) layout(set=0,binding=index,format) uniform writeonly image2D out_##name; | ||
RAY_PRIMARY_OUTPUTS(X) | ||
#undef X | ||
|
||
layout(set = 0, binding = 1) uniform accelerationStructureEXT tlas; | ||
|
||
void main() { | ||
const ivec2 pix = ivec2(gl_GlobalInvocationID); | ||
const ivec2 res = ivec2(imageSize(out_position_t)); | ||
if (any(greaterThanEqual(pix, res))) { | ||
return; | ||
} | ||
const vec2 uv = (gl_GlobalInvocationID.xy + .5) / res * 2. - 1.; | ||
|
||
// FIXME start on a near plane | ||
const vec3 origin = (ubo.ubo.inv_view * vec4(0, 0, 0, 1)).xyz; | ||
const vec4 target = ubo.ubo.inv_proj * vec4(uv.x, uv.y, 1, 1); | ||
const vec3 direction = normalize((ubo.ubo.inv_view * vec4(target.xyz, 0)).xyz); | ||
|
||
RayPayloadPrimary payload; | ||
payload.hit_t = vec4(0.); | ||
payload.base_color_a = vec4(0.); | ||
payload.normals_gs = vec4(0.); | ||
payload.material_rmxx = vec4(0.); | ||
payload.emissive = vec4(0.); | ||
|
||
rayQueryEXT rq; | ||
const uint flags = 0 | ||
| gl_RayFlagsCullFrontFacingTrianglesEXT | ||
//| gl_RayFlagsOpaqueEXT | ||
//| gl_RayFlagsTerminateOnFirstHitEXT | ||
//| gl_RayFlagsSkipClosestHitShaderEXT | ||
; | ||
const float L = 10000.; // TODO Why 10k? | ||
rayQueryInitializeEXT(rq, tlas, flags, GEOMETRY_BIT_OPAQUE, origin, 0., direction, L); | ||
// TODO alpha test | ||
while (rayQueryProceedEXT(rq)) { } | ||
if (rayQueryGetIntersectionTypeEXT(rq, true) == gl_RayQueryCommittedIntersectionTriangleEXT) { | ||
primaryRayHit(rq, payload); | ||
} | ||
|
||
imageStore(out_position_t, pix, payload.hit_t); | ||
imageStore(out_base_color_a, pix, payload.base_color_a); | ||
imageStore(out_normals_gs, pix, payload.normals_gs); | ||
imageStore(out_material_rmxx, pix, payload.material_rmxx); | ||
imageStore(out_emissive, pix, payload.emissive); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
#ifndef RAY_PRIMARY_HIT_GLSL_INCLUDED | ||
#define RAY_PRIMARY_HIT_GLSL_INCLUDED | ||
#extension GL_EXT_nonuniform_qualifier : enable | ||
|
||
#include "utils.glsl" | ||
#include "ray_primary_common.glsl" | ||
#include "ray_kusochki.glsl" | ||
#include "rt_geometry.glsl" | ||
#include "color_spaces.glsl" | ||
|
||
layout(set = 0, binding = 6) uniform sampler2D textures[MAX_TEXTURES]; | ||
layout(set = 0, binding = 2) uniform UBO { UniformBuffer ubo; } ubo; | ||
layout(set = 0, binding = 7) uniform samplerCube skybox; | ||
|
||
vec4 sampleTexture(uint tex_index, vec2 uv, vec4 uv_lods) { | ||
return textureGrad(textures[nonuniformEXT(tex_index)], uv, uv_lods.xy, uv_lods.zw); | ||
} | ||
|
||
void primaryRayHit(rayQueryEXT rq, inout RayPayloadPrimary payload) { | ||
Geometry geom = readHitGeometry(rq, ubo.ubo.ray_cone_width, rayQueryGetIntersectionBarycentricsEXT(rq, true)); | ||
const float hitT = rayQueryGetIntersectionTEXT(rq, true); //gl_HitTEXT; | ||
const vec3 rayDirection = rayQueryGetWorldRayDirectionEXT(rq); //gl_WorldRayDirectionEXT | ||
payload.hit_t = vec4(geom.pos, hitT); | ||
|
||
const Kusok kusok = getKusok(geom.kusok_index); | ||
const uint tex_base_color = kusok.tex_base_color; | ||
|
||
if ((tex_base_color & KUSOK_MATERIAL_FLAG_SKYBOX) != 0) { | ||
payload.emissive.rgb = SRGBtoLINEAR(texture(skybox, rayDirection).rgb); | ||
return; | ||
} else { | ||
payload.base_color_a = sampleTexture(tex_base_color, geom.uv, geom.uv_lods) * kusok.color; | ||
payload.material_rmxx.r = (kusok.tex_roughness > 0) ? sampleTexture(kusok.tex_roughness, geom.uv, geom.uv_lods).r : kusok.roughness; | ||
payload.material_rmxx.g = (kusok.tex_metalness > 0) ? sampleTexture(kusok.tex_metalness, geom.uv, geom.uv_lods).r : kusok.metalness; | ||
|
||
const uint tex_normal = kusok.tex_normalmap; | ||
vec3 T = geom.tangent; | ||
if (tex_normal > 0 && dot(T,T) > .5) { | ||
T = normalize(T - dot(T, geom.normal_shading) * geom.normal_shading); | ||
const vec3 B = normalize(cross(geom.normal_shading, T)); | ||
const mat3 TBN = mat3(T, B, geom.normal_shading); | ||
const vec3 tnorm = sampleTexture(tex_normal, geom.uv, geom.uv_lods).xyz * 2. - 1.; // TODO is this sampling correct for normal data? | ||
geom.normal_shading = normalize(TBN * tnorm); | ||
} | ||
} | ||
|
||
payload.normals_gs.xy = normalEncode(geom.normal_geometry); | ||
payload.normals_gs.zw = normalEncode(geom.normal_shading); | ||
|
||
#if 1 | ||
// Real correct emissive color | ||
//payload.emissive.rgb = kusok.emissive; | ||
payload.emissive.rgb = clamp(kusok.emissive / (1.0/3.0) / 25, 0, 1.5) * SRGBtoLINEAR(payload.base_color_a.rgb); | ||
#else | ||
// Fake texture color | ||
if (any(greaterThan(kusok.emissive, vec3(0.)))) | ||
payload.emissive.rgb = payload.base_color_a.rgb; | ||
#endif | ||
} | ||
|
||
#endif // ifndef RAY_PRIMARY_HIT_GLSL_INCLUDED |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters