Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

V3.8.5 ray query #17719

Draft
wants to merge 106 commits into
base: v3.8.5
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
106 commits
Select commit Hold shift + click to select a range
71c899e
add acceleration structure
Makalou Sep 28, 2022
284cbc4
Implement VKaccelerationStructure compaction
Makalou Oct 9, 2022
aaa4061
add accelStruct chunk and ray query effect
Makalou Oct 9, 2022
b6448c5
fix some bugs
Makalou Oct 13, 2022
3503481
add some ray query effect
Makalou Oct 13, 2022
3473df3
add glslV460 support
Makalou Oct 13, 2022
3796d35
add effect compiler acceleration structure support
Makalou Oct 13, 2022
af4c385
fix some bugs
Makalou Oct 13, 2022
c44d453
fix some bugs
Makalou Oct 13, 2022
7893aaa
add accelerationstructure Ref se-to-native support
Makalou Oct 14, 2022
ce0ceab
memory barrier bugs
Makalou Oct 14, 2022
0a71a2d
refactor
Makalou Oct 14, 2022
603002f
fix device memory leak
Makalou Oct 17, 2022
993e0d0
change VKAccelerationStructure instanceData buffer upload schema
Makalou Oct 17, 2022
3be1113
fix accel struct descriptor invalid issue
Makalou Oct 18, 2022
df2e629
add AABB blas (memory leak)
Makalou Oct 18, 2022
c489843
add AABB blas (mem leak fixed)
Makalou Oct 18, 2022
62f179b
reformat
Makalou Oct 18, 2022
38bbc2d
dummy implementations for Acceleration Structure on unsupport platforms
Makalou Oct 18, 2022
5ebf592
change CMakeList
Makalou Oct 18, 2022
6605f13
Merge branch 'develop' into gfx-ray-query
Makalou Oct 18, 2022
6645c04
merge develop gfx-ray-query
Makalou Oct 18, 2022
c3d7558
dummy implementations for device and commandbuffer
Makalou Oct 18, 2022
4978af4
modify
Makalou Oct 18, 2022
7be44d3
fix vkbuffer leak
Makalou Oct 19, 2022
dcc94d2
fix jsb_conversion_spec
Makalou Oct 19, 2022
adccc03
reformat
Makalou Oct 19, 2022
6c57b56
rename
Makalou Oct 19, 2022
9d29f87
rename
Makalou Oct 19, 2022
3614b40
fix small bug
Makalou Oct 19, 2022
8475e7b
fix include files missing
Makalou Oct 19, 2022
e73c8ff
refactor fillBlasInfo
Makalou Oct 20, 2022
50de0b8
refactor
Makalou Oct 20, 2022
978ecf2
refactor
Makalou Oct 20, 2022
0029c27
refactor
Makalou Oct 20, 2022
c29dfcb
Merge branch 'develop' into gfx-ray-query
Makalou Oct 20, 2022
dcd8124
Merge branch 'develop' into gfx-ray-query
Makalou Oct 24, 2022
174b5bf
defered lighting
Makalou Oct 25, 2022
a07e068
Merge branch 'develop' into gfx-ray-query
Makalou Oct 25, 2022
94d403f
add shadow ray shading
Makalou Oct 27, 2022
1d24101
Merge branch 'develop' into gfx-ray-query
Makalou Oct 27, 2022
a21d51f
add stochastic AO
Makalou Oct 28, 2022
1adda81
Merge branch 'develop' into gfx-ray-query
Makalou Oct 28, 2022
fb57d5d
Refactor
Makalou Oct 31, 2022
84b44ce
Merge branch 'develop' into gfx-ray-query
Makalou Oct 31, 2022
94b2294
refactor
Makalou Nov 1, 2022
8d5dadb
Merge branch 'develop' into gfx-ray-query
Makalou Nov 1, 2022
b9ccd2f
scene desc experiment
Makalou Nov 2, 2022
d3ea42c
Merge branch 'develop' into gfx-ray-query
Makalou Nov 2, 2022
f8d9ada
scene desc experiment refactor
Makalou Nov 7, 2022
ba67a9e
Merge branch 'develop' into gfx-ray-query
Makalou Nov 7, 2022
e6aa3af
refactor
Makalou Nov 7, 2022
17ce24a
add blue noise
Makalou Nov 9, 2022
36aec0c
try add rtpipeline but trigger gfxBuffer bug
Makalou Nov 10, 2022
6954df0
fix gfx::buffer bug
Makalou Nov 10, 2022
e19ef05
comment unused function
Makalou Nov 11, 2022
30d57cf
Merge branch 'develop' into gfx-ray-query
Makalou Nov 11, 2022
88a8cf3
refactor rtpipeline creation"
Makalou Nov 11, 2022
543e087
refactor
Makalou Nov 11, 2022
41cd937
add hit group SBT
Makalou Nov 11, 2022
25c701b
merge develop to gfx-ray-query
Makalou Nov 14, 2022
8775b21
refactor
Makalou Nov 14, 2022
d8cd5c7
rtpipeline
Makalou Nov 14, 2022
e1feb29
refactor
Makalou Nov 14, 2022
bd94dff
Merge branch 'develop' into gfx-ray-query
Makalou Nov 14, 2022
4a56034
refactor
Makalou Nov 15, 2022
6d2cc60
Merge branch 'develop' into gfx-ray-query
Makalou Nov 15, 2022
7a2d648
Merge branch 'develop' into gfx-ray-query
Makalou Nov 15, 2022
d24a730
Merge branch 'develop' into gfx-ray-query
Makalou Nov 16, 2022
995fdfe
refactor
Makalou Nov 16, 2022
b19d64e
refactor
Makalou Nov 17, 2022
5896a0e
refactor
Makalou Nov 17, 2022
8f235be
refactor
Makalou Nov 17, 2022
4687229
refactor
Makalou Nov 18, 2022
53f2c87
refactor
Makalou Nov 18, 2022
8cf9e7d
refactor
Makalou Nov 18, 2022
567e323
refactor
Makalou Nov 18, 2022
ce4d659
refactor
Makalou Nov 21, 2022
28f9ab7
refactor
Makalou Nov 21, 2022
1ab301c
refactor
Makalou Nov 21, 2022
ccf136e
arena allocator
Makalou Nov 22, 2022
3314702
Merge branch 'develop' into gfx-ray-query
Makalou Nov 22, 2022
10631ce
Merge branch 'develop' into gfx-ray-query
Makalou Nov 23, 2022
6f08a99
arena allocatorq
Makalou Nov 23, 2022
1aad8f0
refactor
Makalou Nov 23, 2022
fff7a8d
refactor
Makalou Nov 23, 2022
60c3a8e
Merge branch 'develop' into gfx-ray-query
Makalou Nov 23, 2022
d32d567
Merge branch 'develop' into gfx-ray-query
Makalou Nov 24, 2022
933efa3
refactor
Makalou Nov 25, 2022
9c4e508
Merge branch 'develop' into gfx-ray-query
Makalou Nov 25, 2022
e8cca69
refactor
Makalou Nov 25, 2022
a452e70
refactor
Makalou Nov 29, 2022
c2be24b
Merge branch 'develop' into gfx-ray-query
Makalou Nov 29, 2022
c6dc861
fix acceleration structure scratch buffer alignemen issue
Makalou Nov 29, 2022
fb6947a
refactor
Makalou Nov 29, 2022
c522a69
refactor
Makalou Dec 1, 2022
3b40dea
Merge branch 'develop' into gfx-ray-query
Makalou Dec 1, 2022
3536e81
refactor
Makalou Dec 1, 2022
dac5563
refactor
Makalou Dec 2, 2022
5f2fd95
Merge branch 'develop' into gfx-ray-query
Makalou Dec 2, 2022
92cd779
refactor
Makalou Dec 2, 2022
a415bed
refactor
Makalou Dec 5, 2022
d0d475c
Merge branch 'develop' into gfx-ray-query
Makalou Dec 26, 2022
5131614
reformat
Makalou Jan 3, 2023
c7c47ab
Merge branch 'develop' into gfx-ray-query
Makalou Jan 17, 2023
86b6365
Merge branch 'gfx-ray-query' into v3.8.5-pipeline
star-e Oct 15, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions cocos/asset/assets/effect-asset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,14 @@ export declare namespace EffectAsset {
count: number;
stageFlags: ShaderStageFlags;
}

export interface IIAccelerationStructureInfp{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

II -> I ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Infp -> Info

set: number;
binding: number;
name: string;
count: number;
stageFlags: ShaderStageFlags;
}
export interface IAttributeInfo {
name: string;
format: Format;
Expand Down Expand Up @@ -174,6 +182,7 @@ export declare namespace EffectAsset {
images: IImageInfo[];
subpassInputs: IInputAttachmentInfo[];
descriptors: IDescriptorInfo[];
accelerationStructures: IIAccelerationStructureInfp[];
}
export interface IPreCompileInfo {
[name: string]: boolean[] | number[] | string[];
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

#pragma extension([GL_EXT_ray_query, __VERSION__ >= 460, enable])

#pragma builtin(global)
layout(set = 0, binding = 8) uniform accelerationStructureEXT cc_topLevelAS;

34 changes: 34 additions & 0 deletions editor/assets/chunks/builtin/uniforms/cc-scene-shading-data.chunk
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#pragma extension([GL_EXT_scalar_block_layout, __VERSION__ >= 450, enable])
#pragma extension([GL_EXT_buffer_reference2, __VERSION__ >= 450, require])
#pragma extension([GL_EXT_shader_explicit_arithmetic_types,__VERSION__>=450,enable])

layout(buffer_reference, scalar) readonly buffer IndicesBuffer32 { ivec3 i[]; };
layout(buffer_reference, scalar) readonly buffer IndicesBuffer16 { i16vec3 i[]; };

struct VertexAttributes {
vec3 position;
vec3 normal;
vec2 texCoord;
vec4 tangent;
};

layout(buffer_reference, scalar) readonly buffer VertexAttributesBuffer { VertexAttributes v[];};

struct GeomDesc{
uint64_t indexAddress;
uint64_t vertexAddress;
};

struct MeshDesc
{
uint16_t subMeshGeometryOffset;
uint16_t subMeshMaterialOffset;
uint16_t subMeshCount;
uint16_t padding;
};

#pragma builtin(global)
layout(set = 0, binding = 9) readonly buffer cc_scene_geometry_desc {GeomDesc geomDescs[];};

#pragma builtin(global)
layout(set = 0, binding = 10) readonly buffer cc_scene_instance_desc {MeshDesc instanceDescs[];};
67 changes: 67 additions & 0 deletions editor/assets/chunks/legacy/shading-standard-additive.chunk
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,70 @@ vec4 CCStandardShadingAdditive (StandardSurface s, vec4 shadowPos) {
return vec4(finalColor, 0.0);
}
#endif

#if __VERSION__ >= 460

#pragma extension([GL_EXT_ray_query, __VERSION__ >= 460, enable])

vec4 CCStandardShadingAdditiveShadowRay(in StandardSurface s, in vec3 V,in accelerationStructureEXT as) {
vec3 position;
HIGHP_VALUE_FROM_STRUCT_DEFINED(position, s.position);
// Calculate diffuse & specular
vec3 diffuse = s.albedo.rgb * (1.0 - s.metallic);
vec3 specular = mix(vec3(0.04), s.albedo.rgb, s.metallic);
vec3 diffuseContrib = diffuse / PI;

vec3 N = normalize(s.normal);
float NV = max(abs(dot(N, V)), 0.0);
specular = BRDFApprox(specular, s.roughness, NV);
vec3 finalColor = vec3(0.0);

int numLights = CC_PIPELINE_TYPE == CC_PIPELINE_TYPE_FORWARD ? LIGHTS_PER_PASS : int(cc_lightDir[0].w);

for (int i = 0; i < LIGHTS_PER_PASS; i++) {
if (i >= numLights) break;
vec3 SLU = cc_lightPos[i].xyz - position;
vec3 SL = normalize(SLU);
vec3 SH = normalize(SL + V);
float SNL = max(dot(N, SL), 0.0);
float SNH = max(dot(N, SH), 0.0);

float distSqr = dot(SLU, SLU);
float litRadius = cc_lightSizeRangeAngle[i].x;
float litRadiusSqr = litRadius * litRadius;
float illum = litRadiusSqr / max(litRadiusSqr, distSqr);
float attRadiusSqrInv = 1.0 / max(cc_lightSizeRangeAngle[i].y, 0.01);
attRadiusSqrInv *= attRadiusSqrInv;
float att = GetDistAtt(distSqr, attRadiusSqrInv);
vec3 lspec = specular * CalcSpecular(s.roughness, SNH, SH, N);

if (cc_lightPos[i].w > 0.0) {
float cosInner = max(dot(-cc_lightDir[i].xyz, SL), 0.01);
float cosOuter = cc_lightSizeRangeAngle[i].z;
float litAngleScale = 1.0 / max(0.001, cosInner - cosOuter);
float litAngleOffset = -cosOuter * litAngleScale;
att *= GetAngleAtt(SL, -cc_lightDir[i].xyz, litAngleScale, litAngleOffset);
}

vec3 lightColor = cc_lightColor[i].rgb;

float shadow = 1.0;
rayQueryEXT rayQuery;
rayQueryInitializeEXT(rayQuery,as,gl_RayFlagsTerminateOnFirstHitEXT, 0xFF, position, 0.1f, SL, length(SLU));

while(rayQueryProceedEXT(rayQuery));

if(rayQueryGetIntersectionTypeEXT(rayQuery, true) != gl_RayQueryCommittedIntersectionNoneEXT)
{
float t = rayQueryGetIntersectionTEXT(rayQuery, true);
shadow -= (length(SLU) - t) / length(SLU);
}

lightColor *= shadow;
finalColor += SNL * lightColor * cc_lightColor[i].w * illum * att * (diffuseContrib + lspec);
}

return vec4(finalColor, 0.0);
}

#endif
99 changes: 99 additions & 0 deletions editor/assets/chunks/legacy/shading-standard-base.chunk
Original file line number Diff line number Diff line change
Expand Up @@ -293,3 +293,102 @@ vec4 CCStandardShadingBase (StandardSurface s, vec4 shadowPos) {

return vec4(finalColor, s.albedo.a);
}

#if __VERSION__ >=460

#pragma extension([GL_EXT_ray_query, __VERSION__ >= 460, enable])

vec4 CCStandardShadingBaseShadowRay (in StandardSurface s,in vec3 V,in accelerationStructureEXT as) {
// Calculate diffuse & specular

vec3 diffuse = s.albedo.rgb * (1.0 - s.metallic);
vec3 specular = mix(vec3(0.08 * s.specularIntensity), s.albedo.rgb, s.metallic);

vec3 position;
HIGHP_VALUE_FROM_STRUCT_DEFINED(position, s.position);

vec3 N = normalize(s.normal);
vec3 L = normalize(-cc_mainLitDir.xyz);
float NL = max(dot(N, L), 0.0);

float shadow = 1.0;

rayQueryEXT rayQuery;
rayQueryInitializeEXT(rayQuery,as,gl_RayFlagsTerminateOnFirstHitEXT, 0xFF, position, 0.1f, normalize(vec3(L.x,L.y,L.z)), 10000.0);
while(rayQueryProceedEXT(rayQuery));

if(rayQueryGetIntersectionTypeEXT(rayQuery, true) != gl_RayQueryCommittedIntersectionNoneEXT)
{
shadow = 0.0;
}

#if CC_USE_LIGHTMAP && !CC_FORWARD_ADD
vec3 lightmap = s.lightmap.rgb;
#if CC_USE_HDR
// convert from standard camera exposure parameters to current exposure value
// baked in LDR scene still regarded as exposured with standard camera parameters
lightmap.rgb *= cc_exposure.w * cc_exposure.x;
#endif
vec3 finalColor = diffuse * lightmap.rgb * shadow;
#else
float NV = max(abs(dot(N, V)), 0.0);
specular = BRDFApprox(specular, s.roughness, NV);

vec3 H = normalize(L + V);
float NH = max(dot(N, H), 0.0);
vec3 finalColor = NL * cc_mainLitColor.rgb * cc_mainLitColor.w;
vec3 diffuseContrib = diffuse / PI;

// Cook-Torrance Microfacet Specular BRDF
vec3 specularContrib = specular * CalcSpecular(s.roughness, NH, H, N);
vec3 dirlightContrib = (diffuseContrib + specularContrib);

dirlightContrib *= shadow;
finalColor *= dirlightContrib;
#endif

float fAmb = 0.5 - N.y * 0.5;
vec3 ambDiff = mix(cc_ambientSky.rgb, cc_ambientGround.rgb, fAmb);


#if CC_USE_IBL
#if CC_USE_DIFFUSEMAP && (!CC_LIGHT_PROBE_ENABLED || !CC_USE_LIGHT_PROBE)
// Diffuse reflection irradiance
vec4 diffuseMap = texture(cc_diffuseMap, N);
#if CC_USE_DIFFUSEMAP == IBL_RGBE
ambDiff = unpackRGBE(diffuseMap);
#else
ambDiff = SRGBToLinear(diffuseMap.rgb);
#endif
#endif

vec3 R = normalize(reflect(-V, N));

vec3 rotationDir = RotationVecFromAxisY(R.xyz, cc_surfaceTransform.z, cc_surfaceTransform.w);
#if USE_REFLECTION_DENOISE && !CC_IBL_CONVOLUTED
vec3 env = GetEnvReflectionWithMipFiltering(rotationDir, s.roughness, cc_ambientGround.w, 0.6);
#else
vec4 envmap = fragTextureLod(cc_environment, rotationDir, s.roughness * (cc_ambientGround.w - 1.0));

#if CC_USE_IBL == IBL_RGBE
vec3 env = unpackRGBE(envmap);
#else
vec3 env = SRGBToLinear(envmap.rgb);
#endif
#endif

finalColor += env * cc_ambientSky.w * specular * s.occlusion;
#endif

#if CC_LIGHT_PROBE_ENABLED && CC_USE_LIGHT_PROBE
ambDiff = SHEvaluate(N);
finalColor += ambDiff.rgb * diffuse * s.occlusion;
#else
finalColor += ambDiff.rgb * cc_ambientSky.w * diffuse * s.occlusion;
#endif

finalColor += s.emissive;

return vec4(finalColor, s.albedo.a);
}
#endif
Loading
Loading