Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

[Solved] Help Bending Object Shader

Discussion in 'Shaders' started by Johnck, Sep 9, 2015.

  1. Johnck

    Johnck

    Joined:
    Sep 9, 2015
    Posts:
    2
    Hi, I want to make a shader to bend an object from the pivot point.
    The problem is, the shader bellow is working in editor mode but not in play mode.
    Help please!

    PS. I don't have any script screwing up the object or the shader.

    Code (CSharp):
    1. Shader "Bend" {
    2.     Properties {
    3.         _MainTex("Texture (RGBA)", 2D) = "white" {}
    4.         _Curvature("Curvature", Float) = 1
    5.     }
    6.     SubShader {
    7.         Tags { "Queue"="Transparent" "RenderType"="Transparent"  }
    8.         Blend SrcAlpha OneMinusSrcAlpha
    9.  
    10.         LOD 100
    11.         Cull      Off
    12.         Lighting  Off
    13.         ZWrite    Off
    14.         Fog {Mode Off}
    15.        
    16.         Pass {
    17.             CGPROGRAM
    18.             #pragma vertex         vert
    19.             #pragma fragment       frag
    20.             #pragma fragmentoption ARB_precision_hint_fastest
    21.             #include "UnityCG.cginc"
    22.  
    23.             sampler2D _MainTex;
    24.             float4    _MainTex_ST;
    25.            
    26.             float _Curvature;
    27.  
    28.             struct VS_IN{
    29.                 float4 vertex   : POSITION;
    30.                 float4 texcoord : TEXCOORD0;
    31.                 fixed4 color    : COLOR;
    32.             };
    33.             struct VS_OUT {
    34.                 float4 position : SV_POSITION;
    35.                 fixed4 color    : COLOR;
    36.                 float2 uv       : TEXCOORD0;
    37.             };
    38.  
    39.             VS_OUT vert (VS_IN input) {
    40.  
    41.                 float4 v = input.vertex;
    42.  
    43.                 v = float4((v.y * v.y) * -_Curvature, (v.y * v.y) * abs(_Curvature), 0.0f, 0.0f);
    44.                
    45.                 VS_OUT result;
    46.                 result.position = mul(UNITY_MATRIX_MVP, input.vertex + v);
    47.                 result.uv = TRANSFORM_TEX(input.texcoord, _MainTex);
    48.                 result.color = input.color;
    49.  
    50.                 return result;
    51.             }
    52.  
    53.             fixed4 frag (VS_OUT input) : COLOR {
    54.                 fixed4 color = tex2D(_MainTex, input.uv);
    55.                 return color * input.color;
    56.             }
    57.             ENDCG
    58.         }
    59.     }
    60. }
    61.  
     
  2. Johnck

    Johnck

    Joined:
    Sep 9, 2015
    Posts:
    2
    I've found the guilty :)

    Turning off static batching in the player settings or disable the static object will solve the problem, otherwise Unity will combine all objects meshes.