Lock in $30 Savings on PRO—Offer Ends Soon! ⏳

Unity×レイマーチングによる映像制作の実践手法 / KLab Tech Meetup 4

がむ
June 19, 2019

Unity×レイマーチングによる映像制作の実践手法 / KLab Tech Meetup 4

がむ

June 19, 2019
Tweet

More Decks by がむ

Other Decks in Programming

Transcript

  1. ϨΠϚʔνϯάͱσϞγʔϯ • ڑ཭ؔ਺ʢdistance functionʣͱ͍͏਺ࣜͰܗঢ়Λఆٛ ‣ 3DϞσϧΛ༻ҙ͢Δඞཁ͕ͳ͍ ‣ ݫ͍͠༰ྔͷ੍໿ͷ͋ΔσϞγʔϯͷ෦໳ʢ4k intro౳ʣͱ૬ੑ͕ྑ͍ •

    TDFʢTokyo Demo Festʣͷ্Ґ࡞඼΋ϨΠϚʔνϯάΛར༻ 4 WORMHOLE by gam0022 & sadakkey 1st place@Combined Demo Compo, TDF2018 2nd stage BOSS by 0x4015&YET11 1st place@Combined Demo Compo, TDF2016 Shift by FMS_Cat 1st place@Combined Demo Compo, TDF2017
  2. ڑ཭ؔ਺ͷ͓͞Β͍ ڑ཭ؔ਺ = ఺p͔Β෺ମද໘΁ͷ࠷୹ڑ཭Λฦؔ͢਺ 5 float sdSphere( vec3 p, float

    s ) { return length(p)-s; } float udBox( vec3 p, vec3 b ) { return length(max(abs(p)-b,0.0)); } http://iquilezles.org/www/articles/distfunctions/distfunctions.htm
  3. IFSʢIterated function systemʣͱ͸ • ࣗ਎ͷॖখίϐʔΛॏͶ߹ΘͤΔ͜ͱ ͰϑϥΫλϧਤܗΛͭ͘ΔςΫχοΫ • forϧʔϓ ͷதͰૢ࡞Λ܁Γฦ͢ ‣

    fold ‣ ֦େॖখ ‣ ฏߦҠಈ 12 // IFSʹΑΔMengerSpongeͷڑ཭ؔ਺ float dMenger(float3 z0, float3 offset, float scale) { float4 z = float4(z0, 1.0); for (int n = 0; n < 4; n++) { z = abs(z); if (z.x < z.y) z.xy = z.yx; if (z.x < z.z) z.xz = z.zx; if (z.y < z.z) z.yz = z.zy; z *= scale; z.xyz -= offset * (scale - 1.0); if (z.z < -0.5 * offset.z * (scale - 1.0)) z.z += offset.z * (scale - 1.0); } return (length(max(abs(z.xyz) - float3(1.0, 1.0, 1.0), 0.0)) - 0.05) / z.w; } sdBox ➞ fold ➞ ֦େॖখ ฏߦҠಈ ➞
  4. IFSʢIterated function systemʣͷΞϨϯδ • OffsetʢฏߦҠಈʣͱ Scaleʢ֦େॖখʣ
 ͷύϥϝʔλʹΑͬͯܗঢ়΋มԽ͢Δ 13 // IFSʹΑΔMengerSpongeͷڑ཭ؔ਺

    float dMenger(float3 z0, float3 offset, float scale) { float4 z = float4(z0, 1.0); for (int n = 0; n < 4; n++) { z = abs(z); if (z.x < z.y) z.xy = z.yx; if (z.x < z.z) z.xz = z.zx; if (z.y < z.z) z.yz = z.zy; z *= scale; z.xyz -= offset * (scale - 1.0); if (z.z < -0.5 * offset.z * (scale - 1.0)) z.z += offset.z * (scale - 1.0); } return (length(max(abs(z.xyz) - float3(1.0, 1.0, 1.0), 0.0)) - 0.05) / z.w; } Offset = (1, 1, 1) Scale = 3 Offset = (0.79, 1.1, 0.47) Scale = 2.31
  5. foldRotateͷ࣮૷ • 2Dͷճసߦྻ 16 // 2Dͷճసߦྻͷੜ੒ float2x2 rotate(in float a)

    { float s = sin(a), c = cos(a); return float2x2(c, s, -s, c); } // ճస fold // https://www.shadertoy.com/view/Mlf3Wj float2 foldRotate(in float2 p, in float s) { float a = PI / s - atan2(p.x, p.y); float n = PI2 / s; a = floor(a / n) * n; p = mul(rotate(a), p); return p; } • foldRotate ‣ ۃ࠲ඪͷ֯౓ΛٻΊΔ ‣ ଐ͍ͯ͠ΔྖҬʹԠͯ͡ճస
  6. τϯωϧͷڑ཭ؔ਺ͷ׬੒ʂ 18 // IFSʹΑΔMengerSpongeͷڑ཭ؔ਺ float dMenger(float3 z0, float3 offset, float

    scale) { float4 z = float4(z0, 1.0); for (int n = 0; n < 4; n++) { z = abs(z); if (z.x < z.y) z.xy = z.yx; if (z.x < z.z) z.xz = z.zx; if (z.y < z.z) z.yz = z.zy; z *= scale; z.xyz -= offset * (scale - 1.0); if (z.z < -0.5 * offset.z * (scale - 1.0)) z.z += offset.z * (scale - 1.0); } return (length(max(abs(z.xyz) - float3(1.0, 1.0, 1.0), 0.0)) - 0.05) / z.w; } // 2Dͷճసߦྻͷੜ੒ float2x2 rotate(in float a) { float s = sin(a), c = cos(a); return float2x2(c, s, -s, c); } // ճస fold // https://www.shadertoy.com/view/Mlf3Wj float2 foldRotate(in float2 p, in float s) { float a = PI / s - atan2(p.x, p.y); float n = PI2 / s; a = floor(a / n) * n; p = mul(rotate(a), p); return p; } inline float DistanceFunction(float3 pos) { // ճసfoldͷద༻ pos.yx = foldRotate(pos.yx, _MengerFold); return dMenger(pos, _MengerOffset, _MengerScale); } Θ͔ͣߦͷίʔυͰෳࡶͳܗঢ়ΛఆٛͰ͖ͨʂ .FOHFS4QPOHF GPME3PUBUF
  7. σΟϑΝʔυϨϯμϦϯάΛ࠾༻ σΟϑΝʔυϨϯμϦϯά͸2ͭͷύεͰγʔϯΛඳը 21 G-Bufferύε ϥΠςΟϯάʹඞཁͳ৘ใʢGόοϑΝʣΛੜ੒ RT0: Diffuse color (RGB), occlusion

    (A). RT1: Specular color (RGB), roughness (A). ɹRT3: Emission + lighting + lightmaps + reflection probes buffer. RT2: World space normal (RGB), unused (A). Depth + Stencil Lightingύε GόοϑΝΛݩʹ
 ϥΠςΟϯάΛܭࢉ
  8. σΟϑΝʔυϨϯμϦϯάΛ࠾༻ͨ͠3ͭͷཧ༝ ᶃ ڑ཭ؔ਺ͱϙϦΰϯ͕ࠞࡏͨ͠γʔϯͷҰ؏ͨ͠ϥΠςΟϯάॲཧ͕Մೳ ‣ ϨΠϚʔνϯάͷ݁ՌΛG-Bufferʹॻ͖ࠐΉ
 G-BufferύεͷγΣʔμʔΛ࣮૷͢Ε͹OK ‣ @hecomi ͞Μͷ uRaymarching

    Λར༻͢Δͱָ ᶄ 6OJUZඪ४ͷ-JHIUJOHύεΛར༻Ͱ͖Δ ‣ ࣗ෼ͰϥΠςΟϯάॲཧΛ࣮૷͠ͳͯ͘΋
 Unityͷશछྨͷޫݯ΍ReflectionProbeʹରԠͰ͖Δ ᶅ େྔͷޫݯͳͲϦονͳϥΠςΟϯάʹڧ͍ 22 @hecomi
  9. TextMeshProͷγΣʔμʔͷΧελϚΠζํ๏ 1. TextMeshProͷγΣʔμʔΛίϐʔ ‣ TMP_SDF-Mobile.shader 
 ͕࣮૷͕γϯϓϧͳͷͰΦεεϝ 2. γΣʔμʔΛվ଄ ‣

    ৭Λܾఆ͢Δ෦෼ ‣ SDFͷϑΣον෦෼ 3. TextMeshProͷΠϯεϖΫλ͔Β
 վ଄ͨ͠γΣʔμʔΛઃఆ 31
  10. TextMeshProͷγΣʔμʔͷΧελϚΠζྫ จࣈΛύϥύϥͱग़ݱɾফࣦͤ͞ΔΤϑΣΫτ 33 // PIXEL SHADER fixed4 PixShader(pixel_t input) :

    SV_Target { - half d = tex2D(_MainTex, input.texcoord0.xy).a * input.param.x; + half2 uv = input.texcoord0.xy; + uv.y = clamp(uv.y, 0.0, 0.5 + 0.5 * sin(_Time.y)); + half d = tex2D(_MainTex, uv).a * input.param.x; half4 c = input.faceColor * saturate(d - input.param.w); SDFςΫενϟΛϑΣον͢Δ UVΛ࣌ؒͰ clamp ϑΥϯτΛҾ͖৳͹͢ޮՌ͕ੜ·ΕΔ
  11. ԋग़ͷ·ͱΊ • نଇతͳಈ͖͸γΣʔμʔ͕ಘҙ ‣ نଇత = ਺ࣜͰදݱ͕Ͱ͖Δ ‣ ྫ: ԻָͷBPMʹ߹ΘͤͯνΧνΧ఺໓ͤ͞Δ

    • ෆنଇͳಈ͖͸Unity Timeline͕ಘҙ ‣ ྫ: ΧϝϥϫʔΫ 41 ෳ਺ͷಓ۩Λ࢖͍෼͚Δ͜ͱͰɺ ࡞ۀޮ཰ΛUP͠Α͏✌
  12. WORMHOLEͷؔ࿈৘ใ • UnityϓϩδΣΫτΛGitHubʹެ։த ‣ https://github.com/gam0022/unity-demoscene ‣ Assets/Demoscene/Projects/2018-10-28-TDF2018/ • ϒϩά ‣

    Tokyo Demo Fest 2018ͷDemo Compo༏উ࡞඼ͷղઆʢάϥϑΟοΫฤʣ • KLab Tech Book Vol.4 ‣ ٕज़ॻయ6ͰಉਓࢽΛ൦෍͠·͢&ిࢠ൛μ΢ϯϩʔυϖʔδ 42