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!
Add a transform.eulerAngles = new Vector3(0, 0, transform.eulerAngles.z) It will fix this
– PositiveAnion