今度は2個以上のオブジェクトがあるときに一番最初にヒットするオブジェクトに付いてライトを作成しようというのがポイント。
はい、挿絵


狭いので2回目以降の反射はそれこそせせこましい範囲でごにゃごにゃと。
intersectRayでは裏面ポリゴンは勝手に無視してくれるみたいなので便利ですね。
コードはこれ。だんだん長くなってきました。ほんとファイル添付できればいいのになぁ。
fn refRay lgh objList refNum v_hotspot v_falloff = (
local r = lgh as ray
local obj = #()
if (intersectRay objList[1] r) != undefined then(
obj = #(objList[1],(length ((intersectRay objList[1] r).position - lgh.position)))
)
for i = 1 to objList.count do(
local hitLength = undefined
hitLength = (intersectRay objList[i] r)
if hitLength != undefined then(
hitLength = (length (hitLength.position - lgh.position))
if obj[2] > hitLength then obj = #(objList[i],hitLength)
)
)
if (intersectRay obj[1] r) != undefined then(--レイ値がundefined出なければ反射を計算
local newLgh = freeSpot rgb:lgh.rgb shadowColor:(color 0 0 0)
newLgh.position = (intersectRay obj[1] r).position
newLgh.wirecolor = green
newLgh.dir = -(intersectRay obj[1] r).dir
--<長いので略>
--反射回数refNumがまだ0でなければ反射計算
if refNum > 0 then(refRay newLgh $geometry (refNum-1) v_hotspot v_falloff)
)
)
refRay $Spot01 $geometry 3 90 175
光の強さは当たるたびに半分になってるとか、距離を考慮してないとかで、もちろんまだ仕組みは単純です。
これで面に貼ってあるマップの色を拾いながら反射したり、エネルギーを減少させながら反射していけばよさそうですよ。