質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
Unity

Unityは、Unity Technologiesが開発・販売している、IDEを内蔵するゲームエンジンです。主にC#を用いたプログラミングでコンテンツの開発が可能です。

Q&A

解決済

1回答

3806閲覧

以下に記載のシェーダーにエミッションを追加したい

kudo201810

総合スコア30

Unity

Unityは、Unity Technologiesが開発・販売している、IDEを内蔵するゲームエンジンです。主にC#を用いたプログラミングでコンテンツの開発が可能です。

0グッド

0クリップ

投稿2020/07/31 22:14

以下のシェーダーにエミッションを追加したいのですが、可能でしょうか。

Shader "Particles/Priority Additive" { Properties { _TintColor ("Tint Color", Color) = (0.5,0.5,0.5,0.5) _MainTex ("Particle Texture", 2D) = "white" {} _InvFade ("Soft Particles Factor", Range(0.01,3.0)) = 1.0 } Category { Tags { "Queue"="Transparent+1" "IgnoreProjector"="True" "RenderType"="Transparent" } Blend SrcAlpha One AlphaTest Greater .01 ColorMask RGB Cull Off Lighting Off ZWrite Off Fog { Color (0,0,0,0) } BindChannels { Bind "Color", color Bind "Vertex", vertex Bind "TexCoord", texcoord } // ---- Fragment program cards SubShader { Pass { CGPROGRAM #pragma vertex vert #pragma fragment frag #pragma fragmentoption ARB_precision_hint_fastest #pragma multi_compile_particles #include "UnityCG.cginc" sampler2D _MainTex; fixed4 _TintColor; struct appdata_t { float4 vertex : POSITION; fixed4 color : COLOR; float2 texcoord : TEXCOORD0; }; struct v2f { float4 vertex : POSITION; fixed4 color : COLOR; float2 texcoord : TEXCOORD0; #ifdef SOFTPARTICLES_ON float4 projPos : TEXCOORD1; #endif }; float4 _MainTex_ST; v2f vert (appdata_t v) { v2f o; o.vertex = UnityObjectToClipPos(v.vertex); #ifdef SOFTPARTICLES_ON o.projPos = ComputeScreenPos (o.vertex); COMPUTE_EYEDEPTH(o.projPos.z); #endif o.color = v.color; o.texcoord = TRANSFORM_TEX(v.texcoord,_MainTex); return o; } sampler2D _CameraDepthTexture; float _InvFade; fixed4 frag (v2f i) : COLOR { #ifdef SOFTPARTICLES_ON float sceneZ = LinearEyeDepth (UNITY_SAMPLE_DEPTH(tex2Dproj(_CameraDepthTexture, UNITY_PROJ_COORD(i.projPos)))); float partZ = i.projPos.z; float fade = saturate (_InvFade * (sceneZ-partZ)); i.color.a *= fade; #endif return 2.0f * i.color * _TintColor * tex2D(_MainTex, i.texcoord); } ENDCG } } // ---- Dual texture cards SubShader { Pass { SetTexture [_MainTex] { constantColor [_TintColor] combine constant * primary } SetTexture [_MainTex] { combine texture * previous DOUBLE } } } // ---- Single texture cards (does not do color tint) SubShader { Pass { SetTexture [_MainTex] { combine texture * primary } } } } }

上記のシェーダーを使って、剣撃のエフェクトを作っています。
その剣撃のエフェクトを光らせたいと考えています。

カメラにはBloomのスクリプトをつけ、エミッションを追加することで
それを実現したいのですが、いろいろ調べて
上記、スクリプトをいじったのですがシェーダーエラーがでてしまい、できませんでした。

シェーダーのことはよくわかっていないのですが
そもそも、上記のシェーダーではエミッションを追加できないのではないかと思い
質問させていただきました。
他のシェーダーだと剣撃が作れなかったのでなんとかなるものなのか
はっきりさせたいと思い、質問させていただきました。
よろしくお願いいたします。

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答1

0

ベストアンサー

出力する色にエミッションを上乗せしてやればいいんじゃないでしょうかね?

ShaderLab

1Shader "Particles/Priority Additive" { 2Properties { 3 _TintColor ("Tint Color", Color) = (0.5,0.5,0.5,0.5) 4 _MainTex ("Particle Texture", 2D) = "white" {} 5 _InvFade ("Soft Particles Factor", Range(0.01,3.0)) = 1.0 6 7 // エミッション用プロパティを追加 8 [HDR] _EmissionColor ("Emission", Color) = (0, 0, 0, 0) 9} 10 11Category { 12 Tags { "Queue"="Transparent+1" "IgnoreProjector"="True" "RenderType"="Transparent" } 13 Blend SrcAlpha One 14 AlphaTest Greater .01 15 ColorMask RGB 16 Cull Off Lighting Off ZWrite Off Fog { Color (0,0,0,0) } 17 BindChannels { 18 Bind "Color", color 19 Bind "Vertex", vertex 20 Bind "TexCoord", texcoord 21 } 22 23 // ---- Fragment program cards 24 SubShader { 25 Pass { 26 27 CGPROGRAM 28 #pragma vertex vert 29 #pragma fragment frag 30 #pragma fragmentoption ARB_precision_hint_fastest 31 #pragma multi_compile_particles 32 33 #include "UnityCG.cginc" 34 35 sampler2D _MainTex; 36 fixed4 _TintColor; 37 38 // エミッション用変数を追加 39 float3 _EmissionColor; 40 41 struct appdata_t { 42 float4 vertex : POSITION; 43 fixed4 color : COLOR; 44 float2 texcoord : TEXCOORD0; 45 }; 46 47 struct v2f { 48 float4 vertex : POSITION; 49 fixed4 color : COLOR; 50 float2 texcoord : TEXCOORD0; 51 #ifdef SOFTPARTICLES_ON 52 float4 projPos : TEXCOORD1; 53 #endif 54 }; 55 56 float4 _MainTex_ST; 57 58 59 v2f vert (appdata_t v) 60 { 61 v2f o; 62 o.vertex = UnityObjectToClipPos(v.vertex); 63 #ifdef SOFTPARTICLES_ON 64 o.projPos = ComputeScreenPos (o.vertex); 65 COMPUTE_EYEDEPTH(o.projPos.z); 66 #endif 67 o.color = v.color; 68 o.texcoord = TRANSFORM_TEX(v.texcoord,_MainTex); 69 return o; 70 } 71 72 sampler2D _CameraDepthTexture; 73 float _InvFade; 74 75 float4 frag (v2f i) : COLOR 76 { 77 #ifdef SOFTPARTICLES_ON 78 float sceneZ = LinearEyeDepth (UNITY_SAMPLE_DEPTH(tex2Dproj(_CameraDepthTexture, UNITY_PROJ_COORD(i.projPos)))); 79 float partZ = i.projPos.z; 80 float fade = saturate (_InvFade * (sceneZ-partZ)); 81 i.color.a *= fade; 82 #endif 83 84 // 出力色を計算したのち、さらにRGBにエミッションを上乗せする 85 float4 color = 2.0f * i.color * _TintColor * tex2D(_MainTex, i.texcoord); 86 color.rgb += _EmissionColor; 87 88 return color; 89 } 90 ENDCG 91 } 92 } 93 94 // ---- Dual texture cards 95 SubShader { 96 Pass { 97 SetTexture [_MainTex] { 98 constantColor [_TintColor] 99 combine constant * primary 100 } 101 SetTexture [_MainTex] { 102 combine texture * previous DOUBLE 103 } 104 } 105 } 106 107 // ---- Single texture cards (does not do color tint) 108 SubShader { 109 Pass { 110 SetTexture [_MainTex] { 111 combine texture * primary 112 } 113 } 114 } 115} 116}

投稿2020/08/01 02:38

Bongo

総合スコア10807

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

kudo201810

2020/08/01 04:40

ありがとうございました。できました。
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問