Skip to content

Commit 663f090

Browse files
committed
Set shadow bias according to quality and angle
1 parent 42b7aae commit 663f090

File tree

1 file changed

+161
-14
lines changed

1 file changed

+161
-14
lines changed

extensions/reviewed/Light3D.json

Lines changed: 161 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@
223223
" }",
224224
"",
225225
" /**",
226-
" * @param shadowQuality {\"Low\" | \"Medium\" | \"High\"}",
226+
" * @param shadowQuality {\"Low\" | \"Medium\" | \"High\" | \"VeryHigh\"}",
227227
" */",
228228
" setShadowQuality(shadowQuality) {",
229229
" let size = 512;",
@@ -271,9 +271,19 @@
271271
"",
272272
" /**",
273273
" * @param value {number}",
274+
" * @param quality {\"Low\" | \"Medium\" | \"High\"}",
275+
" * @param coneAngle {number}",
274276
" */",
275-
" setShadowBias(value) {",
276-
" this.spotLight.shadow.bias = -value;",
277+
" setShadowBias(value, quality, coneAngle) {",
278+
" const biasMultiplier =",
279+
" quality === 'Low'",
280+
" ? 8",
281+
" : quality === 'Medium'",
282+
" ? 4",
283+
" : quality === 'High'",
284+
" ? 2 : 1;",
285+
" this.spotLight.shadow.bias = -value * biasMultiplier *",
286+
" Math.tan(gdjs.toRad(gdjs.evtTools.common.clamp(coneAngle, 0, 89)));",
277287
" }",
278288
"",
279289
" /**",
@@ -337,8 +347,8 @@
337347
" * @param {PointLightRuntimeObject} object",
338348
"\t */",
339349
" constructor(object) {",
340-
"\t\tconst geometry = new THREE.SphereGeometry( 16, 4, 2 );",
341-
"\t\tconst material = new THREE.MeshBasicMaterial( { wireframe: true, fog: false, toneMapped: false } );",
350+
" const geometry = new THREE.SphereGeometry(16, 4, 2);",
351+
" const material = new THREE.MeshBasicMaterial({ wireframe: true, fog: false, toneMapped: false });",
342352
" super(geometry, material);",
343353
" this.object = object;",
344354
" this.update();",
@@ -348,8 +358,8 @@
348358
" }",
349359
"",
350360
" dispose() {",
351-
"\t\tthis.geometry.dispose();",
352-
"\t\tthis.material.dispose();",
361+
" this.geometry.dispose();",
362+
" this.material.dispose();",
353363
" }",
354364
"",
355365
" update() {",
@@ -481,9 +491,16 @@
481491
"",
482492
" /**",
483493
" * @param value {number}",
494+
" * @param quality {\"Low\" | \"Medium\" | \"High\"}",
484495
" */",
485-
" setShadowBias(value) {",
486-
" this.pointLight.shadow.bias = -value;",
496+
" setShadowBias(value, quality) {",
497+
" const biasMultiplier =",
498+
" quality === 'Low'",
499+
" ? 4",
500+
" : quality === 'Medium'",
501+
" ? 2",
502+
" : 1;",
503+
" this.pointLight.shadow.bias = -value * biasMultiplier;",
487504
" }",
488505
"}",
489506
"",
@@ -1620,6 +1637,18 @@
16201637
"=",
16211638
"Value"
16221639
]
1640+
},
1641+
{
1642+
"type": {
1643+
"value": "Light3D::SpotLight3D::ApplyShadowBias"
1644+
},
1645+
"parameters": [
1646+
"Object",
1647+
"ShadowBias",
1648+
"ShadowQuality",
1649+
"ConeAngle",
1650+
""
1651+
]
16231652
}
16241653
]
16251654
},
@@ -2279,6 +2308,18 @@
22792308
"=",
22802309
"Value"
22812310
]
2311+
},
2312+
{
2313+
"type": {
2314+
"value": "Light3D::SpotLight3D::ApplyShadowBias"
2315+
},
2316+
"parameters": [
2317+
"Object",
2318+
"ShadowBias",
2319+
"ShadowQuality",
2320+
"ConeAngle",
2321+
""
2322+
]
22822323
}
22832324
]
22842325
},
@@ -2676,16 +2717,49 @@
26762717
"=",
26772718
"Value"
26782719
]
2720+
},
2721+
{
2722+
"type": {
2723+
"value": "Light3D::SpotLight3D::ApplyShadowBias"
2724+
},
2725+
"parameters": [
2726+
"Object",
2727+
"Value",
2728+
"ShadowQuality",
2729+
"ConeAngle",
2730+
""
2731+
]
26792732
}
26802733
]
2681-
},
2734+
}
2735+
],
2736+
"parameters": [
2737+
{
2738+
"description": "Object",
2739+
"name": "Object",
2740+
"supplementaryInformation": "Light3D::SpotLight3D",
2741+
"type": "object"
2742+
}
2743+
],
2744+
"objectGroups": []
2745+
},
2746+
{
2747+
"fullName": "Apply shadow bias",
2748+
"functionType": "Action",
2749+
"group": "3D spot light shadow configuration",
2750+
"name": "ApplyShadowBias",
2751+
"private": true,
2752+
"sentence": "Apply shadow bias of _PARAM0_ to _PARAM1_ for a _PARAM2_ quality and cone angle _PARAM3_",
2753+
"events": [
26822754
{
26832755
"type": "BuiltinCommonInstructions::JsCode",
26842756
"inlineCode": [
26852757
"const object = objects[0];\r",
26862758
"const value = eventsFunctionContext.getArgument(\"Value\");\r",
2759+
"const quality = eventsFunctionContext.getArgument(\"Quality\");\r",
2760+
"const coneAngle = eventsFunctionContext.getArgument(\"Angle\");\r",
26872761
"\r",
2688-
"object.__spotLightAdapter.setShadowBias(value);\r",
2762+
"object.__spotLightAdapter.setShadowBias(value, quality, coneAngle);\r",
26892763
""
26902764
],
26912765
"parameterObjects": "Object",
@@ -2699,6 +2773,21 @@
26992773
"name": "Object",
27002774
"supplementaryInformation": "Light3D::SpotLight3D",
27012775
"type": "object"
2776+
},
2777+
{
2778+
"description": "Value",
2779+
"name": "Value",
2780+
"type": "expression"
2781+
},
2782+
{
2783+
"description": "Quality",
2784+
"name": "Quality",
2785+
"type": "string"
2786+
},
2787+
{
2788+
"description": "Cone angle",
2789+
"name": "Angle",
2790+
"type": "expression"
27022791
}
27032792
],
27042793
"objectGroups": []
@@ -2807,6 +2896,9 @@
28072896
},
28082897
{
28092898
"functionName": "SetShadowBias"
2899+
},
2900+
{
2901+
"functionName": "ApplyShadowBias"
28102902
}
28112903
]
28122904
}
@@ -3962,6 +4054,17 @@
39624054
"=",
39634055
"Value"
39644056
]
4057+
},
4058+
{
4059+
"type": {
4060+
"value": "Light3D::PointLight3D::ApplyShadowBias"
4061+
},
4062+
"parameters": [
4063+
"Object",
4064+
"ShadowBias",
4065+
"ShadowQuality",
4066+
""
4067+
]
39654068
}
39664069
]
39674070
},
@@ -4373,16 +4476,47 @@
43734476
"=",
43744477
"Value"
43754478
]
4479+
},
4480+
{
4481+
"type": {
4482+
"value": "Light3D::PointLight3D::ApplyShadowBias"
4483+
},
4484+
"parameters": [
4485+
"Object",
4486+
"Value",
4487+
"ShadowQuality",
4488+
""
4489+
]
43764490
}
43774491
]
4378-
},
4492+
}
4493+
],
4494+
"parameters": [
4495+
{
4496+
"description": "Object",
4497+
"name": "Object",
4498+
"supplementaryInformation": "Light3D::PointLight3D",
4499+
"type": "object"
4500+
}
4501+
],
4502+
"objectGroups": []
4503+
},
4504+
{
4505+
"fullName": "Apply shadow bias",
4506+
"functionType": "Action",
4507+
"group": "3D point light shadow configuration",
4508+
"name": "ApplyShadowBias",
4509+
"private": true,
4510+
"sentence": "Apply shadow bias of _PARAM0_ to _PARAM1_ for a _PARAM2_ quality",
4511+
"events": [
43794512
{
43804513
"type": "BuiltinCommonInstructions::JsCode",
43814514
"inlineCode": [
43824515
"const object = objects[0];\r",
43834516
"const value = eventsFunctionContext.getArgument(\"Value\");\r",
4517+
"const quality = eventsFunctionContext.getArgument(\"Quality\");\r",
43844518
"\r",
4385-
"object.__pointLightAdapter.setShadowBias(value);\r",
4519+
"object.__pointLightAdapter.setShadowBias(value, quality);\r",
43864520
""
43874521
],
43884522
"parameterObjects": "Object",
@@ -4396,6 +4530,16 @@
43964530
"name": "Object",
43974531
"supplementaryInformation": "Light3D::PointLight3D",
43984532
"type": "object"
4533+
},
4534+
{
4535+
"description": "Value",
4536+
"name": "Value",
4537+
"type": "expression"
4538+
},
4539+
{
4540+
"description": "Quality",
4541+
"name": "Quality",
4542+
"type": "string"
43994543
}
44004544
],
44014545
"objectGroups": []
@@ -4478,6 +4622,9 @@
44784622
},
44794623
{
44804624
"functionName": "SetShadowBias"
4625+
},
4626+
{
4627+
"functionName": "ApplyShadowBias"
44814628
}
44824629
]
44834630
}
@@ -4605,4 +4752,4 @@
46054752
}
46064753
}
46074754
]
4608-
}
4755+
}

0 commit comments

Comments
 (0)