- Home /
mainTextureOffset scrolling Performance issue
Hi, I have big performance issue with scrolling background with mainTextureOffset. It is 2D scrolling endless runner type of game and uses mainTextureOffset to scroll bacgrounds. I generated Quad and gave the background texture material and set static to the Quad. I tested on the ipad. Game starts smooth but the background starts to lose its smoothness. Other gameobjects like player, obstacles are running smooth. I'm using following script to animate background.
float scrollSpeed = 5;
Vector2 scrolling = new Vector2(0, 0);
void Update(){
// Calculating scroll speed according to covered distance.
scrollSpeed = CalculateScrollingSpeed();
//Apply scroll speed to scroll vector
scrolling.x = scrollSpeed;
//Scroll the first and second layers
firstLayerRender.material.mainTextureOffset += scrolling * Time.deltaTime;
secondLayerRender.material.mainTextureOffset += scrolling * Time.deltaTime * 0.5f;
}
No solution yet ;-(. I gave up scrolling with uv. I decided to scroll by transform position. UV scrolling hurt my feeling :-)
Answer by Andres-Fernandez · Mar 12, 2014 at 04:20 PM
I like using this shader when uv_scrolling:
Shader "ScrollingTexture" {
Properties {
_MainTint ("Diffuse Tint", Color) = (1,1,1,1)
_MainTex ("Base (RGB)", 2D) = "white" {}
_ScrollXSpeed ("X Scroll Speed", Range(0, 10)) = 2
_ScrollYSpeed ("Y Scroll Speed", Range(0, 10)) = 2
}
SubShader {
Tags { "RenderType"="Opaque" }
LOD 200
CGPROGRAM
#pragma surface surf Lambert
fixed4 _MainTint;
sampler2D _MainTex;
fixed _ScrollXSpeed;
fixed _ScrollYSpeed;
struct Input {
float2 uv_MainTex;
};
void surf (Input IN, inout SurfaceOutput o) {
// Get UVs
fixed2 scrolledUV = IN.uv_MainTex;
// Modify them by time
fixed xScrollValue = _ScrollXSpeed * _Time;
fixed yScrollValue = _ScrollYSpeed * _Time;
// Apply them
scrolledUV += fixed2(xScrollValue, yScrollValue);
half4 c = tex2D (_MainTex, scrolledUV);
o.Albedo = c.rgb * _MainTint;
o.Alpha = c.a;
}
ENDCG
}
FallBack "Diffuse"
}
Answer by David-Lindsay · Apr 01, 2016 at 04:05 AM
fixed has an incredibly small range. Are you sure this isn't overflowing?
Try using floats for UV coordinates and see if it's smoother.
Also... why do this in frag? UVs are per vertex, so no point to calculate per pixel. Recommend you put UV calc into vertex shader.
Your answer
Follow this Question
Related Questions
What in my stats makes the game crash on web or iPad 1 Answer
Game Lagging in iOS 0 Answers
Confusing Ipad performance problems - help! 1 Answer
Mesh Collider slow down the app 1 Answer