Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 WilliamS · Sep 09, 2011 at 05:14 PM · shadervertex shader3.4

Vertex displacement shader not working

I am trying to combine a vertex wiggle shader one our programmers converted from CGFx with the built-in Reflect BumpSpec shader.

Here is the original:

     Shader "Bio/Wiggle" {
     Properties {
       _MainTex ("Texture", 2D) = "white" {}
       _TimeScale ("Time Scaling", Range(0,10)) = 1.0
       _XAmount ("X Wiggle", Range(0,5)) = 1.0
       _YAmount ("Y Wiggle", Range(0,5)) = 1.0
     }
     SubShader {
       Tags { "RenderType" = "Opaque" }
       Cull Off
       CGPROGRAM
       #pragma surface surf Lambert vertex:vert
     
       
       struct Input {
           float2 uv_MainTex;
       };
       float _XAmount;
       float _YAmount;
       float _TimeScale;
       void vert(inout appdata_full v)
       {
         float time = _TimeScale * _Time.y;
         float iny = v.vertex.y * _YAmount + time;
         float wiggleX = sin(iny) * _XAmount;
         float wiggleY = cos(iny) * _XAmount;
         v.normal.y = v.normal.y + wiggleY;
         normalize(v.normal);
         v.vertex.x = v.vertex.x + wiggleX;
         
       }
       
       sampler2D _MainTex;
 
       void surf (Input IN, inout SurfaceOutput o) {
           
           o.Albedo = tex2D (_MainTex, IN.uv_MainTex).rgb;
 
       }
       ENDCG
     }
     Fallback "Diffuse"
   }

And here is my attempt at combining with the reflective shader:

     Shader "Bio/Reflective Bumped Specular Wiggle" {
 Properties {
     _Color ("Main Color", Color) = (1,1,1,1)
     _SpecColor ("Specular Color", Color) = (0.5,0.5,0.5,1)
     _Shininess ("Shininess", Range (0.01, 1)) = 0.078125
     _ReflectColor ("Reflection Color", Color) = (1,1,1,0.5)
     _MainTex ("Base (RGB) RefStrGloss (A)", 2D) = "white" {}
     _Cube ("Reflection Cubemap", Cube) = "" { TexGen CubeReflect }
     _BumpMap ("Normalmap", 2D) = "bump" {}
     _TimeScale ("Time Scaling", Range(0,10)) = 1.0
     _XAmount ("X Wiggle", Range(0,5)) = 1.0
     _YAmount ("Y Wiggle", Range(0,5)) = 1.0
 }
 
 SubShader {
     Tags { "RenderType"="Opaque" }
     LOD 400
 CGPROGRAM
 #pragma surface surf BlinnPhong
 #pragma target 3.0
 
 sampler2D _MainTex;
 sampler2D _BumpMap;
 samplerCUBE _Cube;
 
 fixed4 _Color;
 fixed4 _ReflectColor;
 half _Shininess;
 
 struct Input {
     float2 uv_MainTex;
     float2 uv_BumpMap;
     float3 worldRefl;
     INTERNAL_DATA
 };
 
 float _XAmount;
 float _YAmount;
 float _TimeScale;
 void vert(inout appdata_full v)
     {
     float time = _TimeScale * _Time.y;
     float iny = v.vertex.y * _YAmount + time;
     float wiggleX = sin(iny) * _XAmount;
     float wiggleY = cos(iny) * _XAmount;
     v.normal.y = v.normal.y + wiggleY;
     normalize(v.normal);
     v.vertex.x = v.vertex.x + wiggleX;    
     }
 
 void surf (Input IN, inout SurfaceOutput o) {
     fixed4 tex = tex2D(_MainTex, IN.uv_MainTex);
     fixed4 c = tex * _Color;
     o.Albedo = c.rgb;
     
     o.Gloss = tex.a;
     o.Specular = _Shininess;
     
     o.Normal = UnpackNormal(tex2D(_BumpMap, IN.uv_BumpMap));
     
     float3 worldRefl = WorldReflectionVector (IN, o.Normal);
     fixed4 reflcol = texCUBE (_Cube, worldRefl);
     reflcol *= tex.a;
     o.Emission = reflcol.rgb * _ReflectColor.rgb;
     o.Alpha = reflcol.a * _ReflectColor.a;
 }
 ENDCG
 }
 
 FallBack "Reflective/Bumped Diffuse"
 }

The original works fine for the vertex wiggle, but I can't figure out what I broke. I'm an artist with not much coding experience. Thanks!

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

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Owen-Reynolds · Sep 10, 2011 at 03:14 PM

On the first, there's a line:

 #pragma surface surf Lambert vertex:vert

...and below the replacement shader is named vert: void vert(inout appdata_full v). The part vertex:vert (I assume) says to use the new vert instead of the standard vertex shader. In your replacement you have just #pragma surface surf BlinnPhong, which substitutes your BlinnPhong, but leaves out the replacement vert.

Comment
Add comment · Show 1 · Share
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 WilliamS · Sep 12, 2011 at 01:46 PM 0
Share

That worked perfectly Owen. Thanks!

avatar image
0

Answer by WilliamS · Sep 12, 2011 at 02:28 PM

I have one other question regarding this shader. I am trying to add in a random, smooth translation in the XYZ coordinates. I have tried the perlin noise that is part of the Unity Procedural package, but it wouldn't work for me. I kept getting warnings about behaviours missing, etc.

We are making a game that takes place inside of a cell, so I need some cheap, ambient movement for organelles. Any suggestions on where to look or how to get started would be appreciated.

Comment
Add comment · Show 1 · Share
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 Owen-Reynolds · Sep 12, 2011 at 08:05 PM 0
Share

I'd write this as a separate Q. You're wanting to warp the background "cell wall" texture like a lava-lamp? (it looks like you are already wiggling the verts)

I'd guess someone who knows the Perlin package can give you an easier Unity way than my hammer and tongs approach. If not, I can dig it up, but you won't like it.

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Mobile performance of splat map shader with distance blending 0 Answers

Shader Fallback changed in 3.4? 1 Answer

Modify vertex position using shaders on Windows Phone 8 0 Answers

How do I render a scene's depth buffer when I have custom vertex shaders? 0 Answers

UnityPixelSnap in custom vertex shader behaves differently to implementation in default sprite shader. 0 Answers


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