• 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 gangafinti · Jul 02, 2015 at 10:51 PM · cg

Ocean shader

  1. List item

I am making a shader that makes a cartoony ocean, I am currently using sin and cos but the waves are too repetetive, does anyone know a algorithm to make the waves more random? This is what I have at the moment, thanks in advance!

 Shader "Custom/NoobShader_03" {
     Properties {
         _Color ("Color", Color) = (0,0.55,0.83,1)
     
         _Scale ("Wave Scale", float) = 0.7
         _Frequency ("Frequency", float) = 0.6
         _Speed ("Speed", float) = 0.5
         
         _Scale2 ("Wave Scale", float) = 0.6
         _Frequency2 ("Frequency", float) = 1
         _Speed2 ("Speed", float) = 1
     }
     SubShader {
         Pass{
         Tags { "LightMode" = "ForwardBase"}
         CGPROGRAM
         #pragma vertex vert
         #pragma fragment frag
         
         float4 _Color;
         
         float _Scale;
         float _Frequency;
         float _Speed;
         
         float _Scale2;
         float _Frequency2;
         float _Speed2;
         
         float4 _LightColor0;
             
         struct VertexOutput
         {
             float4 pos : SV_POSITION;
             float3 nor : NORMAL;
             float4 col : COLOR;
         };
         
         struct VertexInput
         {
             float4 vertex : POSITION;
             float3 normal : NORMAL;
         };
         
         struct FragmentOutput
         {
             float4 color : COLOR;
         };
 
         VertexOutput vert (VertexInput i)
         {
             VertexOutput VOUT;
             float newPos = _Scale * sin(_Time.w * _Speed + i.vertex.x * _Frequency);
             float newPos2 = _Scale2 * cos(_Time.w * _Speed2 + i.vertex.z * _Frequency2);
             float4 tempPos = i.vertex;
             tempPos.y += newPos * newPos2;
             
             float3 tempNor = normalize( mul(float4(i.normal,0.0),_World2Object).xyz);
             tempNor.y += newPos * newPos2;
             
             VOUT.pos = mul(UNITY_MATRIX_MVP,tempPos);
             VOUT.nor = tempNor;
 
             float3 normalDirection = tempNor;
             float3 lightDirection;
             float atten = 1.0;
             
             lightDirection = normalize(_WorldSpaceLightPos0.xyz);
             
             float3 diffuseRefflection = atten * _LightColor0.xyz * _Color.rgb *  max( 0.0, dot(normalDirection, lightDirection));
             float3 lightFinal = diffuseRefflection + UNITY_LIGHTMODEL_AMBIENT.xyz;
             
             VOUT.col = float4(lightFinal, 1.0);
             
             return VOUT;
         }
         
         FragmentOutput frag(VertexOutput v) 
         {
             FragmentOutput FOUT;
             FOUT.color = v.col;
             return FOUT;
         }
         ENDCG
         }
     } 
     FallBack "Diffuse"
 }


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

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

21 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Blinn-Phong shader (vertex lit) from scratch. 1 Answer

unity_LightmapMatrix in Cg ? 1 Answer

Modify custom shader to add bump and normal maps 2 Answers

Material doesn't have a color property '_Color' 0 Answers

Shader compiler: internal error compiling shader snippet type=0 platform=0: 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges