Skip to content

Commit 92777e8

Browse files
committed
Set shadow bias according to quality and angle
1 parent dd37550 commit 92777e8

1 file changed

Lines changed: 181 additions & 17 deletions

File tree

examples/3d-car-coin-hunt/3d-car-coin-hunt.json

Lines changed: 181 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5907,6 +5907,22 @@
59075907
"numberProperties": [],
59085908
"stringProperties": [],
59095909
"initialVariables": []
5910+
},
5911+
{
5912+
"angle": 188,
5913+
"customSize": false,
5914+
"height": 40,
5915+
"layer": "",
5916+
"name": "NewSpotLight",
5917+
"persistentUuid": "256fbdbd-a67b-46db-a917-c553e9ac9149",
5918+
"width": 40,
5919+
"x": -1408,
5920+
"y": 512,
5921+
"z": 32,
5922+
"zOrder": 0,
5923+
"numberProperties": [],
5924+
"stringProperties": [],
5925+
"initialVariables": []
59105926
}
59115927
],
59125928
"objects": [
@@ -6910,6 +6926,7 @@
69106926
{
69116927
"assetStoreId": "fad6af3a34db69705540270898681716e47359bbb1b474b27104f823098ef0aa",
69126928
"name": "RoadIntersectionPath",
6929+
"persistentUuid": "60a7bced-5992-4d1a-b615-e6364490b733",
69136930
"type": "Scene3D::Model3DObject",
69146931
"variables": [],
69156932
"effects": [],
@@ -7292,17 +7309,17 @@
72927309
}
72937310
],
72947311
"content": {
7295-
"Color": "255;107;0",
7312+
"Color": "248;231;28",
72967313
"Smoothing": 1,
72977314
"Image": "",
72987315
"ShadowQuality": "Low",
7299-
"ConeAngle": 30,
7316+
"ConeAngle": 45,
73007317
"VisibilityDistanceMax": 2000,
73017318
"IsCastingShadow": true,
73027319
"Intensity": 4,
73037320
"ConeLength": 2000,
73047321
"ShadowCameraFarPlane": 2000,
7305-
"ShadowBias": 0.001
7322+
"ShadowBias": 0.00024
73067323
}
73077324
},
73087325
{
@@ -42127,7 +42144,7 @@
4212742144
" }",
4212842145
"",
4212942146
" /**",
42130-
" * @param shadowQuality {\"Low\" | \"Medium\" | \"High\"}",
42147+
" * @param shadowQuality {\"Low\" | \"Medium\" | \"High\" | \"VeryHigh\"}",
4213142148
" */",
4213242149
" setShadowQuality(shadowQuality) {",
4213342150
" let size = 512;",
@@ -42175,9 +42192,19 @@
4217542192
"",
4217642193
" /**",
4217742194
" * @param value {number}",
42195+
" * @param quality {\"Low\" | \"Medium\" | \"High\"}",
42196+
" * @param coneAngle {number}",
4217842197
" */",
42179-
" setShadowBias(value) {",
42180-
" this.spotLight.shadow.bias = -value;",
42198+
" setShadowBias(value, quality, coneAngle) {",
42199+
" const biasMultiplier =",
42200+
" quality === 'Low'",
42201+
" ? 8",
42202+
" : quality === 'Medium'",
42203+
" ? 4",
42204+
" : quality === 'High'",
42205+
" ? 2 : 1;",
42206+
" this.spotLight.shadow.bias = -value * biasMultiplier *",
42207+
" Math.tan(gdjs.toRad(gdjs.evtTools.common.clamp(coneAngle, 0, 89)));",
4218142208
" }",
4218242209
"",
4218342210
" /**",
@@ -42241,8 +42268,8 @@
4224142268
" * @param {PointLightRuntimeObject} object",
4224242269
"\t */",
4224342270
" constructor(object) {",
42244-
"\t\tconst geometry = new THREE.SphereGeometry( 16, 4, 2 );",
42245-
"\t\tconst material = new THREE.MeshBasicMaterial( { wireframe: true, fog: false, toneMapped: false } );",
42271+
" const geometry = new THREE.SphereGeometry(16, 4, 2);",
42272+
" const material = new THREE.MeshBasicMaterial({ wireframe: true, fog: false, toneMapped: false });",
4224642273
" super(geometry, material);",
4224742274
" this.object = object;",
4224842275
" this.update();",
@@ -42252,8 +42279,8 @@
4225242279
" }",
4225342280
"",
4225442281
" dispose() {",
42255-
"\t\tthis.geometry.dispose();",
42256-
"\t\tthis.material.dispose();",
42282+
" this.geometry.dispose();",
42283+
" this.material.dispose();",
4225742284
" }",
4225842285
"",
4225942286
" update() {",
@@ -42385,9 +42412,16 @@
4238542412
"",
4238642413
" /**",
4238742414
" * @param value {number}",
42415+
" * @param quality {\"Low\" | \"Medium\" | \"High\"}",
4238842416
" */",
42389-
" setShadowBias(value) {",
42390-
" this.pointLight.shadow.bias = -value;",
42417+
" setShadowBias(value, quality) {",
42418+
" const biasMultiplier =",
42419+
" quality === 'Low'",
42420+
" ? 4",
42421+
" : quality === 'Medium'",
42422+
" ? 2",
42423+
" : 1;",
42424+
" this.pointLight.shadow.bias = -value * biasMultiplier;",
4239142425
" }",
4239242426
"}",
4239342427
"",
@@ -43524,6 +43558,18 @@
4352443558
"=",
4352543559
"Value"
4352643560
]
43561+
},
43562+
{
43563+
"type": {
43564+
"value": "Light3D::SpotLight3D::ApplyShadowBias"
43565+
},
43566+
"parameters": [
43567+
"Object",
43568+
"ShadowBias",
43569+
"ShadowQuality",
43570+
"ConeAngle",
43571+
""
43572+
]
4352743573
}
4352843574
]
4352943575
},
@@ -44183,6 +44229,18 @@
4418344229
"=",
4418444230
"Value"
4418544231
]
44232+
},
44233+
{
44234+
"type": {
44235+
"value": "Light3D::SpotLight3D::ApplyShadowBias"
44236+
},
44237+
"parameters": [
44238+
"Object",
44239+
"ShadowBias",
44240+
"ShadowQuality",
44241+
"ConeAngle",
44242+
""
44243+
]
4418644244
}
4418744245
]
4418844246
},
@@ -44580,16 +44638,49 @@
4458044638
"=",
4458144639
"Value"
4458244640
]
44641+
},
44642+
{
44643+
"type": {
44644+
"value": "Light3D::SpotLight3D::ApplyShadowBias"
44645+
},
44646+
"parameters": [
44647+
"Object",
44648+
"Value",
44649+
"ShadowQuality",
44650+
"ConeAngle",
44651+
""
44652+
]
4458344653
}
4458444654
]
44585-
},
44655+
}
44656+
],
44657+
"parameters": [
44658+
{
44659+
"description": "Object",
44660+
"name": "Object",
44661+
"supplementaryInformation": "Light3D::SpotLight3D",
44662+
"type": "object"
44663+
}
44664+
],
44665+
"objectGroups": []
44666+
},
44667+
{
44668+
"fullName": "Apply shadow bias",
44669+
"functionType": "Action",
44670+
"group": "3D spot light shadow configuration",
44671+
"name": "ApplyShadowBias",
44672+
"private": true,
44673+
"sentence": "Apply shadow bias of _PARAM0_ to _PARAM1_ for a _PARAM2_ quality and cone angle _PARAM3_",
44674+
"events": [
4458644675
{
4458744676
"type": "BuiltinCommonInstructions::JsCode",
4458844677
"inlineCode": [
4458944678
"const object = objects[0];\r",
4459044679
"const value = eventsFunctionContext.getArgument(\"Value\");\r",
44680+
"const quality = eventsFunctionContext.getArgument(\"Quality\");\r",
44681+
"const coneAngle = eventsFunctionContext.getArgument(\"Angle\");\r",
4459144682
"\r",
44592-
"object.__spotLightAdapter.setShadowBias(value);\r",
44683+
"object.__spotLightAdapter.setShadowBias(value, quality, coneAngle);\r",
4459344684
""
4459444685
],
4459544686
"parameterObjects": "Object",
@@ -44603,6 +44694,21 @@
4460344694
"name": "Object",
4460444695
"supplementaryInformation": "Light3D::SpotLight3D",
4460544696
"type": "object"
44697+
},
44698+
{
44699+
"description": "Value",
44700+
"name": "Value",
44701+
"type": "expression"
44702+
},
44703+
{
44704+
"description": "Quality",
44705+
"name": "Quality",
44706+
"type": "string"
44707+
},
44708+
{
44709+
"description": "Cone angle",
44710+
"name": "Angle",
44711+
"type": "expression"
4460644712
}
4460744713
],
4460844714
"objectGroups": []
@@ -44711,6 +44817,9 @@
4471144817
},
4471244818
{
4471344819
"functionName": "SetShadowBias"
44820+
},
44821+
{
44822+
"functionName": "ApplyShadowBias"
4471444823
}
4471544824
]
4471644825
}
@@ -45867,6 +45976,17 @@
4586745976
"=",
4586845977
"Value"
4586945978
]
45979+
},
45980+
{
45981+
"type": {
45982+
"value": "Light3D::PointLight3D::ApplyShadowBias"
45983+
},
45984+
"parameters": [
45985+
"Object",
45986+
"ShadowBias",
45987+
"ShadowQuality",
45988+
""
45989+
]
4587045990
}
4587145991
]
4587245992
},
@@ -46278,16 +46398,47 @@
4627846398
"=",
4627946399
"Value"
4628046400
]
46401+
},
46402+
{
46403+
"type": {
46404+
"value": "Light3D::PointLight3D::ApplyShadowBias"
46405+
},
46406+
"parameters": [
46407+
"Object",
46408+
"Value",
46409+
"ShadowQuality",
46410+
""
46411+
]
4628146412
}
4628246413
]
46283-
},
46414+
}
46415+
],
46416+
"parameters": [
46417+
{
46418+
"description": "Object",
46419+
"name": "Object",
46420+
"supplementaryInformation": "Light3D::PointLight3D",
46421+
"type": "object"
46422+
}
46423+
],
46424+
"objectGroups": []
46425+
},
46426+
{
46427+
"fullName": "Apply shadow bias",
46428+
"functionType": "Action",
46429+
"group": "3D point light shadow configuration",
46430+
"name": "ApplyShadowBias",
46431+
"private": true,
46432+
"sentence": "Apply shadow bias of _PARAM0_ to _PARAM1_ for a _PARAM2_ quality",
46433+
"events": [
4628446434
{
4628546435
"type": "BuiltinCommonInstructions::JsCode",
4628646436
"inlineCode": [
4628746437
"const object = objects[0];\r",
4628846438
"const value = eventsFunctionContext.getArgument(\"Value\");\r",
46439+
"const quality = eventsFunctionContext.getArgument(\"Quality\");\r",
4628946440
"\r",
46290-
"object.__pointLightAdapter.setShadowBias(value);\r",
46441+
"object.__pointLightAdapter.setShadowBias(value, quality);\r",
4629146442
""
4629246443
],
4629346444
"parameterObjects": "Object",
@@ -46301,6 +46452,16 @@
4630146452
"name": "Object",
4630246453
"supplementaryInformation": "Light3D::PointLight3D",
4630346454
"type": "object"
46455+
},
46456+
{
46457+
"description": "Value",
46458+
"name": "Value",
46459+
"type": "expression"
46460+
},
46461+
{
46462+
"description": "Quality",
46463+
"name": "Quality",
46464+
"type": "string"
4630446465
}
4630546466
],
4630646467
"objectGroups": []
@@ -46383,6 +46544,9 @@
4638346544
},
4638446545
{
4638546546
"functionName": "SetShadowBias"
46547+
},
46548+
{
46549+
"functionName": "ApplyShadowBias"
4638646550
}
4638746551
]
4638846552
}
@@ -59308,4 +59472,4 @@
5930859472
}
5930959473
}
5931059474
]
59311-
}
59475+
}

0 commit comments

Comments
 (0)