• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Nolnocn · Apr 05, 2016 at 05:22 AM · shadersmaterialsshader programming

Adding object to scene causes problem with other objects material/shader

Hello!

I'm working on a simple shader to make wavy water and have run into a strange issue. The only thing the shader does is offset the y-position of each vertex with the value from a sine wave (code below). I set up a 3x3 grid of planes using the shader and everything works fine on its own.

However, when I add any other model into the scene, the closest tile to the camera becomes disconnected from the others. The wave still moves across the mesh, but it's as if the time value that is used to calculate the y-position is different from the other tiles.

Disabling the added object "fixes" the issue (disabling the mesh renderer specifically also works). The problem also only occurs at certain camera angles and distances. To top it off, changing the shader of the object to the water shader makes it so the tile furthest away has the problem, rather than the closest.

Here is an image of the scene with and without a barrel (The material on the barrel uses only the Standard shader with a texture): alt text

There are no scripts attached to the barrel, it is simply the model dropped into the scene.

This issue also occurs in the editor view (The camera is zoomed out a bit to "fix" the tile in the second image): alt text

Here is the water shader:

 Shader "Custom/Simple Water"
 {
     Properties
     {
         _MainTex( "Texture", 2D ) = "white" {}
         _Speed( "Wave Speed", Float ) = 1.0
         _Amplitude( "Wave Amplitude", Float ) = 0.1
         _Period( "Wave Period", Float ) = 1.0
     }
     SubShader
     {
         Tags { "RenderType" = "Opaque" }
         LOD 100
 
         Pass
         {
             CGPROGRAM
             #pragma vertex vert
             #pragma fragment frag
             // make fog work
             #pragma multi_compile_fog
             
             #include "UnityCG.cginc"
 
             struct appdata
             {
                 float4 vertex : POSITION;
                 float2 uv : TEXCOORD0;
             };
 
             struct v2f
             {
                 float2 uv : TEXCOORD0;
                 UNITY_FOG_COORDS( 1 )
                 float4 vertex : POSITION;
             };
 
             sampler2D _MainTex;
             float4 _MainTex_ST;
 
             float _Speed;
             float _Amplitude;
             float _Period;
             
             v2f vert( appdata v )
             {
                 v2f o;
 
                 float t = _Time * _Speed;
 
                 v.vertex.y = sin( ( v.vertex.x + t ) * _Period ) * _Amplitude;
 
                 o.vertex = mul( UNITY_MATRIX_MVP, v.vertex );
                 o.uv = TRANSFORM_TEX( v.uv, _MainTex );
                 UNITY_TRANSFER_FOG( o, o.vertex );
                 return o;
             }
             
             fixed4 frag( v2f i ) : SV_Target
             {
                 // sample the texture
                 fixed4 col = tex2D( _MainTex, i.uv );
                 // apply fog
                 UNITY_APPLY_FOG( i.fogCoord, col );
                 return col;
             }
             ENDCG
         }
     }
 }

I would love some hints on what might be wrong here, because I'm completely stumped.

In case it matters, the version of Unity I'm using is 5.3.2f1, Personal Edition. Let me know if any additional details are needed.

editor.png (320.8 kB)
game.png (180.6 kB)
Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

3 People are following this question.

avatar image avatar image avatar image

Related Questions

How do I make a water shader that has depth. 1 Answer

See backside of a transparent emissive shader? 0 Answers

Turning standard materials from opaque to transparent and back in runtime 1 Answer

Shader for distorting a texture as if it were on a sphere 3 Answers

Alpha texture overlaying opaque texture, both with colors? 0 Answers

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges