hello
im working on a flickering fx shader powered by _Time and want to add an offset-value calculated out of the objects-worldposition to get different effects on multiple objects.
but it work very strange.
moving an object works out like i want but…
… changing the camera position or angle takes also effect ???
pleasy help with some functional code coz im not very experienced with cg-coding
thanks, turbo
Shader "turbo/LightFx/Additive" {
Properties {
_TintColor ("Tint Color", Color) = (0.5,0.5,0.5,0.5)
_MainTex ("Texture", 2D) = "white" {}
_NoiseTex ("LightFX Texture", 2D) = "white" {}
_Boost ("Light Boost", Range(0.01, 10)) = 1
_Speed ("Speed", Range(0.1, 100)) = 1
_Style ("Style", Range(0, 1)) = 0.1
}
Category {
Tags { "Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent" }
Blend SrcAlpha One
AlphaTest Greater .01
ColorMask RGB
Cull Off Lighting Off ZWrite Off Fog { Color (0,0,0,0) }
BindChannels {
Bind "Color", color
Bind "Vertex", vertex
Bind "TexCoord", texcoord
}
// ---- Fragment program cards
SubShader {
Pass {
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#pragma fragmentoption ARB_precision_hint_fastest
#pragma multi_compile_particles
#include "UnityCG.cginc"
sampler2D _MainTex;
sampler2D _NoiseTex;
fixed4 _TintColor;
struct appdata_t {
float4 vertex : POSITION;
fixed4 color : COLOR;
float2 texcoord : TEXCOORD0;
};
struct v2f {
float4 vertex : POSITION;
fixed4 color : COLOR;
float2 texcoord : TEXCOORD0;
};
float4 _MainTex_ST;
v2f vert (appdata_t v)
{
v2f o;
o.vertex = mul(UNITY_MATRIX_MVP, v.vertex);
o.color = v.color;
o.texcoord = TRANSFORM_TEX(v.texcoord,_MainTex);
return o;
}
sampler2D _CameraDepthTexture;
fixed _Boost;
fixed _Speed;
fixed _Style;
fixed4 frag (v2f i) : COLOR
{
float4 wPos = mul(_Object2World, float4(0,0,0,-1)); // getting Object-Worldposition
fixed panner = frac(_Time[0] + wPos.x * wPos.y * wPos.z); // using Object-Worldposition
fixed4 noisetex = tex2D (_NoiseTex, float2( panner * _Speed, _Style));
return 2.0f * i.color * _TintColor * tex2D(_MainTex, i.texcoord) * (noisetex.r * _Boost);
}
ENDCG
}
}
// ---- Dual texture cards
SubShader {
Pass {
SetTexture [_MainTex] {
constantColor [_TintColor]
combine constant * primary
}
SetTexture [_MainTex] {
combine texture * previous DOUBLE
}
}
}
// ---- Single texture cards (does not do color tint)
SubShader {
Pass {
SetTexture [_MainTex] {
combine texture * primary
}
}
}
}
}