Search Unity

Has anyone gotten the UV2BlendAndFrame output working?

Discussion in '5.5 Beta' started by Howard-Day, Sep 4, 2016.

  1. Howard-Day

    Howard-Day

    Joined:
    Oct 25, 2013
    Posts:
    133
    I've tried everything I can think of to get this working...


    Code (CSharp):
    1. struct Input {
    2.         float2 uv_MainTex;
    3.         float3 uv_BlendTex : TEXCOORD1;
    4.         float4 color : COLOR;
    5.       };
    6.  
    7.       sampler2D _MainTex;
    8.       sampler2D _BumpMap;
    9.  
    10.       void surf (Input IN, inout SurfaceOutput o) {
    11.           fixed4 packRGB1 = tex2D (_MainTex, IN.uv_MainTex);
    12.           fixed4 normals1 = tex2D (_BumpMap, IN.uv_MainTex);
    13.           fixed4 packRGB2 = tex2D (_MainTex, float2(IN.uv_BlendTex.x,IN.uv_BlendTex.y) );
    14.           fixed4 normals2 = tex2D (_BumpMap, float2(IN.uv_BlendTex.x,IN.uv_BlendTex.y) );
    15.  
    16.           fixed4 packRGB = lerp(packRGB1,packRGB2,IN.uv_BlendTex.z)
    17.           fixed4 normals = lerp(normals1,normals2,IN.uv_BlendTex.z);
    18.  
    But Unity refuses to let me init a shader with TEXCOORD1 as a float3. It must be a float2 to compile. :/
    " cannot implicitly convert from 'const float2' to 'float3' at line 109 (on d3d9)"
    This is despite the fact that the vert stream out of the particle system callse for the UV2BlendFrame to be a float3.
    Any thoughts on how to fix this?
    Thanks!
     
  2. richardkettlewell

    richardkettlewell

    Unity Technologies

    Joined:
    Sep 9, 2015
    Posts:
    1,861
    Hey, try adding TEXCOORD0 to your main tex uv input ;)
     
  3. Howard-Day

    Howard-Day

    Joined:
    Oct 25, 2013
    Posts:
    133
    Like so?
    Code (CSharp):
    1.  struct Input {
    2.         float2 uv_MainTex : TEXCOORD0;
    3.         float3 uv_BlendTex : TEXCOORD1;
    4.         float4 color : COLOR;
    5.       };
    6.  
    7.       sampler2D _MainTex;
    8.       sampler2D _BumpMap;
    9.      
    10.       void surf (Input IN, inout SurfaceOutput o) {
    11.         fixed InvAlpha = 1-IN.color.a;
    12.         fixed Alpha = IN.color.a;
    13.           fixed4 packRGB1 = tex2D (_MainTex, IN.uv_MainTex);
    14.           fixed4 normals1 = tex2D (_BumpMap, IN.uv_MainTex);
    15.           fixed4 packRGB2 = tex2D (_MainTex, float2(IN.uv_BlendTex.x,IN.uv_BlendTex.y) );
    16.           fixed4 normals2 = tex2D (_BumpMap, float2(IN.uv_BlendTex.x,IN.uv_BlendTex.y) );
    17.  
    18.           fixed4 packRGB = lerp(packRGB1,packRGB2,IN.uv_BlendTex.z);//packRGB1;//
    Now I get two shader errors instead of just one! :D
    cannot implicitly convert from 'const float2' to 'float3' at line 88 (on d3d11)
    cannot implicitly convert from 'const float2' to 'float3' at line 114 (on d3d11)

    I hope you can help. :)
     

    Attached Files:

  4. Noisecrime

    Noisecrime

    Joined:
    Apr 7, 2010
    Posts:
    1,626
    Not used this and had to look up what was meant by 'UV2BlendAndFrame', but looking at the existing shaders ( you can download the builtin shaders via additional resources on download page), it would look as though you'll meant to be using a float4 not a float3 to start with.

    Not sure why, could be a workaround due to Unity wanting to try and pack multiple float2 uv coord streams into float4. Could be something else entirely. You might also need to write a custom Vertex shader for your surface shader as surface shaders may not understand this blendAndFrame construct.

    Anyway here is the Particle Anim Alpha Blend shader from the builtin shaders, hopefully will give you a better starting point.

    Code (CSharp):
    1. Shader "Particles/Anim Alpha Blended" {
    2. Properties {
    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. Category {
    9.     Tags { "Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent" "PreviewType"="Plane" }
    10.     Blend SrcAlpha OneMinusSrcAlpha
    11.     ColorMask RGB
    12.     Cull Off Lighting Off ZWrite Off
    13.  
    14.     SubShader {
    15.         Pass {
    16.        
    17.             CGPROGRAM
    18.             #pragma vertex vert
    19.             #pragma fragment frag
    20.             #pragma target 2.0
    21.             #pragma multi_compile_particles
    22.             #pragma multi_compile_fog
    23.            
    24.             #include "UnityCG.cginc"
    25.  
    26.             sampler2D _MainTex;
    27.             fixed4 _TintColor;
    28.            
    29.             struct appdata_t {
    30.                 float4 vertex : POSITION;
    31.                 fixed4 color : COLOR;
    32.                 float2 texcoord : TEXCOORD0;
    33.                 float4 texcoordBlendFrame : TEXCOORD1;
    34.             };
    35.  
    36.             struct v2f {
    37.                 float4 vertex : SV_POSITION;
    38.                 fixed4 color : COLOR;
    39.                 float2 texcoord : TEXCOORD0;
    40.                 float2 texcoord2 : TEXCOORD1;
    41.                 fixed blend : TEXCOORD2;
    42.                 UNITY_FOG_COORDS(3)
    43.                 #ifdef SOFTPARTICLES_ON
    44.                 float4 projPos : TEXCOORD4;
    45.                 #endif
    46.             };
    47.            
    48.             float4 _MainTex_ST;
    49.  
    50.             v2f vert (appdata_t v)
    51.             {
    52.                 v2f o;
    53.                 o.vertex = UnityObjectToClipPos(v.vertex);
    54.                 #ifdef SOFTPARTICLES_ON
    55.                 o.projPos = ComputeScreenPos (o.vertex);
    56.                 COMPUTE_EYEDEPTH(o.projPos.z);
    57.                 #endif
    58.                 o.color = v.color * _TintColor;
    59.                 o.texcoord = TRANSFORM_TEX(v.texcoord,_MainTex);
    60.                 o.texcoord2 = TRANSFORM_TEX(v.texcoordBlendFrame.xy,_MainTex);
    61.                 o.blend = v.texcoordBlendFrame.z;
    62.                 UNITY_TRANSFER_FOG(o,o.vertex);
    63.                 return o;
    64.             }
    65.  
    66.             sampler2D_float _CameraDepthTexture;
    67.             float _InvFade;
    68.            
    69.             fixed4 frag (v2f i) : SV_Target
    70.             {
    71.                 #ifdef SOFTPARTICLES_ON
    72.                 float sceneZ = LinearEyeDepth (SAMPLE_DEPTH_TEXTURE_PROJ(_CameraDepthTexture, UNITY_PROJ_COORD(i.projPos)));
    73.                 float partZ = i.projPos.z;
    74.                 float fade = saturate (_InvFade * (sceneZ-partZ));
    75.                 i.color.a *= fade;
    76.                 #endif
    77.                
    78.                 fixed4 colA = tex2D(_MainTex, i.texcoord);
    79.                 fixed4 colB = tex2D(_MainTex, i.texcoord2);
    80.                 fixed4 col = 2.0f * i.color * lerp(colA, colB, i.blend);
    81.                 UNITY_APPLY_FOG(i.fogCoord, col);
    82.                 return col;
    83.             }
    84.             ENDCG
    85.         }
    86.     }  
    87. }
    88. }
    89.  
     
    richardkettlewell likes this.
  5. richardkettlewell

    richardkettlewell

    Unity Technologies

    Joined:
    Sep 9, 2015
    Posts:
    1,861
    NoiseCrime has summed this up very well :)

    We are packing data into a float4 to minimise the number of streams required. The docs should explain the layout (xy=uv,z=blend factor,w=frame number)

    We haven't tried using this system much with surface shaders, which may explain why you are struggling. I suspect if you press the Show Generated Code button on that shader, it will show that it is expecting other vertex inputs that are hidden from you when writing a surface shader. (Things like lightmap uvs) You can declare your own vertex input and vertex shader to replace the default one. Or use pragma to turn off lightmapping etc. I can give you a more specific solution later next week when I have the code in front of me, so just post back again if you are still stuck :)
     
  6. Howard-Day

    Howard-Day

    Joined:
    Oct 25, 2013
    Posts:
    133
    So everything I try to build on this.. doesn't compile or throws random errors I just can't seem to track down. (Show generated code with a non-compiling shader shows nothing!) I really don't want to have to re-write this as a fragment shader, so if, when you're back in around the code, you're willing - I'd love to have a more in depth solution. I'm afraid I just can't seem to grok what's needed here, and I need to move onto working on other things. Thanks!
     
    richardkettlewell likes this.
  7. richardkettlewell

    richardkettlewell

    Unity Technologies

    Joined:
    Sep 9, 2015
    Posts:
    1,861
    I've had a look at what is required to use this tech with Surface Shaders.

    The key is that you must be explicit about your vertex shader input, and you must copy that data your surface shader manually.

    Eg:

    Code (CSharp):
    1. #pragma surface surf Standard vertex:vert
    2.  
    3. struct appdata_t {
    4.     float4 position : POSITION;
    5.     float3 normal : NORMAL;
    6.     float2 uv : TEXCOORD0;
    7.     float4 uv2BlendAndFrame : TEXCOORD1;
    8. };
    9.  
    10. struct Input {
    11.     float2 uv;
    12.     float4 uv2BlendAndFrame;
    13. };
    14.  
    15. void vert(inout appdata_t v, out Input o) {
    16.     UNITY_INITIALIZE_OUTPUT(Input,o);
    17.     o.uv = v.uv;
    18.     o.uv2BlendAndFrame = v.uv2BlendAndFrame;
    19. }
    20.  
    21. void surf (Input IN, inout SurfaceOutputStandard o) {
    22.     .....
    23. }
    24.  
    Hope it helps!
     
  8. Howard-Day

    Howard-Day

    Joined:
    Oct 25, 2013
    Posts:
    133
    Okay, I'm still having issues with this. :/ I'm trying to put all the stuff thats needed to support the rest of the shader into the Inputs - color, tangents, etc, but when I do I'm getting "invalid subscript 'texcoord' at line xxx" which really makes no sense to me. :/ Here's the code I'm using, please tell me there's something obviously stupid I'm doing here, because from all I know and have seen this *should* be working.
    Code (CSharp):
    1. struct appdata_t {
    2.         float4 position : POSITION;
    3.         float4 vertex : VERTEX;
    4.         float3 normal : NORMAL;
    5.         float4 tangent : TANGENT;
    6.         float4 color : COLOR;
    7.         float2 uv_MainTex : TEXCOORD0;
    8.         float4 uv_BlendTex : TEXCOORD1;
    9.         };
    10.  
    11.       struct Input {
    12.         float2 uv_MainTex;
    13.         float4 uv_BlendTex;
    14.         float4 color;
    15.       };
    16.  
    17.       void vert(inout appdata_t v, out Input o) {
    18.             UNITY_INITIALIZE_OUTPUT(Input,o);
    19.             o.uv_MainTex = v.uv_MainTex;
    20.             o.uv_BlendTex = v.uv_BlendTex;
    21.             o.color = v.color;
    22.       }
    23.  
    Thanks for all your help so far. I get the feeling I'm just not grasping something basic here. :/
     
  9. richardkettlewell

    richardkettlewell

    Unity Technologies

    Joined:
    Sep 9, 2015
    Posts:
    1,861
    Could you post your entire shader? (Or send it via pm) I can take a look on Monday :)
     
  10. Howard-Day

    Howard-Day

    Joined:
    Oct 25, 2013
    Posts:
    133
    Oh, sure! Here you go!
    Code (CSharp):
    1. Shader "Custom/Explosion_Greasy_01" {
    2.     Properties {
    3.       _MainTex ("Packed RGBA", 2D) = "white" {}
    4.       _SmokeColor ("Smoke Start Color", Color) = (1,1,1,1)
    5.       _EndColor ("Smoke End Color", Color) = (1,1,1,1)
    6.       _GlowPower ("Glow Power", Float) = 10
    7.       _DiffuseWrap ("Diffuse Wrap", Range(0,1)) = 0
    8.       _BumpMap ("Bumpmap", 2D) = "bump" {}
    9.  
    10.     }
    11.     SubShader {
    12.       Tags {"Queue"="Transparent" "RenderType"="Transparent"}
    13.       Blend SrcAlpha OneMinusSrcAlpha
    14.       ZWrite off
    15.       Cull off
    16.       CGPROGRAM
    17.       #pragma surface surf WrapLambert alpha vertex:vert
    18.       //#pragma debug
    19.       sampler2D _MainTex;
    20.       sampler2D _BumpMap;
    21.       float4 _SmokeColor;
    22.       float4 _EndColor;
    23.       fixed _GlowPower;
    24.       fixed _DiffuseWrap;
    25.  
    26.           half4 LightingWrapLambert (SurfaceOutput s, half3 lightDir, half atten) {
    27.             half NdotL = dot (s.Normal, lightDir);
    28.             half4 c;
    29.             c.rgb = s.Albedo *_LightColor0.rgb * saturate((NdotL + _DiffuseWrap) / ((1 + _DiffuseWrap) * (1 + _DiffuseWrap)));
    30.             c.a = s.Alpha;
    31.             return c;
    32.         }
    33.         struct appdata_t {
    34.         float4 position : POSITION;
    35.         float4 vertex : VERTEX;
    36.         float3 normal : NORMAL;
    37.         float4 tangent : TANGENT;
    38.         float4 color : COLOR;
    39.         float2 uv_MainTex : TEXCOORD0;
    40.         float4 uv_BlendTex : TEXCOORD1;
    41.  
    42.         };
    43.  
    44.       struct Input {
    45.         float2 uv_MainTex;
    46.         float4 uv_BlendTex;
    47.         float4 color;
    48.       };
    49.  
    50.       void vert(inout appdata_t v, out Input o) {
    51.             UNITY_INITIALIZE_OUTPUT(Input,o);
    52.             o.uv_MainTex = v.uv_MainTex;
    53.             o.uv_BlendTex = v.uv_BlendTex;
    54.             o.color = v.color;
    55.       }
    56.  
    57.       void surf (Input IN, inout SurfaceOutput o) {
    58.         fixed InvAlpha = 1-IN.color.a;
    59.         fixed Alpha = IN.color.a;
    60.           fixed4 packRGB1 = tex2D (_MainTex, IN.uv_MainTex);
    61.           fixed4 normals1 = tex2Dlod(_BumpMap, float4(IN.uv_MainTex.xy,0,4*(1-saturate(Alpha*3-1.25))) );
    62.           fixed4 packRGB2 = tex2D (_MainTex, IN.uv_BlendTex.xy );
    63.           fixed4 normals2 = tex2Dlod(_BumpMap, float4(IN.uv_BlendTex.xy,0,4*(1-saturate(Alpha*3-1.25))) );
    64.  
    65.           fixed4 packRGB = lerp(packRGB1,packRGB2,IN.uv_BlendTex.z);//packRGB1;//
    66.           fixed4 normals = lerp(normals1,normals2,IN.uv_BlendTex.z);
    67.           clip((packRGB.a*Alpha)-.01);
    68.  
    69.           fixed Smoke = packRGB.r*Alpha+InvAlpha*.5;            
    70.         o.Albedo = lerp(Smoke*_SmokeColor,Smoke*_EndColor.rgb,saturate(InvAlpha*1.1-.1))*4;
    71.  
    72.         fixed SSGlow = packRGB.g*saturate(Alpha*6-(2+InvAlpha*3));
    73.         fixed Flame = saturate((packRGB.b)*saturate(packRGB.a+.125)-(InvAlpha*2)-.1);
    74.         o.Alpha =saturate((packRGB.a*Alpha*2)*saturate(Alpha*2));
    75.  
    76.         o.Emission = (SSGlow*2*saturate(IN.color.rgb-.01))+(Flame*_GlowPower*(Alpha))*saturate(IN.color.rgb-.05
    77.         *InvAlpha);
    78.         o.Normal = UnpackNormal (normals);//*saturate(Alpha*2-1);
    79.       }
    80.       ENDCG
    81.     }
    82.     Fallback "Diffuse"
    83.   }
     
    richardkettlewell likes this.
  11. Noisecrime

    Noisecrime

    Joined:
    Apr 7, 2010
    Posts:
    1,626
    I had a quick look at this and I strongly suspect Shaderlab compilation is to blame for the error and thus is a bug.

    I tried various changes to the shader posted, but the best I was able to get was to a single error when I switched to using appdata_full ( see below for code) 'Shader error in 'Custom/Explosion_Greasy_01': cannot implicitly convert from 'const float2' to 'float4' at line 118 (on d3d9)'

    I believe its ShaderLab or whatever it is that compiles surface shaders that is at fault due to these lines in the generated code.

    Code (CSharp):
    1. v2f_surf vert_surf (appdata_t v)
    2. {
    3. <snip>
    4.   o.pack0.xy = TRANSFORM_TEX(v.texcoord, _MainTex);
    5.   o.pack1.xyzw = TRANSFORM_TEX(v.texcoord, _BlendTex);
    6. <snip>
    7. }
    Notice how its trying to use v.texcoord for both MainTex and BlendTex, which explains the error above and any float2 to float4 issues in general.

    This exact same code error was present in the original shader and my modified version using appdata_full which is why I think its ShaderLab that is at fault.


    For reference the code changes I made to the shader was to fall back to using appdata_full.

    So ...

    Code (CSharp):
    1.     void vert(inout appdata_full v, out Input o)
    2.     {
    3.         UNITY_INITIALIZE_OUTPUT(Input,o);
    4.         o.uv_MainTex = v.texcoord.xy; // v.uv_MainTex;
    5.         o.uv_BlendTex = v.texcoord1; //v.uv_BlendTex;
    6.         o.color = v.color;
    7.     }
     
  12. Noisecrime

    Noisecrime

    Joined:
    Apr 7, 2010
    Posts:
    1,626
    Ah, ok. So this reminded me of an issue I reported last year about trying to pack uv data into custom INPUT struct. Essentially I wanted to have a float3 such as xy were uv and z was a depth value I wrote to in vert().

    The interesting response was
    So the problem here is the name 'uv_BlendTex' as ShaderLab will see its starts with uv and will automatically pack it to a float2. You can see this if you check the 'Show Generated Code' option of the shader. You'll notice that color becomes ' half4 custompack0 : TEXCOORD5; // color' but uv_BlendTex is ' float4 pack1 : TEXCOORD1; // _BlendTex'. Although this might be misleading as it suggest uv_BlendTex has its own textureinterpolator and its own property 'pack1', ( which I guess it might) but what happens later is Unity tries to access this using ' o.pack1.xyzw = TRANSFORM_TEX(v.texcoord, _BlendTex);' which is wrong.

    So is the solution as simple as renaming your INPUT struct? Maybe to 'coord_BlendTex'? Sadly no as doing that still gives errors, although you can see in the generated code that at least its no longer trying to pack it with mainTex.

    Errors are now
    Code (CSharp):
    1. Shader error in 'Custom/Explosion_Greasy_01_Standard': invalid subscript 'texcoord' at line 98 (on d3d11)
    2.  
    3. Shader warning in 'Custom/Explosion_Greasy_01_Standard': texcoord1 missing from surface shader's vertex input struct (appdata_t), disabled lightmaps and meta pass generation
    4.  
    5. Shader warning in 'Custom/Explosion_Greasy_01_Standard': texcoord2 missing from surface shader's vertex input struct (appdata_t), disabled dynamic GI and meta pass generation
    and i'm really not sure where to go with it. Sorry.
     
    richardkettlewell likes this.
  13. Peter77

    Peter77

    QA Jesus

    Joined:
    Jun 12, 2013
    Posts:
    6,025
    What is this VERTEX semantic? I haven't seen that before and it's not listed in MSDN nor Unity docs. Could this confuse the shader code generation?

    Code (CSharp):
    1. struct appdata_t {
    2. float4 position : POSITION;
    3. float4 vertex : VERTEX;

    'position' does not seem to be used in the earlier posted shader code, so I assume it could be changed to this instead:
    Code (CSharp):
    1. struct appdata_t {
    2. //float4 position : POSITION;
    3. float4 vertex : POSITION;
    Not sure if it makes a difference, just thought I've found something that looks suspicious.
     
    richardkettlewell likes this.
  14. Howard-Day

    Howard-Day

    Joined:
    Oct 25, 2013
    Posts:
    133
    So, taking into account all the advice posted here (and seriously, thanks guys, I very much appreciate it!) Here's where the shader is now:
    Code (CSharp):
    1. Shader "Custom/Explosion_Greasy_01" {
    2.     Properties {
    3.       _MainTex ("Packed RGBA", 2D) = "white" {}
    4.       _SmokeColor ("Smoke Start Color", Color) = (1,1,1,1)
    5.       _EndColor ("Smoke End Color", Color) = (1,1,1,1)
    6.       _GlowPower ("Glow Power", Float) = 10
    7.       _DiffuseWrap ("Diffuse Wrap", Range(0,1)) = 0
    8.       _BumpMap ("Bumpmap", 2D) = "bump" {}
    9.     }
    10.     SubShader {
    11.       Tags {"Queue"="Transparent" "RenderType"="Transparent"}
    12.       Blend SrcAlpha OneMinusSrcAlpha
    13.       ZWrite off
    14.       Cull off
    15.       CGPROGRAM
    16.       #pragma surface surf WrapLambert alpha vertex:vert
    17.       //#pragma debug
    18.       sampler2D _MainTex;
    19.       sampler2D _BumpMap;
    20.       float4 _SmokeColor;
    21.       float4 _EndColor;
    22.       fixed _GlowPower;
    23.       fixed _DiffuseWrap;
    24.           half4 LightingWrapLambert (SurfaceOutput s, half3 lightDir, half atten) {
    25.             half NdotL = dot (s.Normal, lightDir);
    26.             half4 c;
    27.             c.rgb = s.Albedo *_LightColor0.rgb * saturate((NdotL + _DiffuseWrap) / ((1 + _DiffuseWrap) * (1 + _DiffuseWrap)));
    28.             c.a = s.Alpha;
    29.             return c;
    30.         }
    31.         struct appdata_t {
    32.         float4 vertex : POSITION;
    33.         float3 normal : NORMAL;
    34.         float4 tangent : TANGENT;
    35.         float4 color : COLOR;
    36.         float2 uv_MainTex : TEXCOORD0;
    37.         float4 uv2BlendAndFrame : TEXCOORD1;
    38.         };
    39.       struct Input {
    40.         float2 uv_MainTex;
    41.         float4 uv2BlendAndFrame;
    42.         float4 color;
    43.       };
    44.       void vert(inout appdata_t v, out Input o) {
    45.             UNITY_INITIALIZE_OUTPUT(Input,o);
    46.             o.uv_MainTex = v.texcoord.xy;
    47.             o.uv2BlendAndFrame = v.texcoord1;
    48.             o.color = v.color;
    49.       }
    50.       void surf (Input IN, inout SurfaceOutput o) {
    51.         fixed InvAlpha = 1-IN.color.a;
    52.         fixed Alpha = IN.color.a;
    53.           fixed4 packRGB1 = tex2D (_MainTex, IN.uv_MainTex);
    54.           fixed4 normals1 = tex2Dlod(_BumpMap, float4(IN.uv_MainTex.xy,0,4*(1-saturate(Alpha*3-1.25))) );
    55.           fixed4 packRGB2 = tex2D (_MainTex, IN.uv2BlendAndFrame.xy );
    56.           fixed4 normals2 = tex2Dlod(_BumpMap, float4(IN.uv2BlendAndFrame.xy,0,4*(1-saturate(Alpha*3-1.25))) );
    57.           fixed4 packRGB = lerp(packRGB1,packRGB2,IN.uv2BlendAndFrame.z);//packRGB1;//
    58.           fixed4 normals = lerp(normals1,normals2,IN.uv2BlendAndFrame.z);
    59.           clip((packRGB.a*Alpha)-.01);
    60.           fixed Smoke = packRGB.r*Alpha+InvAlpha*.5;          
    61.         o.Albedo = lerp(Smoke*_SmokeColor,Smoke*_EndColor.rgb,saturate(InvAlpha*1.1-.1))*4;
    62.         fixed SSGlow = packRGB.g*saturate(Alpha*6-(2+InvAlpha*3));
    63.         fixed Flame = saturate((packRGB.b)*saturate(packRGB.a+.125)-(InvAlpha*2)-.1);
    64.         o.Alpha =saturate((packRGB.a*Alpha*2)*saturate(Alpha*2));
    65.         o.Emission = (SSGlow*2*saturate(IN.color.rgb-.01))+(Flame*_GlowPower*(Alpha))*saturate(IN.color.rgb-.05
    66.         *InvAlpha);
    67.         o.Normal = UnpackNormal (normals);//*saturate(Alpha*2-1);
    68.       }
    69.       ENDCG
    70.     }
    71.     Fallback "Diffuse"
    72.   }
    Which still gives an error. I'd love to figure this out. I promise half-way decent looking explosions when we do! :D
     

    Attached Files:

    richardkettlewell likes this.
  15. Peter77

    Peter77

    QA Jesus

    Joined:
    Jun 12, 2013
    Posts:
    6,025
    This one compiles for me:
    Code (CSharp):
    1.     Shader "Custom/Explosion_Greasy_01" {
    2.         Properties {
    3.           _MainTex ("Packed RGBA", 2D) = "white" {}
    4.           _SmokeColor ("Smoke Start Color", Color) = (1,1,1,1)
    5.           _EndColor ("Smoke End Color", Color) = (1,1,1,1)
    6.           _GlowPower ("Glow Power", Float) = 10
    7.           _DiffuseWrap ("Diffuse Wrap", Range(0,1)) = 0
    8.           _BumpMap ("Bumpmap", 2D) = "bump" {}
    9.         }
    10.         SubShader {
    11.           Tags {"Queue"="Transparent" "RenderType"="Transparent"}
    12.           Blend SrcAlpha OneMinusSrcAlpha
    13.           ZWrite off
    14.           Cull off
    15.           CGPROGRAM
    16.           #pragma surface surf WrapLambert alpha vertex:vert
    17.           //#pragma debug
    18.           sampler2D _MainTex;
    19.           sampler2D _BumpMap;
    20.           float4 _SmokeColor;
    21.           float4 _EndColor;
    22.           fixed _GlowPower;
    23.           fixed _DiffuseWrap;
    24.               half4 LightingWrapLambert (SurfaceOutput s, half3 lightDir, half atten) {
    25.                 half NdotL = dot (s.Normal, lightDir);
    26.                 half4 c;
    27.                 c.rgb = s.Albedo *_LightColor0.rgb * saturate((NdotL + _DiffuseWrap) / ((1 + _DiffuseWrap) * (1 + _DiffuseWrap)));
    28.                 c.a = s.Alpha;
    29.                 return c;
    30.             }
    31.             struct appdata_t {
    32.             float4 vertex : POSITION;
    33.             float3 normal : NORMAL;
    34.             float4 tangent : TANGENT;
    35.             float4 color : COLOR;
    36.             float2 texcoord : TEXCOORD0; // changed from uv_MainTex to texcoord
    37.             float4 texcoord1 : TEXCOORD1; // changed from uv2BlendAndFrame to texcoord1
    38.             };
    39.           struct Input {
    40.             float2 uv_MainTex;
    41.             float4 st_BlendAndFrame; // changed from uv2BlendAndFrame to st_BlendAndFrame
    42.             float4 color;
    43.           };
    44.           void vert(inout appdata_t v, out Input o) {
    45.                 UNITY_INITIALIZE_OUTPUT(Input,o);
    46.                 o.uv_MainTex = v.texcoord.xy;
    47.                 o.st_BlendAndFrame = v.texcoord1;
    48.                 o.color = v.color;
    49.           }
    50.           void surf (Input IN, inout SurfaceOutput o) {
    51.             fixed InvAlpha = 1-IN.color.a;
    52.             fixed Alpha = IN.color.a;
    53.               fixed4 packRGB1 = tex2D (_MainTex, IN.uv_MainTex);
    54.               fixed4 normals1 = tex2Dlod(_BumpMap, float4(IN.uv_MainTex.xy,0,4*(1-saturate(Alpha*3-1.25))) );
    55.               fixed4 packRGB2 = tex2D (_MainTex, IN.st_BlendAndFrame.xy );
    56.               fixed4 normals2 = tex2Dlod(_BumpMap, float4(IN.st_BlendAndFrame.xy,0,4*(1-saturate(Alpha*3-1.25))) );
    57.               fixed4 packRGB = lerp(packRGB1,packRGB2,IN.st_BlendAndFrame.z);//packRGB1;//
    58.               fixed4 normals = lerp(normals1,normals2,IN.st_BlendAndFrame.z);
    59.               clip((packRGB.a*Alpha)-.01);
    60.               fixed Smoke = packRGB.r*Alpha+InvAlpha*.5;        
    61.             o.Albedo = lerp(Smoke*_SmokeColor,Smoke*_EndColor.rgb,saturate(InvAlpha*1.1-.1))*4;
    62.             fixed SSGlow = packRGB.g*saturate(Alpha*6-(2+InvAlpha*3));
    63.             fixed Flame = saturate((packRGB.b)*saturate(packRGB.a+.125)-(InvAlpha*2)-.1);
    64.             o.Alpha =saturate((packRGB.a*Alpha*2)*saturate(Alpha*2));
    65.             o.Emission = (SSGlow*2*saturate(IN.color.rgb-.01))+(Flame*_GlowPower*(Alpha))*saturate(IN.color.rgb-.05
    66.             *InvAlpha);
    67.             o.Normal = UnpackNormal (normals);//*saturate(Alpha*2-1);
    68.           }
    69.           ENDCG
    70.         }
    71.         Fallback "Diffuse"
    72.       }
    73.  
     
    Noisecrime and richardkettlewell like this.
  16. Howard-Day

    Howard-Day

    Joined:
    Oct 25, 2013
    Posts:
    133
    It Does! Wow, thanks Peter. That works perfectly! I thought it didn't for a second - but I had forgotten to re-add the vertex stream. My bad. Now, as promised.... EXPLOSION!


    Thanks, guys!
     
    Last edited: Sep 10, 2016
  17. richardkettlewell

    richardkettlewell

    Unity Technologies

    Joined:
    Sep 9, 2015
    Posts:
    1,861
    Hey, great that you have gotten this working! Those explosions looks cool!

    Most of the internal examples we had previously made, had used custom shaders (not surface shaders), so this was a new use case for us. Admittedly, we should have experimented more with surface shader usage!

    We are currently working on documentation before the main release, so I will make sure to include surface shader examples, and explain the issue where streams prefixed with "uv" conflict with the surface shader parsing.

    Thanks again!
     
unityunity