2.滚屏
滚屏概述:
打飞机游戏场景背景设计通常很简单,因为角色敌人道具等都不与背景发生交互事件。开发者只需要根据设定的游戏类型,为游戏制作背景,模拟一个大环境即可。
滚屏原理:
材质UV动画,实现背景图片的滚屏循环。
实现方法:
步骤1:
创建背景载体。创建立方体->适当缩放物体,使物体形状上接近长方形,这样正面在视觉上接近竖版手机屏幕。
步骤2:SS
创建背景材质球。项目视图中创建材质球->将材质球赋给步骤1创建的cube物体->将材质球命名为UVAnim。
步骤3:
3.1为材质球设置Shader文件。将制作好的UV循环播放的Shader文件,导入到项目视图中。这里需要注意,引擎对shader文件识别有一定命名条件,命名原则实例: Common_Diffuse_UVani.wjshader,其中只有VUani可以*命名。选择UVAnim,common->Diffuse->UVani.wjshader,如下图2-3-1-1所示。
图2-3-1-1
3.2屏幕的滚屏最终效果,屏幕一直像下滚动播放,shader文件如下所示,滚屏效果如图2-3-2-1所示。
图2-3-2-1
shader文件代码:
01 |
WJShader "Surface_Surface_Diffuse"
|
05 |
Vector [_diffuseColor]<diffuse color= "" > = "1.0, 1.0, 1.0, 1.0"
|
06 |
sampler2D [_diffuseMap]<diffuse map= "" (rgb)= "" > = "sys:white.dds"
|
07 |
Vector [_speed] = "0.1, 0.1, 0.1, 0.1"
|
10 |
Technique "Surface_Surface_Diffuse"
|
22 |
samplerState "g_LightLitMap" [Clamp] [Point]
|
23 |
samplerState "_diffuseMap" [Wrap] [Linear]
|
24 |
samplerState "g_Lightmap" [Clamp] [Linear]
|
28 |
#pragma surface surfMain customlight lightmap:on |
29 |
sampler2D _diffuseMap; |
34 |
float2 _diffuseMap_UV; |
38 |
float4 customlight(SURFACE_OUTPUT sin, float3 viewDir, float lightAtten)
|
40 |
float4 diffuse = float4(0.0,0.0,0.0,0.0); |
41 |
float4 specular = float4(0.0,0.0,0.0,0.0); |
42 |
Forward_Shading(sin.Normal,viewDir,sin.Shininess,diffuse,specular,lightAtten); |
43 |
float4 c = diffuse * sin.Diffuse; |
46 |
void surfMain(INPUT p, inout SURFACE_OUTPUT o)
|
48 |
p._diffuseMap_UV.x += _speed.x*g_Time; |
49 |
p._diffuseMap_UV.y += _speed.y*g_Time; |
50 |
o.Diffuse.xyz = tex2D(_diffuseMap,p._diffuseMap_UV).xyz*_diffuseColor.xyz; |
53 |
o.Specular = float4(0.0f,0.0f,0.0f,0.0f); |
54 |
o.Normal = float4 ( normalize(mul(g_InvTransModel, float4(p.input_Normal, 1.0f)).xyz), 0.0f ); |