@rings-webgpu/core 1.0.1 → 1.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2095,11 +2095,7 @@
2095
2095
  if (!dic) {
2096
2096
  dic = window["__Component__"] = {};
2097
2097
  }
2098
- if (key) {
2099
- dic[key] = cls;
2100
- } else {
2101
- dic[cls.name] = cls;
2102
- }
2098
+ dic[key] = cls;
2103
2099
  }
2104
2100
  function GetComponentClass(name) {
2105
2101
  let coms = window["__Component__"];
@@ -2113,11 +2109,7 @@
2113
2109
  if (!dic) {
2114
2110
  dic = window["__shader__"] = {};
2115
2111
  }
2116
- if (key) {
2117
- dic[key] = cls;
2118
- } else {
2119
- dic[cls.name] = cls;
2120
- }
2112
+ dic[key] = cls;
2121
2113
  }
2122
2114
  function GetShader(name) {
2123
2115
  let coms = window["__shader__"];
@@ -2139,6 +2131,10 @@
2139
2131
  const _Struct = class _Struct {
2140
2132
  __refection;
2141
2133
  __size = 0;
2134
+ /**
2135
+ * get reflection name
2136
+ * @returns
2137
+ */
2142
2138
  getValueType() {
2143
2139
  if (!this.__refection) {
2144
2140
  let self = this;
@@ -2156,6 +2152,11 @@
2156
2152
  }
2157
2153
  return this.__refection;
2158
2154
  }
2155
+ /**
2156
+ * get any type value memory size
2157
+ * @param value any type value
2158
+ * @returns
2159
+ */
2159
2160
  static getValueSize(value) {
2160
2161
  let type = value.constructor.name;
2161
2162
  switch (type) {
@@ -2202,6 +2203,10 @@
2202
2203
  }
2203
2204
  return struct;
2204
2205
  }
2206
+ /**
2207
+ * get any struct memory size
2208
+ * @returns
2209
+ */
2205
2210
  static GetSize(c) {
2206
2211
  let struct = this.Get(c);
2207
2212
  if (struct.__size == 0) {
@@ -4000,511 +4005,559 @@
4000
4005
  `;
4001
4006
 
4002
4007
  class CubeSky_Shader {
4003
- static sky_vs_frag_wgsl = `
4004
- #include "WorldMatrixUniform"
4005
- #include "GlobalUniform"
4008
+ static sky_vs_frag_wgsl = (
4009
+ /* wgsl */
4010
+ `
4011
+ #include "WorldMatrixUniform"
4012
+ #include "GlobalUniform"
4006
4013
 
4007
- struct VertexOutput {
4008
- @location(auto) fragUV: vec2<f32>,
4009
- @location(auto) vClipPos: vec4<f32>,
4010
- @location(auto) vWorldPos: vec4<f32>,
4011
- @location(auto) vWorldNormal: vec3<f32>,
4012
- @builtin(position) member: vec4<f32>
4013
- };
4014
+ struct VertexOutput {
4015
+ @location(auto) fragUV: vec2<f32>,
4016
+ @location(auto) vClipPos: vec4<f32>,
4017
+ @location(auto) vWorldPos: vec4<f32>,
4018
+ @location(auto) vWorldNormal: vec3<f32>,
4019
+ @builtin(position) member: vec4<f32>
4020
+ };
4014
4021
 
4015
- var<private> ORI_VertexOut: VertexOutput;
4022
+ var<private> ORI_VertexOut: VertexOutput ;
4016
4023
 
4017
- @vertex
4018
- fn main {
4019
- @builtin(instance_index) index: u32,
4020
- @location(auto) position: vec3<f32>,
4021
- @location(auto) normal: vec3<f32>,
4022
- @location(auto) uv: vec2<f32>
4023
- } -> VertexOutput {
4024
- ORI_VertexOut.fragUV = uv;
4025
- let modelMat = models.matrix[u32(index)];
4026
- let vm = modelMat;
4027
- let normalMatrix = mat3x3<f32>(vm[0].xyz,vm[1].xyz,vm[2].xyz);
4028
- ORI_VertexOut.vWorldNormal = normalize(normalMatrix * normal);
4029
- ORI_VertexOut.vWorldPos = modelMat * vec4<f32>(position.xyz, 1.0);
4030
-
4031
- var fixProjMat = globalUniform.projMat;
4032
- fixProjMat[2].z = 1.0;
4033
- fixProjMat[3].z = -1.0;
4024
+ @vertex
4025
+ fn main(
4026
+ @builtin(instance_index) index : u32,
4027
+ @location(auto) position: vec3<f32>,
4028
+ @location(auto) normal: vec3<f32>,
4029
+ @location(auto) uv: vec2<f32>
4030
+ ) -> VertexOutput {
4031
+ ORI_VertexOut.fragUV = uv;
4032
+ let modelMat = models.matrix[u32(index)];
4033
+ let vm = modelMat;
4034
+ let normalMatrix = mat3x3<f32>(vm[0].xyz,vm[1].xyz,vm[2].xyz);
4035
+ ORI_VertexOut.vWorldNormal = normalize( normalMatrix * normal );
4036
+ ORI_VertexOut.vWorldPos = modelMat * vec4<f32>(position.xyz,1.0) ;
4037
+
4038
+ var fixProjMat = globalUniform.projMat ;
4039
+ fixProjMat[2].z = 1.0 ;//99999.0 / (99999.0 - 1.0) ;
4040
+ fixProjMat[3].z = -1.0 ;//(-1.0 * 99999.0) / (99999.0 - 1.0) ;
4034
4041
 
4035
- var fixViewMat = globalUniform.viewMat;
4036
- fixViewMat[3].x = 0.0;
4037
- fixViewMat[3].y = 0.0;
4038
- fixViewMat[3].z = 0.0;
4042
+ var fixViewMat = globalUniform.viewMat ;
4043
+ fixViewMat[3].x = 0.0 ;
4044
+ fixViewMat[3].y = 0.0 ;
4045
+ fixViewMat[3].z = 0.0 ;
4039
4046
 
4040
- var clipPos = fixProjMat * fixViewMat * ORI_VertexOut.vWorldPos;
4041
- ORI_VertexOut.vClipPos = clipPos;
4042
- ORI_VertexOut.member = clipPos;
4043
- return ORI_VertexOut;
4044
- }
4045
- `;
4046
- static sky_fs_frag_wgsl = `
4047
- #include "GlobalUniform"
4048
- #include "MathShader"
4049
- #include "BitUtil"
4050
- #include "ColorUtil_frag"
4051
- #include "FragmentOutput"
4047
+ var clipPos = fixProjMat * fixViewMat * ORI_VertexOut.vWorldPos;
4048
+ ORI_VertexOut.vClipPos = clipPos ;
4049
+ ORI_VertexOut.member = clipPos;
4050
+ return ORI_VertexOut;
4051
+ }
4052
+ `
4053
+ );
4054
+ static sky_fs_frag_wgsl = (
4055
+ /* wgsl */
4056
+ `
4057
+ #include "GlobalUniform"
4058
+ #include "MathShader"
4059
+ #include "BitUtil"
4060
+ #include "ColorUtil_frag"
4061
+ #include "FragmentOutput"
4052
4062
 
4053
- struct uniformData {
4054
- exposure: f32,
4055
- roughness: f32
4056
- }
4063
+ struct uniformData {
4064
+ exposure: f32,
4065
+ roughness: f32
4066
+ };
4057
4067
 
4058
- @group(1) @binding(0)
4059
- var baseMapSampler: sampler;
4060
- @group(1) @binding(1)
4061
- var baseMap: texture_cube<f32>;
4068
+ @group(1) @binding(0)
4069
+ var baseMapSampler: sampler;
4070
+ @group(1) @binding(1)
4071
+ var baseMap: texture_cube<f32>;
4062
4072
 
4063
- @group(2) @binding(0)
4064
- var<uniform> global: uniformData;
4073
+ @group(2) @binding(0)
4074
+ var<uniform> global: uniformData;
4065
4075
 
4066
- @fragment
4067
- fn main(@location(auto) fragUV: vec2<f32>,@location(auto) vClipPos: vec4<f32>, @location(auto) vWorldPos: vec4<f32>, @location(auto) vWorldNormal: vec3<f32>, @builtin(position) fragCoord: vec4<f32>) ->FragmentOutPut {
4068
- let maxLevel: u32 = textureNumLevels(baseMap);
4069
- let dir = normalize(vWorldPos.xyz);
4070
- var textureColor: vec3<f32> = textureSampleLevel(baseMap, baseMapSampler, normalize(dir.xyz), global.roughness * f32(maxLevel)).xyz;
4071
- #if IS_HDR_SKY
4072
- textureColor = LinearToGammaSpace(textureColor);
4073
- #endif
4076
+ @fragment
4077
+ fn main(@location(auto) fragUV: vec2<f32>,@location(auto) vClipPos: vec4<f32>, @location(auto) vWorldPos: vec4<f32>, @location(auto) vWorldNormal: vec3<f32> , @builtin(position) fragCoord : vec4<f32> ) -> FragmentOutput {
4078
+ let maxLevel: u32 = textureNumLevels(baseMap);
4079
+ let dir = normalize(vWorldPos.xyz);
4080
+ var textureColor:vec3<f32> = textureSampleLevel(baseMap, baseMapSampler, normalize(dir.xyz), global.roughness * f32(maxLevel) ).xyz;
4081
+ #if IS_HDR_SKY
4082
+ textureColor = LinearToGammaSpace(textureColor);
4083
+ #endif
4074
4084
 
4075
- let o_Target: vec4<f32> = vec4<f32>(textureColor, 1.0) * globalUniform.skyExposure;
4076
- let finalMatrix = globalUniform.projMat * globalUniform.viewMat;
4077
- let nMat = mat3x3<f32>(finalMatrix[0].xyz, finalMatrix[1].xyz, finalMatrix[2].xyz);
4078
- let ORI_NORMALMATRIX = transpose(inverse(nMat));
4085
+ // let o_Target: vec4<f32> = globalUniform.hdrExposure * vec4<f32>(textureColor, 1.0) * globalUniform.skyExposure ;
4086
+ let o_Target: vec4<f32> = vec4<f32>(textureColor, 1.0) * globalUniform.skyExposure;
4087
+ let finalMatrix = globalUniform.projMat * globalUniform.viewMat ;
4088
+ let nMat = mat3x3<f32>(finalMatrix[0].xyz,finalMatrix[1].xyz,finalMatrix[2].xyz) ;
4089
+ let ORI_NORMALMATRIX = transpose(inverse( nMat ));
4090
+
4091
+ var vNormal = (ORI_NORMALMATRIX * -vWorldNormal );
4092
+ var gBuffer = packGBuffer(
4093
+ -globalUniform.far,
4094
+ vec3f(0.0),
4095
+ o_Target.rgb,
4096
+ vec3f(0.0),
4097
+ vNormal
4098
+ ) ;
4099
+ var fragmentOutput:FragmentOutput;
4100
+ #if USE_CASTREFLECTION
4101
+ fragmentOutput.gBuffer = gBuffer ;
4102
+ #else
4103
+ fragmentOutput.color = o_Target ;
4104
+ fragmentOutput.gBuffer = gBuffer ;
4105
+ #endif
4106
+ return fragmentOutput;
4107
+ }
4079
4108
 
4080
- var vNormal = (ORI_NORMALMATRIX - vWorldNormal);
4081
- var gBuffer = packGBuffer(
4082
- -globalUniform.far,
4083
- vec3f(0.0),
4084
- o_Target.rgb,
4085
- vec3f(0.0),
4086
- vNormal
4087
- );
4109
+ fn packGBuffer(depth:f32, albedo:vec3f,hdrLighting:vec3f,rmao:vec3f,normal:vec3f) -> vec4f{
4110
+ var gBuffer : vec4f ;
4111
+ var octUVNormal = (octEncode(normalize(normal)) + 1.0) * 0.5 ;
4088
4112
 
4089
- var fragmentOutput: FragmentOutput;
4090
- #if USE_CASTREFLECTION
4091
- fragmentOutput.gBuffer = gBuffer;
4092
- #else
4093
- fragmentOutput.color = o_Target;
4094
- fragmentOutput.gBuffer = gBuffer;
4095
- #endif
4096
- return fragmentOutput;
4097
- }
4113
+ var yc = f32(r11g11b9_to_float(vec3f(octUVNormal,0.0))) ;
4114
+ #if USE_CASTREFLECTION
4115
+ var rgbm = EncodeRGBM(hdrLighting);
4116
+ var zc = f32(pack4x8unorm(vec4f(rgbm.rgb,0.0))) ;
4117
+ var wc = f32(pack4x8unorm(vec4f(rmao.rg,rgbm.a,0.0)));
4118
+ #else
4119
+ var zc = f32(vec4fToFloat_7bits(vec4f(albedo.rgb,0.0)));
4120
+ var wc = f32(r22g8_to_float(vec2f(f32(0.0),rmao.g)));
4121
+ #endif
4122
+
4123
+ gBuffer.x = depth ;
4124
+ gBuffer.y = yc ;
4125
+ gBuffer.z = zc ;
4126
+ gBuffer.w = wc ;
4127
+ return gBuffer ;
4128
+ }
4129
+ `
4130
+ );
4131
+ }
4098
4132
 
4099
- fn packGBuffer(depth:f32, albedo:vec3f, hdrLighting:vec3f, ramo:vec3f, normal:vec3f) -> vec4f{
4100
- var gBuffer: vec4f;
4101
- var octUVNormal = (octEncode(normalize(normal)) + 1.0) * 0.5;
4102
- var yc = f32(r11g11b9_to_float(vec3f(octUVNormal,0.0)));
4103
-
4104
- #if USE_CASTREFLECTION
4105
- var rgbm = EncodeRGBM(hdrLighting);
4106
- var zc = f32(pack4x8unorm(vec4f(rgbm.rgb,0.0)));
4107
- var wc = f32(pack4x8unorm(vec4f(rmao.rg,rgbm.a,0.0)));
4108
- #else
4109
- var zc = f32(vec4ToFloat_7bits(vec4f(albedo.rgb,0.0)));
4110
- var wc = f32(r22g8_to_float(vec2f(f32(0.0),rmao.g)))
4111
- #endif
4133
+ let LightingFunction_frag = (
4134
+ /*wgsl*/
4135
+ `
4136
+ #include "BRDF_frag"
4137
+ #include "ClusterLight"
4138
+ #include "ShadowMapping_frag"
4112
4139
 
4113
- gBuffer.x = depth;
4114
- gBuffer.y = yc;
4115
- gBuffer.z = zc;
4116
- gBuffer.w = wc;
4117
- return gBuffer;
4118
- }
4119
- `;
4120
- }
4140
+ #if USE_IES_PROFILE
4141
+ #include "IESProfiles_frag"
4142
+ #endif
4121
4143
 
4122
- let LightingFunction_frag = `
4123
- #include "BRDF_frag"
4124
- #include "ClusterLight"
4125
- #include "ShadowMapping_frag"
4144
+ const PI2 = 3.1415926 * 3.1415926 ;
4126
4145
 
4127
- #if USE_IES_PROFILE
4128
- #include "IESProfiles_frag"
4129
- #endif
4146
+ fn sampleLighting(light:LightData,direction:vec3f,iblSpecularResult:vec3f , intensity :f32 , shadow:f32 ) -> vec3f{
4147
+ var ret = vec3f(0.0);
4148
+ var normalDir = fragData.N;
4149
+ var viewDir = fragData.V;
4130
4150
 
4131
- const PI2 = 3.1415926 * 3.1415926;
4132
-
4133
- fn sampleLighting(light:LightData, direction:vec3f, iblSpecularResult:vec3f, intensity: f32, shadow: f32) -> vec3f {
4134
- var ret = vec3f(0.0);
4135
- var normalDir = fragData.N;
4136
- var viewDir = fragData.V;
4137
- var lightDir = normalize(-direction.xyz);
4138
- var halfDir = normalize(lightDir + viewDir);
4139
- var reflectDir = normalize(reflect(-viewDir,normalDir));
4140
- var NdotH = max(0.00001,dot(normalDir,halfDir));
4141
- var NdotL = max(0.00001,dot(normalDir,lightDir));
4142
- var NdotV = max(0.00001,dot(normalDir,viewDir));
4143
- var HdotL = max(0.00001,dot(halfDir,lightDir));
4144
- var baseColor = fragData.Albedo.rgb ;
4145
- var metallic = fragData.Metallic;
4146
- var roughness = fragData.Roughness;
4147
- var lightColor = getHDRColor( light.lightColor.rgb , light.linear ) ;
4148
- var att = max(0.0,intensity);
4149
- var lighting:vec3f = lightContribution(NdotH,NdotL,NdotV,HdotL,fragData.Roughness,fragData.Albedo.rgb / 3.14, metallic ,shadow,fragData.F0,lightColor.rgb);
4150
- lighting = ACESToneMapping(lighting,att);
4151
- return lighting;
4152
- }
4153
-
4154
- fn directLighting(light: LightData, ibSpecularResult: vec3f) -> vec3f<f32> {
4155
- var color = vec3<f32>(0.0);
4156
- #if USE_LIGHT
4157
- var L = normalize(light.direction.xyz);
4158
- #if USE_BRDF
4159
- var shadow = directShadowVisibility[(light.castShadow)];
4160
- var att = light.intensity;
4161
- color = sampleLighting(light,L,iblSpecularResult,att,shadow);
4162
- #endif
4151
+ var lightDir = normalize(-direction.xyz);
4152
+ var halfDir = normalize(lightDir + viewDir);
4153
+ var reflectDir = normalize(reflect(-viewDir,normalDir));
4154
+
4155
+ var NdotH = max(0.00001,dot(normalDir,halfDir));
4156
+ var NdotL = max(0.00001,dot(normalDir,lightDir));
4157
+ var NdotV = max(0.00001,dot(normalDir,viewDir));
4158
+ var HdotL = max(0.00001,dot(halfDir,lightDir));
4159
+
4160
+ var baseColor = fragData.Albedo.rgb ;
4161
+ var metallic = fragData.Metallic ;
4162
+ var roughness = fragData.Roughness ;
4163
+
4164
+ var lightColor = getHDRColor( light.lightColor.rgb , light.linear ) ;
4165
+ var att = max(0.0,intensity);
4166
+
4167
+ var lighting:vec3f = lightContribution(NdotH,NdotL,NdotV,HdotL,fragData.Roughness,fragData.Albedo.rgb / 3.14, metallic ,shadow,fragData.F0,lightColor.rgb);
4168
+
4169
+ lighting = ACESToneMapping(lighting,att);
4170
+ return lighting ;
4171
+ }
4172
+
4173
+ fn directLighting( light:LightData , iblSpecularResult : vec3f) -> vec3<f32> {
4174
+ var color = vec3<f32>(0.0) ;
4175
+ #if USE_LIGHT
4176
+ var L = normalize(light.direction.xyz) ;
4177
+ #if USE_BRDF
4178
+ var shadow = directShadowVisibility[(light.castShadow)] ;
4179
+ var att = light.intensity;
4180
+ color = sampleLighting(light,L,iblSpecularResult,att, shadow);
4181
+ #endif
4182
+ #endif
4183
+ return color;
4184
+ }
4185
+
4186
+ fn directDulLighting( albedo:vec3<f32>, N:vec3<f32>, V:vec3<f32>, roughness:f32 , metallic:f32 , light:LightData , shadowBias:f32 ) -> vec3<f32> {
4187
+ var color = vec3<f32>(0.0) ;
4188
+ #if USE_LIGHT
4189
+ var L = -normalize(light.direction.xyz) ;
4190
+ let lightCC = pow( light.lightColor.rgb,vec3<f32>(2.2));
4191
+ var lightColor = getHDRColor( lightCC.rgb , light.linear ) ;
4192
+ var att = light.intensity;
4193
+ if(light.castShadow>=0){
4194
+ #if USE_SHADOWMAPING
4195
+ for (var j: i32 = 0; j < 8; j += 1) {
4196
+ if(j == light.castShadow){
4197
+ att *= directShadowVisibility[j] ;
4198
+ }
4199
+ }
4163
4200
  #endif
4164
- return color;
4165
4201
  }
4202
+ #if USE_LAMBERT
4203
+ color = vec3<f32>(1.0,1.0,1.0) ;
4204
+ #endif
4205
+
4206
+ #if USE_BRDF
4207
+ color = 0.85 * simpleBRDF(albedo,N,V,L,att,lightColor,0.85 * roughness,metallic) ;
4208
+ color += 0.15 * simpleBRDF(albedo,N,V,L,att,lightColor,0.15 * roughness,metallic) ;
4209
+ #endif
4210
+ #endif
4211
+ return color;
4212
+ }
4166
4213
 
4167
- fn directDulLighting(albedo:vec3<f32>, N:vec3<f32>, V:vec3<f32>, roughness:f32 , metallic:f32 , light:LightData , shadowBias:f32) -> vec3<f32> {
4168
- var color = vec3<f32>(0.0);
4169
- #if USE_LIGHT
4170
- var L = -normalize(light.direction.xyz);
4171
- let lightCC = pow(light.lightColor.rgb, vec3<f32>(2.2));
4172
- var lightColor = getHDRColor(lightCC.rgb, light.linear);
4173
- var att = light.intensity;
4174
- if(light.castShadow>=0){
4175
- #if USE_SHADOWMAPING
4176
- for(var j: i32 = 0; j < 8; j+=1){
4177
- if(j == light.castShadow){
4178
- att *= directShadowVisibility[j];
4179
- }
4180
- }
4181
- #endif
4182
- }
4183
- #if USE_LAMBERT
4184
- color = vec3<f32>(1.0,1.0,1.0);
4214
+ fn directHairLighting( albedo:vec3<f32>, N:vec3<f32>, V:vec3<f32>, roughness:f32 , metallic:f32 , light:LightData , shadowBias:f32 ) -> vec3<f32> {
4215
+ var color = vec3<f32>(0.0) ;
4216
+ #if USE_LIGHT
4217
+ var L = -normalize(light.direction.xyz) ;
4218
+ let lightCC = pow( light.lightColor.rgb,vec3<f32>(2.2));
4219
+ var lightColor = getHDRColor( lightCC.rgb , light.linear ) ;
4220
+ var att = light.intensity;
4221
+ if(light.castShadow>=0){
4222
+ #if USE_SHADOWMAPING
4223
+ for (var j: i32 = 0; j < 8; j += 1) {
4224
+ if(j == light.castShadow){
4225
+ att *= directShadowVisibility[j] ;
4226
+ }
4227
+ }
4185
4228
  #endif
4229
+ }
4230
+ #if USE_LAMBERT
4231
+ color = vec3<f32>(1.0,1.0,1.0) ;
4232
+ #endif
4233
+
4234
+ #if USE_BRDF
4235
+ color = 0.5 * simpleBRDF(albedo,N,V,L,att,lightColor,0.85 ,metallic) ;
4236
+ color += 0.5 * simpleBRDF(albedo,N,V,L,att,lightColor,0.15 ,metallic) ;
4237
+ #endif
4238
+ #endif
4239
+ return color;
4240
+ }
4186
4241
 
4187
- #if USE_BRDF
4188
- color = 0.85 * simpleBRDF(albedo,N,V,L,att,lightColor,0.85 * roughness,metallic);
4189
- color += 0.15 * simpleBRDF(albedo,N,V,L,att,lightColor,0.15 * roughness,metallic);
4190
- #endif
4191
- #endif
4192
- return color;
4242
+
4243
+ fn pointLighting( WP:vec3<f32>, light:LightData , iblSpecularResult : vec3f ) -> vec3<f32> {
4244
+ var color = vec3<f32>(0.0) ;
4245
+ let lightPos = light.position.xyz;
4246
+ var dir = lightPos.xyz - WP ;
4247
+ let dist = length(dir);
4248
+ if(dist != 0.0){
4249
+ dir *= 1.0 / dist ;
4193
4250
  }
4251
+ if( abs(dist) < light.range ){
4252
+ var L = dir ;
4253
+ var atten = 1.0 ;
4254
+ atten = 1.0 - smoothstep(0.0,light.range,dist) ;
4255
+ atten *= 1.0 / max(light.radius,0.001) ;
4194
4256
 
4195
- fn directHairLighting ( albedo:vec3<f32>, N:vec3<f32>, V:vec3<f32>, roughness:f32 , metallic:f32 , light:LightData , shadowBias:f32 ) -> vec3<f32> {
4196
- var color = vec3<f32>(0.0);
4197
- #if USE_LIGHT
4198
- var L = -normalize(light.direction.xyz);
4199
- let lightCC = pow( light.lightColor.rgb, vec3<f32>(2.2) );
4200
- var lightColor = getHDRColor(lightCC.rgb, light.linear);
4201
- var att = light.intensity;
4202
- if(light.castShadow>=0){
4203
- #if USE_SHADOWMAPING
4204
- for (var j: i32 = 0; j < 8; j += 1) {
4205
- if(j == light.castShadow){
4206
- att *= directShadowVisibility[j];
4207
- }
4208
- }
4209
- #endif
4210
- }
4211
- #if USE_LAMBERT
4212
- color = vec3<f32>(1.0,1.0,1.0) ;
4257
+ var shadow = pointShadows[i32(light.castShadow)] ;
4258
+
4259
+ #if USE_IES_PROFILE
4260
+ atten *= getLightIESProfileAtt(WP,light);
4213
4261
  #endif
4214
4262
 
4215
- #if USE_BRDF
4216
- color = 0.5 * simpleBRDF(albedo,N,V,L,att,lightColor,0.85 ,metallic) ;
4217
- color += 0.5 * simpleBRDF(albedo,N,V,L,att,lightColor,0.15 ,metallic) ;
4218
- #endif
4219
- #endif
4220
- return color
4221
- }
4263
+ atten *= sphere_unit(light.range,light.intensity) ;
4222
4264
 
4223
- fn pointLighting ( WP: vec3<f32>, light: LightData, iblSpecularResult: vec3f ) -> vec3f<f32> {
4224
- var color = vec3<f32>(0.0);
4225
- let lightPos = light.position.xyz;
4226
- var dir = lightPos.xyz - WP;
4227
- let dist = length(dir);
4228
- if(dist != 0.0){
4229
- dir *= 1.0 / dist;
4230
- }
4231
- if(abs(dist) < light.range){
4232
- var L = dir;
4233
- var atten = 1.0;
4234
- atten = 1.0 - smoothstep(0.0, light.range, dist);
4235
- atten *= 1.0 / max(light.radius, 0.001);
4236
- var shadow = pointShadows[i32(light.castShadow)];
4237
-
4238
- #if USE_IES_PROFILE
4239
- atten *= getLightIESProfileAtt(WP, light);
4240
- #endif
4265
+ color = sampleLighting(light,-L,iblSpecularResult,atten,shadow);
4266
+ }
4267
+ return color ;
4268
+ }
4241
4269
 
4242
- atten *= sphere_unit(light.range, light.intensity);
4243
- color = sampleLighting(light, -L, iblSpecularResult, atten, shadow);
4244
- }
4245
- return color;
4246
- }
4270
+ fn pointAtt( WP:vec3<f32>, light:LightData ) -> f32 {
4271
+ var atten = 0.0 ;
4272
+ let lightPos = light.position.xyz;
4273
+ var dir = lightPos.xyz - WP ;
4274
+ let dist = length(dir);
4275
+ if(dist != 0.0){
4276
+ dir *= 1.0 / dist ;
4277
+ }
4278
+ if( abs(dist) < light.range ){
4279
+ var L = dir ;
4280
+ atten = 1.0 - smoothstep(0.0,light.range,dist) ;
4281
+ atten *= 1.0 / max(light.radius,0.001) ;
4282
+ var shadow = pointShadows[i32(light.castShadow)] ;
4283
+ #if USE_IES_PROFILE
4284
+ atten *= getLightIESProfileAtt(WP,light);
4285
+ #endif
4286
+ atten *= sphere_unit(light.range,light.intensity) ;
4287
+ }
4288
+ return atten ;
4289
+ }
4247
4290
 
4248
- fn pointAtt(WP:vec3<f32>, light:LightData) -> f32 {
4249
- var atten = 0.0;
4250
- let lightPos = light.position.xyz;
4251
- var dir = lightPos.xyz - WP;
4252
- let dist = length(dir);
4253
- if(dist != 0.0){
4254
- dir *= 1.0 / dist;
4255
- }
4256
- if(abs(dist) < light.range){
4257
- var L = dir;
4258
- atten = 1.0 - smoothstep(0.0, light.range, dist);
4259
- atten *= 1.0 / max(light.radius, 0.001);
4260
- var shadow = pointShadows[i32(light.castShadow)];
4261
- #if USE_IES_PROFILE
4262
- atten *= getLightIESProfileAtt(WP, light);
4263
- #endif
4264
- atten *= sphere_unit(light.range, light.intensity);
4265
- }
4266
- return atten;
4267
- }
4291
+ fn getDistanceAtten( light:LightData , dist : f32 ) -> f32 {
4292
+ return 1.0 - smoothstep(0.0,light.range,dist) ;
4293
+ }
4268
4294
 
4269
- fn getDistanceAtten(light:LightData, dist:f32) -> f32 {
4270
- return 1.0 - smoothstep(0.0, light.range, dist);
4295
+ fn spotLighting( WP:vec3<f32>, light:LightData , iblSpecularResult : vec3f) -> vec3<f32> {
4296
+ let lightPos = light.position.xyz;
4297
+ var dir = lightPos.xyz - WP ;
4298
+ let dist = length(dir) ;
4299
+ if(dist != 0.0){
4300
+ dir *= 1.0 / dist ;
4271
4301
  }
4272
4302
 
4273
- fn spotLighting(WP:vec3<f32>, light:LightData, iblSpecularResult: vec3f) -> vec3f<f32> {
4274
- let lightPos = light.position.xyz;
4275
- var dir = lightPos.xyz - WP;
4276
- let dist = length(dir);
4277
- if(dist != 0.0){
4278
- dir *= 1.0 / dist
4303
+ var color = vec3<f32>(0.0) ;
4304
+ if( abs(dist) < light.range * 2.0 ){
4305
+ var L = dir ;
4306
+ let theta = dot(-L, normalize(light.direction));
4307
+ let angle = acos(theta) ;
4308
+ var atten = 1.0 ;
4309
+ var lightColor = light.lightColor.rgb ;
4310
+
4311
+ atten = 1.0 - smoothstep(0.0,light.range,dist) ;
4312
+ atten *= 1.0 / max(light.radius,0.001) ;
4313
+ if(angle < light.outerCutOff){
4314
+ if(angle > light.innerCutOff){
4315
+ atten *= 1.0 - smoothstep(light.innerCutOff, light.outerCutOff, angle) ;
4316
+ }
4317
+ }else{
4318
+ atten = 0.0 ;
4279
4319
  }
4280
4320
 
4281
- var color = vec3<f32>(0.0);
4282
- if(abs(dist) < light.range * 2.0){
4283
- var L = dir;
4284
- let theta = dot(-L, normalize(light.direction));
4285
- let angle = acos(theta);
4286
- var atten = 1.0;
4287
- var lightColor = light.lightColor.rgb;
4288
-
4289
- atten = 1.0 - smoothstep(0.0, light.range, dist);
4290
- atten *= 1.0 / max(light.radius, 0.001);
4291
- if(angle < light.outerCutOff){
4292
- if(angle > light.innerCutOff){
4293
- atten *= 1.0 - smoothstep(light.innerCutOff, light.outerCutOff, angle);
4294
- }
4295
- }else{
4296
- atten = 0.0;
4297
- }
4321
+ var shadow = pointShadows[i32(light.castShadow)] ;
4298
4322
 
4299
- var shadow = pointShadows[i32(light.castShadow)];
4323
+ #if USE_IES_PROFILE
4324
+ atten *= getLightIESProfileAtt(WP,light);
4325
+ #endif
4300
4326
 
4301
- #if USE_IES_PROFILE
4302
- atten *= getLightIESProfileAtt(WP, light);
4303
- #endif
4327
+ atten *= sphere_unit(light.range, light.intensity) ;
4304
4328
 
4305
- atten *= sphere_unit(light.range, light.intensity);
4306
- color = sampleLighting(light, -L, iblSpecularResult, atten, shadow);
4307
- }
4308
- return color;
4329
+ color = sampleLighting(light,-L,iblSpecularResult,atten,shadow);
4309
4330
  }
4331
+ return color ;
4332
+ }
4310
4333
 
4311
- fn sphere_unit( radius:f32, intensity: f32 ) -> f32 {
4312
- return intensity / (4.0 * PI2 * radius * radius);
4313
- }
4314
- `;
4334
+ fn sphere_unit( radius:f32 , intensity:f32 ) -> f32 {
4335
+ return intensity / (4.0 * PI2 * radius * radius) ;
4336
+ }
4337
+ `
4338
+ );
4315
4339
 
4316
- let MathShader = `
4317
- #include 'BitUtil'
4340
+ let MathShader = (
4341
+ /* wgsl */
4342
+ `
4343
+ #include 'BitUtil'
4318
4344
 
4319
- struct TBN_ret{
4320
- tan:vec3f,
4321
- bit:vec3f,
4345
+ struct TBN_ret{
4346
+ tan:vec3f,
4347
+ bit:vec3f,
4348
+ }
4349
+
4350
+ fn TBN( N:vec3f) -> mat3x3<f32>{
4351
+ //Returns the simple tangent space matrix
4352
+ var Nb : vec3f;
4353
+ var Nt : vec3f;
4354
+ if (abs(N.y)>0.999) {
4355
+ Nb = vec3f(1.0,0.0,0.0);
4356
+ Nt = vec3f(0.0,0.0,1.0);
4357
+ } else {
4358
+ Nb = normalize(cross(N,vec3f(0.0,1.0,0.0)));
4359
+ Nt = normalize(cross(Nb,N));
4322
4360
  }
4323
4361
 
4324
- fn TBN(N:vec3f) -> mat3x3<f32>{
4325
- var Nb: vec3f;
4326
- var Nt: vec3f;
4327
- if(abs(N.y)>0.999){
4328
- Nb = vec3f(1.0,0.0,0.0);
4329
- Nt = vec3f(0.0,0.0,1.0)
4330
- }else{
4331
- Nb = normalize(cross(N,vec3f(0.0,1.0,0.0)));
4332
- Nt = normalize(cross(Nb,N));
4333
- }
4362
+ var mat3 = mat3x3<f32>(
4363
+ Nb.x,Nt.x,N.x,
4364
+ Nb.y,Nt.y,N.y,
4365
+ Nb.z,Nt.z,N.z
4366
+ );
4334
4367
 
4335
- var mat3 = mat3x3<f32>(
4336
- Nb.x,Nt.x,N.x,
4337
- Nb.y,Nt.y,N.y,
4338
- Nb.z,Nt.z,N.z
4339
- );
4368
+ return mat3;
4369
+ }
4340
4370
 
4341
- return mat3;
4342
- }
4371
+ fn TBN_out( N : vec3f ) -> TBN_ret {
4372
+ var tbn_ret : TBN_ret;
4373
+ //Returns the simple tangent space directions
4374
+ if (abs(N.y)>0.999) {
4375
+ tbn_ret.tan = vec3f(1.0,0.0,0.0);
4376
+ tbn_ret.bit = vec3f(0.0,0.0,1.0);
4377
+ } else {
4378
+ tbn_ret.tan = normalize(cross(N,vec3f(0.0,1.0,0.0)));
4379
+ tbn_ret.bit = normalize(cross(tbn_ret.tan,N));
4380
+ }
4343
4381
 
4344
- fn TBN_out(N:vec3f) -> TBN_ret {
4345
- var tbn_ret: TBN_ret;
4346
- if(abs(N.y)>0.999) {
4347
- tbn_ret.tan = vec3f(1.0,0.0,0.0);
4348
- tbn_ret.bit = vec3f(0.0,0.0,1.0);
4349
- }else{
4350
- tbn_ret.tan = normalize(cross(N,vec3f(0.0,1.0,0.0)));
4351
- tbn_ret.bit = normalize(cross(tbn_ret.tan,N));
4352
- }
4382
+ return tbn_ret;
4383
+ }
4353
4384
 
4354
- return tbn_ret;
4355
- }
4356
4385
 
4357
- fn ARand21(uv:vec2f) -> f32 {
4358
- return fract(sin(uv.x*uv.y)*403.125+cos(dot(uv,vec2f(13.18273,51.2134)))*173.137);
4359
- }
4386
+ fn ARand21( uv: vec2f) -> f32 {
4387
+ //Returns 1D noise from 2D
4388
+ return fract(sin(uv.x*uv.y)*403.125+cos(dot(uv,vec2f(13.18273,51.2134)))*173.137);
4389
+ }
4360
4390
 
4361
- fn applyQuaternion(position:vec3<f32>,q:vec4<f32>) -> vec3<f32>{
4362
- let x:f32 = position.x;
4363
- let y:f32 = position.y;
4364
- let z:f32 = position.z;
4391
+ fn applyQuaternion(position:vec3<f32>, q:vec4<f32>) -> vec3<f32>{
4392
+ let x:f32 = position.x;
4393
+ let y:f32 = position.y;
4394
+ let z:f32 = position.z;
4365
4395
 
4366
- let qx:f32 = q.x;
4367
- let qy:f32 = q.y;
4368
- let qz:f32 = q.z;
4369
- let qw:f32 = q.w;
4396
+ let qx:f32 = q.x;
4397
+ let qy:f32 = q.y;
4398
+ let qz:f32 = q.z;
4399
+ let qw:f32 = q.w;
4370
4400
 
4371
- let ix:f32 = qw*x + qy*z - qz*y;
4372
- let iy:f32 = qw*y + qz*x - qx*z;
4373
- let iz:f32 = qw*z + qx*y - qy*x;
4374
- let iw:f32 = -qx*x - qy*y - qz*z;
4401
+ let ix:f32 = qw * x + qy * z - qz * y;
4402
+ let iy:f32 = qw * y + qz * x - qx * z;
4403
+ let iz:f32 = qw * z + qx * y - qy * x;
4404
+ let iw:f32 = -qx * x - qy * y - qz * z;
4375
4405
 
4376
- var ret: vec3<f32>;
4377
- ret.x = ix*qw + iw*-qx + iy*-qz - iz*-qy;
4378
- ret.y = iy*qw + iw*-qy + iz*-qx - ix*-qz;
4379
- ret.z = iz*qw + iw*-qz + ix*-qy - iy*-qx;
4406
+ var ret: vec3<f32>;
4407
+ ret.x = ix * qw + iw * -qx + iy * -qz - iz * -qy;
4408
+ ret.y = iy * qw + iw * -qy + iz * -qx - ix * -qz;
4409
+ ret.z = iz * qw + iw * -qz + ix * -qy - iy * -qx;
4380
4410
 
4381
- return ret;
4382
- }
4411
+ return ret;
4412
+ }
4383
4413
 
4384
- fn inverse(m:mat3x3<f32>) -> mat3*3<f32>{
4385
- var a00 = m[0][0];
4386
- var a01 = m[0][1];
4387
- var a02 = m[0][2];
4388
- var a10 = m[1][0];
4389
- var a11 = m[1][1];
4390
- var a12 = m[1][2];
4391
- var a20 = m[2][0];
4392
- var a21 = m[2][1];
4393
- var a22 = m[2][2];
4394
-
4395
- var b01 = a22*a11 - a12*a21;
4396
- var b11 = -a22*a10 + a12*a20;
4397
- var b21 = a21*a10 - a11*a20;
4398
-
4399
- var det =a00*b01 + a01*b11 + a02*b21;
4400
- return mat3x3<f32>(
4401
- vec3<f32>(b01/ det, (-a22 * a01 + a02 * a21)/ det, (a12 * a01 - a02 * a11)/ det),
4402
- vec3<f32>(b11/ det, (a22 * a00 - a02 * a20)/ det, (-a12 * a00 + a02 * a10)/ det),
4403
- vec3<f32>(b21/ det, (-a21 * a00 + a01 * a20)/ det, (a11 * a00 - a01 * a10)/ det)
4404
- );
4405
- }
4406
-
4407
- fn dir_to_faceId(pt:vec3<f32>) -> i32 {
4408
- var abs_x = abs(pt.x);
4409
- var abs_y = abs(pt.y);
4410
- var abs_z = abs(pt.z);
4411
- var coord = max(max(abs_x, abs_y),abs_z);
4412
- if(coord == -pt.x){
4413
- return 0;
4414
- }
4415
- if(coord == pt.x){
4416
- return 1;
4417
- }
4418
- if(coord == -pt.y){
4419
- return 2;
4420
- }
4421
- if(coord == pt.y){
4422
- return 3;
4423
- }
4424
- if(coord == -pt.z){
4425
- return 4;
4426
- }
4427
- return 5;
4428
- }
4429
-
4430
- const us = 1.0/6.0;
4431
- fn uv_2_xyz(u:f32,v:f32) -> vec3f{
4432
- let face = floor(u/us);
4433
- var uu = (u - face*us)/us;
4434
- var uc = 2.0*uu - 1.0;
4435
- var vc = 2.0*v - 1.0;
4436
- var xyz = vec3f(0,0,0);
4437
- if(face == 0.0){
4438
- xyz = vec3f(1.0,-vc,uc);
4439
- }else if(face == 1.0){
4440
- xyz = vec3f(-1.0,-vc,-uc);
4441
- }else if(face == 2.0){
4442
- xyz = vec3f(uc,1.0,-vc);
4443
- }else if(face == 3.0){
4444
- xyz = vec3f(uc,-1.0,vc);
4445
- }else if(face == 4.0){
4446
- xyz = vec3f(-uc,-vc,1.0);
4447
- }else if(face == 5.0){
4448
- xyz = vec3f(uc,-vc,-1.0);
4449
- }
4450
- return xyz;
4451
- }
4452
-
4453
- fn convert_xyz_to_cube_uv(x:f32, y:f32, z:f32) -> vec2f{
4454
- var dir = vec3f(x,y,z);
4455
- var absX = abs(dir.x);
4456
- var absY = abs(dir.y);
4457
- var absZ = abs(dir.z);
4458
-
4459
- var isXPositive = 0;
4460
- if(dir.x > 0.0){isXPositive=1};
4461
- var isYPositive = 0;
4462
- if(dir.y > 0.0){isXPositive=1};
4463
- var isZPositive = 0;
4464
- if(dir.z > 0.0){isZPositive=1};
4465
-
4466
- var maxAxis:f32 = 0.0;
4467
- var uc:f32 = 0.0;
4468
- var vc:f32 = 0.0;
4469
-
4470
- if(isXPositive == 1 && absX >= absY && absX >= absZ){
4471
- maxAxis = absX;
4472
- uc = -z;
4473
- vc = y;
4474
- }
4475
- if(isXPositive == 0 && absX >= absY && absX >= absZ){
4476
- maxAxis = absX;
4477
- uc = z;
4478
- vc = y;
4479
- }
4480
- if(isYPositive == 1 && absY >= absX && absY >= absZ){
4481
- maxAxis = absY;
4482
- uc = x;
4483
- vc = -z;
4484
- }
4485
- if(isYPositive == 0 && absY >= absX && absY >= absZ){
4486
- maxAxis = absY;
4487
- uc = x;
4488
- vc = z;
4489
- }
4490
- if (isZPositive == 1 && absZ >= absX && absZ >= absY) {
4491
- maxAxis = absZ;
4492
- uc = x;
4493
- vc = y;
4494
- }
4495
- if (isZPositive ==0 && absZ >= absX && absZ >= absY) {
4496
- maxAxis = absZ;
4497
- uc = -x;
4498
- vc = y;
4499
- }
4500
-
4501
- var u = 0.5f*(uc / maxAxis + 1.0f);
4502
- var v = 0.5f*(vc / maxAxis + 1.0f);
4414
+ fn inverse( m:mat3x3<f32>) -> mat3x3<f32>{
4415
+ var a00 = m[0][0];
4416
+ var a01 = m[0][1];
4417
+ var a02 = m[0][2];
4418
+ var a10 = m[1][0];
4419
+ var a11 = m[1][1];
4420
+ var a12 = m[1][2];
4421
+ var a20 = m[2][0];
4422
+ var a21 = m[2][1];
4423
+ var a22 = m[2][2];
4424
+
4425
+ var b01 = a22 * a11 - a12 * a21;
4426
+ var b11 = -a22 * a10 + a12 * a20;
4427
+ var b21 = a21 * a10 - a11 * a20;
4428
+
4429
+ var det = a00 * b01 + a01 * b11 + a02 * b21 ;
4430
+ return mat3x3<f32>(
4431
+ vec3<f32>(b01/ det, (-a22 * a01 + a02 * a21)/ det, (a12 * a01 - a02 * a11)/ det),
4432
+ vec3<f32>(b11/ det, (a22 * a00 - a02 * a20)/ det, (-a12 * a00 + a02 * a10)/ det),
4433
+ vec3<f32>(b21/ det, (-a21 * a00 + a01 * a20)/ det, (a11 * a00 - a01 * a10)/ det)
4434
+ );
4435
+ }
4503
4436
 
4504
- return vec2f(u, v);
4505
- }
4506
-
4507
- fn signNotZero(v1:vec2<f32>) -> vec2<f32>{
4437
+ fn dir_to_faceId(pt:vec3<f32>) -> i32 {
4438
+ //**** nx px ny py nz pz
4439
+ var abs_x = abs(pt.x);
4440
+ var abs_y = abs(pt.y);
4441
+ var abs_z = abs(pt.z);
4442
+ var coord = max(max(abs_x, abs_y), abs_z);
4443
+ if(coord == -pt.x){ return 0;}
4444
+ if(coord == pt.x) { return 1;}
4445
+
4446
+ if(coord == -pt.y){ return 2;}
4447
+ if(coord == pt.y) { return 3;}
4448
+
4449
+ if(coord == -pt.z) { return 4;}
4450
+ return 5;
4451
+ }
4452
+
4453
+ const us = 1.0 /6.0 ;
4454
+ fn uv_2_xyz(u:f32,v:f32) -> vec3f
4455
+ {
4456
+ let face = floor(u / us);
4457
+ var uu = (u - face * us) / us ;
4458
+
4459
+ var uc = 2.0 * uu - 1.0;
4460
+ var vc = 2.0 * v - 1.0;
4461
+ var xyz = vec3f(0,0,0);
4462
+
4463
+ if(face == 0.0){
4464
+ // x,y,z = 1.0,vc,-uc
4465
+ xyz = vec3f(1.0,-vc,uc);
4466
+ }else if(face == 1.0){
4467
+ // x,y,z = -1.0,vc,uc
4468
+ xyz = vec3f(-1.0,-vc,-uc);
4469
+ }else if(face == 2.0){
4470
+ // x,y,z = uc,1.0,-vc
4471
+ xyz = vec3f(uc,1.0,-vc);
4472
+ }else if(face == 3.0){
4473
+ // x,y,z = uc,-1.0,vc
4474
+ xyz = vec3f(uc,-1.0,vc);
4475
+ }else if(face == 4.0){
4476
+ // x,y,z = uc,vc,1.0
4477
+ xyz = vec3f(-uc,-vc,1.0);
4478
+ }else if(face == 5.0){
4479
+ // x,y,z = -uc,vc,-1.0
4480
+ xyz = vec3f(uc,-vc,-1.0);
4481
+ }
4482
+ return xyz ;
4483
+ }
4484
+
4485
+ fn convert_xyz_to_cube_uv(x:f32, y:f32, z:f32 ) -> vec2f
4486
+ {
4487
+ var dir = vec3f(x, y, z);
4488
+ var absX = abs(dir.x);
4489
+ var absY = abs(dir.y);
4490
+ var absZ = abs(dir.z);
4491
+
4492
+ var isXPositive = 0;
4493
+ if(dir.x > 0.0){isXPositive = 1;}
4494
+ var isYPositive = 0;
4495
+ if(dir.y > 0.0){isYPositive = 1;}
4496
+ var isZPositive = 0;
4497
+ if(dir.z > 0.0){isZPositive = 1;}
4498
+
4499
+ var maxAxis:f32 = 0.0;
4500
+ var uc:f32 = 0.0;
4501
+ var vc:f32 = 0.0;
4502
+
4503
+ // POSITIVE X
4504
+ if (isXPositive == 1 && absX >= absY && absX >= absZ) {
4505
+ // u (0 to 1) goes from +z to -z
4506
+ // v (0 to 1) goes from -y to +y
4507
+ maxAxis = absX;
4508
+ uc = -z;
4509
+ vc = y;
4510
+ }
4511
+ // NEGATIVE X
4512
+ if (isXPositive ==0 && absX >= absY && absX >= absZ) {
4513
+ // u (0 to 1) goes from -z to +z
4514
+ // v (0 to 1) goes from -y to +y
4515
+ maxAxis = absX;
4516
+ uc = z;
4517
+ vc = y;
4518
+ }
4519
+ // POSITIVE Y
4520
+ if (isYPositive==1 && absY >= absX && absY >= absZ) {
4521
+ // u (0 to 1) goes from -x to +x
4522
+ // v (0 to 1) goes from +z to -z
4523
+ maxAxis = absY;
4524
+ uc = x;
4525
+ vc = -z;
4526
+ }
4527
+ // NEGATIVE Y
4528
+ if (isYPositive ==0 && absY >= absX && absY >= absZ) {
4529
+ // u (0 to 1) goes from -x to +x
4530
+ // v (0 to 1) goes from -z to +z
4531
+ maxAxis = absY;
4532
+ uc = x;
4533
+ vc = z;
4534
+ }
4535
+ // POSITIVE Z
4536
+ if (isZPositive == 1&& absZ >= absX && absZ >= absY) {
4537
+ // u (0 to 1) goes from -x to +x
4538
+ // v (0 to 1) goes from -y to +y
4539
+ maxAxis = absZ;
4540
+ uc = x;
4541
+ vc = y;
4542
+ }
4543
+ // NEGATIVE Z
4544
+ if (isZPositive ==0 && absZ >= absX && absZ >= absY) {
4545
+ // u (0 to 1) goes from +x to -x
4546
+ // v (0 to 1) goes from -y to +y
4547
+ maxAxis = absZ;
4548
+ uc = -x;
4549
+ vc = y;
4550
+ }
4551
+
4552
+ // Convert range from -1 to 1 to 0 to 1
4553
+ var u = 0.5f * (uc / maxAxis + 1.0f);
4554
+ var v = 0.5f * (vc / maxAxis + 1.0f);
4555
+
4556
+ return vec2f(u, v);
4557
+ }
4558
+
4559
+ // Returns ±1
4560
+ fn signNotZero( v1:vec2<f32>) -> vec2<f32> {
4508
4561
  var v:vec2<f32> = v1;
4509
4562
  if(v.x >= 0.0){
4510
4563
  v.x = 1.0;
@@ -4514,118 +4567,123 @@
4514
4567
  if(v.y >= 0.0){
4515
4568
  v.y = 1.0;
4516
4569
  }else{
4517
- v.y = -1.0;
4570
+ v.y= -1.0;
4518
4571
  }
4519
4572
  return v;
4520
4573
  }
4521
4574
 
4522
- fn octEncode(v:vec3<f32>) -> vec2<f32> {
4575
+ fn octEncode( v:vec3<f32> ) -> vec2<f32> {
4523
4576
  var l1norm = abs(v.x) + abs(v.y) + abs(v.z);
4524
4577
  var result = v.xy * (1.0 / l1norm);
4525
- if(v.z < 0.0){
4578
+ if (v.z < 0.0) {
4526
4579
  result = (1.0 - abs(result.yx)) * signNotZero(result.xy);
4527
4580
  }
4528
4581
  return result;
4529
4582
  }
4530
4583
 
4531
- fn octDecode(o:vec2<f32>) -> vec3<f32> {
4584
+ // Returns a unit vector. Argument o is an octahedral vector packed via octEncode,on the [-1, +1] square*/
4585
+ fn octDecode( o:vec2<f32> ) -> vec3<f32> {
4532
4586
  var v = vec3<f32>(o.x, o.y, 1.0 - abs(o.x) - abs(o.y));
4533
- if(v.z < 0.0) {
4534
- var tmp = (1.0 -abs(v.yx))*signNotZero(v.xy);
4587
+ if (v.z < 0.0) {
4588
+ var tmp = (1.0 - abs(v.yx)) * signNotZero(v.xy);
4535
4589
  v.x = tmp.x;
4536
4590
  v.y = tmp.y;
4537
4591
  }
4538
4592
  return normalize(v);
4539
4593
  }
4540
4594
 
4541
- fn Linear01Depth(z:f32,near:f32,far:f32) -> f32{
4542
- let ZBufferZ = (-1.0+(far/near))/far;
4543
- let ZBufferW = near/far;
4544
- return 1.0 / (ZBufferZ * z + ZBufferW);
4595
+ fn Linear01Depth(z:f32,near:f32,far:f32)-> f32{
4596
+ let ZBufferZ = (-1.0+(far/near)) / far;
4597
+ let ZBufferW = near /far ;
4598
+ return 1.0 / (ZBufferZ * z + ZBufferW) ;
4545
4599
  }
4546
4600
 
4547
- fn LinearizeDepth(depth:f32, nearPlane:f32, farPlane:f32) -> f32 {
4548
- var z = depth * 2.0 - 1.0;
4549
- return (2.0 * nearPlane * farPlane) / (farPlane + nearPlane - z * (farPlane - nearPlane));
4601
+
4602
+ fn LinearizeDepth( depth:f32 , nearPlane:f32 , farPlane:f32 )-> f32 {
4603
+ var z = depth * 2.0 - 1.0;
4604
+ return (2.0 * nearPlane * farPlane) / (farPlane + nearPlane - z * (farPlane - nearPlane));
4550
4605
  }
4551
4606
 
4552
- fn logDepth(depth:f32, far:f32) -> f32 {
4553
- return log2(depth + 1.0) * 2.0 / (log(far + 1.0) / 0.6931471805599453) * 0.5;
4607
+ fn logDepth(depth : f32, far:f32) -> f32 {
4608
+ return log2(depth + 1.0) * 2.0 / (log(far + 1.0) / 0.6931471805599453) * 0.5;
4554
4609
  }
4555
4610
 
4556
4611
  fn log2Depth(depth:f32, near:f32, far:f32) -> f32 {
4557
- let Fcoef:f32 = 2.0 / log2(far + 1.0);
4558
- var result:f32 = (log2(max(1e-6, 1.0 + depth)) * Fcoef - 1.0);
4559
- result = (1.0 + result) / 2.0;
4560
- return result * depth;
4612
+ let Fcoef:f32 = 2.0 / log2(far + 1.0);
4613
+ var result:f32 = (log2(max(1e-6, 1.0 + depth)) * Fcoef - 1.0);
4614
+ result = (1.0 + result) / 2.0;
4615
+ return result * depth;
4561
4616
  }
4562
4617
 
4563
4618
  fn log2DepthFixPersp(depth:f32, near:f32, far:f32) -> f32 {
4564
- let flogz:f32 = 1.0 + depth;
4565
- let Fcoef_half:f32 = (2.0 / log2(far + 1.0)) * 0.5;
4566
- var result:f32 = log2(flogz) * Fcoef_half;
4567
- result = (1.0 + result) / 2.0;
4568
- return result;
4619
+ let flogz:f32 = 1.0 + depth;
4620
+ let Fcoef_half:f32 = (2.0 / log2(far + 1.0)) * 0.5;
4621
+ var result:f32 = log2(flogz) * Fcoef_half;
4622
+ result = (1.0 + result) / 2.0;
4623
+ return result;
4569
4624
  }
4570
4625
 
4571
- fn QuaternionToMatrix(q:vec4<f32>) -> mat4x4<f32> {
4572
- var result: mat4x4<f32>;
4573
-
4574
- let x = q.x * 2.0;
4575
- let y = q.y * 2.0;
4576
- let z = q.z * 2.0;
4577
- let xx = q.x * x;
4578
- let yy = q.y * y;
4579
- let zz = q.z * z;
4580
- let xy = q.x * y;
4581
- let xz = q.x * z;
4582
- let yz = q.y * z;
4583
- let wx = q.w * x;
4584
- let wy = q.w * y;
4585
- let wz = q.w * z;
4586
-
4587
- result[0][0] = 1.0 - (yy + zz);
4588
- result[0][1] = xy + wz;
4589
- result[0][2] = xz - wy;
4590
- result[0][3] = 0.0;
4591
-
4592
- result[1][0] = xy - wz;
4593
- result[1][1] = 1.0 - (xx + zz);
4594
- result[1][2] = yz + wx;
4595
- result[1][3] = 0.0;
4596
-
4597
- result[2][0] = xz + wy;
4598
- result[2][1] = yz - wx;
4599
- result[2][2] = 1.0 - (xx + yy);
4600
- result[2][3] = 0.0;
4601
-
4602
- result[3][0] = 0.0;
4603
- result[3][1] = 0.0;
4604
- result[3][2] = 0.0;
4605
- result[3][3] = 1.0;
4606
4626
 
4607
- return result;
4627
+ fn QuaternionToMatrix(q: vec4<f32>) -> mat4x4<f32> {
4628
+ var result: mat4x4<f32>;
4629
+
4630
+ // Precalculate coordinate products
4631
+ let x = q.x * 2.0;
4632
+ let y = q.y * 2.0;
4633
+ let z = q.z * 2.0;
4634
+ let xx = q.x * x;
4635
+ let yy = q.y * y;
4636
+ let zz = q.z * z;
4637
+ let xy = q.x * y;
4638
+ let xz = q.x * z;
4639
+ let yz = q.y * z;
4640
+ let wx = q.w * x;
4641
+ let wy = q.w * y;
4642
+ let wz = q.w * z;
4643
+
4644
+ // Calculate 3x3 matrix from orthonormal basis
4645
+ result[0][0] = 1.0 - (yy + zz);
4646
+ result[0][1] = xy + wz;
4647
+ result[0][2] = xz - wy;
4648
+ result[0][3] = 0.0;
4649
+
4650
+ result[1][0] = xy - wz;
4651
+ result[1][1] = 1.0 - (xx + zz);
4652
+ result[1][2] = yz + wx;
4653
+ result[1][3] = 0.0;
4654
+
4655
+ result[2][0] = xz + wy;
4656
+ result[2][1] = yz - wx;
4657
+ result[2][2] = 1.0 - (xx + yy);
4658
+ result[2][3] = 0.0;
4659
+
4660
+ result[3][0] = 0.0;
4661
+ result[3][1] = 0.0;
4662
+ result[3][2] = 0.0;
4663
+ result[3][3] = 1.0;
4664
+
4665
+ return result;
4608
4666
  }
4609
4667
 
4610
4668
  fn MakeScaleMatrix(scale: vec3<f32>) -> mat4x4<f32> {
4611
4669
  return mat4x4<f32>(
4612
- scale.x, 0.0, 0.0, 0.0,
4613
- 0.0, scale.y, 0.0, 0.0,
4614
- 0.0, 0.0, scale.z, 0.0,
4615
- 0.0, 0.0, 0.0, 1.0,
4670
+ scale.x, 0.0, 0.0, 0.0,
4671
+ 0.0, scale.y, 0.0, 0.0,
4672
+ 0.0, 0.0, scale.z, 0.0,
4673
+ 0.0, 0.0, 0.0, 1.0,
4616
4674
  );
4617
4675
  }
4618
-
4676
+
4619
4677
  fn MakeRotationMatrix(rotationQuaternion: vec4<f32>) -> mat4x4<f32> {
4620
- return QuaternionToMatrix(rotationQuaternion);
4678
+ return QuaternionToMatrix(rotationQuaternion);
4621
4679
  }
4622
4680
 
4623
4681
  fn MakeTranslationMatrix(translation: vec3<f32>) -> mat4x4<f32> {
4624
4682
  return mat4x4<f32>(
4625
- 1.0, 0.0, 0.0, 0.0,
4626
- 0.0, 1.0, 0.0, 0.0,
4627
- 0.0, 0.0, 1.0, 0.0,
4628
- translation.x, translation.y, translation.z, 1.0,
4683
+ 1.0, 0.0, 0.0, 0.0,
4684
+ 0.0, 1.0, 0.0, 0.0,
4685
+ 0.0, 0.0, 1.0, 0.0,
4686
+ translation.x, translation.y, translation.z, 1.0,
4629
4687
  );
4630
4688
  }
4631
4689
 
@@ -4637,191 +4695,206 @@
4637
4695
  }
4638
4696
 
4639
4697
  fn mixMatrix4x4(a: mat4x4<f32>, b: mat4x4<f32>, t:f32) -> mat4x4<f32> {
4640
- return a * (1.0 - t) + b * t;
4698
+ return a * (1.0 - t) + b * t;
4641
4699
  }
4642
4700
 
4643
- fn decodeDepth(color:vec4<f32>) -> f32{
4644
- var depth = 0.0;
4645
- const bitShifts = vec4f<f32>(1.0 / (256.0 * 256.0 * 256.0), 1.0 / (256.0 * 256.0), 1.0 / 256.0, 1.0);
4646
- depth = dot(color, bitShifts);
4647
- return depth;
4701
+ fn decodeDepth( color:vec4<f32> ) -> f32{
4702
+ var depth = 0.0 ;
4703
+ const bitShifts = vec4<f32>(1.0 / (256.0 * 256.0 * 256.0), 1.0 / (256.0 * 256.0), 1.0 / 256.0, 1.0);
4704
+ depth = dot(color, bitShifts);
4705
+ return depth;
4648
4706
  }
4649
4707
 
4650
- fn encodeDepth(depth:f32) -> vec4<f32>{
4651
- const bitSh = vec4<f32>(256.0 * 256.0 * 256.0, 256.0 * 256.0, 256.0, 1.0);
4652
- const bitMsk = vec4<f32>(0, 1.0 / 256.0, 1.0 / 256.0, 1.0 / 256.0);
4653
- var comp: vec4<f32>;
4654
- comp = depth * bitSh;
4655
- comp = fract(comp);
4656
- comp -= comp.xxyz * bitMsk;
4657
- return comp;
4708
+ fn encodeDepth( depth:f32 ) -> vec4<f32>{
4709
+ const bitSh = vec4<f32>(256.0 * 256.0 * 256.0, 256.0 * 256.0, 256.0, 1.0);
4710
+ const bitMsk = vec4<f32>(0, 1.0 / 256.0, 1.0 / 256.0, 1.0 / 256.0);
4711
+ var comp:vec4<f32>;
4712
+ comp = depth * bitSh;
4713
+ comp = fract(comp);
4714
+ comp -= comp.xxyz * bitMsk;
4715
+ return comp;
4658
4716
  }
4659
4717
 
4660
- fn calculateBillboardMatrix2(eye:vec3f, pos:vec3f, up:vec3f) -> mat3x3<f32> {
4661
- let zAxis: vec3f = -normalize(pos.xyz - eye);
4662
- var xAxis: vec3f = cross(up, zAxis);
4663
- xAxis = normalize(cross(zAxis, xAxis));
4664
- let yAxis = normalize(cross(zAxis, xAxis));
4665
- return mat3x3<f32>(xAxis, yAxis, zAxis);
4718
+ fn calculateBillboardMatrix2(eye:vec3f,pos:vec3f,up:vec3f) -> mat3x3<f32> {
4719
+
4720
+ let zAxis: vec3f = -normalize(pos.xyz - eye);
4721
+ var xAxis: vec3f = cross(up,zAxis);
4722
+ xAxis = normalize(cross(zAxis,xAxis));
4723
+ let yAxis = normalize(cross(zAxis, xAxis));
4724
+ return mat3x3<f32>(xAxis, yAxis, zAxis);
4666
4725
  }
4667
4726
 
4668
- struct SH9Struct {
4669
- SHAr:vec4f,
4670
- SHAg:vec4f,
4671
- SHAb:vec4f,
4672
- SHBr:vec4f,
4673
- SHBg:vec4f,
4674
- SHBb:vec4f,
4675
- SHC:vec4f,
4727
+ struct SH9Struct{
4728
+ SHAr:vec4f,
4729
+ SHAg:vec4f,
4730
+ SHAb:vec4f,
4731
+ SHBr:vec4f,
4732
+ SHBg:vec4f,
4733
+ SHBb:vec4f,
4734
+ SHC:vec4f,
4676
4735
  }
4677
4736
 
4678
- fn ShadeSH9(normal: vec4f, sh9: SH9Struct) -> vec3f {
4679
- var x1:vec3f = vec3f(0.0);
4680
- var x2:vec3f = vec3f(0.0);
4681
- var x3:vec3f = vec3f(0.0);
4682
-
4683
- x1.r = dot(sh9.SHAr,normal);
4684
- x1.g = dot(sh9.SHAg,normal);
4685
- x1.b = dot(sh9.SHAb,normal);
4686
-
4687
- var vB = normal.xyzz * normal.yzzx;
4688
- x2.r = dot(sh9.SHBr,vB);
4689
- x2.g = dot(sh9.SHBg,vB);
4690
- x2.b = dot(sh9.SHBb,vB);
4691
-
4692
- var vC = normal.x*normal.x - normal.y*normal.y;
4693
- x3 = sh9.SHC.rgb * vC;
4694
- return x1 + x2 + x3;
4695
- }
4737
+ fn ShadeSH9 ( normal:vec4f , sh9:SH9Struct) -> vec3f
4738
+ {
4739
+ var x1:vec3f = vec3f(0.0);
4740
+ var x2:vec3f = vec3f(0.0);
4741
+ var x3:vec3f = vec3f(0.0);
4742
+
4743
+ // Linear + constant polynomial terms
4744
+ x1.r = dot(sh9.SHAr,normal);
4745
+ x1.g = dot(sh9.SHAg,normal);
4746
+ x1.b = dot(sh9.SHAb,normal);
4747
+
4748
+ // 4 of the quadratic polynomials
4749
+ var vB = normal.xyzz * normal.yzzx;
4750
+ x2.r = dot(sh9.SHBr,vB);
4751
+ x2.g = dot(sh9.SHBg,vB);
4752
+ x2.b = dot(sh9.SHBb,vB);
4753
+
4754
+ // Final quadratic polynomial
4755
+ var vC = normal.x*normal.x - normal.y*normal.y;
4756
+ x3 = sh9.SHC.rgb * vC;
4757
+ return x1 + x2 + x3;
4758
+ }
4696
4759
 
4697
- fn clipViewUV(viewRectangle:vec4f, size:vec2f, fragCoord:vec2f) -> vec2u {
4698
- let subViewUV = (fragCoord - viewRectangle.xy) / viewRectangle.zw;
4699
- return vec2u(subViewUV*size);
4760
+ fn clipViewUV(viewRectangle:vec4f,size:vec2f,fragCoord:vec2f) -> vec2u {
4761
+ let subViewUV = (fragCoord - viewRectangle.xy) / viewRectangle.zw ;
4762
+ return vec2u(subViewUV*size) ;
4700
4763
  }
4701
4764
 
4702
- fn insideRectangle(point:vec2f, rec:vec4f) -> bool {
4703
- if( point.x > rec.x && point.y > rec.y && point.x < (rec.x + rec.z ) && point.y < (rec.y + rec.w ) ){
4704
- return true ;
4705
- }
4706
- return false;
4765
+ fn insideRectangle( point:vec2f , rec:vec4f) -> bool {
4766
+ if( point.x > rec.x && point.y > rec.y && point.x < (rec.x + rec.z ) && point.y < (rec.y + rec.w ) ){
4767
+ return true ;
4768
+ }
4769
+ return false;
4707
4770
  }
4708
4771
 
4709
- fn convert_cube_uv_to_xyz(index:i32, u:f32, v:f32) -> vec3f {
4710
- var ret: vec3f;
4711
- var uc = 2.0f * u - 1.0f;
4712
- var vc = 2.0f * v - 1.0f;
4713
- switch(index){
4714
- case 0: {
4715
- ret.x = 1.0f;
4716
- ret.y = vc;
4717
- ret.z = -uc;
4718
- break;
4719
- }
4720
- case 1: {
4721
- ret.x = -1.0f;
4722
- ret.y = vc;
4723
- ret.z = uc;
4724
- break;
4725
- }
4726
- case 2: {
4727
- ret.x = uc;
4728
- ret.y = 1.0f;
4729
- ret.z = -vc;
4730
- break;
4731
- }
4732
- case 3: {
4733
- ret.x = uc;
4734
- ret.y = -1.0f;
4735
- ret.z = vc;
4736
- break;
4737
- }
4738
- case 4: {
4739
- ret.x = uc;
4740
- ret.y = vc;
4741
- ret.z = 1.0f;
4742
- break;
4743
- }
4744
- case 5: {
4745
- ret.x = -uc;
4746
- ret.y = vc;
4747
- ret.z = -1.0f;
4748
- break;
4749
- }
4750
- default: {
4751
- ret = vec3f(0.0);
4752
- }
4772
+ fn convert_cube_uv_to_xyz( index:i32, u:f32, v:f32) -> vec3f
4773
+ {
4774
+ var ret : vec3f ;
4775
+ // convert range 0 to 1 to -1 to 1
4776
+ var uc = 2.0f * u - 1.0f;
4777
+ var vc = 2.0f * v - 1.0f;
4778
+ switch (index)
4779
+ {
4780
+ case 0: {
4781
+ ret.x = 1.0f;
4782
+ ret.y = vc;
4783
+ ret.z = -uc;
4784
+ break;
4785
+ } // POSITIVE X
4786
+ case 1: {
4787
+ ret.x = -1.0f;
4788
+ ret.y = vc;
4789
+ ret.z = uc;
4790
+ break;
4791
+ } // NEGATIVE X
4792
+ case 2: {
4793
+ ret.x = uc;
4794
+ ret.y = 1.0f;
4795
+ ret.z = -vc;
4796
+ break;
4797
+ } // POSITIVE Y
4798
+ case 3: {
4799
+ ret.x = uc;
4800
+ ret.y = -1.0f;
4801
+ ret.z = vc;
4802
+ break;
4803
+ } // NEGATIVE Y
4804
+ case 4: {
4805
+ ret.x = uc;
4806
+ ret.y = vc;
4807
+ ret.z = 1.0f;
4808
+ break;
4809
+ } // POSITIVE Z
4810
+ case 5: {
4811
+ ret.x = -uc;
4812
+ ret.y = vc;
4813
+ ret.z = -1.0f;
4814
+ break;
4815
+ } // NEGATIVE Z
4816
+ default:{
4817
+ ret = vec3f(0.0);
4753
4818
  }
4754
- return ret;
4819
+ }
4820
+ return ret ;
4755
4821
  }
4756
4822
 
4757
- fn convert_cube_uv_to_normal(index:i32, u:f32, v:f32) -> vec3f{
4758
- var ret: vec3f;
4759
- var uc = 2.0f * u - 1.0f;
4760
- var vc = 2.0f * v - 1.0f;
4761
- switch(index){
4762
- case 0: {
4763
- ret.x = 1.0f;
4764
- ret.y = vc;
4765
- ret.z = -uc;
4766
- break;
4767
- } // POSITIVE X
4768
- case 1: {
4769
- ret.x = -1.0f;
4770
- ret.y = vc;
4771
- ret.z = uc;
4772
- break;
4773
- } // NEGATIVE X
4774
- case 2: {
4775
- ret.x = uc;
4776
- ret.y = 1.0f;
4777
- ret.z = -vc;
4778
- break;
4779
- } // POSITIVE Y
4780
- case 3: {
4781
- ret.x = uc;
4782
- ret.y = -1.0f;
4783
- ret.z = vc;
4784
- break;
4785
- } // NEGATIVE Y
4786
- case 4: {
4787
- ret.x = uc;
4788
- ret.y = vc;
4789
- ret.z = 1.0f;
4790
- break;
4791
- } // POSITIVE Z
4792
- case 5: {
4793
- ret.x = -uc;
4794
- ret.y = vc;
4795
- ret.z = -1.0f;
4796
- break;
4797
- } // NEGATIVE Z
4798
- default:{
4799
- ret = vec3f(0.0);
4800
- }
4823
+ fn convert_cube_uv_to_normal( index:i32, u:f32, v:f32) -> vec3f
4824
+ {
4825
+ var ret : vec3f ;
4826
+ // convert range 0 to 1 to -1 to 1
4827
+ var uc = 2.0f * u - 1.0f;
4828
+ var vc = 2.0f * v - 1.0f;
4829
+ switch (index)
4830
+ {
4831
+ case 0: {
4832
+ ret.x = 1.0f;
4833
+ ret.y = vc;
4834
+ ret.z = -uc;
4835
+ break;
4836
+ } // POSITIVE X
4837
+ case 1: {
4838
+ ret.x = -1.0f;
4839
+ ret.y = vc;
4840
+ ret.z = uc;
4841
+ break;
4842
+ } // NEGATIVE X
4843
+ case 2: {
4844
+ ret.x = uc;
4845
+ ret.y = 1.0f;
4846
+ ret.z = -vc;
4847
+ break;
4848
+ } // POSITIVE Y
4849
+ case 3: {
4850
+ ret.x = uc;
4851
+ ret.y = -1.0f;
4852
+ ret.z = vc;
4853
+ break;
4854
+ } // NEGATIVE Y
4855
+ case 4: {
4856
+ ret.x = uc;
4857
+ ret.y = vc;
4858
+ ret.z = 1.0f;
4859
+ break;
4860
+ } // POSITIVE Z
4861
+ case 5: {
4862
+ ret.x = -uc;
4863
+ ret.y = vc;
4864
+ ret.z = -1.0f;
4865
+ break;
4866
+ } // NEGATIVE Z
4867
+ default:{
4868
+ ret = vec3f(0.0);
4801
4869
  }
4802
- return ret;
4870
+ }
4871
+ return ret ;
4803
4872
  }
4804
4873
 
4805
- fn UvToDir(uv1:vec2f) -> vec3f{
4806
- var uv = uv1;
4807
- uv *= vec2f(2.0*3.1415926535897932384626433832795, 3.1415926535897932384626433832795);
4808
- var theta = uv.y;
4809
- var phi = uv.x + 3.1415926535897932384626433832795 * 0.5 ;
4810
- var dir = vec3f(0.0,0.0,0.0);
4811
- dir.x = sin(phi) * sin(theta) * -1;
4812
- dir.y = cos(theta) * -1;
4813
- dir.z = cos(phi) * sin(theta);
4814
- return dir;
4874
+ fn UvToDir( uv1:vec2f) -> vec3f{
4875
+ var uv = uv1 ;
4876
+ uv *= vec2f(2.0*3.1415926535897932384626433832795, 3.1415926535897932384626433832795);
4877
+ var theta = uv.y;
4878
+ var phi = uv.x + 3.1415926535897932384626433832795 * 0.5 ;
4879
+ // var phi = uv.x ;
4880
+ var dir = vec3f(0.0,0.0,0.0);
4881
+ dir.x = sin(phi) * sin(theta) * -1;
4882
+ dir.y = cos(theta) * -1;
4883
+ dir.z = cos(phi) * sin(theta);
4884
+ return dir;
4815
4885
  }
4816
4886
 
4817
- fn DirTOUV(a_coords:vec3f) -> vec2f {
4818
- var coords = normalize(a_coords);
4819
- var lon = atan2(coords.z, coords.x);
4820
- var lat = acos(coords.y);
4821
- var sphereCoords = vec2f(lon, lat) * (1.0 / 3.1415926535897932384626433832795);
4822
- return vec2f(sphereCoords.x * 0.5 + 0.5, 1.0 - sphereCoords.y);
4887
+ fn DirTOUV( a_coords:vec3f ) ->vec2f
4888
+ {
4889
+ var coords = normalize(a_coords);
4890
+ var lon = atan2(coords.z, coords.x);
4891
+ var lat = acos(coords.y);
4892
+ var sphereCoords = vec2f(lon, lat) * (1.0 / 3.1415926535897932384626433832795);
4893
+ return vec2f(sphereCoords.x * 0.5 + 0.5 , 1.0 - sphereCoords.y);
4823
4894
  }
4824
- `;
4895
+
4896
+ `
4897
+ );
4825
4898
 
4826
4899
  let PhysicMaterialUniform_frag = `
4827
4900
  #if USE_CUSTOMUNIFORM
@@ -5172,7 +5245,9 @@ var<uniform> materialUniform: MaterialUniform;
5172
5245
  }
5173
5246
  `;
5174
5247
 
5175
- let Inline_vert = `
5248
+ let Inline_vert = (
5249
+ /*wgsl*/
5250
+ `
5176
5251
  #include "MathShader"
5177
5252
  #include "FastMathShader"
5178
5253
  #include "InstanceUniform"
@@ -5193,35 +5268,35 @@ var<uniform> materialUniform: MaterialUniform;
5193
5268
  }
5194
5269
 
5195
5270
  fn TIME_frame() -> f32 {
5196
- return globalUniform.frame;
5271
+ return globalUniform.frame ;
5197
5272
  }
5198
5273
 
5199
5274
  fn TIME_time() -> f32 {
5200
- return globalUniform.time;
5275
+ return globalUniform.time ;
5201
5276
  }
5202
5277
 
5203
5278
  fn TIME_delta() -> f32 {
5204
- return globalUniform.delta;
5279
+ return globalUniform.delta ;
5205
5280
  }
5206
5281
 
5207
5282
  fn MOUSE() -> vec2f {
5208
- return vec2f( globalUniform.mouseX, globalUniform.mouseY);
5283
+ return vec2f( globalUniform.mouseX, globalUniform.mouseY) ;
5209
5284
  }
5210
5285
 
5211
5286
  fn SCREEN() -> vec2f {
5212
- return vec2f( globalUniform.windowWidth, globalUniform.windowHeight);
5287
+ return vec2f( globalUniform.windowWidth, globalUniform.windowHeight) ;
5213
5288
  }
5214
5289
 
5215
5290
  fn ProjectionParams() -> vec3f {
5216
- return vec3f( globalUniform.near, globalUniform.far,1.0 + 1.0 / globalUniform.far);
5291
+ return vec3f( globalUniform.near, globalUniform.far,1.0 + 1.0 / globalUniform.far) ;
5217
5292
  }
5218
5293
 
5219
5294
  fn vertex_inline(vertex:VertexAttributes){
5220
- ORI_MATRIX_P = globalUniform.projMat;
5221
- ORI_MATRIX_V = globalUniform.viewMat;
5222
- ORI_MATRIX_PV = ORI_MATRIX_P * ORI_MATRIX_V;
5223
- ORI_MATRIX_PVInv = globalUniform.pvMatrixInv;
5224
- ORI_CAMERAMATRIX = globalUniform.cameraWorldMatrix;
5295
+ ORI_MATRIX_P = globalUniform.projMat ;
5296
+ ORI_MATRIX_V = globalUniform.viewMat ;
5297
+ ORI_MATRIX_PV = ORI_MATRIX_P * ORI_MATRIX_V ;
5298
+ ORI_MATRIX_PVInv = globalUniform.pvMatrixInv ;
5299
+ ORI_CAMERAMATRIX = globalUniform.cameraWorldMatrix ;
5225
5300
 
5226
5301
  ORI_MATRIX_M = models.matrix[u32(vertex.index)];
5227
5302
 
@@ -5230,7 +5305,8 @@ var<uniform> materialUniform: MaterialUniform;
5230
5305
  ORI_MATRIX_M = models.matrix[modelID];
5231
5306
  #endif
5232
5307
  }
5233
- `;
5308
+ `
5309
+ );
5234
5310
 
5235
5311
  let Common_frag = `
5236
5312
  #include "GlobalUniform"
@@ -5295,7 +5371,9 @@ var<uniform> materialUniform: MaterialUniform;
5295
5371
  }
5296
5372
  `;
5297
5373
 
5298
- let Common_vert = `
5374
+ let Common_vert = (
5375
+ /*wgsl*/
5376
+ `
5299
5377
  #include "WorldMatrixUniform"
5300
5378
  #include "VertexAttributes_vert"
5301
5379
  #include "GlobalUniform"
@@ -5304,9 +5382,10 @@ var<uniform> materialUniform: MaterialUniform;
5304
5382
  fn VertMain( vertex:VertexAttributes ) -> VertexOutput {
5305
5383
  vertex_inline(vertex);
5306
5384
  vert(vertex);
5307
- return ORI_VertexOut;
5385
+ return ORI_VertexOut ;
5308
5386
  }
5309
- `;
5387
+ `
5388
+ );
5310
5389
 
5311
5390
  let BrdfLut_frag = (
5312
5391
  /*wgsl*/
@@ -5336,103 +5415,122 @@ var<uniform> materialUniform: MaterialUniform;
5336
5415
  static Cascades = 4;
5337
5416
  }
5338
5417
 
5339
- let GlobalUniform = `
5418
+ let GlobalUniform = (
5419
+ /*wgsl*/
5420
+ `
5340
5421
 
5341
- #include "MathShader"
5422
+ #include "MathShader"
5342
5423
 
5343
- struct GlobalUniform {
5344
-
5345
- projMat: mat4x4<f32>,
5346
- viewMat: mat4x4<f32>,
5347
- cameraWorldMatrix: mat4x4<f32>,
5348
- pvMatrixInv: mat4x4<f32>,
5349
- viewToWorld: mar4x4<f32>,
5350
- shadowMatrix: array<mat4x4<f32>, 8u>,
5351
- csmShadowBias: vec4<f32>,
5352
- csmMatrix: array<mat4x4<f32>,${CSM.Cascades}>,
5353
- shadowLights:mat4x4<f32>,
5354
- reflectionProbeSize:f32,
5355
- reflectionProbeMaxCount:f32,
5356
- reflectionMapWidth:f32,
5357
- reflectionMapHeight:f32,
5358
- reflectionCount:f32,
5359
- test2:f32,
5360
- test3:f32,
5361
- test4:f32,
5362
- CameraPos: vec3<f32>,
5363
- frame: f32,
5364
- SH: array<vec4f,9u>,
5365
- time: f32,
5366
- delta: f32,
5367
- shadowBias: f32,
5368
- skyExposure: f32,
5369
- renderPassState: f32,
5370
- quadScale: f32,
5371
- hdrExposure: f32,
5372
- renderState_left: i32,
5373
- renderState_right: i32,
5374
- renderState_split: f32,
5375
- mouseX: f32,
5376
- mouseY: f32,
5377
- windowWidth: f32,
5378
- windowHeight: f32,
5379
- near: f32,
5380
- far: f32,
5381
- pointShadowBias: f32,
5382
- shadowMapSize: f32,
5383
- shadowSoft: f32,
5384
- enableCSM:f32,
5385
- csmMargin:f32,
5386
- nDirShadowStart: i32,
5387
- nDirShadowEnd: i32,
5388
- nPointShadowStart: i32,
5389
- nPointShadowEnd: i32,
5390
- cameraForward:vec3f,
5391
- frustumPlanes: array<vec4f, 6u>,
5392
- };
5424
+ struct GlobalUniform {
5393
5425
 
5394
- @group(0) @binding(0)
5395
- var<uniform> globalUniform: GlobalUniform;
5426
+ projMat: mat4x4<f32>,
5427
+ viewMat: mat4x4<f32>,
5428
+ cameraWorldMatrix: mat4x4<f32>,
5429
+ pvMatrixInv : mat4x4<f32>,
5430
+ viewToWorld : mat4x4<f32>,
5431
+ shadowMatrix: array<mat4x4<f32>, 8u>,
5396
5432
 
5397
- fn getViewPosition(z:f32,uv:vec2f) -> vec3f {
5398
- let pvMatrixInv = globalUniform.pvMatrixInv;
5399
- let clip = vec4<f32>((uv * 2.0 - 1.0), z, 1.0);
5400
- var viewPos = pvMatrixInv * clip;
5401
- return viewPos.xyz / viewPos.w;
5402
- }
5433
+ csmShadowBias: vec4<f32>,
5403
5434
 
5404
- fn getWorldPosition(z:f32,uv:vec2f) -> vec3f {
5405
- let viewToWorld = globalUniform.viewToWorld;
5406
- let clip = vec4<f32>((uv * 2.0 -1.0), z, 1.0);
5407
- var worldPos = viewToWorld * clip;
5408
- worldPos = worldPos / worldPos.w;
5409
- return worldPos.xyz;
5410
- }
5435
+ csmMatrix: array<mat4x4<f32>,${CSM.Cascades}>,
5436
+
5437
+ shadowLights:mat4x4<f32>,
5411
5438
 
5412
- var<private> NORMALMATRIX_INV : mat3x3<f32>;
5413
- var<private> NORMALMATRIX : mat3x3<f32>;
5414
- fn useNormalMatrix() {
5415
- let finalMatrix = globalUniform.projMat * globalUniform.viewMat;
5416
- let nMat = mat3x3<f32>(finalMatrix[0].xyz,finalMatrix[1].xyz,fianlMatrix[2].xyz);
5417
- NORMALMATRIX = transpose(inverse(nMat));
5418
- }
5439
+ reflectionProbeSize:f32,
5440
+ reflectionProbeMaxCount:f32,
5441
+ reflectionMapWidth:f32,
5442
+ reflectionMapHeight:f32,
5419
5443
 
5420
- fn useNormalMatrixInv() {
5421
- let finalMatrix = globalUniform.projMat * globalUniform.viewMat;
5422
- let nMat = mat3x3<f32>(finalMatrix[0].xyz,finalMatrix[1].xyz,finalMatrix[2].xyz);
5423
- NORMALMATRIX_INV = transpose((nMat));
5424
- }
5444
+ reflectionCount:f32,
5445
+ test2:f32,
5446
+ test3:f32,
5447
+ test4:f32,
5425
5448
 
5426
- fn getWorldNormal(viewNormal:vec3f) -> vec3f {
5427
- var worldNormal = NORMALMATRIX_INV * viewNormal;
5428
- return normalize(worldNormal.xyz);
5429
- }
5449
+ CameraPos: vec3<f32>,
5450
+ frame: f32,
5451
+ SH: array<vec4f, 9u> ,
5430
5452
 
5431
- fn getViewNormal(worldNormal:vec3f) -> vec3f {
5432
- var viewNormal = globalUniform.viewMat * vec4f(worldNormal,0.0);
5433
- return normalize(viewNormal.xyz);
5434
- }
5435
- `;
5453
+ time: f32,
5454
+ delta: f32,
5455
+ shadowBias: f32,
5456
+ skyExposure: f32,
5457
+
5458
+ renderPassState:f32,
5459
+ quadScale: f32,
5460
+ hdrExposure: f32,
5461
+ renderState_left: i32,
5462
+
5463
+ renderState_right: i32,
5464
+ renderState_split: f32,
5465
+ mouseX: f32,
5466
+ mouseY: f32,
5467
+
5468
+ windowWidth: f32,
5469
+ windowHeight: f32,
5470
+ near: f32,
5471
+ far: f32,
5472
+
5473
+ pointShadowBias: f32,
5474
+ shadowMapSize: f32,
5475
+ shadowSoft: f32,
5476
+ enableCSM:f32,
5477
+
5478
+
5479
+ csmMargin:f32,
5480
+ nDirShadowStart: i32,
5481
+ nDirShadowEnd: i32,
5482
+ nPointShadowStart: i32,
5483
+
5484
+ nPointShadowEnd: i32,
5485
+ cameraForward:vec3f,
5486
+
5487
+ frustumPlanes: array<vec4f, 6u>,
5488
+
5489
+ };
5490
+
5491
+ @group(0) @binding(0)
5492
+ var<uniform> globalUniform: GlobalUniform;
5493
+
5494
+ fn getViewPosition(z:f32,uv:vec2f) -> vec3f {
5495
+ let pvMatrixInv = globalUniform.pvMatrixInv ;
5496
+ let clip = vec4<f32>((uv * 2.0 - 1.0) , z , 1.0);
5497
+ var viewPos = pvMatrixInv * clip ;
5498
+ return viewPos.xyz / viewPos.w ;
5499
+ }
5500
+
5501
+ fn getWorldPosition(z:f32,uv:vec2f) -> vec3f {
5502
+ let viewToWorld = globalUniform.viewToWorld ;
5503
+ let clip = vec4<f32>((uv * 2.0 - 1.0) , z , 1.0);
5504
+ var worldPos = viewToWorld * clip ;
5505
+ worldPos = worldPos / worldPos.w ;
5506
+ return worldPos.xyz ;
5507
+ }
5508
+
5509
+ var<private> NORMALMATRIX_INV : mat3x3<f32> ;
5510
+ var<private> NORMALMATRIX : mat3x3<f32> ;
5511
+ fn useNormalMatrix() {
5512
+ let finalMatrix = globalUniform.projMat * globalUniform.viewMat ;
5513
+ let nMat = mat3x3<f32>(finalMatrix[0].xyz,finalMatrix[1].xyz,finalMatrix[2].xyz) ;
5514
+ NORMALMATRIX = transpose(inverse( nMat ));
5515
+ }
5516
+
5517
+ fn useNormalMatrixInv() {
5518
+ let finalMatrix = globalUniform.projMat * globalUniform.viewMat ;
5519
+ let nMat = mat3x3<f32>(finalMatrix[0].xyz,finalMatrix[1].xyz,finalMatrix[2].xyz) ;
5520
+ NORMALMATRIX_INV = transpose(( nMat ));
5521
+ }
5522
+
5523
+ fn getWorldNormal(viewNormal:vec3f) -> vec3f {
5524
+ var worldNormal = NORMALMATRIX_INV * viewNormal ;
5525
+ return normalize(worldNormal.xyz);
5526
+ }
5527
+
5528
+ fn getViewNormal(worldNormal:vec3f) -> vec3f {
5529
+ var viewNormal = globalUniform.viewMat * vec4f(worldNormal,0.0) ;
5530
+ return normalize(viewNormal.xyz);
5531
+ }
5532
+ `
5533
+ );
5436
5534
 
5437
5535
  let InstanceUniform = `
5438
5536
  #if USE_INSTANCEDRAW
@@ -5444,14 +5542,17 @@ var<uniform> materialUniform: MaterialUniform;
5444
5542
  #endif
5445
5543
  `;
5446
5544
 
5447
- let WorldMatrixUniform = `
5545
+ let WorldMatrixUniform = (
5546
+ /*wgsl*/
5547
+ `
5448
5548
  struct Uniforms {
5449
- matrix: array<mat4x4<f32>>
5549
+ matrix : array<mat4x4<f32>>
5450
5550
  };
5451
5551
 
5452
- @group(0) @building(1)
5453
- var<storage, read> models: Uniforms;
5454
- `;
5552
+ @group(0) @binding(1)
5553
+ var<storage, read> models : Uniforms;
5554
+ `
5555
+ );
5455
5556
 
5456
5557
  let FastMathShader = `
5457
5558
  fn pow2(x:f32) -> f32 {
@@ -5522,7 +5623,7 @@ var<uniform> materialUniform: MaterialUniform;
5522
5623
  return res ;
5523
5624
  }else{
5524
5625
  return PI - res ;
5525
- }
5626
+ };
5526
5627
  }
5527
5628
 
5528
5629
  fn acosFast4( inX : f32 )-> f32
@@ -5541,12 +5642,15 @@ var<uniform> materialUniform: MaterialUniform;
5541
5642
  return s ;
5542
5643
  }else{
5543
5644
  return PI - s ;
5544
- }
5645
+ };
5545
5646
  }
5546
5647
  `;
5547
5648
 
5548
- let NormalMap_frag = `
5549
- fn perturbNormal( worldPos:vec3<f32>, surf_norm:vec3<f32>, mapN:vec3<f32>, normalScale:f32, face:f32 ) -> vec3<f32> {
5649
+ let NormalMap_frag = (
5650
+ /*wgsl*/
5651
+ `
5652
+
5653
+ fn perturbNormal( worldPos:vec3<f32>, surf_norm:vec3<f32>, mapN:vec3<f32> , normalScale:f32 , face:f32 ) -> vec3<f32> {
5550
5654
  var q0 = vec3<f32>( dpdx( worldPos.x ), dpdx( worldPos.y ), dpdx( worldPos.z ) );
5551
5655
  var q1 = vec3<f32>( dpdy( worldPos.x ), dpdy( worldPos.y ), dpdy( worldPos.z ) );
5552
5656
  var st0 = dpdx( ORI_VertexVarying.fragUV0.xy );
@@ -5554,12 +5658,17 @@ var<uniform> materialUniform: MaterialUniform;
5554
5658
  var N = surf_norm;
5555
5659
  var q0perp = cross( N, q0 );
5556
5660
  var q1perp = cross( q1, N );
5661
+
5662
+ var T = q1perp * st0.x + q0perp * st1.x;
5663
+
5557
5664
  var B = q1perp * st0.y + q0perp * st1.y;
5665
+
5558
5666
  var det = max( dot( T, T ), dot( B, B ) );
5559
5667
  var scale = 1.0 ;
5560
5668
  if( det != 0.0 ){
5561
5669
  scale = inverseSqrt( det ) ;
5562
5670
  }
5671
+
5563
5672
  scale *= normalScale;
5564
5673
  return normalize( (T * ( -mapN.x * scale ) + B * ( mapN.y * scale ) + N * mapN.z ) * face ) ;
5565
5674
  }
@@ -5600,7 +5709,8 @@ var<uniform> materialUniform: MaterialUniform;
5600
5709
  var outN = perturbNormal(ORI_VertexVarying.vWorldPos.xyz,ORI_VertexVarying.vWorldNormal,mapNormal,1.0,face) ;
5601
5710
  return outN ;
5602
5711
  }
5603
- `;
5712
+ `
5713
+ );
5604
5714
 
5605
5715
  let FragmentVarying = `
5606
5716
  struct FragmentVarying {
@@ -5694,7 +5804,7 @@ var<uniform> materialUniform: MaterialUniform;
5694
5804
  return textureSampleLevel(iesTextureArrayMap, iesTextureArrayMapSampler, vec2<f32>(normAngle , normTangentAngle) , i32(light.ies) , 0.0).r ;
5695
5805
  }else{
5696
5806
  return 1.0;
5697
- }
5807
+ };
5698
5808
  #else
5699
5809
  return 1.0;
5700
5810
  #endif
@@ -5762,12 +5872,12 @@ var<uniform> materialUniform: MaterialUniform;
5762
5872
  weight *= 1.0 - totalWeight;
5763
5873
  visibility += csmShadowResult.x * weight;
5764
5874
  totalWeight += weight;
5765
- }
5875
+ };
5766
5876
 
5767
5877
  if(validCount >= 2 || totalWeight >= 0.99){
5768
5878
  csmLevel = csm;
5769
5879
  break;
5770
- }
5880
+ };
5771
5881
  }
5772
5882
  }
5773
5883
 
@@ -5776,7 +5886,7 @@ var<uniform> materialUniform: MaterialUniform;
5776
5886
  visibility = 1.0;
5777
5887
  }else{
5778
5888
  visibility = visibility / totalWeight ;
5779
- }
5889
+ };
5780
5890
  } else {
5781
5891
  shadowMatrix = globalUniform.shadowMatrix[shadowIndex];
5782
5892
  if(enableCSM) {
@@ -5825,7 +5935,7 @@ var<uniform> materialUniform: MaterialUniform;
5825
5935
  totalWeight += weight;
5826
5936
  }else{
5827
5937
  totalWeight += 1.0;
5828
- }
5938
+ };
5829
5939
  }
5830
5940
  }
5831
5941
  visibility /= totalWeight;
@@ -6638,7 +6748,9 @@ var<uniform> materialUniform: MaterialUniform;
6638
6748
  }
6639
6749
  `;
6640
6750
 
6641
- let BxDF_frag = `
6751
+ let BxDF_frag = (
6752
+ /*wgsl*/
6753
+ `
6642
6754
  #include "Clearcoat_frag"
6643
6755
  #include "BRDF_frag"
6644
6756
  #include "MathShader"
@@ -6656,7 +6768,9 @@ var<uniform> materialUniform: MaterialUniform;
6656
6768
  #include "BxdfDebug_frag"
6657
6769
  #include "ReflectionCG"
6658
6770
 
6771
+ //ORI_ShadingInput
6659
6772
  fn initFragData() {
6773
+ // fragData.Albedo = vec4f(gammaToLiner(ORI_ShadingInput.BaseColor.rgb),ORI_ShadingInput.BaseColor.w) ;
6660
6774
  fragData.Albedo = vec4f((ORI_ShadingInput.BaseColor.rgb),ORI_ShadingInput.BaseColor.w) ;
6661
6775
  fragData.Ao = clamp( pow(ORI_ShadingInput.AmbientOcclusion,materialUniform.ao) , 0.0 , 1.0 ) ;
6662
6776
  fragData.Roughness = clamp((ORI_ShadingInput.Roughness),0.0001,1.0) * 1.85 ;
@@ -6672,13 +6786,19 @@ var<uniform> materialUniform: MaterialUniform;
6672
6786
 
6673
6787
  let R = 2.0 * dot( fragData.V , fragData.N ) * fragData.N - fragData.V ;
6674
6788
  fragData.R = R ;//reflect( fragData.V , fragData.N ) ;
6789
+
6675
6790
  fragData.NoV = saturate(dot(fragData.N, fragData.V)) ;
6791
+
6676
6792
  fragData.F0 = mix(vec3<f32>(0.04), fragData.Albedo.rgb , fragData.Metallic);
6793
+ // fragData.F0 = gammaToLiner(fragData.F0);
6794
+
6677
6795
  fragData.F = computeFresnelSchlick(fragData.NoV, fragData.F0);
6678
6796
  fragData.KD = vec3<f32>(fragData.F) ;
6679
6797
  fragData.KS = vec3<f32>(0.0) ;
6798
+
6680
6799
  fragData.Indirect = 0.0 ;
6681
6800
  fragData.Reflectance = 1.0 ;
6801
+
6682
6802
  fragData.ClearcoatRoughness = materialUniform.clearcoatRoughnessFactor ;
6683
6803
  fragData.ClearcoatIor = materialUniform.clearcoatIor ;
6684
6804
  fragData.ClearcoatFactor = materialUniform.clearcoatFactor;
@@ -6691,7 +6811,9 @@ var<uniform> materialUniform: MaterialUniform;
6691
6811
 
6692
6812
  fn BxDFShading(){
6693
6813
  initFragData();
6814
+
6694
6815
  let sunLight = lightBuffer[0] ;
6816
+
6695
6817
  var irradiance = vec3<f32>(0.0) ;
6696
6818
  #if USEGI
6697
6819
  irradiance += getIrradiance().rgb ;
@@ -6752,6 +6874,7 @@ var<uniform> materialUniform: MaterialUniform;
6752
6874
  }
6753
6875
 
6754
6876
  //***********indirect-ambient part*********
6877
+ // var kdLast = (1.0 - 0.04) * (1.0 - fragData.Metallic);
6755
6878
  var iblDiffuseResult : vec3f ;
6756
6879
 
6757
6880
  let MAX_LOD = i32(textureNumLevels(prefilterMap)) ;
@@ -6765,7 +6888,8 @@ var<uniform> materialUniform: MaterialUniform;
6765
6888
  indirectionSpec *= globalUniform.hdrExposure ;
6766
6889
  #endif
6767
6890
 
6768
- var color = vec3f(iblDiffuseResult + indirectionSpec + specColor);
6891
+ var color = vec3f(iblDiffuseResult + indirectionSpec + specColor) ;
6892
+ // var color = vec3f(indirectionDiffuse ) ;
6769
6893
 
6770
6894
  var clearCoatColor = vec3<f32>(0.0);
6771
6895
  #if USE_CLEARCOAT
@@ -6790,6 +6914,9 @@ var<uniform> materialUniform: MaterialUniform;
6790
6914
  break;
6791
6915
  }
6792
6916
  case SpotLightType: {
6917
+ // var lightColor = light.lightColor.rgb ;
6918
+ // var att = pointAtt(ORI_VertexVarying.vWorldPos.xyz, light);
6919
+ // clearCoatColor += ClearCoat_BRDF( color , materialUniform.clearcoatColor.rgb , 1.5 , clearNormal , light.direction , fragData.V , clearcoatRoughness , lightColor, att );
6793
6920
  break;
6794
6921
  }
6795
6922
  default: {
@@ -6828,7 +6955,9 @@ var<uniform> materialUniform: MaterialUniform;
6828
6955
  ORI_FragmentOutput.color = viewColor ;
6829
6956
  #endif
6830
6957
  }
6831
- `;
6958
+
6959
+ `
6960
+ );
6832
6961
 
6833
6962
  let BsDF_frag = `
6834
6963
  #include "Clearcoat_frag"
@@ -7028,7 +7157,9 @@ var<uniform> materialUniform: MaterialUniform;
7028
7157
  }
7029
7158
  `;
7030
7159
 
7031
- let PBRLItShader = `
7160
+ let PBRLItShader = (
7161
+ /*wgsl*/
7162
+ `
7032
7163
  #include "Common_vert"
7033
7164
  #include "Common_frag"
7034
7165
  #include "BxDF_frag"
@@ -7043,10 +7174,10 @@ var<uniform> materialUniform: MaterialUniform;
7043
7174
  @group(1) @binding(auto)
7044
7175
  var normalMap: texture_2d<f32>;
7045
7176
 
7046
- @group(1) @binding(auto)
7047
- var maskMapSampler: sampler;
7048
- @group(1) @binding(auto)
7049
- var maskMap: texture_2d<f32>;
7177
+ @group(1) @binding(auto)
7178
+ var maskMapSampler: sampler;
7179
+ @group(1) @binding(auto)
7180
+ var maskMap: texture_2d<f32>;
7050
7181
 
7051
7182
  #if USE_AOTEX
7052
7183
  @group(1) @binding(auto)
@@ -7060,38 +7191,39 @@ var<uniform> materialUniform: MaterialUniform;
7060
7191
  @group(1) @binding(auto)
7061
7192
  var emissiveMap: texture_2d<f32>;
7062
7193
 
7063
- var<private> debugOut: vec4f = vec4f(0.0);
7194
+ var<private> debugOut : vec4f = vec4f(0.0) ;
7064
7195
 
7065
7196
  fn vert(inputData:VertexAttributes) -> VertexOutput {
7066
- ORI_Vert(inputData);
7067
- return ORI_VertextOut;
7197
+ ORI_Vert(inputData) ;
7198
+ return ORI_VertexOut ;
7068
7199
  }
7069
7200
 
7070
7201
  fn frag(){
7202
+
7071
7203
  let baseMapOffsetSize = materialUniform.baseMapOffsetSize;
7072
- var uv = transformUV(ORI_VertexVarying.fragUV0, baseMapOffsetSize);
7204
+ var uv = transformUV(ORI_VertexVarying.fragUV0,baseMapOffsetSize) ;
7073
7205
 
7074
7206
  #if USE_SRGB_ALBEDO
7075
- ORI_ShadingInput.BaseColor = textureSample(baseMap, baseMapSampler, uv);
7076
- ORI_ShadingInput.BaseColor = vec4<f32>(ORI_ShadingInput.BaseColor * materialUniform.baseColor.rgb, ORI_ShadingInput.BaseColor.w * materialUniform.baseColor.a);
7207
+ ORI_ShadingInput.BaseColor = textureSample(baseMap, baseMapSampler, uv ) ;
7208
+ ORI_ShadingInput.BaseColor = vec4<f32>( ORI_ShadingInput.BaseColor * materialUniform.baseColor.rgb, ORI_ShadingInput.BaseColor.w * materialUniform.baseColor.a) ;
7077
7209
  #else
7078
- ORI_ShadingInput.BaseColor = textureSampler(baseMap, baseMapSampler, uv);
7079
- ORI_ShadingInput.BaseColor = vec4f(gammaToLiner(ORI_ShadingInput.BaseColor.rgb), ORI_ShadingInput.BaseColor.a);
7080
- ORI_ShadingInput.BaseColor *= vec4f(materialUniform.baseColor.rgba);
7210
+ ORI_ShadingInput.BaseColor = textureSample(baseMap, baseMapSampler, uv ) ;
7211
+ ORI_ShadingInput.BaseColor = vec4f(gammaToLiner(ORI_ShadingInput.BaseColor.rgb),ORI_ShadingInput.BaseColor.a) ;
7212
+ ORI_ShadingInput.BaseColor *= vec4f(materialUniform.baseColor.rgba) ;
7081
7213
  #endif
7082
7214
 
7083
7215
  let roughnessMapOffsetSize = materialUniform.roughnessMapOffsetSize;
7084
- var uv4 = transformUV(ORI_VertexVarying.fragUV0, roughnessMapOffsetSize);
7085
- var maskTex = textureSample(maskMap, maskMapSampler, uv4);
7086
-
7216
+ var uv4 = transformUV(ORI_VertexVarying.fragUV0,roughnessMapOffsetSize);
7217
+ var maskTex = textureSample(maskMap, maskMapSampler, uv4 );
7218
+
7087
7219
  #if USE_ALPHA_A
7088
- ORI_ShadingInput.BaseColor.a = ORI_ShadingInput.BaseColor.a * (maskTex.a);
7220
+ ORI_ShadingInput.BaseColor.a = ORI_ShadingInput.BaseColor.a * (maskTex.a) ;
7089
7221
  #endif
7090
7222
 
7091
- #if USE_ALPHACUT
7223
+ #if USE_ALPHACUT
7092
7224
  if( (ORI_ShadingInput.BaseColor.a - materialUniform.alphaCutoff) <= 0.0 ){
7093
7225
  ORI_FragmentOutput.color = vec4<f32>(0.0,0.0,0.0,1.0);
7094
-
7226
+
7095
7227
  #if USEGBUFFER
7096
7228
  ORI_FragmentOutput.worldPos = vec4<f32>(0.0,0.0,0.0,1.0);
7097
7229
  ORI_FragmentOutput.worldNormal = vec4<f32>(0.0,0.0,0.0,1.0);
@@ -7104,7 +7236,7 @@ var<uniform> materialUniform: MaterialUniform;
7104
7236
 
7105
7237
  useShadow();
7106
7238
 
7107
- var roughnessChannel: f32 = 1.0;
7239
+ var roughnessChannel:f32 = 1.0 ;
7108
7240
  #if USE_ROUGHNESS_A
7109
7241
  roughnessChannel = maskTex.a ;
7110
7242
  #else if USE_ROUGHNESS_R
@@ -7115,16 +7247,16 @@ var<uniform> materialUniform: MaterialUniform;
7115
7247
  roughnessChannel = maskTex.b ;
7116
7248
  #else if USE_ALBEDO_A
7117
7249
  roughnessChannel = ORI_ShadingInput.BaseColor.a ;
7118
- #endif
7250
+ #endif
7119
7251
 
7120
7252
  #if USE_SMOOTH
7121
7253
  var roughness = ( 1.0 - roughnessChannel ) * materialUniform.roughness;
7122
- ORI_ShadingInput.Roughness = clamp(roughness, 0.0001, 1.0);
7254
+ ORI_ShadingInput.Roughness = clamp(roughness , 0.0001 , 1.0);
7123
7255
  #else
7124
- ORI_ShadingInput.Roughness = clamp(roughness * materialUniform.roughness, 0.0001, 1.0);
7125
- #endif
7256
+ ORI_ShadingInput.Roughness = clamp(roughnessChannel * materialUniform.roughness ,0.0001,1.0);
7257
+ #endif
7126
7258
 
7127
- var metallicChannel:f32 = 1.0;
7259
+ var metallicChannel:f32 = 1.0 ;
7128
7260
  #if USE_METALLIC_A
7129
7261
  metallicChannel = maskTex.a ;
7130
7262
  #else if USE_METALLIC_R
@@ -7133,16 +7265,16 @@ var<uniform> materialUniform: MaterialUniform;
7133
7265
  metallicChannel = maskTex.g ;
7134
7266
  #else if USE_METALLIC_B
7135
7267
  metallicChannel = maskTex.b ;
7136
- #endif
7137
-
7138
- ORI_ShadingInput.Metallic = metallicChannel * materialUniform.metallic;
7268
+ #endif
7139
7269
 
7140
- var aoChannel: f32 = 1.0;
7141
- #if USE_AOTEX;
7270
+ ORI_ShadingInput.Metallic = metallicChannel * materialUniform.metallic ;
7271
+
7272
+ var aoChannel:f32 = 1.0 ;
7273
+ #if USE_AOTEX
7142
7274
  let aoMapOffsetSize = materialUniform.aoMapOffsetSize;
7143
7275
  var aoMapOffsetSizeUV = transformUV(ORI_VertexVarying.fragUV0,aoMapOffsetSize);
7144
7276
  var aoMap = textureSample(aoMap, aoMapSampler, ORI_VertexVarying.fragUV0 );
7145
- aoChannel = aoMap.g;
7277
+ aoChannel = aoMap.g ;
7146
7278
  #else
7147
7279
  #if USE_AO_A
7148
7280
  aoChannel = maskTex.a ;
@@ -7155,12 +7287,11 @@ var<uniform> materialUniform: MaterialUniform;
7155
7287
  #endif
7156
7288
  #endif
7157
7289
 
7158
- ORI_ShadingInput.AmbientOcclusion = aoChannel;
7159
- ORI_ShadingInput.Specular = 1.0;
7290
+ ORI_ShadingInput.AmbientOcclusion = aoChannel ;
7291
+ ORI_ShadingInput.Specular = 1.0 ;
7160
7292
 
7161
7293
  let emissiveMapOffsetSize = materialUniform.emissiveMapOffsetSize;
7162
- var emissiveUV = transformUV(ORI_VertexVarying.fragUV0,emissiveMapOffsetSize);
7163
-
7294
+ var emissiveUV = transformUV(ORI_VertexVarying.fragUV0,emissiveMapOffsetSize) ;
7164
7295
  #if USE_EMISSIVEMAP
7165
7296
  var emissiveMapColor = textureSample(emissiveMap, emissiveMapSampler , emissiveUV ) ;
7166
7297
  let emissiveColor = materialUniform.emissiveColor.rgb * emissiveMapColor.rgb * materialUniform.emissiveIntensity ;
@@ -7171,23 +7302,66 @@ var<uniform> materialUniform: MaterialUniform;
7171
7302
  #endif
7172
7303
 
7173
7304
  let normalMapOffsetSize = materialUniform.normalMapOffsetSize;
7174
- var nomralUV = transformUV(ORI_VertexVarying.fragUV0,normalMapOffsetSize);
7175
- var Normal = textureSample(normalMap,normalMapSampler,nomralUV).rgb;
7176
- let normal = unPackRGNormal(Normal,1.0,1.0);
7177
- ORI_ShadingInput.Normal = normal;
7178
-
7305
+ var nomralUV = transformUV(ORI_VertexVarying.fragUV0,normalMapOffsetSize) ;
7306
+ var Normal = textureSample(normalMap,normalMapSampler,nomralUV).rgb ;
7307
+ let normal = unPackRGNormal(Normal,1.0,1.0) ;
7308
+ ORI_ShadingInput.Normal = normal ;
7309
+
7179
7310
  BxDFShading();
7311
+
7180
7312
  }
7181
- `;
7313
+ `
7314
+ );
7182
7315
 
7183
- let BxdfDebug_frag = `
7184
- #include "ClusterDebug_frag"
7316
+ let BxdfDebug_frag = (
7317
+ /*wgsl*/
7318
+ `
7319
+ #include "ClusterDebug_frag"
7320
+
7321
+ fn debugPosition(){
7322
+ }
7185
7323
 
7186
7324
  fn debugMeshID(){
7187
7325
  let meshIDColor = u32(round(ORI_VertexVarying.vWorldPos.w) ) ;
7188
7326
  let color = colorSet[ meshIDColor % 9u] ;
7189
7327
  }
7190
7328
 
7329
+ fn debugNormal(){
7330
+ }
7331
+
7332
+ fn debugUV(){
7333
+ }
7334
+
7335
+ fn debugColor(){
7336
+ }
7337
+
7338
+ fn debugDiffuse(){
7339
+ }
7340
+
7341
+ fn debugAmbient(){
7342
+ }
7343
+
7344
+ fn debugEmissive(){
7345
+ }
7346
+
7347
+ fn debugEnvment(){
7348
+ }
7349
+
7350
+ fn debugAo(){
7351
+ }
7352
+
7353
+ fn debugRoughness(){
7354
+ }
7355
+
7356
+ fn debugMetallic(){
7357
+ }
7358
+
7359
+ fn debugIrradiance(){
7360
+ }
7361
+
7362
+ fn debugTangent(){
7363
+ }
7364
+
7191
7365
  fn debugFragmentOut(){
7192
7366
  if(ORI_VertexVarying.fragCoord.x > globalUniform.renderState_split) {
7193
7367
  switch (globalUniform.renderState_right)
@@ -7317,17 +7491,20 @@ var<uniform> materialUniform: MaterialUniform;
7317
7491
  }
7318
7492
  }
7319
7493
  }
7320
- `;
7494
+ `
7495
+ );
7321
7496
 
7322
- let FullQuad_vert_wgsl = `
7497
+ let FullQuad_vert_wgsl = (
7498
+ /*wgsl*/
7499
+ `
7323
7500
  #include "WorldMatrixUniform"
7324
7501
  #include "GlobalUniform"
7325
7502
 
7326
7503
  struct MaterialUniform {
7327
- x:f32,
7328
- y:f32,
7329
- width:f32,
7330
- height:f32,
7504
+ x:f32,
7505
+ y:f32,
7506
+ width:f32,
7507
+ height:f32,
7331
7508
  };
7332
7509
 
7333
7510
  struct VertexOutput {
@@ -7336,39 +7513,51 @@ var<uniform> materialUniform: MaterialUniform;
7336
7513
  };
7337
7514
 
7338
7515
  @vertex
7339
- fn main(@builtin(vertex_index) vertexIndex: u32, @builtin(instance_index) index){
7340
- const pos = array(vec2(-1.0, -1.0), vec2(-1.0, 1.0), vec2(-1.0, 1.0), vec2(-1.0, 1.0), vec2(1.0, -1.0), vec2(1.0, 1.0));
7341
- const uv = array(vec2(1.0, 0.0), vec2(1.0, 1.0), vec2(0.0, 1.0), vec2(1.0, 0.0), vec2(0.0, 1.0), vec2(0.0, 0.0));
7342
- let id = u32(index);
7343
- var output: VertexOutput;
7344
- output.fragUV = uv[vertexIndex];
7345
- output.position = vec4<f32>(pos[vertexIndex] , 0.0, 1.0);
7346
- return output;
7516
+ fn main(@builtin(vertex_index) vertexIndex : u32, @builtin(instance_index) index : u32 ) -> VertexOutput {
7517
+ const pos = array(
7518
+ vec2(-1.0, -1.0), vec2(1.0, -1.0), vec2(-1.0, 1.0),
7519
+ vec2(-1.0, 1.0), vec2(1.0, -1.0), vec2(1.0, 1.0),
7520
+ );
7521
+ const uv = array(
7522
+ vec2(1.0, 0.0), vec2(1.0, 1.0), vec2(0.0, 1.0),
7523
+ vec2(1.0, 0.0), vec2(0.0, 1.0), vec2(0.0, 0.0),
7524
+ );
7525
+ let id = u32(index) ;
7526
+ var output : VertexOutput;
7527
+ output.fragUV = uv[vertexIndex] ;
7528
+ output.position = vec4<f32>(pos[vertexIndex] , 0.0, 1.0) ;
7529
+ return output ;
7347
7530
  }
7348
- `;
7349
- let Quad_vert_wgsl = `
7350
- #include "WorldMatrixUniform"
7351
- #include "GlobalUniform"
7352
-
7353
- struct MaterialUniform {
7354
- x: f32,
7355
- y: f32,
7531
+ `
7532
+ );
7533
+ let Quad_vert_wgsl = (
7534
+ /*wgsl*/
7535
+ `
7536
+ #include "WorldMatrixUniform"
7537
+ #include "GlobalUniform"
7538
+
7539
+ struct MaterialUniform {
7540
+ x:f32,
7541
+ y:f32,
7356
7542
  width:f32,
7357
7543
  height:f32,
7358
- };
7544
+ };
7359
7545
 
7360
- struct VertexOutput {
7361
- @location(auto) fragUV: vec2<f32>,
7362
- @builtin(position) member: vec4<f32>
7363
- };
7546
+ struct VertexOutput {
7547
+ @location(auto) fragUV: vec2<f32>,
7548
+ @builtin(position) member: vec4<f32>
7549
+ };
7364
7550
 
7365
- @vertex
7366
- fn main(@builtin(instance_index) index: u32, @location(auto) position: vec3<f32>, @location(auto) TEXCOORD_1: vec2<f32>) -> VertexOutput {
7367
- let uv = vec2(((TEXCOORD_1.xy * 2.0) - vec2<f32>(1.0)));
7368
- return VertexOutput(TEXCOORD_1, vec4<f32>(uv, 0.0, 1.0));
7369
- }
7370
- `;
7371
- let Quad_frag_wgsl = `
7551
+ @vertex
7552
+ fn main(@builtin(instance_index) index : u32,@location(auto) position: vec3<f32>, @location(auto) TEXCOORD_1: vec2<f32>) -> VertexOutput {
7553
+ let uv = vec2(((TEXCOORD_1.xy * 2.0) - vec2<f32>(1.0))) ;// / windowSize * size - offset ;
7554
+ return VertexOutput(TEXCOORD_1, vec4<f32>(uv, 0.0, 1.0));
7555
+ }
7556
+ `
7557
+ );
7558
+ let Quad_frag_wgsl = (
7559
+ /*wgsl*/
7560
+ `
7372
7561
  struct FragmentOutput {
7373
7562
  @location(auto) o_Target: vec4<f32>
7374
7563
  };
@@ -7377,22 +7566,25 @@ var<uniform> materialUniform: MaterialUniform;
7377
7566
  var<private> o_Target: vec4<f32>;
7378
7567
  @group(1) @binding(0)
7379
7568
  var baseMapSampler: sampler;
7380
- @group(1) @binding(0)
7569
+ @group(1) @binding(1)
7381
7570
  var baseMap: texture_2d<f32>;
7382
7571
 
7383
7572
  @fragment
7384
7573
  fn main(@location(auto) fragUV: vec2<f32>) -> FragmentOutput {
7385
- var uv = fragUV;
7386
- uv.y = 1.0 -uv.y;
7387
- var color: vec4<f32> = textureSample(baseMap, baseMapSampler, uv);
7574
+ var uv = fragUV ;
7575
+ uv.y = 1.0 - uv.y ;
7576
+ var color: vec4<f32> = textureSample(baseMap, baseMapSampler, uv );
7388
7577
 
7389
7578
  return FragmentOutput(color);
7390
7579
  }
7391
- `;
7392
- let Quad_depth2d_frag_wgsl = `
7580
+ `
7581
+ );
7582
+ let Quad_depth2d_frag_wgsl = (
7583
+ /*wgsl*/
7584
+ `
7393
7585
  struct FragmentOutput {
7394
7586
  @location(auto) o_Target: vec4<f32>
7395
- };
7587
+ };
7396
7588
 
7397
7589
  var<private> fragUV1: vec2<f32>;
7398
7590
  var<private> o_Target: vec4<f32>;
@@ -7400,21 +7592,25 @@ var<uniform> materialUniform: MaterialUniform;
7400
7592
  @group(1) @binding(0)
7401
7593
  var baseMapSampler: sampler;
7402
7594
  @group(1) @binding(1)
7403
- var baseMap: texture_depth_2d;
7595
+ var baseMap: texture_depth_2d ;
7404
7596
 
7405
- fn Linear01Depth(z:f32) -> f32 {
7597
+ fn Linear01Depth( z : f32 ) -> f32
7598
+ {
7406
7599
  return 1.0 / (1.0 * z + 5000.0);
7407
7600
  }
7408
7601
 
7409
7602
  @fragment
7410
7603
  fn main(@location(auto) fragUV: vec2<f32>) -> FragmentOutput {
7411
- var uv = fragUV;
7412
- uv.y = 1.0 - uv.y;
7413
- var depth = textureSample(baseMap, baseMapSampler, uv, vec2<i32>(0));
7414
- return FragmentOutput(vec4<f32>(depth, 0.0, 0.0, 1.0));
7604
+ var uv = fragUV ;
7605
+ uv.y = 1.0 - uv.y ;
7606
+ var depth = textureSample(baseMap, baseMapSampler, uv , vec2<i32>(0) ) ;
7607
+ return FragmentOutput(vec4<f32>(depth,0.0,0.0,1.0));
7415
7608
  }
7416
- `;
7417
- let Quad_depthCube_frag_wgsl = `
7609
+ `
7610
+ );
7611
+ let Quad_depthCube_frag_wgsl = (
7612
+ /*wgsl*/
7613
+ `
7418
7614
  struct FragmentOutput {
7419
7615
  @location(auto) o_Target: vec4<f32>
7420
7616
  };
@@ -7424,10 +7620,11 @@ var<uniform> materialUniform: MaterialUniform;
7424
7620
 
7425
7621
  @group(1) @binding(0)
7426
7622
  var baseMapSampler: sampler;
7427
- @group(1) @binding(0)
7428
- var baseMap: texture_depth_cube;
7623
+ @group(1) @binding(1)
7624
+ var baseMap: texture_depth_cube ;
7429
7625
 
7430
- fn uvToXYZ(face: i32, uv: vec2<f32>) -> vec3<f32> {
7626
+ fn uvToXYZ( face : i32 , uv : vec2<f32> ) -> vec3<f32>
7627
+ {
7431
7628
  var out : vec3<f32> ;
7432
7629
  if(face == 0){
7433
7630
  out = vec3<f32>( 1.0, uv.y, -uv.x);
@@ -7447,12 +7644,12 @@ var<uniform> materialUniform: MaterialUniform;
7447
7644
 
7448
7645
  @fragment
7449
7646
  fn main(@location(auto) fragUV: vec2<f32>) -> FragmentOutput {
7450
- var uv = fragUV;
7451
- uv.y = 1.0 - uv.y;
7452
- var ii = 0.16;
7647
+ var uv = fragUV ;
7648
+ uv.y = 1.0 - uv.y ;
7649
+ var ii = 0.16 ;
7453
7650
  var ouv = vec3<f32>(0.0);
7454
7651
  if(uv.x < ii * 6.0){
7455
- ouv = uvToXYZ(5, uv/ii);
7652
+ ouv = uvToXYZ(5,uv/ii);
7456
7653
  }
7457
7654
  if(uv.x < ii * 5.0){
7458
7655
  ouv = uvToXYZ(4,uv/ii);
@@ -7469,15 +7666,19 @@ var<uniform> materialUniform: MaterialUniform;
7469
7666
  if(uv.x < ii * 1.0){
7470
7667
  ouv = uvToXYZ(0,uv/ii);
7471
7668
  }
7472
- var depth = textureSample(baseMap, baseMapSampler, ouv);
7473
- depth = 1.0 - depth;
7474
- return FragmentOutput(vec4<f32>(depth, 0.0, 0.0, 1.0));
7669
+ var depth = textureSample(baseMap, baseMapSampler, ouv ) ;
7670
+ depth = 1.0 - depth;
7671
+
7672
+ return FragmentOutput(vec4<f32>(depth,0.0,0.0,1.0));
7475
7673
  }
7476
- `;
7477
- let Quad_depth2dArray_frag_wgsl = `
7674
+ `
7675
+ );
7676
+ let Quad_depth2dArray_frag_wgsl = (
7677
+ /*wgsl*/
7678
+ `
7478
7679
  struct FragmentOutput {
7479
7680
  @location(auto) o_Target: vec4<f32>
7480
- }
7681
+ };
7481
7682
 
7482
7683
  var<private> fragUV1: vec2<f32>;
7483
7684
  var<private> o_Target: vec4<f32>;
@@ -7485,7 +7686,7 @@ var<uniform> materialUniform: MaterialUniform;
7485
7686
  @group(1) @binding(0)
7486
7687
  var baseMapSampler: sampler;
7487
7688
  @group(1) @binding(1)
7488
- var baseMap: texture_2d_array;
7689
+ var baseMap: texture_2d_array ;
7489
7690
 
7490
7691
  struct MaterialData{
7491
7692
  index:f32;
@@ -7493,15 +7694,16 @@ var<uniform> materialUniform: MaterialUniform;
7493
7694
 
7494
7695
  @fragment
7495
7696
  fn main(@location(auto) fragUV: vec2<f32>) -> FragmentOutput {
7496
- var uv = fragUV;
7497
- uv.y = 1.0 - uv.y;
7498
-
7499
- var depth = textureSample(baseMap, baseMapSampler, ouv);
7500
- depth = 1.0 - depth;
7697
+ var uv = fragUV ;
7698
+ uv.y = 1.0 - uv.y ;
7699
+
7700
+ var depth = textureSample(baseMap, baseMapSampler, ouv ) ;
7701
+ depth = 1.0 - depth;
7501
7702
 
7502
- return FragmentOutput(vec4<f32>(depth, 0.0, 0.0, 1.0));
7703
+ return FragmentOutput(vec4<f32>(depth,0.0,0.0,1.0));
7503
7704
  }
7504
- `;
7705
+ `
7706
+ );
7505
7707
 
7506
7708
  let ColorUtil = `
7507
7709
  fn getHDRColor(color: vec3<f32>, exposure: f32) -> vec3<f32> {
@@ -7648,25 +7850,31 @@ var<uniform> materialUniform: MaterialUniform;
7648
7850
  }
7649
7851
  `;
7650
7852
 
7651
- let GenerayRandomDir = `
7652
- fn madfrac(A:f32, B:f32) -> f32 {
7653
- return A*B-floor(A*B);
7853
+ let GenerayRandomDir = (
7854
+ /*wgsl*/
7855
+ `
7856
+ fn madfrac(A:f32, B:f32)-> f32 {
7857
+ return A*B-floor(A*B) ;
7654
7858
  }
7655
7859
 
7656
- fn sampleRandomDir(count:u32, SAMPLE_COUNT: u32) -> vec3<f32> {
7657
- var ray_dir = sphericalFibonacci(f32((count)), f32(SAMPLE_COUNT));
7658
- return normalize(ray_dir);
7860
+ fn sampleRandomDir(count:u32,SAMPLE_COUNT:u32) -> vec3<f32>{
7861
+ var ray_dir = sphericalFibonacci(f32((count)), f32(SAMPLE_COUNT) );
7862
+ return normalize(ray_dir) ;
7659
7863
  }
7660
7864
 
7661
- fn sphericalFibonacci(i:f32, n:f32) -> vec3<f32> {
7662
- constPHI = sqrt(5.0) * 0.5 + 0.5;
7865
+ fn sphericalFibonacci( i : f32 , n : f32 ) -> vec3<f32>{
7866
+ const PHI = sqrt(5.0) * 0.5 + 0.5;
7663
7867
  let phi = 2.0 * PI * madfrac(i, PHI - 1);
7664
7868
  let cosTheta = 1.0 - (2.0 * i + 1.0) * (1.0 / n);
7665
7869
  let sinTheta = sqrt(saturate(1.0 - cosTheta*cosTheta));
7666
7870
 
7667
- return vec3<f32>(cos(phi) * sinTheta, sin(phi) * sinTheta, cosTheta);
7871
+ return vec3<f32>(
7872
+ cos(phi) * sinTheta,
7873
+ sin(phi) * sinTheta,
7874
+ cosTheta);
7668
7875
  }
7669
- `;
7876
+ `
7877
+ );
7670
7878
 
7671
7879
  let MatrixShader = `
7672
7880
  #include "MathShader"
@@ -7921,7 +8129,7 @@ var<uniform> materialUniform: MaterialUniform;
7921
8129
  face = 1.0 ;
7922
8130
  }else{
7923
8131
  face = -1.0 ;
7924
- }
8132
+ };
7925
8133
  #if USE_TANGENT
7926
8134
  let T = ORI_VertexVarying.TANGENT.xyz;
7927
8135
  let N = ORI_VertexVarying.vWorldNormal ;
@@ -8788,15 +8996,18 @@ fn main(vertex:VertexAttributes) -> VertexOutput {
8788
8996
  }
8789
8997
  `;
8790
8998
 
8791
- let BitUtil = `
8999
+ let BitUtil = (
9000
+ /* wgsl */
9001
+ `
9002
+
8792
9003
  const inv256:f32 = 1.0/256.0;
8793
9004
  const inv1024:f32 = 1.0/1024.0;
8794
9005
 
8795
- const bit7_inv128:f32 = 1.0/128.0;
9006
+ const bit7_inv128:f32 = 1.0 / 128.0;
8796
9007
  const bit7_128:f32 = 128.0;
8797
-
9008
+
8798
9009
  const r10g10b10 = vec2i(0x3FFFFF,0xFF);
8799
- fn floatToVec3f(v:f32) -> vec3f {
9010
+ fn floatToVec3f( v:f32 ) -> vec3f {
8800
9011
  var VPInt:i32 = bitcast<i32>(v);
8801
9012
  var VPInt1024:i32 = VPInt%1024;
8802
9013
  var VPInt10241024:i32 = ((VPInt-VPInt1024)/1024)%1024;
@@ -8823,6 +9034,11 @@ fn main(vertex:VertexAttributes) -> VertexOutput {
8823
9034
  return vec4f(f32(VPInt128),f32(VPInt128128),f32(VPInt128128128),f32(VPInt128128128128))*vec4f(bit7_inv128);
8824
9035
  }
8825
9036
 
9037
+
9038
+
9039
+
9040
+
9041
+
8826
9042
  const i_r11g11b11 = vec3i(0x7FF,0x7FF,0x7FF);
8827
9043
  const f_r11g11b11 = vec3f(f32(0x7FF),f32(0x7FF),f32(0x7FF));
8828
9044
  fn r11g11b11_to_float( v:vec3f) -> f32{
@@ -8871,6 +9087,9 @@ fn main(vertex:VertexAttributes) -> VertexOutput {
8871
9087
  return vec3f(r,g,b);
8872
9088
  }
8873
9089
 
9090
+
9091
+
9092
+
8874
9093
  fn floatToRGBA(v:f32) -> vec4f{
8875
9094
  var iv = bitcast<u32>(v);
8876
9095
  var color = vec4f(0.0);
@@ -8885,7 +9104,9 @@ fn main(vertex:VertexAttributes) -> VertexOutput {
8885
9104
  var f = dot(v, bitShift);
8886
9105
  return f;
8887
9106
  }
8888
- `;
9107
+
9108
+ `
9109
+ );
8889
9110
 
8890
9111
  let GBufferStand = `
8891
9112
  #include "MathShader"
@@ -22180,7 +22401,7 @@ fn SH9(dir: vec3<f32>, coefficients: array<vec4f, 9>) -> vec4<f32> {
22180
22401
  }
22181
22402
  /**
22182
22403
  * current instance attached from parent instance
22183
- * @param ref reference current
22404
+ * @param ref reference current
22184
22405
  * @param target reference parent
22185
22406
  */
22186
22407
  attached(ref, target) {
@@ -22192,7 +22413,7 @@ fn SH9(dir: vec3<f32>, coefficients: array<vec4f, 9>) -> vec4<f32> {
22192
22413
  }
22193
22414
  /**
22194
22415
  * current instance detached from parent instance
22195
- * @param ref reference current
22416
+ * @param ref reference current
22196
22417
  * @param target reference parent
22197
22418
  */
22198
22419
  detached(ref, target) {
@@ -22202,7 +22423,7 @@ fn SH9(dir: vec3<f32>, coefficients: array<vec4f, 9>) -> vec4<f32> {
22202
22423
  }
22203
22424
  }
22204
22425
  /**
22205
- * current instance has reference
22426
+ * current instance has reference
22206
22427
  */
22207
22428
  hasReference(ref) {
22208
22429
  let refMap = this.reference.get(ref);
@@ -22213,8 +22434,8 @@ fn SH9(dir: vec3<f32>, coefficients: array<vec4f, 9>) -> vec4<f32> {
22213
22434
  }
22214
22435
  /**
22215
22436
  * get current instance reference count
22216
- * @param ref
22217
- * @returns
22437
+ * @param ref
22438
+ * @returns
22218
22439
  */
22219
22440
  getReferenceCount(ref) {
22220
22441
  let refMap = this.reference.get(ref);
@@ -22224,10 +22445,10 @@ fn SH9(dir: vec3<f32>, coefficients: array<vec4f, 9>) -> vec4<f32> {
22224
22445
  return 0;
22225
22446
  }
22226
22447
  /**
22227
- * get current instance reference from where
22228
- * @param ref
22229
- * @returns
22230
- */
22448
+ * get current instance reference from where
22449
+ * @param ref
22450
+ * @returns
22451
+ */
22231
22452
  getReference(ref) {
22232
22453
  let refMap = this.reference.get(ref);
22233
22454
  if (refMap) {
@@ -24859,8 +25080,7 @@ fn SH9(dir: vec3<f32>, coefficients: array<vec4f, 9>) -> vec4<f32> {
24859
25080
  this.indicesGPUBuffer = new IndicesGPUBuffer(indicesData.data);
24860
25081
  }
24861
25082
  upload(data) {
24862
- const buffer = data.buffer instanceof ArrayBuffer ? data.buffer : new Uint8Array(data.buffer).buffer;
24863
- this.indicesGPUBuffer.indicesNode.setArrayBuffer(0, buffer);
25083
+ this.indicesGPUBuffer.indicesNode.setArrayBuffer(0, data);
24864
25084
  this.indicesGPUBuffer.apply();
24865
25085
  }
24866
25086
  compute() {
@@ -24873,6 +25093,22 @@ fn SH9(dir: vec3<f32>, coefficients: array<vec4f, 9>) -> vec4<f32> {
24873
25093
  this.indicesGPUBuffer.destroy();
24874
25094
  this.indicesGPUBuffer = null;
24875
25095
  }
25096
+ /**
25097
+ * Get indices from geometry data
25098
+ * Get position attribute from geometry data
25099
+ * Get normal attribute from geometry data
25100
+ * Get tangent attribute from geometry data
25101
+ * Get uv0 attribute from geometry data
25102
+ * Get uv1 attribute from geometry data
25103
+ * Get uv2 attribute from geometry data
25104
+ *
25105
+ * Change position data to GPUBuffer and apply
25106
+ * Change normal data to GPUBuffer and apply
25107
+ * Change tangent data to GPUBuffer and apply
25108
+ * Change uv0 data to GPUBuffer and apply
25109
+ * Change uv1 data to GPUBuffer and apply
25110
+ * Change uv2 data to GPUBuffer and apply
25111
+ */
24876
25112
  }
24877
25113
 
24878
25114
  class SubGeometry {
@@ -25682,7 +25918,7 @@ fn SH9(dir: vec3<f32>, coefficients: array<vec4f, 9>) -> vec4<f32> {
25682
25918
  }
25683
25919
  };
25684
25920
  exports.QuadShader = __decorateClass$e([
25685
- RegisterShader
25921
+ RegisterShader(exports.QuadShader, "QuadShader")
25686
25922
  ], exports.QuadShader);
25687
25923
 
25688
25924
  class ViewQuad extends exports.Object3D {
@@ -28040,131 +28276,147 @@ fn SH9(dir: vec3<f32>, coefficients: array<vec4f, 9>) -> vec4<f32> {
28040
28276
  }
28041
28277
  }
28042
28278
 
28043
- let PreFilteredEnvironment_cs = `
28279
+ let PreFilteredEnvironment_cs = (
28280
+ /*wgsl*/
28281
+ `
28044
28282
  #include "GenerayRandomDir"
28045
28283
  #include "BitUtil"
28046
28284
  #include "MathShader"
28047
28285
  #include "ColorUtil_frag"
28048
-
28049
- struct UniformData {
28050
- probeSize: f32,
28051
- probeCount: f32,
28052
- width: f32,
28053
- height: f32,
28286
+
28287
+ struct UniformData{
28288
+ probeSize : f32 ,
28289
+ probeCount : f32 ,
28290
+ width : f32 ,
28291
+ height : f32 ,
28054
28292
  }
28055
28293
 
28056
- @group(0) @binding(0) var inputTex: texture_2d<f32>;
28057
- @group(0) @binding(1) var outputTexture: texture_storage_2d<rgba16float,write>;
28058
- @group(1) @binding(0) var<uniform> uniformData: UniformData;
28294
+ @group(0) @binding(0) var inputTex : texture_2d<f32>;
28295
+ @group(0) @binding(1) var outputTexture : texture_storage_2d<rgba16float, write>;//rgba32float rgba16float
28296
+ @group(1) @binding(0) var<uniform> uniformData:UniformData;//rgba32float
28059
28297
 
28060
- var<private> reflectionSize: vec2f;
28061
- var<private> PROBE_SOURCESIZE: vec2f;
28062
- var<private> PROBEMAP_SOURCESIZE: vec2f;
28063
- var<private> aspect: vec2f;
28064
- var<private> spaceV: f32;
28298
+ var<private> reflectionSize : vec2f ;
28299
+ var<private> PROBE_SOURCESIZE : vec2f ;
28300
+ var<private> PROBEMAP_SOURCESIZE : vec2f ;
28301
+ var<private> aspect : vec2f ;
28302
+ var<private> spaceV : f32 ;
28065
28303
 
28066
28304
  var<private> i32InputFragCoord : vec2i;
28067
28305
  var<private> PI_2 : f32 = 3.1415926 * 2.0 ;
28068
28306
  var<private> PI : f32 = 3.1415926 ;
28069
28307
 
28070
- var<private> probeSize: f32 = 256.0;
28071
- var<private> probeCount: f32 = 8.0;
28072
- var<private> faceCount: f32 = 6.0;
28073
- var<private> mipCount: f32 = 8.0;
28308
+ var<private> probeSize : f32 = 256.0 ;
28309
+ var<private> probeCount : f32 = 8.0 ;
28310
+ var<private> faceCount : f32 = 6.0 ;
28311
+ var<private> mipCount : f32 = 8.0 ;
28074
28312
 
28075
28313
  const NUM_SAMPLES = 256u;
28076
- var<private> inputSize: vec2f;
28077
- var<private> outSize: vec2f;
28314
+ var<private> inputSize : vec2f ;
28315
+ var<private> outSize : vec2f ;
28078
28316
 
28079
28317
  fn useSphereReflection(){
28080
- probeSize = uniformData.probeSize;
28318
+ probeSize = uniformData.probeSize ;
28081
28319
  probeCount = uniformData.probeCount;
28082
28320
  reflectionSize = vec2f(textureDimensions(inputTex).xy);
28083
28321
  PROBE_SOURCESIZE = reflectionSize / vec2f(faceCount,probeCount);
28084
- PROBEMAP_SOURCESIZE = reflectionSize;
28322
+ PROBEMAP_SOURCESIZE = reflectionSize ;
28085
28323
  aspect = PROBE_SOURCESIZE / PROBEMAP_SOURCESIZE;
28086
- spaceV = 1.0 / probeCount;
28324
+ spaceV = 1.0 / probeCount ;
28087
28325
  }
28088
28326
 
28089
- @compute @workgroup_size(16, 16, 1)
28090
- fn CsMain(@builtin(workgroup_id) workgroup_id: vec3<u32>, @builtin(global_invocation_id) globalInvocation_id: vec3<u32>){
28091
- var color: vec4f;
28327
+ @compute @workgroup_size( 16 , 16 , 1 )
28328
+ fn CsMain( @builtin(workgroup_id) workgroup_id : vec3<u32> , @builtin(global_invocation_id) globalInvocation_id : vec3<u32>)
28329
+ {
28330
+ var color : vec4f ;
28092
28331
  useSphereReflection();
28093
28332
  inputSize = vec2f(textureDimensions(inputTex).xy);
28094
28333
  outSize = vec2f(textureDimensions(outputTexture).xy);
28095
- i32InputFragCoord = vec2<i32>(globalInvocation_id.xy);
28096
- let i = f32(globalInvocation_id.z);
28097
- let count = floor(i/mipCount);
28098
- preOneMip(count, floor(i%mipCount));
28334
+
28335
+ i32InputFragCoord = vec2<i32>( globalInvocation_id.xy ) ;
28336
+
28337
+ let i = f32(globalInvocation_id.z) ;
28338
+ let count = floor(i / mipCount) ;
28339
+ preOneMip(count,floor(i % mipCount));
28099
28340
  }
28100
28341
 
28101
- fn preOneMip(gid: f32, mip: f32){
28102
- let isuv = vec2f(i32InputFragCoord);
28342
+ fn preOneMip( gid:f32,mip:f32 ){
28343
+ let isuv = vec2f(i32InputFragCoord) ;
28103
28344
  let suv = isuv * (inputSize/outSize);
28104
28345
  let probeID = i32(floor(suv.y / probeSize));
28105
28346
  let mipID = i32((isuv.x / probeSize));
28106
28347
  if(probeID == i32(gid) && mipID == i32(mip)){
28107
- let sphereUV = vec2f((isuv.x+0.5)%(probeSize), (isuv.y+0.5)%probeSize/vec2f((probeSize),probeSize));
28108
- var dir: vec3<f32> = octDecode(sphereUV * 2.0 - 1.0);
28109
- var preColor = PreFilterEnvMap(mip/mipCount + 0.05, dir, gid);
28110
- textureStore(outputTexture, vec2i(i32InputFragCoord), preColor);
28348
+
28349
+ let sphereUV = vec2f((isuv.x+0.5) % (probeSize),(isuv.y+0.5) % probeSize) / vec2f( (probeSize), probeSize ) ;
28350
+ var dir: vec3<f32> = octDecode(sphereUV * 2.0 - 1.0) ;
28351
+ var preColor = PreFilterEnvMap(mip/mipCount + 0.05,dir,gid);
28352
+ textureStore(outputTexture,vec2i(i32InputFragCoord),preColor);
28111
28353
  }
28112
28354
  }
28113
28355
 
28114
- fn PreFilterEnvMap(roughness2:f32, R:vec3f , gid:f32) -> vec4f {
28115
- var resColor = vec3f(0.0f);
28116
- var resDepth = 0.0;
28356
+ fn PreFilterEnvMap( roughness2:f32, R:vec3f , gid:f32 ) -> vec4f
28357
+ {
28358
+ var resColor = vec3f(0.0f);
28359
+ var resDepth = 0.0;
28360
+
28117
28361
  var totalColorWeight = 0.0f;
28118
28362
  var totalDepthWeight = 0.0f;
28363
+
28119
28364
  var normal = normalize(R);
28120
28365
  var toEye = normal;
28366
+
28121
28367
  var roughness = roughness2;
28122
-
28368
+
28123
28369
  for(var i=1u;i<=NUM_SAMPLES;i+=1u)
28124
28370
  {
28125
- var xi:vec2f = hammersley(i, NUM_SAMPLES);
28371
+ var xi:vec2f = hammersley(i, NUM_SAMPLES) ;
28372
+
28126
28373
  var halfway = ImportanceSampleGGX(xi,roughness,normal);
28127
- var lightVec = 2.0f * dot(toEye,halfway) * halfway - toEye;
28128
- var NdotL = dot(normal, lightVec);
28129
- var NdotH = max(0.0,dot( normal, halfway ));
28130
- var HdotV = max(0.0,dot( halfway, toEye ));
28374
+ var lightVec = 2.0f * dot( toEye,halfway ) * halfway - toEye;
28375
+
28376
+ var NdotL = dot( normal, lightVec ) ;
28377
+ var NdotH = max(0.0,dot( normal, halfway )) ;
28378
+ var HdotV = max(0.0,dot( halfway, toEye )) ;
28379
+
28131
28380
  if( NdotL > 0.0 )
28132
28381
  {
28133
28382
  var D = specularD(roughness,NdotH);
28134
- var pdf = (D * NdotH / (4.0 * HdotV)) + 0.0001f;
28383
+ var pdf = (D * NdotH / (4.0 * HdotV)) + 0.0001f ;
28384
+
28135
28385
  var saSample = 1.0f / (f32(NUM_SAMPLES) * pdf + 0.00001f);
28136
28386
  lightVec = normalize(lightVec);
28387
+
28137
28388
  var buffer = getReflectionsMap(lightVec,gid);
28138
28389
  var rgb = unpack4x8unorm(u32(buffer.z)).rgb;
28139
28390
  var m = unpack4x8unorm(u32(buffer.w)).z;
28140
28391
  var rgbmColor = DecodeRGBM(vec4f(rgb,m));
28141
- resDepth += buffer.x;
28392
+ resDepth += buffer.x ;
28142
28393
  resColor += rgbmColor * NdotL;
28394
+
28143
28395
  totalColorWeight += NdotL;
28144
28396
  totalDepthWeight += 1.0;
28145
28397
  }
28146
28398
  }
28147
-
28399
+
28148
28400
  resDepth = resDepth / max(totalDepthWeight,0.001f);
28149
28401
  resColor = resColor / max(totalColorWeight,0.001f);
28150
-
28402
+
28151
28403
  let rgbm = EncodeRGBM(resColor) ;
28152
28404
  let gBuffer = vec4f(
28153
28405
  resDepth,
28154
28406
  0.0,
28155
28407
  f32(pack4x8unorm(vec4f(rgbm.rgb,0.0))),
28156
28408
  f32(pack4x8unorm(vec4f(0.0,0.0,rgbm.w,0.0))),
28157
- );
28158
- return vec4f(resColor, 1.0);
28159
- }
28409
+ ) ;
28410
+ return vec4f(resColor,1.0) ;
28411
+ }
28160
28412
 
28161
- fn getReflectionsMap(n: vec3<f32>,gid: f32) -> vec4f {
28413
+ fn getReflectionsMap(n:vec3<f32>,gid:f32) -> vec4f {
28162
28414
  var uv = getSampleProbeUV(n,gid);
28163
- let color = textureLoad(inputTex, vec2i(uv*inputSize), 0);
28164
- return color;
28415
+ let color = textureLoad(inputTex, vec2i(uv*inputSize) , 0);
28416
+ return color ;
28165
28417
  }
28166
28418
 
28167
- fn getSampleProbeUV(dir: vec3<f32>,gid: f32) -> vec2<f32> {
28419
+ fn getSampleProbeUV(dir:vec3<f32>,gid:f32) -> vec2<f32> {
28168
28420
  let faceId = dir_to_faceId(dir);
28169
28421
  var targetUV:vec2<f32> = convert_xyz_to_cube_uv(dir.x, dir.y, dir.z);
28170
28422
  targetUV.x = 1.0 - targetUV.x;
@@ -28174,17 +28426,18 @@ fn SH9(dir: vec3<f32>, coefficients: array<vec4f, 9>) -> vec4<f32> {
28174
28426
  let aspect:vec2f = PROBE_SOURCESIZE / PROBEMAP_SOURCESIZE;
28175
28427
  targetUV = targetUV * aspect ;
28176
28428
  targetUV.y = targetUV.y + (spaceV * gid);
28177
- return targetUV;
28178
- }
28429
+ return targetUV ;
28430
+ }
28179
28431
 
28180
- fn radicalInverse_VdC(bits2:u32) -> f32 {
28432
+ fn radicalInverse_VdC( bits2:u32) -> f32
28433
+ {
28181
28434
  var bits = bits2;
28182
28435
  bits = (bits << 16u) | (bits >> 16u);
28183
28436
  bits = ((bits & 0x55555555u) << 1u) | ((bits & 0xAAAAAAAAu) >> 1u);
28184
28437
  bits = ((bits & 0x33333333u) << 2u) | ((bits & 0xCCCCCCCCu) >> 2u);
28185
28438
  bits = ((bits & 0x0F0F0F0Fu) << 4u) | ((bits & 0xF0F0F0F0u) >> 4u);
28186
28439
  bits = ((bits & 0x00FF00FFu) << 8u) | ((bits & 0xFF00FF00u) >> 8u);
28187
- return f32(bits) * 2.3283064365386963e-10f;
28440
+ return f32(bits) * 2.3283064365386963e-10f; // / 0x100000000
28188
28441
  }
28189
28442
 
28190
28443
  fn hammersley( i:u32, N:u32) -> vec2f
@@ -28195,21 +28448,25 @@ fn SH9(dir: vec3<f32>, coefficients: array<vec4f, 9>) -> vec4<f32> {
28195
28448
  fn ImportanceSampleGGX( xi:vec2f, roughness:f32, N:vec3f) -> vec3f
28196
28449
  {
28197
28450
  var alpha2 = roughness * roughness * roughness * roughness;
28451
+
28198
28452
  var phi = 2.0f * 3.1415926 * xi.x ;
28199
28453
  var cosTheta = sqrt( (1.0f - xi.y) / (1.0f + (alpha2 - 1.0f) * xi.y ));
28200
28454
  var sinTheta = sqrt( 1.0f - cosTheta*cosTheta );
28201
- var h: vec3f ;
28455
+
28456
+ var h : vec3f ;
28202
28457
  h.x = sinTheta * cos( phi );
28203
28458
  h.y = sinTheta * sin( phi );
28204
28459
  h.z = cosTheta;
28460
+
28205
28461
  var up = vec3f(1,0,0) ;
28206
28462
  if(abs(N.z) < 0.9999){
28207
28463
  up = vec3f(0,0,1) ;
28208
28464
  }
28465
+
28209
28466
  var tangentX = normalize( cross( up, N ) );
28210
28467
  var tangentY = cross( N, tangentX );
28211
28468
  return (tangentX * h.x + tangentY * h.y + N * h.z);
28212
- }
28469
+ }
28213
28470
 
28214
28471
  fn specularD( roughness:f32, NoH:f32) -> f32
28215
28472
  {
@@ -28217,7 +28474,9 @@ fn SH9(dir: vec3<f32>, coefficients: array<vec4f, 9>) -> vec4<f32> {
28217
28474
  var r2 = roughness * roughness;
28218
28475
  return r2 / pow(NoH2 * (r2 - 1.0) + 1.0, 2.0);
28219
28476
  }
28220
- `;
28477
+
28478
+ `
28479
+ );
28221
28480
 
28222
28481
  class ReflectionRenderer extends RendererBase {
28223
28482
  cubeCamera;
@@ -28476,8 +28735,10 @@ fn SH9(dir: vec3<f32>, coefficients: array<vec4f, 9>) -> vec4<f32> {
28476
28735
  }
28477
28736
  }
28478
28737
 
28479
- let FXAAShader = `
28480
- @include 'BitUtil'
28738
+ let FXAAShader = (
28739
+ /*wgsl*/
28740
+ `
28741
+ #include 'BitUtil'
28481
28742
  struct FragmentOutput {
28482
28743
  @location(auto) o_Target: vec4<f32>
28483
28744
  };
@@ -28496,6 +28757,7 @@ fn SH9(dir: vec3<f32>, coefficients: array<vec4f, 9>) -> vec4<f32> {
28496
28757
  @group(2) @binding(0)
28497
28758
  var<uniform> materialUniform: MaterialUniform;
28498
28759
 
28760
+
28499
28761
  fn LinearToGammaSpace(linRGB0: vec3<f32>) -> vec3<f32> {
28500
28762
  var linRGB = max(linRGB0, vec3(0.0, 0.0, 0.0));
28501
28763
  linRGB.r = pow(linRGB.r,0.416666667);
@@ -28504,30 +28766,35 @@ fn SH9(dir: vec3<f32>, coefficients: array<vec4f, 9>) -> vec4<f32> {
28504
28766
  return max(1.055 * linRGB - 0.055, vec3(0.0, 0.0, 0.0));
28505
28767
  }
28506
28768
 
28507
- fn texture2D(uv:vec2<f32>, offset:vec2<f32>) -> vec4<f32> {
28508
- let buffer = textureSample(baseMap, baseMapSampler, uv.xy + offset).rgba;
28509
- return buffer;
28769
+ fn texture2D( uv:vec2<f32> , offset:vec2<f32> ) -> vec4<f32> {
28770
+ let buffer = textureSample(baseMap, baseMapSampler, uv.xy + offset ).rgba ;
28771
+ return buffer ;
28510
28772
  }
28511
28773
 
28512
28774
  @fragment
28513
28775
  fn main(@location(auto) fragUV: vec2<f32>) -> FragmentOutput {
28514
- var v_vTexcoord = fragUV;
28776
+ var v_vTexcoord = fragUV ;
28515
28777
  v_vTexcoord.y = 1.0 - v_vTexcoord.y ;
28778
+
28516
28779
  var reducemul = 1.0 / 8.0;
28517
28780
  var reducemin = 1.0 / 128.0;
28781
+
28518
28782
  var basecol = texture2D(v_vTexcoord , vec2<f32>(0.0)).rgba;
28519
28783
  var baseNW = texture2D(v_vTexcoord , -materialUniform.u_texel).rgb;
28520
28784
  var baseNE = texture2D(v_vTexcoord , vec2<f32>(materialUniform.u_texel.x, -materialUniform.u_texel.y)).rgb;
28521
28785
  var baseSW = texture2D(v_vTexcoord , vec2<f32>(-materialUniform.u_texel.x, materialUniform.u_texel.y)).rgb;
28522
28786
  var baseSE = texture2D(v_vTexcoord , materialUniform.u_texel ).rgb;
28787
+
28523
28788
  var gray = vec3<f32>(0.213, 0.715, 0.072);
28524
28789
  var monocol = dot(basecol.rgb, gray);
28525
28790
  var monoNW = dot(baseNW, gray);
28526
28791
  var monoNE = dot(baseNE, gray);
28527
28792
  var monoSW = dot(baseSW, gray);
28528
28793
  var monoSE = dot(baseSE, gray);
28794
+
28529
28795
  var monomin = min(monocol, min(min(monoNW, monoNE), min(monoSW, monoSE)));
28530
28796
  var monomax = max(monocol, max(max(monoNW, monoNE), max(monoSW, monoSE)));
28797
+
28531
28798
  var dir = vec2<f32>(-((monoNW + monoNE) - (monoSW + monoSE)), ((monoNW + monoSW) - (monoNE + monoSE)));
28532
28799
  var dirreduce = max((monoNW + monoNE + monoSW + monoSE) * reducemul * 0.25, reducemin);
28533
28800
  var dirmin = 1.0 / (min(abs(dir.x), abs(dir.y)) + dirreduce);
@@ -28535,9 +28802,11 @@ fn SH9(dir: vec3<f32>, coefficients: array<vec4f, 9>) -> vec4<f32> {
28535
28802
 
28536
28803
  var resultA = 0.5 * (texture2D(v_vTexcoord , dir * -0.166667).rgb +
28537
28804
  texture2D(v_vTexcoord , dir * 0.166667).rgb);
28805
+
28538
28806
  var resultB = resultA * 0.5 + 0.25 * (texture2D( v_vTexcoord , dir * -0.5).rgb +
28539
28807
  texture2D( v_vTexcoord , dir * 0.5).rgb);
28540
28808
  var monoB = dot(resultB.rgb, gray);
28809
+
28541
28810
  var color:vec3<f32> ;
28542
28811
  if(monoB < monomin || monoB > monomax) {
28543
28812
  color = resultA ;//* v_vColour;
@@ -28546,7 +28815,8 @@ fn SH9(dir: vec3<f32>, coefficients: array<vec4f, 9>) -> vec4<f32> {
28546
28815
  }
28547
28816
  return FragmentOutput(vec4<f32>(color.rgb,basecol.a));
28548
28817
  }
28549
- `;
28818
+ `
28819
+ );
28550
28820
 
28551
28821
  class FXAAPost extends PostBase {
28552
28822
  postQuad;
@@ -28965,12 +29235,12 @@ fn SH9(dir: vec3<f32>, coefficients: array<vec4f, 9>) -> vec4<f32> {
28965
29235
  cornerCoord.x = sideBorderCnt - 1;
28966
29236
  }else{
28967
29237
  cornerCoord.x = 0;
28968
- }
29238
+ };
28969
29239
  if(modeXY.y == 0){
28970
29240
  cornerCoord.y = sideBorderCnt - 1;
28971
29241
  }else{
28972
29242
  cornerCoord.y = 0;
28973
- }
29243
+ };
28974
29244
  cornerCoord = indexXY * sideBorderCnt + cornerCoord;
28975
29245
  textureStore(texture, cornerCoord, color);
28976
29246
  }
@@ -29492,7 +29762,7 @@ fn directShadowMaping(P:vec3<f32>, N:vec3<f32>, shadowBias: f32) {
29492
29762
  }else{
29493
29763
  shadowMatrix = globalUniform.shadowMatrix[shadowIndex];
29494
29764
  visibility = directShadowMapingIndex(light, shadowMatrix, P, N, shadowIndex, shadowBias).x;
29495
- }
29765
+ };
29496
29766
  }
29497
29767
  shadowStrut.directShadowVisibility = visibility;
29498
29768
  }
@@ -29601,7 +29871,7 @@ fn spotLight( albedo:vec3<f32>,WP:vec3<f32>, N:vec3<f32>, V:vec3<f32>, light:Lig
29601
29871
  }
29602
29872
  }else{
29603
29873
  atten = 0.0 ;
29604
- }
29874
+ };
29605
29875
  var lightColor = light.lightColor.rgb ;
29606
29876
  lightColor = getHDRColor(lightColor , light.linear ) * light.intensity / LUMEN * 2.0;
29607
29877
  color = (albedo / PI) * lightColor.rgb * atten ;
@@ -37312,16 +37582,16 @@ fn CsMain( @builtin(workgroup_id) workgroup_id : vec3<u32> , @builtin(global_inv
37312
37582
  return 4.0 * vec2<f32>(A, B) / f32(numSamples);
37313
37583
  }
37314
37584
 
37315
- @group(0) @binding(0) var brdfluTexture: texture_storage_2d<rgba8unorm, write>;
37585
+ @group(0) @binding(0) var brdflutTexture: texture_storage_2d<rgba8unorm, write>;
37316
37586
  @compute @workgroup_size(8,8,1)
37317
- fn CsMain(@builtin(global_invocation_id) workgroup_id: vec3<u32>, @builtin(local_invocation_id) local_invocation_id: vec3<u32>){
37318
- var fragCoord = vec2<u32>(global_invocation_id.x, global_invocation_id.y);
37319
- var fragColor = vec4<f32>(0,0);
37320
- var res = integrateBRDF(f32(fragCoord.y + 1u) / 256.0, f32(fragCoord.x + 1u) / 256.0);
37321
- fragColor = vec4<f32>(res.x, res.y, 0.0, 1.0);
37322
-
37323
- textureStore(brdflutTexture, vec2<i32>(fragCoord.xy), fragColor);
37324
- }
37587
+ fn CsMain(@builtin(global_invocation_id) global_invocation_id : vec3<u32>){
37588
+ var fragCoord = vec2<u32>(global_invocation_id.x, global_invocation_id.y);
37589
+ var fragColor = vec4<f32>(0.0);
37590
+ // Output to screen
37591
+ var res = integrateBRDF(f32(fragCoord.y + 1u) / 256.0, f32(fragCoord.x + 1u) / 256.0);
37592
+ fragColor = vec4<f32>(res.x, res.y, 0.0, 1.0);
37593
+ textureStore(brdflutTexture, vec2<i32>(fragCoord.xy), fragColor);
37594
+ }
37325
37595
  `;
37326
37596
 
37327
37597
  class BRDFLUTGenerate {
@@ -38166,7 +38436,7 @@ fn CsMain( @builtin(workgroup_id) workgroup_id : vec3<u32> , @builtin(global_inv
38166
38436
  }
38167
38437
  }
38168
38438
 
38169
- const version = "1.0.0";
38439
+ const version = "1.0.3";
38170
38440
 
38171
38441
  class Engine3D {
38172
38442
  /**
@@ -39165,7 +39435,7 @@ fn CsMain(@builtin(workgroup_id) workgroup_id: vec3<u32>, @builtin(global_invoca
39165
39435
  }else{
39166
39436
  shadowMatrix = globalUniform.shadowMatrix[shadowIndex];
39167
39437
  visibility = directShadowMapingIndex(light, shadowMatrix, P, N, shadowIndex, shadowBias).x;
39168
- }
39438
+ };
39169
39439
  }
39170
39440
  shadowStruct.directShadowVisibility = visibility;
39171
39441
  }
@@ -39370,7 +39640,7 @@ fn CsMain(@builtin(workgroup_id) workgroup_id: vec3<u32>, @builtin(global_invoca
39370
39640
  blendColor = inColor.xyz + outLineColor.xyz * outLineColor.w;
39371
39641
  }else{
39372
39642
  blendColor = mix(inColor.xyz, outLineColor.xyz, outLineColor.w);
39373
- }
39643
+ };
39374
39644
  textureStore(outlineTex, fragCoord, vec4<f32>(blendColor, inColor.w));
39375
39645
  }
39376
39646
  `
@@ -40098,7 +40368,7 @@ fn CsMain(@builtin(global_invocation_id) global_invocation_id: vec3<u32>){
40098
40368
 
40099
40369
  }else{
40100
40370
  Output = vec4f(wColor.xyz, 1.0);
40101
- }
40371
+ };
40102
40372
 
40103
40373
  return Output;
40104
40374
  }
@@ -40367,12 +40637,12 @@ struct SSRUniformData {
40367
40637
  }
40368
40638
  }else{
40369
40639
  rayTraceRet.alpha = 0.0;
40370
- }
40640
+ };
40371
40641
  rayTraceRet.skyColor = getSkyColor();
40372
40642
  }else{
40373
40643
  rayTraceRet.alpha = -1.0;
40374
40644
  rayTraceRet.skyColor = vec3<f32>(0.0);
40375
- }
40645
+ };
40376
40646
 
40377
40647
  rayTraceRet.roughness = roughness;
40378
40648
  rayTraceRet.fresnel = fresnel;
@@ -40524,7 +40794,7 @@ struct SSRUniformData {
40524
40794
  hitData.hitCoord = uv;
40525
40795
  return 1;
40526
40796
  }
40527
- }
40797
+ };
40528
40798
  }
40529
40799
  return 0;
40530
40800
  }
@@ -40676,7 +40946,7 @@ fn blendColor() -> vec4<f32>{
40676
40946
  preCoord = vec2<i32>(reProjectionCoord);
40677
40947
  }else{
40678
40948
  mixWeight = 1.0;
40679
- }
40949
+ };
40680
40950
  }
40681
40951
 
40682
40952
  var curUV01 = fragUV;
@@ -40749,7 +41019,7 @@ fn minmax4(coord:vec2<i32>) {
40749
41019
  return vec4<f32>(p_clip, color_avg.w) + v_clip / ma_unit;
40750
41020
  }else{
40751
41021
  return input_texel;
40752
- }
41022
+ };
40753
41023
  }
40754
41024
  `
40755
41025
  );
@@ -41238,7 +41508,7 @@ fn containsBox( size:vec3<f32> , center:vec3<f32> ) -> f32 {
41238
41508
  return 2.0 ;
41239
41509
  }else{
41240
41510
  return 1.0 ;
41241
- }
41511
+ };
41242
41512
  }
41243
41513
 
41244
41514
  @compute @workgroup_size(128)
@@ -41993,11 +42263,13 @@ fn frag(){
41993
42263
  );
41994
42264
 
41995
42265
  let UnLitTextureArray = (
41996
- /*wgsl */
42266
+ /*wgsl*/
41997
42267
  `
42268
+ // #include "Common_vert"
41998
42269
  #include "Common_frag"
41999
42270
  #include "UnLit_frag"
42000
42271
  #include "UnLitMaterialUniform_frag"
42272
+
42001
42273
  #include "WorldMatrixUniform"
42002
42274
  #include "VertexAttributeIndexShader"
42003
42275
  #include "GlobalUniform"
@@ -42005,8 +42277,8 @@ fn frag(){
42005
42277
  #include "EnvMap_frag"
42006
42278
  #include "ColorUtil_frag"
42007
42279
 
42008
- const DEGREES_TO_RADIANS: f32 = 3.1415926 / 180.0;
42009
- const PI: f32 = 3.1415926;
42280
+ const DEGREES_TO_RADIANS : f32 = 3.1415926 / 180.0 ;
42281
+ const PI : f32 = 3.1415926 ;
42010
42282
 
42011
42283
  #if USE_CUSTOMUNIFORM
42012
42284
  struct MaterialUniform {
@@ -42017,15 +42289,19 @@ fn frag(){
42017
42289
  };
42018
42290
  #endif
42019
42291
 
42020
- @group(1) @binding(0) var baseMapSampler: sampler;
42021
- @group(1) @binding(1) var baseMap: texture_2d_array<f32>;
42022
- @group(2) @binding(5) var<storage,read> graphicBuffer: array<GraphicNodeStruct>;
42292
+ @group(1) @binding(0)
42293
+ var baseMapSampler: sampler;
42294
+ @group(1) @binding(1)
42295
+ var baseMap: texture_2d_array<f32>;
42023
42296
 
42297
+ @group(2) @binding(5)
42298
+ var<storage,read> graphicBuffer : array<GraphicNodeStruct>;
42299
+
42024
42300
  @vertex
42025
- fn VertMain(vertex: VertexAttributes) -> VertexOutput {
42301
+ fn VertMain( vertex:VertexAttributes ) -> VertexOutput {
42026
42302
  vertex_inline(vertex);
42027
42303
  vert(vertex);
42028
- return ORI_VertexOut;
42304
+ return ORI_VertexOut ;
42029
42305
  }
42030
42306
 
42031
42307
  fn vert(inputData:VertexAttributes) -> VertexOutput {
@@ -42036,9 +42312,15 @@ fn frag(){
42036
42312
  fn frag(){
42037
42313
  var transformUV1 = materialUniform.transformUV1;
42038
42314
  var transformUV2 = materialUniform.transformUV2;
42315
+
42316
+ // var irradiance = vec3<f32>(0.0) ;
42317
+ // let MAX_REFLECTION_LOD = f32(textureNumLevels(prefilterMap)) ;
42318
+ // irradiance += (globalUniform.skyExposure * textureSampleLevel(prefilterMap, prefilterMapSampler, ORI_VertexVarying.vWorldNormal.xyz, 0.8 * (MAX_REFLECTION_LOD) ).rgb);
42319
+
42039
42320
  graphicNode = graphicBuffer[u32(round(ORI_VertexVarying.index))];
42040
42321
 
42041
42322
  var uv = transformUV1.zw * ORI_VertexVarying.fragUV0 + transformUV1.xy;
42323
+ //The fragUV1.x is 1.0 when the vertex belongs to line.
42042
42324
  if(ORI_VertexVarying.fragUV1.x > 0.5){
42043
42325
  uv = graphicNode.uvRect2.zw * uv.xy + graphicNode.uvRect2.xy;
42044
42326
  uv += graphicNode.uvSpeed.zw * globalUniform.time;
@@ -42054,7 +42336,7 @@ fn frag(){
42054
42336
  );
42055
42337
  uv = (zrot * vec3f(uv, 0.0)).xy;
42056
42338
  }
42057
- }
42339
+ };
42058
42340
  var graphicTextureID = graphicNode.texIndex;
42059
42341
  var graphicNodeColor = graphicNode.baseColor;
42060
42342
  if(ORI_VertexVarying.fragUV1.x > 0.5){
@@ -42062,12 +42344,23 @@ fn frag(){
42062
42344
  graphicNodeColor = graphicNode.lineColor;
42063
42345
  }
42064
42346
  var color = textureSample(baseMap,baseMapSampler,uv, u32(round(graphicTextureID)) ) * materialUniform.baseColor * graphicNodeColor ;
42065
- color += graphicNode.emissiveColor;
42347
+ // let color = textureSample(baseMap,baseMapSampler,uv, u32(round(ORI_VertexVarying.index)));
42348
+
42349
+ // ORI_ViewDir = normalize( globalUniform.CameraPos.xyz - ORI_VertexVarying.vWorldPos.xyz);
42350
+ // let att = dot( ORI_ViewDir , ORI_VertexVarying.vWorldNormal.xyz );
42351
+
42352
+ // irradiance = LinearToGammaSpace(irradiance.rgb) * color.rgb ;//* att ;
42353
+
42354
+ color += graphicNode.emissiveColor ;
42066
42355
  if(color.w < materialUniform.alphaCutoff){
42067
- discard;
42356
+ discard ;
42068
42357
  }
42069
- let outColor = vec4f( color.rgb , 1.0 ) * materialUniform.baseColor;
42070
- ORI_ShadingInput.BaseColor = vec4f(outColor.xyz,1.0);
42358
+
42359
+ // let outColor = vec4f( color.rgb * (att * 0.5 + 0.5 ) , 1.0 ) * materialUniform.baseColor ;
42360
+ let outColor = vec4f( color.rgb , 1.0 ) * materialUniform.baseColor ;
42361
+
42362
+ // ORI_ShadingInput.BaseColor = color ;
42363
+ ORI_ShadingInput.BaseColor = vec4f(outColor.xyz,1.0) ;
42071
42364
  UnLit();
42072
42365
  }
42073
42366
  `
@@ -42202,7 +42495,7 @@ fn frag(){
42202
42495
  let sunLight = lightBuffer[0] ;
42203
42496
  var inScatteringValue = inScatterIng(sunLight.direction, texPosition.xyz, sunLight.lightColor);
42204
42497
  opColor += inScatteringValue;
42205
- }
42498
+ };
42206
42499
 
42207
42500
  textureStore(outTex, fragCoord , vec4<f32>(opColor.xyz, texColor.a));
42208
42501
  }
@@ -42592,14 +42885,16 @@ fn frag(){
42592
42885
  _internalTexture;
42593
42886
  _cubeSize;
42594
42887
  setting;
42888
+ /**
42889
+ * @constructor
42890
+ * @param setting AtmosphericScatteringSkySetting
42891
+ * @returns
42892
+ */
42595
42893
  constructor(setting) {
42596
42894
  super();
42597
42895
  this.setting = setting;
42598
42896
  this._cubeSize = setting.defaultTextureCubeSize;
42599
- this._internalTexture = new AtmosphericTexture2D(
42600
- setting.defaultTexture2DSize,
42601
- setting.defaultTexture2DSize * 0.5
42602
- );
42897
+ this._internalTexture = new AtmosphericTexture2D(setting.defaultTexture2DSize, setting.defaultTexture2DSize * 0.5);
42603
42898
  this._internalTexture.update(this.setting);
42604
42899
  this.createFromTexture(this._cubeSize, this._internalTexture);
42605
42900
  return this;
@@ -42607,6 +42902,10 @@ fn frag(){
42607
42902
  get texture2D() {
42608
42903
  return this._internalTexture;
42609
42904
  }
42905
+ /**
42906
+ * @internal
42907
+ * @returns
42908
+ */
42610
42909
  apply() {
42611
42910
  this._internalTexture.update(this.setting);
42612
42911
  this._faceData.uploadErpTexture(this._internalTexture);
@@ -42617,13 +42916,7 @@ fn frag(){
42617
42916
  _computeShader;
42618
42917
  _uniformBuffer;
42619
42918
  constructor(width, height) {
42620
- super(
42621
- width,
42622
- height,
42623
- GPUTextureFormat.rgba16float,
42624
- false,
42625
- GPUTextureUsage.STORAGE_BINDING | GPUTextureUsage.TEXTURE_BINDING
42626
- );
42919
+ super(width, height, GPUTextureFormat.rgba16float, false, GPUTextureUsage.STORAGE_BINDING | GPUTextureUsage.TEXTURE_BINDING);
42627
42920
  this.initCompute(width, height);
42628
42921
  }
42629
42922
  initCompute(w, h) {
@@ -42683,7 +42976,7 @@ fn frag(){
42683
42976
  }
42684
42977
  };
42685
42978
  exports.SkyShader = __decorateClass$a([
42686
- RegisterShader
42979
+ RegisterShader(exports.SkyShader, "SkyShader")
42687
42980
  ], exports.SkyShader);
42688
42981
 
42689
42982
  class SkyMaterial extends Material {
@@ -47653,7 +47946,7 @@ fn frag(){
47653
47946
  s = border.x + (s / centerPartMax) * centerPartMin;
47654
47947
  }else{
47655
47948
  s = s - centerPartMax + border.x + centerPartMin;
47656
- }
47949
+ };
47657
47950
  }
47658
47951
  return s;
47659
47952
  }
@@ -47805,12 +48098,12 @@ fn frag(){
47805
48098
  ret.x = quad.x;
47806
48099
  }else{
47807
48100
  ret.x = quad.z;
47808
- }
48101
+ };
47809
48102
  if(index == 0 || index == 1){
47810
48103
  ret.y = quad.w;
47811
48104
  }else{
47812
48105
  ret.y = quad.y;
47813
- }
48106
+ };
47814
48107
  return ret;
47815
48108
  }
47816
48109
  `
@@ -56749,7 +57042,7 @@ fn frag(){
56749
57042
  }
56750
57043
  };
56751
57044
  exports.LitSSSShader = __decorateClass$3([
56752
- RegisterShader
57045
+ RegisterShader(exports.LitSSSShader, "LitSSSShader")
56753
57046
  ], exports.LitSSSShader);
56754
57047
 
56755
57048
  var __getOwnPropDesc$2 = Object.getOwnPropertyDescriptor;
@@ -56851,7 +57144,7 @@ fn frag(){
56851
57144
  }
56852
57145
  };
56853
57146
  exports.LitShader = __decorateClass$2([
56854
- RegisterShader
57147
+ RegisterShader(exports.LitShader, "LitShader")
56855
57148
  ], exports.LitShader);
56856
57149
 
56857
57150
  class ComData {
@@ -57087,7 +57380,7 @@ fn frag(){
57087
57380
  }
57088
57381
  };
57089
57382
  exports.UnLitShader = __decorateClass$1([
57090
- RegisterShader
57383
+ RegisterShader(exports.UnLitShader, "UnLitShader")
57091
57384
  ], exports.UnLitShader);
57092
57385
 
57093
57386
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
@@ -57176,7 +57469,7 @@ fn frag(){
57176
57469
  }
57177
57470
  };
57178
57471
  exports.UnLitTexArrayShader = __decorateClass([
57179
- RegisterShader
57472
+ RegisterShader(exports.UnLitTexArrayShader, "UnLitTexArrayShader")
57180
57473
  ], exports.UnLitTexArrayShader);
57181
57474
 
57182
57475
  class TileSet {
@@ -58054,253 +58347,23 @@ fn frag(){
58054
58347
  }
58055
58348
  }
58056
58349
 
58057
- class PlaneClassification {
58058
- /**
58059
- * @language zh_CN
58060
- * 背面
58061
- * @platform Web,Native
58062
- */
58063
- static BACK = 0;
58064
- /**
58065
- * @language zh_CN
58066
- * 正面
58067
- * @platform Web,Native
58068
- */
58069
- static FRONT = 1;
58070
- /**
58071
- * @language zh_CN
58072
- * 在法线朝上的一面
58073
- * @platform Web,Native
58074
- */
58075
- static IN = 0;
58076
- /**
58077
- * @language zh_CN
58078
- * 在法线朝下的一面
58079
- * @platform Web,Native
58080
- */
58081
- static OUT = 1;
58082
- /**
58083
- * @language zh_CN
58084
- * 相交
58085
- * @platform Web,Native
58086
- */
58087
- static INTERSECT = 2;
58088
- }
58089
-
58090
- class Plane3D {
58091
- /**
58092
- * @language en_US
58093
- * The A coefficient of this plane. (Also the x dimension of the plane normal)
58094
- */
58095
- /**
58096
- * @language zh_CN
58097
- * 平面中的a分量
58098
- * @platform Web,Native
58099
- */
58100
- a;
58101
- /**
58102
- * @language en_US
58103
- * The B coefficient of this plane. (Also the y dimension of the plane normal)
58104
- */
58105
- /**
58106
- * @language zh_CN
58107
- * 平面中的b分量
58108
- * @platform Web,Native
58109
- */
58110
- b;
58111
- /**
58112
- * @language en_US
58113
- * The C coefficient of this plane. (Also the z dimension of the plane normal)
58114
- */
58115
- /**
58116
- * @language zh_CN
58117
- * 平面中的c分量
58118
- * @platform Web,Native
58119
- */
58120
- c;
58121
- /**
58122
- * @language en_US
58123
- * The D coefficient of this plane. (Also the inverse dot product between normal and point)
58124
- */
58125
- /**
58126
- * @language zh_CN
58127
- * 平面中的d分量
58128
- * @platform Web,Native
58129
- */
58130
- d;
58131
- // indicates the alignment of the plane
58132
- /**
58133
- * @private
58134
- */
58135
- static ALIGN_ANY = 0;
58136
- /**
58137
- * @private
58138
- */
58139
- static ALIGN_XY_AXIS = 1;
58140
- /**
58141
- * @private
58142
- */
58143
- static ALIGN_YZ_AXIS = 2;
58144
- /**
58145
- * @private
58146
- */
58147
- static ALIGN_XZ_AXIS = 3;
58148
- /**
58149
- * @language en_US
58150
- * Create a Plane3D with ABCD coefficients
58151
- */
58152
- /**
58153
- * @language zh_CN
58154
- * 创建一个平面实例
58155
- * @param a
58156
- * @param b
58157
- * @param c
58158
- * @param d
58159
- * @platform Web,Native
58160
- */
58161
- constructor(a = 0, b = 0, c = 0, d = 0) {
58162
- this.a = a;
58163
- this.b = b;
58164
- this.c = c;
58165
- this.d = d;
58166
- }
58167
- /**
58168
- * @language zh_CN
58169
- * 填充平面的各分量的值
58170
- * @param a
58171
- * @param b
58172
- * @param c
58173
- * @param d
58174
- * @platform Web,Native
58175
- */
58176
- setTo(a = 0, b = 0, c = 0, d = 0) {
58177
- this.a = a;
58178
- this.b = b;
58179
- this.c = c;
58180
- this.d = d;
58181
- }
58182
- /**
58183
- * @language en_US
58184
- * Fills this Plane3D with the coefficients from 3 points in 3d space.
58185
- * @param p0 Vector3
58186
- * @param p1 Vector3
58187
- * @param p2 Vector3
58188
- */
58189
- /**
58190
- * @language zh_CN
58191
- * 由3个坐标来创建一个3d平面
58192
- * @param p0 Vector3
58193
- * @param p1 Vector3
58194
- * @param p2 Vector3
58195
- * @platform Web,Native
58196
- */
58197
- fromPoints(p0, p1, p2) {
58198
- var d1x = p1.x - p0.x;
58199
- var d1y = p1.y - p0.y;
58200
- var d1z = p1.z - p0.z;
58201
- var d2x = p2.x - p0.x;
58202
- var d2y = p2.y - p0.y;
58203
- var d2z = p2.z - p0.z;
58204
- this.a = d1y * d2z - d1z * d2y;
58205
- this.b = d1z * d2x - d1x * d2z;
58206
- this.c = d1x * d2y - d1y * d2x;
58207
- this.d = -(this.a * p0.x + this.b * p0.y + this.c * p0.z);
58208
- }
58209
- /**
58210
- * @language en_US
58211
- * Fills this Plane3D with the coefficients from the plane's normal and a point in 3d space.
58212
- * @param normal Vector3
58213
- * @param point Vector3
58214
- */
58215
- /**
58216
- * @language zh_CN
58217
- * 由一条normal向量和一个坐标创建一个3d平面
58218
- * @param normal Vector3
58219
- * @param point Vector3
58220
- * @platform Web,Native
58221
- */
58222
- fromNormalAndPoint(normal, point) {
58223
- this.a = normal.x;
58224
- this.b = normal.y;
58225
- this.c = normal.z;
58226
- this.d = -(this.a * point.x + this.b * point.y + this.c * point.z);
58227
- }
58228
- /**
58229
- * @language en_US
58230
- * Normalize this Plane3D
58231
- * @returns Plane3D This Plane3D.
58232
- */
58233
- /**
58234
- * @language zh_CN
58235
- * 单位化3d平面
58236
- * @returns number 返回平面长度
58237
- * @platform Web,Native
58238
- */
58239
- normalize() {
58240
- var len = Math.sqrt(
58241
- this.a * this.a + this.b * this.b + this.c * this.c
58242
- );
58243
- if (len > 0) {
58244
- var invLength = 1 / len;
58245
- this.a *= invLength;
58246
- this.b *= invLength;
58247
- this.c *= invLength;
58248
- this.d *= invLength;
58249
- }
58250
- return len;
58251
- }
58252
- /**
58253
- * @language en_US
58254
- * Returns the signed distance between this Plane3D and the point p.
58255
- * @param p Vector3
58256
- * @returns Number
58257
- */
58258
- /**
58259
- * @language zh_CN
58260
- * 计算3d平面到点p的距离
58261
- * @param p Vector3
58262
- * @returns number 返回计算后的距离
58263
- * @platform Web,Native
58264
- */
58265
- distance(p) {
58266
- return this.a * p.x + this.b * p.y + this.c * p.z + this.d;
58267
- }
58268
- /**
58269
- * @language en_US
58270
- * Classify a point against this Plane3D. (in front, back or intersecting)
58271
- * @param p Vector3
58272
- * @param epsilon
58273
- * @returns PlaneClassification.FRONT在平面正面
58274
- * PlaneClassification.BACK在平面背面面
58275
- * PlaneClassification.INTERSECT在平面上
58276
- */
58277
- /**
58278
- * @language zh_CN
58279
- * 计算3d平面和点p的空间关系
58280
- * @param p Vector3
58281
- * @param epsilon 相对偏移值
58282
- * @returns number int Plane3.FRONT or Plane3D.BACK or Plane3D.INTERSECT
58283
- * @platform Web,Native
58284
- */
58285
- classifyPoint(p, epsilon = 0.01) {
58286
- var dis = this.distance(p);
58287
- if (dis < -epsilon) {
58288
- return PlaneClassification.BACK;
58289
- } else if (dis > epsilon) {
58290
- return PlaneClassification.FRONT;
58291
- }
58292
- return PlaneClassification.INTERSECT;
58293
- }
58294
- /**
58295
- * @language zh_CN
58296
- * 当前Plane3D以字符串形式返回
58297
- * @returns string
58298
- * @platform Web,Native
58299
- */
58300
- toString() {
58301
- return "Plane3D [a:" + this.a + ", b:" + this.b + ", c:" + this.c + ", d:" + this.d + "]";
58302
- }
58303
- }
58350
+ var ParticleSystemRandomnessIds = /* @__PURE__ */ ((ParticleSystemRandomnessIds2) => {
58351
+ ParticleSystemRandomnessIds2[ParticleSystemRandomnessIds2["kParticleSystemClampVelocityCurveId"] = 322376503] = "kParticleSystemClampVelocityCurveId";
58352
+ ParticleSystemRandomnessIds2[ParticleSystemRandomnessIds2["kParticleSystemForceCurveId"] = 306581307] = "kParticleSystemForceCurveId";
58353
+ ParticleSystemRandomnessIds2[ParticleSystemRandomnessIds2["kParticleSystemRotationCurveId"] = 1793934638] = "kParticleSystemRotationCurveId";
58354
+ ParticleSystemRandomnessIds2[ParticleSystemRandomnessIds2["kParticleSystemRotationBySpeedCurveId"] = 3737431713] = "kParticleSystemRotationBySpeedCurveId";
58355
+ ParticleSystemRandomnessIds2[ParticleSystemRandomnessIds2["kParticleSystemStartSpeedCurveId"] = 2527743459] = "kParticleSystemStartSpeedCurveId";
58356
+ ParticleSystemRandomnessIds2[ParticleSystemRandomnessIds2["kParticleSystemSizeCurveId"] = 2368504881] = "kParticleSystemSizeCurveId";
58357
+ ParticleSystemRandomnessIds2[ParticleSystemRandomnessIds2["kParticleSystemSizeBySpeedCurveId"] = 4085612399] = "kParticleSystemSizeBySpeedCurveId";
58358
+ ParticleSystemRandomnessIds2[ParticleSystemRandomnessIds2["kParticleSystemVelocityCurveId"] = 3774601268] = "kParticleSystemVelocityCurveId";
58359
+ ParticleSystemRandomnessIds2[ParticleSystemRandomnessIds2["kParticleSystemUVCurveId"] = 326370691] = "kParticleSystemUVCurveId";
58360
+ ParticleSystemRandomnessIds2[ParticleSystemRandomnessIds2["kParticleSystemColorGradientId"] = 1494990940] = "kParticleSystemColorGradientId";
58361
+ ParticleSystemRandomnessIds2[ParticleSystemRandomnessIds2["kParticleSystemColorByVelocityGradientId"] = 1089181156] = "kParticleSystemColorByVelocityGradientId";
58362
+ ParticleSystemRandomnessIds2[ParticleSystemRandomnessIds2["kParticleSystemMeshSelectionId"] = 3159510623] = "kParticleSystemMeshSelectionId";
58363
+ ParticleSystemRandomnessIds2[ParticleSystemRandomnessIds2["kParticleSystemUVRowSelectionId"] = 2941263940] = "kParticleSystemUVRowSelectionId";
58364
+ return ParticleSystemRandomnessIds2;
58365
+ })(ParticleSystemRandomnessIds || {});
58366
+ const kPI = 3.141592653589793;
58304
58367
 
58305
58368
  class Polynomials {
58306
58369
  }
@@ -58578,6 +58641,403 @@ fn frag(){
58578
58641
  coeff[3] /= 1;
58579
58642
  }
58580
58643
 
58644
+ var ParticleSystemCurveEvalMode = /* @__PURE__ */ ((ParticleSystemCurveEvalMode2) => {
58645
+ ParticleSystemCurveEvalMode2[ParticleSystemCurveEvalMode2["kEMScalar"] = 0] = "kEMScalar";
58646
+ ParticleSystemCurveEvalMode2[ParticleSystemCurveEvalMode2["kEMOptimized"] = 1] = "kEMOptimized";
58647
+ ParticleSystemCurveEvalMode2[ParticleSystemCurveEvalMode2["kEMOptimizedMinMax"] = 2] = "kEMOptimizedMinMax";
58648
+ ParticleSystemCurveEvalMode2[ParticleSystemCurveEvalMode2["kEMSlow"] = 3] = "kEMSlow";
58649
+ return ParticleSystemCurveEvalMode2;
58650
+ })(ParticleSystemCurveEvalMode || {});
58651
+ var MinMaxCurveState = /* @__PURE__ */ ((MinMaxCurveState2) => {
58652
+ MinMaxCurveState2[MinMaxCurveState2["kMMCScalar"] = 0] = "kMMCScalar";
58653
+ MinMaxCurveState2[MinMaxCurveState2["kMMCCurve"] = 1] = "kMMCCurve";
58654
+ MinMaxCurveState2[MinMaxCurveState2["kMMCTwoCurves"] = 2] = "kMMCTwoCurves";
58655
+ MinMaxCurveState2[MinMaxCurveState2["kMMCTwoConstants"] = 3] = "kMMCTwoConstants";
58656
+ return MinMaxCurveState2;
58657
+ })(MinMaxCurveState || {});
58658
+ class MinMaxAnimationCurves {
58659
+ // public SupportsProcedural ();
58660
+ max;
58661
+ min;
58662
+ }
58663
+ class MinMaxPolyCurves {
58664
+ max;
58665
+ min;
58666
+ integrate() {
58667
+ this.max.integrate();
58668
+ this.min.integrate();
58669
+ }
58670
+ doubleIntegrate() {
58671
+ this.max.doubleIntegrate();
58672
+ this.min.doubleIntegrate();
58673
+ }
58674
+ findMinMaxIntegrated() {
58675
+ return null;
58676
+ }
58677
+ findMinMaxDoubleIntegrated() {
58678
+ return null;
58679
+ }
58680
+ }
58681
+ class MinMaxCurve {
58682
+ minMaxState;
58683
+ // see enum MinMaxCurveState
58684
+ minCurve;
58685
+ maxCurve;
58686
+ _scalar = 1;
58687
+ // Since scalar is baked into the optimized curve we use the setter function to modify it.
58688
+ _minScalar;
58689
+ constructor(scalarValue = 1) {
58690
+ this._scalar = scalarValue;
58691
+ this.minMaxState = 0 /* kMMCScalar */;
58692
+ this.minCurve = new AnimationCurve();
58693
+ this.maxCurve = new AnimationCurve();
58694
+ }
58695
+ setScalar(value) {
58696
+ this._scalar = value;
58697
+ }
58698
+ getScalar() {
58699
+ return this._scalar;
58700
+ }
58701
+ static evaluateSlow(curve, t, factor) {
58702
+ let v = curve.maxCurve.getValue(t) * curve.getScalar();
58703
+ if (curve.minMaxState == 2 /* kMMCTwoCurves */) {
58704
+ return lerp(curve.minCurve.getValue(t) * curve.getScalar(), v, factor);
58705
+ } else return v;
58706
+ }
58707
+ static evaluate(curve, t, randomValue = 1) {
58708
+ if (curve.minMaxState == 0 /* kMMCScalar */) {
58709
+ return curve.getScalar();
58710
+ }
58711
+ let v = curve.maxCurve.getValue(t) * curve.getScalar();
58712
+ if (curve.minMaxState == 1 /* kMMCCurve */) {
58713
+ return lerp(curve.minCurve.getValue(t) * curve.getScalar(), v, randomValue);
58714
+ }
58715
+ if (curve.minMaxState == 3 /* kMMCTwoConstants */) {
58716
+ return lerp(curve._minScalar, curve._scalar, randomValue);
58717
+ }
58718
+ if (curve.minMaxState == 2 /* kMMCTwoCurves */) {
58719
+ return lerp(curve.minCurve.getValue(t) * curve.getScalar(), v, 1 * Math.random());
58720
+ }
58721
+ return this.evaluateSlow(curve, t, 1);
58722
+ }
58723
+ unSerialized(data) {
58724
+ this.minMaxState = data["minMaxState"];
58725
+ this._scalar = data["scalar"];
58726
+ this._minScalar = data["minScalar"];
58727
+ this.maxCurve.unSerialized(data["maxCurve"]);
58728
+ this.minCurve.unSerialized(data["minCurve"]);
58729
+ }
58730
+ }
58731
+ class ValueSpread {
58732
+ value = 0;
58733
+ mode = 0;
58734
+ spread = 0;
58735
+ speed = new MinMaxCurve();
58736
+ unSerialized(data) {
58737
+ this.value = data["value"];
58738
+ this.mode = data["mode"];
58739
+ this.spread = data["spread"];
58740
+ this.speed.unSerialized(data["speed"]);
58741
+ }
58742
+ }
58743
+ function curvesSupportProcedural(editorCurves, minMaxState) {
58744
+ let isValid = PolynomialCurve.isValidCurve(editorCurves.max);
58745
+ if (minMaxState != 2 /* kMMCTwoCurves */ && minMaxState != 3 /* kMMCTwoConstants */) {
58746
+ return isValid;
58747
+ } else {
58748
+ return isValid && PolynomialCurve.isValidCurve(editorCurves.min);
58749
+ }
58750
+ }
58751
+ function buildCurves(polyCurves, editorCurves, scalar, minMaxState) {
58752
+ polyCurves.max.buildCurve(editorCurves.max, scalar);
58753
+ if (minMaxState != 2 /* kMMCTwoCurves */ && minMaxState != 3 /* kMMCTwoConstants */) {
58754
+ polyCurves.min.buildCurve(editorCurves.max, scalar);
58755
+ } else {
58756
+ polyCurves.min.buildCurve(editorCurves.min, scalar);
58757
+ }
58758
+ }
58759
+ function calculateCurveRangesValue(minMaxValue, curve) {
58760
+ let keyCount = curve.getKeyCount();
58761
+ if (keyCount == 0) {
58762
+ return;
58763
+ }
58764
+ if (keyCount == 1) {
58765
+ calculateMinMax(minMaxValue, curve.getKey(0).value);
58766
+ } else {
58767
+ let segmentCount = keyCount - 1;
58768
+ calculateMinMax(minMaxValue, curve.getKey(0).value);
58769
+ for (let i = 0; i < segmentCount; i++) {
58770
+ let cache = new FrameCache();
58771
+ curve.calculateCacheData(cache, i, i + 1, 0);
58772
+ let a = 3 * cache.coeff[0];
58773
+ let b = 2 * cache.coeff[1];
58774
+ let c = 1 * cache.coeff[2];
58775
+ let start = curve.getKey(i).time;
58776
+ let end = curve.getKey(i + 1).time;
58777
+ let roots = [];
58778
+ let numRoots = quadraticPolynomialRootsGeneric(a, b, c, { r0: roots[0], r1: roots[1] });
58779
+ for (let r = 0; r < numRoots; r++) {
58780
+ if (roots[r] >= 0 && roots[r] + start < end) {
58781
+ calculateMinMax(minMaxValue, Polynomial.EvalSegment(roots[r], cache.coeff));
58782
+ }
58783
+ }
58784
+ calculateMinMax(minMaxValue, Polynomial.EvalSegment(end - start, cache.coeff));
58785
+ }
58786
+ }
58787
+ }
58788
+ function calculateMinMax(minmax, value) {
58789
+ minmax.x = Math.min(minmax.x, value);
58790
+ minmax.y = Math.max(minmax.y, value);
58791
+ }
58792
+
58793
+ class PlaneClassification {
58794
+ /**
58795
+ * @language zh_CN
58796
+ * 背面
58797
+ * @platform Web,Native
58798
+ */
58799
+ static BACK = 0;
58800
+ /**
58801
+ * @language zh_CN
58802
+ * 正面
58803
+ * @platform Web,Native
58804
+ */
58805
+ static FRONT = 1;
58806
+ /**
58807
+ * @language zh_CN
58808
+ * 在法线朝上的一面
58809
+ * @platform Web,Native
58810
+ */
58811
+ static IN = 0;
58812
+ /**
58813
+ * @language zh_CN
58814
+ * 在法线朝下的一面
58815
+ * @platform Web,Native
58816
+ */
58817
+ static OUT = 1;
58818
+ /**
58819
+ * @language zh_CN
58820
+ * 相交
58821
+ * @platform Web,Native
58822
+ */
58823
+ static INTERSECT = 2;
58824
+ }
58825
+
58826
+ class Plane3D {
58827
+ /**
58828
+ * @language en_US
58829
+ * The A coefficient of this plane. (Also the x dimension of the plane normal)
58830
+ */
58831
+ /**
58832
+ * @language zh_CN
58833
+ * 平面中的a分量
58834
+ * @platform Web,Native
58835
+ */
58836
+ a;
58837
+ /**
58838
+ * @language en_US
58839
+ * The B coefficient of this plane. (Also the y dimension of the plane normal)
58840
+ */
58841
+ /**
58842
+ * @language zh_CN
58843
+ * 平面中的b分量
58844
+ * @platform Web,Native
58845
+ */
58846
+ b;
58847
+ /**
58848
+ * @language en_US
58849
+ * The C coefficient of this plane. (Also the z dimension of the plane normal)
58850
+ */
58851
+ /**
58852
+ * @language zh_CN
58853
+ * 平面中的c分量
58854
+ * @platform Web,Native
58855
+ */
58856
+ c;
58857
+ /**
58858
+ * @language en_US
58859
+ * The D coefficient of this plane. (Also the inverse dot product between normal and point)
58860
+ */
58861
+ /**
58862
+ * @language zh_CN
58863
+ * 平面中的d分量
58864
+ * @platform Web,Native
58865
+ */
58866
+ d;
58867
+ // indicates the alignment of the plane
58868
+ /**
58869
+ * @private
58870
+ */
58871
+ static ALIGN_ANY = 0;
58872
+ /**
58873
+ * @private
58874
+ */
58875
+ static ALIGN_XY_AXIS = 1;
58876
+ /**
58877
+ * @private
58878
+ */
58879
+ static ALIGN_YZ_AXIS = 2;
58880
+ /**
58881
+ * @private
58882
+ */
58883
+ static ALIGN_XZ_AXIS = 3;
58884
+ /**
58885
+ * @language en_US
58886
+ * Create a Plane3D with ABCD coefficients
58887
+ */
58888
+ /**
58889
+ * @language zh_CN
58890
+ * 创建一个平面实例
58891
+ * @param a
58892
+ * @param b
58893
+ * @param c
58894
+ * @param d
58895
+ * @platform Web,Native
58896
+ */
58897
+ constructor(a = 0, b = 0, c = 0, d = 0) {
58898
+ this.a = a;
58899
+ this.b = b;
58900
+ this.c = c;
58901
+ this.d = d;
58902
+ }
58903
+ /**
58904
+ * @language zh_CN
58905
+ * 填充平面的各分量的值
58906
+ * @param a
58907
+ * @param b
58908
+ * @param c
58909
+ * @param d
58910
+ * @platform Web,Native
58911
+ */
58912
+ setTo(a = 0, b = 0, c = 0, d = 0) {
58913
+ this.a = a;
58914
+ this.b = b;
58915
+ this.c = c;
58916
+ this.d = d;
58917
+ }
58918
+ /**
58919
+ * @language en_US
58920
+ * Fills this Plane3D with the coefficients from 3 points in 3d space.
58921
+ * @param p0 Vector3
58922
+ * @param p1 Vector3
58923
+ * @param p2 Vector3
58924
+ */
58925
+ /**
58926
+ * @language zh_CN
58927
+ * 由3个坐标来创建一个3d平面
58928
+ * @param p0 Vector3
58929
+ * @param p1 Vector3
58930
+ * @param p2 Vector3
58931
+ * @platform Web,Native
58932
+ */
58933
+ fromPoints(p0, p1, p2) {
58934
+ var d1x = p1.x - p0.x;
58935
+ var d1y = p1.y - p0.y;
58936
+ var d1z = p1.z - p0.z;
58937
+ var d2x = p2.x - p0.x;
58938
+ var d2y = p2.y - p0.y;
58939
+ var d2z = p2.z - p0.z;
58940
+ this.a = d1y * d2z - d1z * d2y;
58941
+ this.b = d1z * d2x - d1x * d2z;
58942
+ this.c = d1x * d2y - d1y * d2x;
58943
+ this.d = -(this.a * p0.x + this.b * p0.y + this.c * p0.z);
58944
+ }
58945
+ /**
58946
+ * @language en_US
58947
+ * Fills this Plane3D with the coefficients from the plane's normal and a point in 3d space.
58948
+ * @param normal Vector3
58949
+ * @param point Vector3
58950
+ */
58951
+ /**
58952
+ * @language zh_CN
58953
+ * 由一条normal向量和一个坐标创建一个3d平面
58954
+ * @param normal Vector3
58955
+ * @param point Vector3
58956
+ * @platform Web,Native
58957
+ */
58958
+ fromNormalAndPoint(normal, point) {
58959
+ this.a = normal.x;
58960
+ this.b = normal.y;
58961
+ this.c = normal.z;
58962
+ this.d = -(this.a * point.x + this.b * point.y + this.c * point.z);
58963
+ }
58964
+ /**
58965
+ * @language en_US
58966
+ * Normalize this Plane3D
58967
+ * @returns Plane3D This Plane3D.
58968
+ */
58969
+ /**
58970
+ * @language zh_CN
58971
+ * 单位化3d平面
58972
+ * @returns number 返回平面长度
58973
+ * @platform Web,Native
58974
+ */
58975
+ normalize() {
58976
+ var len = Math.sqrt(
58977
+ this.a * this.a + this.b * this.b + this.c * this.c
58978
+ );
58979
+ if (len > 0) {
58980
+ var invLength = 1 / len;
58981
+ this.a *= invLength;
58982
+ this.b *= invLength;
58983
+ this.c *= invLength;
58984
+ this.d *= invLength;
58985
+ }
58986
+ return len;
58987
+ }
58988
+ /**
58989
+ * @language en_US
58990
+ * Returns the signed distance between this Plane3D and the point p.
58991
+ * @param p Vector3
58992
+ * @returns Number
58993
+ */
58994
+ /**
58995
+ * @language zh_CN
58996
+ * 计算3d平面到点p的距离
58997
+ * @param p Vector3
58998
+ * @returns number 返回计算后的距离
58999
+ * @platform Web,Native
59000
+ */
59001
+ distance(p) {
59002
+ return this.a * p.x + this.b * p.y + this.c * p.z + this.d;
59003
+ }
59004
+ /**
59005
+ * @language en_US
59006
+ * Classify a point against this Plane3D. (in front, back or intersecting)
59007
+ * @param p Vector3
59008
+ * @param epsilon
59009
+ * @returns PlaneClassification.FRONT在平面正面
59010
+ * PlaneClassification.BACK在平面背面面
59011
+ * PlaneClassification.INTERSECT在平面上
59012
+ */
59013
+ /**
59014
+ * @language zh_CN
59015
+ * 计算3d平面和点p的空间关系
59016
+ * @param p Vector3
59017
+ * @param epsilon 相对偏移值
59018
+ * @returns number int Plane3.FRONT or Plane3D.BACK or Plane3D.INTERSECT
59019
+ * @platform Web,Native
59020
+ */
59021
+ classifyPoint(p, epsilon = 0.01) {
59022
+ var dis = this.distance(p);
59023
+ if (dis < -epsilon) {
59024
+ return PlaneClassification.BACK;
59025
+ } else if (dis > epsilon) {
59026
+ return PlaneClassification.FRONT;
59027
+ }
59028
+ return PlaneClassification.INTERSECT;
59029
+ }
59030
+ /**
59031
+ * @language zh_CN
59032
+ * 当前Plane3D以字符串形式返回
59033
+ * @returns string
59034
+ * @platform Web,Native
59035
+ */
59036
+ toString() {
59037
+ return "Plane3D [a:" + this.a + ", b:" + this.b + ", c:" + this.c + ", d:" + this.d + "]";
59038
+ }
59039
+ }
59040
+
58581
59041
  function uniform_real_distribution(min, max) {
58582
59042
  return Math.random() * max + Math.random() * min + (max - min) * Math.random();
58583
59043
  }
@@ -63399,6 +63859,10 @@ fn frag(){
63399
63859
  exports.MergeRGBACreator = MergeRGBACreator;
63400
63860
  exports.MergeRGBA_cs = MergeRGBA_cs;
63401
63861
  exports.MeshColliderShape = MeshColliderShape;
63862
+ exports.MinMaxAnimationCurves = MinMaxAnimationCurves;
63863
+ exports.MinMaxCurve = MinMaxCurve;
63864
+ exports.MinMaxCurveState = MinMaxCurveState;
63865
+ exports.MinMaxPolyCurves = MinMaxPolyCurves;
63402
63866
  exports.MorePassParser = MorePassParser;
63403
63867
  exports.MorePassShader = MorePassShader;
63404
63868
  exports.MorphTargetBlender = MorphTargetBlender;
@@ -63446,6 +63910,8 @@ fn frag(){
63446
63910
  exports.PBRLitSSSShader = PBRLitSSSShader;
63447
63911
  exports.ParserBase = ParserBase;
63448
63912
  exports.ParserFormat = ParserFormat;
63913
+ exports.ParticleSystemCurveEvalMode = ParticleSystemCurveEvalMode;
63914
+ exports.ParticleSystemRandomnessIds = ParticleSystemRandomnessIds;
63449
63915
  exports.PassGenerate = PassGenerate;
63450
63916
  exports.PassShader = PassShader;
63451
63917
  exports.PassType = PassType;
@@ -63692,6 +64158,7 @@ fn frag(){
63692
64158
  exports.ValueEnumType = ValueEnumType;
63693
64159
  exports.ValueOp = ValueOp;
63694
64160
  exports.ValueParser = ValueParser;
64161
+ exports.ValueSpread = ValueSpread;
63695
64162
  exports.Vector2 = Vector2;
63696
64163
  exports.Vector3 = Vector3;
63697
64164
  exports.Vector3Ex = Vector3Ex;
@@ -63725,6 +64192,9 @@ fn frag(){
63725
64192
  exports.append = append;
63726
64193
  exports.arrayToString = arrayToString;
63727
64194
  exports.blendComponent = blendComponent;
64195
+ exports.buildCurves = buildCurves;
64196
+ exports.calculateCurveRangesValue = calculateCurveRangesValue;
64197
+ exports.calculateMinMax = calculateMinMax;
63728
64198
  exports.castPointShadowMap_vert = castPointShadowMap_vert;
63729
64199
  exports.clamp = clamp;
63730
64200
  exports.clampRepeat = clampRepeat;
@@ -63732,6 +64202,7 @@ fn frag(){
63732
64202
  exports.crossProduct = crossProduct;
63733
64203
  exports.cubicPolynomialRoot = cubicPolynomialRoot;
63734
64204
  exports.cubicPolynomialRootsGeneric = cubicPolynomialRootsGeneric;
64205
+ exports.curvesSupportProcedural = curvesSupportProcedural;
63735
64206
  exports.deg2Rad = deg2Rad;
63736
64207
  exports.directionShadowCastMap_frag = directionShadowCastMap_frag;
63737
64208
  exports.dot = dot;
@@ -63754,6 +64225,7 @@ fn frag(){
63754
64225
  exports.grad4 = grad4;
63755
64226
  exports.integrateSegment = integrateSegment;
63756
64227
  exports.irradianceDataReader = irradianceDataReader;
64228
+ exports.kPI = kPI;
63757
64229
  exports.lerp = lerp;
63758
64230
  exports.lerpByte = lerpByte;
63759
64231
  exports.lerpColor = lerpColor;