0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

コースティクス(Caustics)を発生させるには、「光の粒(フォトン)」を光源から発射し、ガラスや水で曲げ、地面で受け止めるという一連の物理リレーを繋ぐ必要があります。

mia_mat_x2.jpg

以下の5つのステップを漏れなく設定することで、美しい集光模様がレンダリングされます。

1. グローバルオプションの有効化

まずは、シーン全体でコースティクスの計算を行うためのメインスイッチを入れ、ノイズ(まだら)を消すためのぼかし設定を行います。

options ブロック内の設定:

  • caustic on
    • コースティクス計算のメインスイッチをオンにします
  • caustic accuracy <収集数> <検索半径> (例: 500 3.0)
    • 【ノイズ対策の要】落ちたフォトンをどう滑らかに混ぜ合わせるかの設定です
    • 収集数 (500): 一箇所を塗るために集める光の粒の数。多いほど滑らか
    • 検索半径 (3.0): 粒を探す範囲。巨大な地面がある場合、自動(0.0)だと失敗して「白いまだら」になりやすいので、明示的に数値を指定します

2. 光源(ライト)からフォトンを発射

太陽や照明から、目に見える光とは別に「コースティクス用の光の粒(フォトン)」を発射させます。

light ブロック内の設定:

  • energy (例: 10. 10. 10.)
    • フォトンの持つエネルギー(明るさ)。強すぎると白飛びします(物理太陽の場合は特に下げて調整が必要)
  • caustic photons <発射数> (例: 1000000)
    • 発射する光の粒の数。100万個など多めにすると高品質になります
  • ⚠️注意: 太陽光などの「平行光源(Directional Light)」の場合、減衰率である exponent を設定するとエラーになるので書かない(またはコメントアウトする)こと

3. 屈折マテリアル(水やガラス)のフォトン通過設定

物体が光をどう曲げるかを設定します。見た目(表面)だけでなく、フォトン(光の粒)用の計算ルートも繋ぐ必要があります

material ブロック内の設定:

  • do_refractive_caustics on (mia_material_x 内)
    • シェーダー側で屈折コースティクスを許可します
  • photon = "<シェーダー名>"
    • 【超重要】マテリアルの定義部分で、=(サーフェス/見た目)だけでなく、photon = にも同じシェーダー(または専用のフォトンシェーダー)を割り当てます。これがないとフォトンが物体表面で消滅します

4. オブジェクトの役割分担(フラグ設定)

空間にある物体に対して、「光を曲げる役(生成)」か「光を受け止める役(受光)」かを指示します。

object ブロック内の設定:

  • 屈折する物体(球体など): caustic 1
    • フォトンを受け取り、コースティクスを生成(Generate)するフラグです
  • 光が落ちる物体(地面など): caustic 2
    • コースティクスを受光(Receive)して模様を表示するフラグです
    • ※両方行う物体には caustic 3(1+2)を設定することもあります

5. レイトレース上限(Trace Depth)の解放

光が透明な物体を完全に「通り抜ける」ためには、十分な計算回数の許可が必要です。
options ブロック内の設定:

  • trace depth <反射> <屈折> <合計> (例: 5 5 10)
    • 光の計算回数の上限。デフォルト(1 1 2など)だと光が水球を抜けきる前に計算が打ち切られます。その結果、本来見えるはずの背景(地平線など)が適切な位置に屈折して現れず、不自然に歪んだ「黒い帯」として出力されてしまいます
    • 屈折(2番目の数値)と合計(3番目の数値)を最低でもガラス面を貫通できる回数(4〜5以上)に設定します。

💡 失敗したときのチェックポイント

  • レンダリングがエラーで止まる → ライトに exponent が入っていませんか?
  • 地面に模様が全く出ない → マテリアルに photon = を割り当てていますか?
  • 模様が「白いまだら」になる → caustic accuracy の半径を指定し、caustic photons を増やしてみてください。
  • 透明な物体の中に黒い線が出る(地平線が正しく映り込まない) → trace depth の計算回数が足りず、背景の屈折が途中で破綻しています。回数を増やしてください。
daylight_water_x.mi
verbose off
min version "3.7"
# 🔌 [プラグイン接続] mental rayに「リアルな地球の空気や太陽の光」を計算する特別な回路(シェーダー)を読み込みます
link "base.dll"
$include <base.mi>
link "contour.dll"
$include <contour.mi>
link "physics.dll"
$include <physics.mi>
link "paint.dll"
$include <paint.mi>
link "architectural.dll"
$include <architectural.mi>
link "production.dll"
$include <production.mi>
link "mayabase.dll"
$include <mayabase.mi>
link "AdskShaderSDK.dll"
$include "AdskShaderSDK.mi"

# =========================================================================
# ⚙️ レンダーオプション設定
# =========================================================================
options "opt"
	object space
	desaturate off
	colorclip rgb
	premultiply on
	dither on
	gamma 1.
	acceleration bsp
	bsp size 10
	bsp depth 40
	task size 0
	contrast 0.05 0.05 0.05 0.05
	samples 0 2
	filter box 1. 1.
	jitter 0.
	samplelock on
	scanline off
	trace on
	trace depth 2 2 3
	shadow on
	shadowmap on
	shadowmap rebuild on
	"shadowmap pixel samples" 3
	caustic on
	caustic accuracy 500 3.0 
	caustic filter cone
	photonmap file "caustic_map.pm"
	globillum on
	globillum 0
	globillum accuracy 500 0.
	globillum scale 1. 1. 1. 1.
	photonvol accuracy 30 0.
	photonvol scale 1. 1. 1. 1.
	photon autovolume off
	photon trace depth 5 5 5
	photonmap rebuild on
	finalgather on
	finalgather accuracy 100
	finalgather scale 1. 1. 1. 1.
	finalgather secondary scale 1. 1. 1. 1.
	finalgather rebuild on
	finalgather filter 0
	finalgather falloff 0. 0.
	finalgather trace depth 1 1 0 2
	finalgather presample density 1.
	"finalgather mode" "automatic"
	"finalgather points" 10
	lens on
	volume on
	geometry on
	displace on
	displace presample on
	output on
	merge on
	autovolume off
	hair on
	pass on
	face both
	"ambient occlusion" off
	"ambient occlusion cache" off
	"ambient occlusion cache density" 1.
	"ambient occlusion cache points" 64
	"ambient occlusion rays" 256
	"contrast all buffers" on
	"geom displace motion factor" 1.
	"importon" off
	"importon density" 1.
	"importon merge" 0.
	"importon trace depth" 0
	"importon traverse" on
	"irradiance particles" off
	"irradiance particles env" on
	"irradiance particles env rays" 256
	"irradiance particles env scale" 1
	"irradiance particles indirect passes" 0
	"irradiance particles interpolate" 1
	"irradiance particles interppoints" 64
	"irradiance particles rays" 256
	"irradiance particles rebuild" on
	"irradiance particles scale" 1.
	"rast motion factor" 1.
	"rast transparency depth" 8
	"raster use opacity" on
	"shadowmap pixel samples" 3
	"maya custom alpha" on
	"maya custom depth" off
	"maya custom label" off
	"maya filter size compute" on
	"maya filter size default" 0.0001
	"maya reflection blur limit" 1
	"maya refraction blur limit" 1
	"maya render pass" 0
	"maya shader glow" on
	"maya shader glow buffer" "mayaGlow"
	"maya shadow limit" 2
end options

# =========================================================================
# ☀️ 物理的な太陽光(mia_physicalsun)の定義
# =========================================================================
light "sunShape"
	"mia_physicalsun" ( 
		"on" on, 
		"multiplier" 1.0,   # 太陽光の強さ(エネルギー)です
		"y_is_up" on,       # Y軸を「上空」として扱います
		"rgb_unit_conversion" 0.0001 0.0001 0.0001 
	)
	# 📍 太陽光の向き(光の矢の目的地):
	# [-1, -1, -1] なので、「左(西)へ、下へ、手前(南)へ」向かって斜め45度で突き刺さる、朝方の光です!
	direction -1. -1. -1.
	energy 10. 10. 10.   # 物理サンは超高輝度なので大きめから
	caustic photons 1000000           # 蓄積数
end light

# 💡 太陽をシーンに配置するためのスタンド(インスタンス)です。今回は回転なしのクリーンな状態にしています。
instance "sunDirection" "sunShape"
	transform
		1. 0. 0. 0.
		0. 1. 0. 0.
		0. 0. 1. 0.
		0. 0. 0. 1.
end instance

# =========================================================================
# 🕶️ トーンマッピング(mia_exposure_simple)の定義
# =========================================================================
# 物理的な空や太陽は、普通のライトに比べて「何万倍も眩しい」超高エネルギーを持っています。
# そのままだと画面が真っ白に白飛びしてしまうため、このシェーダーが「人間の目やカメラのレンズ」の代わりになって、
# 眩しさをちょうどいい明るさに自動で引き締める(露出調整をする)フィルターの役割を果たします。
shader "mia_exposure_simple1"
	"mia_exposure_simple" (
		"gain" 0.1,         # 画面全体の明るさの調整弁です
		"gamma" 2.2         # 画面の暗い部分を人間の目に合わせて自然に持ち上げる、おなじみのガンマ値です
		)

# =========================================================================
# 🌤️ 物理的な空(mia_physicalsky)の定義
# =========================================================================
# 太陽の位置を自動的に感知して、地平線から天頂までの「本物の空のグラデーション」を自動生成する贅沢なシェーダーです。
shader "mia_physicalsky1"
	"mia_physicalsky" (
		"on" on,
		"multiplier" 0.5,
		"rgb_unit_conversion" 0.0001 0.0001 0.0001 1.,
		"redblueshift" -0.3, # 空の「青み」の調整です。数値をいじると夕焼け空っぽくすることもできます
		"ground_color" 0.2 0.2 0.2 1., # 地平線より下の「大地の基本色」です
		"sun" "sunDirection",# 【超重要】上で作った太陽のインスタンス「sunDirection」とここでリンク(合体)させます!
		"sun_disk_scale" 4., # 画面に映り込む「太陽の丸いお皿(光源)」の大きさです
		"y_is_up" on
		)


# =========================================================================
# 🎥 カメラ設定(映画の「ショット」を決める監督の視点!)
# =========================================================================
camera "cam"
    output "rgba" "mia_materialx1.tif"
    focal 50.0
    aperture 36.0
    aspect 1.33333
    resolution 800 600
  
    # 🔗 カメラのレンズの前に、さっき作った「露出フィルター」と「リアルな空の背景」をカチッと装着します!
    lens = "mia_exposure_simple1"
    environment = "mia_physicalsky1"
end camera

# カメラを配置するトランスフォーム行列です
instance "cam_inst" "cam"
    transform       -1.0000 0.0000 0.0000 0.0
                    0.0000 0.9806 0.1961 0.0
                    0.0000 0.1961 -0.9806 0.0
                    -0.0000 -4.9029 -29.4757 1.0
end instance

# =========================================================================
# 🎨 マテリアル(質感)と 📐 ジオメトリ(型紙)の定義
# =========================================================================
# ※(ここは前回の「たい焼きの型」のフェーズと同じです。地面用の白いマットと、球体・立方体の型を準備しています)
light "env_light"
    "mib_light_infinite" ( "color" 0.8 0.8 0.8, "shadow" on )
end light

instance "env_light_inst" "env_light"
    transform       -0.7071 0.5774 -0.4082 0.0
                    0.0000 0.5774 0.8165 0.0
                    0.7071 0.5774 -0.4082 0.0
                    0.0000 0.0000 -122.4745 1.0
end instance

material "white_matte"
    "mib_illum_phong" ( "ambient" 0.1 0.1 0.1, "diffuse" 0.7 0.7 0.7,
                        "specular" 0.1 0.1 0.1, "exponent" 10.0,
                        "lights" ["env_light_inst"] )
    photon "mib_photon_basic" ( "diffuse" 0.7 0.7 0.7 )   # ★ 受光用
end material

shader "mia_water_shader"
	"mia_material_x" (
		# =========================================================
		# 🎨 1. 表面の基本色(ディフューズ)
		# =========================================================
		# 透明な水やガラスを作る場合、表面そのものの色は不要なので「0」にして無効化します。
		"diffuse_weight" 0.0,      # 基本色の影響力(0.0で完全に無視されます)
		"diffuse" 0.0 0.0 0.0 1.,  # 基本の色(影響力0なので黒のままでOKです)
		"diffuse_roughness" 0.0,   # 表面のザラつき(光の拡散具合)

		# =========================================================
		# ✨ 2. 反射(リフレクション / 景色が映り込む力)
		# =========================================================
		"reflectivity" 1.0,        # 反射の強さ(1.0で最大。周囲の空や地面を強く映し込みます)
		"refl_color" 1.0 1.0 1.0 1.0, # 反射する光の色(通常は白)
		"refl_gloss" 1.0,          # 反射の鮮明さ(1.0で鏡のようにクッキリ。数値を下げると曇りガラスのようにボケます)
		"refl_gloss_samples" 8,    # ボケた反射の滑らかさ(数値を上げるとノイズが減りますが計算が遅くなります)
		"refl_interpolate" off,
		"refl_hl_only" off,
		"refl_is_metal" off,       # 金属の特性を持たせるか(水なのでoff)

		# =========================================================
		# 💧 3. 屈折(リフラクション / 透明度と光の曲がり方)
		# =========================================================
		"transparency" 1.0,        # 透明度(1.0で完全に透明な物体になります)
		"refr_color" 1.0 1.0 1.0 1.0, # 屈折して透ける色(基本は白)
		"refr_gloss" 1.0,          # 屈折の鮮明さ(下げると中身がボヤけるスリガラスになります)
		"refr_ior" 1.333,          # ★超重要: 屈折率(IOR)。光が曲がる角度です。水は「1.333」、ガラスは「1.5」付近です。
		"refr_gloss_samples" 8,    # ボケた屈折の滑らかさ
		"refr_interpolate" off,

		# --- 半透明(トランスルーセンシー) ---
		"refr_translucency" off,   # 葉っぱやロウソクのように、光を内部で散乱させるか(今回はoff)
		"refr_trans_color" 0.7 0.6 0.5 1.,
		"refr_trans_weight" 0.5,

		# =========================================================
		# 📐 4. フレネル効果(見る角度による反射の変化)
		# =========================================================
		# 現実のガラスや水面は、正面から見ると透けて見え、斜め(フチ)から見ると鏡のように反射します。これを再現します。
		"brdf_fresnel" on,         # ★重要: フレネル反射をオンにします。
		"brdf_0_degree_refl" 0.2,  # 正面から見た時の反射率(少しだけ反射させます)
		"brdf_90_degree_refl" 1.,  # 横(フチ)から見た時の反射率(1.0で鏡のように強く反射します)
		"brdf_curve" 5.,           # 反射率が切り替わるカーブの急激さ
		"brdf_conserve_energy" on, # エネルギー保存の法則(光が不自然に増殖しないようにする。onのままでOK)

		# =========================================================
		# 🌊 5. 水深による色の変化(フォールオフ)
		# =========================================================
		# コップの水は透明ですが、海やプールが青く見えるのは「光が水の中を長く進む間に特定の色が吸収される」からです。
		"refr_falloff_on" on,      # ★重要: 距離による色の変化(減衰)をオンにします
		"refr_falloff_dist" 10.,   # ★調整ポイント: この距離(深さ)まで光が進むと、下の色に染まります
		"refr_falloff_color_on" on,
		"refr_falloff_color" 0.2 0.7 0.8 1.0, # 水の深い部分の色(シアンやエメラルドグリーンにすると美しいです)

		# =========================================================
		# ⚙️ 6. レイトレース(光の追跡)の設定とコースティクス
		# =========================================================
		"refl_depth" 5,            # 反射の計算を何回まで追跡するか
		"refl_cutoff" 0.01,        # 影響がこれ以下になったら計算を打ち切る閾値
		"refr_depth" 5,            # 屈折の計算を何回まで追跡するか(※全体オプションの「trace depth」が優先されます)
		"refr_cutoff" 0.01,
		"skip_inside_refl" on,       # 物体の内側での無駄な反射計算を省いてレンダリングを高速化するか
		"do_refractive_caustics" on, # ★超重要: 屈折による光の集光模様(コースティクス)を発生させるスイッチです!

		# =========================================================
		# 影、バンプ(凹凸)、その他の詳細設定(今回はデフォルト)
		# =========================================================
		"anisotropy" 1.,           # 異方性反射(CDの裏面のような、方向性のある反射)
		"anisotropy_rotation" 0.,
		"anisotropy_channel" -1,
		"intr_grid_density" 2,
		"intr_refl_samples" 2,
		"intr_refl_ddist_on" off,
		"intr_refl_ddist" 0.,
		"intr_refr_samples" 2,
		"single_env_sample" off,
		"refl_falloff_on" off,
		"refl_falloff_dist" 0.,
		"refl_falloff_color_on" off,
		"refl_falloff_color" 0. 0. 0. 1.,
		"indirect_multiplier" 1.,
		"fg_quality" 1.,
		"fg_quality_w" 1.,
		"ao_on" off,               # アンビエントオクルージョン(物体の隅に落ちる影の強調)
		"ao_samples" 16,
		"ao_distance" 10.,
		"ao_dark" 0.2 0.2 0.2 1.,
		"ao_ambient" 0. 0. 0. 1.,
		"ao_do_details" 1,
		"thin_walled" off,         # シャボン玉のような「厚みのない物体」にするか
		"no_visible_area_hl" on,
		"backface_cull" off,
		"propagate_alpha" off,
		"hl_vs_refl_balance" 1.,
		"cutout_opacity" 1.,       # アルファ抜き(型抜き)の透明度
		"additional_color" 0. 0. 0. 1.,
		"no_diffuse_bump" off,
		"mode" 4,
		"lights" ["env_light_inst"], # このマテリアルに影響を与えるライトのリスト
		"bump_mode" 5,
		"overall_bump" 0. 0. 0.,   # バンプマッピング(表面の凹凸。ここに波のテクスチャを繋ぐと水面が波立ちます!)
		"standard_bump" 0. 0. 0.,
		"multiple_outputs" on
		)

material "mia_water_x1"
    = "mia_water_shader"           # 見た目(Surface)の計算に割り当て
    photon = "mia_water_shader"    # 光の粒(Photon)の計算にも割り当て! ★これがコースティクスを生む!
end material

object "sphere_geo" visible shadow trace caustic 1 tag 1   # 球は生成
    basis "bs" bspline 3
    group
             0.0000  5.0000  0.0000          0.7957  5.0000  1.3781
            -0.7956  5.0000  1.3781         -1.5913  5.0000  0.0000
            -0.7957  5.0000 -1.3781          0.7956  5.0000 -1.3781
             1.5913  5.0000  0.0000          2.3448  3.9181  4.0613
            -2.3448  3.9181  4.0613         -4.6896  3.9181  0.0000
            -2.3448  3.9181 -4.0613          2.3448  3.9181 -4.0613
             4.6896  3.9181  0.0000          3.3276  0.0000  5.7636
            -3.3276  0.0000  5.7636         -6.6552  0.0000  0.0000
            -3.3276  0.0000 -5.7636          3.3276  0.0000 -5.7636
             6.6552  0.0000  0.0000          2.3448 -3.9181  4.0613
            -2.3448 -3.9181  4.0613         -4.6896 -3.9181  0.0000
            -2.3448 -3.9181 -4.0613          2.3448 -3.9181 -4.0613
             4.6896 -3.9181  0.0000          0.7957 -5.0000  1.3781
            -0.7956 -5.0000  1.3781         -1.5913 -5.0000  0.0000
            -0.7957 -5.0000 -1.3781          0.7956 -5.0000 -1.3781
             1.5913 -5.0000  0.0000          0.0000 -5.0000  0.0000

            v 0     v 1     v 2     v 3     v 4     v 5     v 6     v 7
            v 8     v 9     v 10    v 11    v 12    v 13    v 14    v 15
            v 16    v 17    v 18    v 19    v 20    v 21    v 22    v 23
            v 24    v 25    v 26    v 27    v 28    v 29    v 30    v 31

            surface "surf" ""
                    "bs" 0 6   -3. -2. -1. 0. 1. 2. 3. 4. 5. 6. 7. 8. 9.
                    "bs" 0 4    0.  0.  0. 0. 1. 2. 3. 4. 4. 4. 4.

                    31 31 31 31 31 31 31 31 31 26 25 30 29 28 27 26
                    25 30 20 19 24 23 22 21 20 19 24 14 13 18 17 16
                    15 14 13 18  8  7 12 11 10  9  8  7 12  2  1  6
                     5  4  3  2  1  6  0  0  0  0  0  0  0  0  0

            approximate surface parametric 3 3 "surf"
    end group
end object

object "ground_geo" visible trace shadow caustic 2 tag 1   # 地面は受光
    group
        -50.0  0  -50.0
        -50.0  0   50.0
         50.0  0  -50.0
         50.0  0   50.0
        v 0  v 1  v 2  v 3
        p "white_matte" 0 1 3 2
    end group
end object

# =========================================================================
# 🎬 配置(型紙を空間に呼び出して、本物のたい焼きとして並べる!)
# =========================================================================

# 世界の中心に白い地面を敷きます
instance "ground_inst" "ground_geo"
    material "white_matte"
    transform       1 0 0 0   0 1 0 0   0 0 1 0   0 0 0 1
end instance

# 🔴 球体の型紙(sphere_geo)から「sphere_inst」を取り出して、高さ-5(地面のすぐ上)へ配置します
instance "sphere_inst" "sphere_geo"
    material "mia_water_x1"
    transform       1.0000 0.0000 0.0000 0.0000
                    0.0000 1.0000 0.0000 0.0000
                    0.0000 0.0000 1.0000 0.0000
                    0.0000 -5.0000 0.0000 1.0000
end instance

# =========================================================================
# ⚙️ 撮影ステージ(instgroup)の組み立てと、本番レンダリング
# =========================================================================
# 💡 ココがポイント!:ステージのメンバー(scene)の中に、普通のオブジェクトだけでなく、
# 太陽の光のスタンドである「 "sunDirection" 」もしっかりと並び立たせています!
instgroup "scene"
    "cam_inst"
    "env_light_inst"
    "ground_inst"
    "sphere_inst"
    "sunDirection"
end instgroup

# よーい、スタート! 組み立てたステージ(scene)を、特製レンズをつけたカメラ(cam_inst)で最高画質でパシャリと撮影します!
render "scene" "cam_inst" "opt"

追記

vMaterialsのJelly_clear.mdlを使用した例。球体にtextureがないとエラーがでる。

MDL  0.11   101 MB error  781038: mi_lookup_vector_texture: bad texture 4000000d
MDL  0.11   101 MB error  781038: mi_lookup_vector_texture: bad texture 4000000d
$include "::nvidia::vMaterials::Design::Food::Jelly_clear.mdl"
material "mdl::nvidia::vMaterials::Design::Food::Jelly_clear::jelly_clear_proto_mtl"

gems_test.tif

ありがとうございます。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?