Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • 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 kilian277 · Sep 30, 2013 at 03:51 PM · shadershaderswatersurfacebootcamp

Shader add vertex displacement

Hi,

i'm a total noob on shaders so that's why i'm asking here since nothing works wat i do.

i had a existing shader that does flowmaps and i want to add vertex displacement and sinus animation.

So i found the bootcamp water and now i'm trying to add things from the bootcamp water shader to the existing shader.

But it doesn't work

Here's the shader:

 Shader "Custom/Animated Water" {
     Properties {
         _Color ("Water Color (RGB) Transparency (A)", COLOR) = (1, 1, 1, 0.5)
         _BumpMap ("Normal Map 1", 2D) = "white" {}
         _BumpMap2 ("Normal Map 2", 2D) = "white" {}
         _FlowMap ("Flow Map", 2D) = "white" {}
         _NoiseMap ("Noise Map", 2D) = "black" {}
         _Cube ("Reflection Cubemap", Cube) = "white" { TexGen CubeReflect }
         _Cycle ("Cycle", float) = 1.0
         _Speed ("Speed", float) = 0.05
         _SpecColor ("Specular Color", Color) = (0.5,0.5,0.5,1)
         _Shininess ("Shininess", Range (0.01, 2)) = 0.078125
         _ReflectColor ("Reflection Color", Color) = (1,1,1,0.5)
         _Displacement ("_Displacement", Range (0.0, 2.0)) = 1.0
         _DisplacementTiling ("_DisplacementTiling", Range (0.1, 4.0)) = 1.0
         _DisSpeed("_DisSpeed", Range (0.0, 10.0)) = 0.8
     }
 
     // Common water code that will be used in all CGPROGRAMS below
 CGINCLUDE
 #include "UnityCG.cginc"
 
 
 struct v2f_aniOnly {
     float4 vertex : POSITION;
 };
 
 sampler2D _MainTex;
         
 float _Displacement;
 float _DisplacementTiling;        
 float _DisSpeed;
                 
 half3 vertexOffsetObjectSpace(appdata_full v) {
     return v.normal.xyz * sin((length(v.vertex.zy + v.color.rgb-0.5) + _Time.w * _DisSpeed )*_DisplacementTiling) * _Displacement * 1.5 * v.color.a;                
 }
                 
 v2f_aniOnly vert_onlyAnimation(appdata_full v)
 {
     v2f_aniOnly o;
                     
     v.vertex.xyz += vertexOffsetObjectSpace(v);        
     o.vertex = mul(UNITY_MATRIX_MVP, v.vertex);                
 
     return o;
 }
 ENDCG
 
     SubShader
     {
         Tags { "RenderType"="Transparent" "Queue"="Transparent" }
         Blend SrcAlpha OneMinusSrcAlpha
 
         LOD 200
         
             CGPROGRAM
             #pragma surface surf BlinnPhong 
             #pragma vertex vert_onlyAnimation    
             #pragma target 3.0
             
             float4 _Color;
             sampler2D _BumpMap;
             sampler2D _BumpMap2;
             samplerCUBE _Cube;
             sampler2D _FlowMap;
             sampler2D _NoiseMap;
             float _Cycle;
             float _Speed;
             float _Shininess;
             float4 _ReflectColor;
 
         
 
             struct Input {
                 float2 uv_BumpMap;
                 float2 uv_FlowMap;
                 float3 worldRefl;
                 float3 worldNormal;
                 float3 viewDir;
                 INTERNAL_DATA
             };
 
             //normal water shader
             void surf (Input IN, inout SurfaceOutput o) {
                 float3 flowDir = tex2D(_FlowMap, IN.uv_FlowMap) * 2 - 1;
                 flowDir *= _Speed;
                 flowDir.y *= -1; // A dirty fix because I didn't want to rearrange my scene, you should be able to remove it
                 float3 noise = tex2D(_NoiseMap, IN.uv_FlowMap);
             
                 float phase = _Time[1] / _Cycle + noise.r * 0.5f;
                 float f = frac(phase);
             
                 half3 n1 = UnpackNormal(tex2D(_BumpMap, IN.uv_BumpMap + flowDir.xy * frac(phase + 0.5f)));
                 half3 n2 = UnpackNormal(tex2D(_BumpMap2, IN.uv_BumpMap + flowDir.xy * f));
             
                 if (f > 0.5f)
                     f = 2.0f * (1.0f - f);
                 else
                     f = 2.0f * f;
             
                 o.Normal = lerp(n1, n2, f);
                 o.Alpha = _Color.a;
                 o.Gloss = 1;
                 o.Specular = _Shininess;
             
                 fixed4 reflcol = texCUBE (_Cube, WorldReflectionVector(IN, o.Normal));
                 o.Albedo = _Color.rgb;
                 o.Emission = reflcol.rgb * _ReflectColor.rgb;
             }
         ENDCG
     }
     FallBack "Reflective/Bumped Specular"
 }    



Can someone help with creating and correct this shader ?

Her'es the bootcamp shader link text

Thanks!

Comment
Add comment · Show 6
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
avatar image kilian277 · Sep 30, 2013 at 04:13 PM 0
Share

i just realized surface shaders can't have vertex displacement :/

avatar image tanoshimi · Sep 30, 2013 at 04:18 PM 0
Share

Sure they can - but only in object space, because the vertex modifier specified in #pragma vertex vert_onlyAnimation acts as a kind of preprocessor to modify appdata_full before it is sent to the vertex shader

avatar image kilian277 · Sep 30, 2013 at 04:32 PM 0
Share

So am i missing some things because i really don't have a clue what i'm doing wrong :)

avatar image kilian277 · Sep 30, 2013 at 04:46 PM 0
Share

$$anonymous$$aybe i should put the link to the bootcamp water shader Shaderdownload

avatar image kilian277 · Sep 30, 2013 at 04:54 PM 0
Share

NV$$anonymous$$ got it working ! just needed to put "inout" at the vertex shader function :)

Show more comments

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.

Follow this Question

Answers Answers and Comments

16 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

Related Questions

Water foam shader that works on planet water 2 Answers

change water4 fade distance 0 Answers

Water Transparency - Help with Shader! 1 Answer

water foam on the horizontal axis 0 Answers

Scale voronoi cells along specific axis in a shader graph,,Scale voronoi cells across specific axis in shader graphs 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