Search Unity

Internal-Flare.shader + vertex transform?

Discussion in 'Shaders' started by cmcpasserby, Jul 22, 2014.

  1. cmcpasserby

    cmcpasserby

    Joined:
    Jul 18, 2014
    Posts:
    315
    Been working on a environment that uses a bending vertex shader, and have been trying to get my lens flares to match up with the positions as well.

    The internal-flare.shader file looked like a pretty basic shader so i tried this.
    Code (CSharp):
    1. Shader "Hidden/Internal-Flare"
    2. {
    3.     SubShader {
    4.  
    5.         Tags {"RenderType"="Overlay"}
    6.         ZWrite Off ZTest Always
    7.         Fog {Mode Off}
    8.         Cull Off
    9.         Blend One One
    10.         ColorMask RGB
    11.  
    12.         Pass {
    13.             CGPROGRAM
    14.             #pragma vertex vert
    15.             #pragma fragment frag
    16.  
    17.             #include "UnityCG.cginc"
    18.  
    19.             sampler2D _FlareTexture;
    20.             float _XTransform;
    21.             float _YTransform;
    22.            
    23.             struct appdata_t {
    24.                 float4 vertex : POSITION;
    25.                 fixed4 color : COLOR;
    26.                 float2 texcoord : TEXCOORD0;
    27.             };
    28.  
    29.             struct v2f {
    30.                 float4 pos : SV_POSITION;
    31.                 fixed4 color : COLOR;
    32.                 float2 texcoord : TEXCOORD0;
    33.             };
    34.  
    35.             float4 _FlareTexture_ST;
    36.            
    37.             v2f vert (appdata_t v)
    38.             {
    39.                 v2f o;
    40.                 float4 vv = mul(_Object2World, v.vertex);
    41.                 vv.xyz -= _WorldSpaceCameraPos.xyz;
    42.  
    43.                 vv = float4((vv.z * vv.z) * 0.00005 * _XTransform, (vv.z * vv.z) * 0.00005f * _YTransform, 0.0f, 0.0f);
    44.  
    45.                 v.vertex += mul(_World2Object, vv);
    46.  
    47.                 o.pos = mul(UNITY_MATRIX_MVP, v.vertex);
    48.  
    49.                 o.color = v.color;
    50.                 o.texcoord = TRANSFORM_TEX(v.texcoord, _FlareTexture);
    51.                 return o;
    52.             }
    53.  
    54.             fixed4 frag (v2f i) : SV_Target
    55.             {
    56.                 return tex2D(_FlareTexture, i.texcoord) * i.color;
    57.             }
    58.             ENDCG
    59.         }
    60.     }
    61. }
    But it seemed to apply that vertex transformation in screenspace as opposed to worldspace like it did for everything else i have the same vertex shader applied too.

    Anyone got any ideas of what this is happening and a way to work around it.
     
  2. drudiverse

    drudiverse

    Joined:
    May 16, 2013
    Posts:
    218
    a curved vertex shader and lens flares? curved vertices from google seems to be rounded vertices, so similar to DX11 shader that makes many vertices on exisiting mesh, forgot the name of the dx11 curved pavings etc thing.

    lens flare is different from curved vertices, it's like sun lens fx.

    can i see a screenshot of the result you have?
     
  3. cmcpasserby

    cmcpasserby

    Joined:
    Jul 18, 2014
    Posts:
    315
    @druidiverse, has nothing to do with dx11, its just a simple vertex transformation done in the vertex shader, im just trying to find a way to apply the same thing to the shader the flares in unity use. So everything matches up.
     
    Last edited: Jul 24, 2014