- Home /
A way to move Texture's offset in runtime?
Hey, I have a mirror like object with a reflective shader on it reflecting a cube map. That works fine as expected. The thing is, the object is a child of the camera, thus because the view angle never changes, you can't see it 'reflecting'. I wanted to fake the reflecting by offsetting the cubemap while the player moved, but I can't seem to find how to do it since the Texture nor Shader class gives the option. Is it not possible to change the offset at runtime? Thanks
EDIT: apparently I can't offset cubemaps so I won't be able to do this, unless some one is nice enough to make a shader where I can offset the cubemap
Answer by kennypu · Feb 11, 2011 at 11:53 PM
I found the answer, apparently the Material Class had a SetTextureOffset method you can use.
Answer by mrde · Feb 11, 2011 at 11:20 PM
I wrote some shader code, maybe help you
Shader "mapTestSurface" {
Properties {
_MainTex ("Texture", 2D) = "white" {}
_MaskTex ("Texture", 2D) = "white" {}
//_Cutoff ("Alpha cutoff", Range(0,1)) = 0.5
_XOffset ("X offset", Range(0, 1.0)) = 0
_YOffset ("Y offset", Range(0, 1.0)) = 0
}
SubShader { //Tags { "RenderType" = "Transparent" } //Tags { "RenderType"="Opaque" } Tags {"IgnoreProjector"="True" "RenderType"="TransparentCutout"} Tags { "Queue" = "Geometry+1" } ZWrite Off ZTest Always LOD 200 Lighting Off
CGPROGRAM //#pragma surface surf Lambert alpha #pragma surface surf WrapLambert alpha struct Input { float2 uv_MainTex; }; sampler2D _MainTex; sampler2D _MaskTex; float _XOffset; float _YOffset;
half4 LightingWrapLambert (SurfaceOutput s, half3 lightDir, half atten) { half NdotL = dot (s.Normal, lightDir); half diff = NdotL 0.5; + 0.5; half4 c; //c.rgb = s.Albedo /_LightColor0.rgb/ (diff atten * 2); c.rgb = s.Albedo; c.a = s.Alpha; return c; }
void surf (Input IN, inout SurfaceOutput o) { float2 a = float2( _XOffset, _YOffset); float2 scale = float2(0.3, 0.3); a = a + IN.uv_MainTex * scale;
half4 c = tex2D (_MainTex, a);
o.Albedo = c.rgb;
half4 mask = tex2D (_MaskTex, IN.uv_MainTex);
o.Alpha = c.a;
//if (mask.a < 1f)
o.Alpha = c.a * mask.a;
} ENDCG } Fallback "Diffuse"
}
this didn't really do what i was looking for. the second texture isn't visible, and you can see the object through other objects. Thanks though
Your answer
Follow this Question
Related Questions
Reflective surface/texture bug in build only (works in play mode in editor) 1 Answer
Applying decals / textures to uneven surfaces runtime 1 Answer
How to update texture during runtime to display damage? 0 Answers
Textures different between editor and device 1 Answer
[Closed] Extracting current state of texture as new texture 0 Answers