water anim in shader
This commit is contained in:
@@ -10,7 +10,7 @@ namespace OpenRa.Game.Graphics
|
|||||||
{
|
{
|
||||||
class HardwarePalette : Sheet
|
class HardwarePalette : Sheet
|
||||||
{
|
{
|
||||||
const int maxEntries = 16;
|
const int maxEntries = 8;
|
||||||
int allocated = 0;
|
int allocated = 0;
|
||||||
|
|
||||||
public HardwarePalette(Renderer renderer, Map map)
|
public HardwarePalette(Renderer renderer, Map map)
|
||||||
|
|||||||
@@ -31,10 +31,13 @@ namespace OpenRa.Game.Graphics
|
|||||||
|
|
||||||
public GraphicsDevice Device { get { return device; } }
|
public GraphicsDevice Device { get { return device; } }
|
||||||
|
|
||||||
|
public static float waterFrame = 0.0f;
|
||||||
|
|
||||||
public void BeginFrame( float2 r1, float2 r2, float2 scroll )
|
public void BeginFrame( float2 r1, float2 r2, float2 scroll )
|
||||||
{
|
{
|
||||||
device.Begin();
|
device.Begin();
|
||||||
|
|
||||||
|
SpriteShader.SetValue("palDist", waterFrame);
|
||||||
SpriteShader.SetValue("Scroll", scroll);
|
SpriteShader.SetValue("Scroll", scroll);
|
||||||
SpriteShader.SetValue("r1", r1);
|
SpriteShader.SetValue("r1", r1);
|
||||||
SpriteShader.SetValue("r2", r2);
|
SpriteShader.SetValue("r2", r2);
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ namespace OpenRa.Game.Graphics
|
|||||||
|
|
||||||
public static void FastCreateQuad(Vertex[] vertices, ushort[] indices, float2 o, Sprite r, int palette, int nv, int ni)
|
public static void FastCreateQuad(Vertex[] vertices, ushort[] indices, float2 o, Sprite r, int palette, int nv, int ni)
|
||||||
{
|
{
|
||||||
float2 attrib = new float2(palette / 16.0f, channelSelect[(int)r.channel]);
|
float2 attrib = new float2(palette / 8.0f, channelSelect[(int)r.channel]);
|
||||||
|
|
||||||
vertices[nv] = new Vertex(KLerp(o, r.size, 0), r.FastMapTextureCoords(0), attrib);
|
vertices[nv] = new Vertex(KLerp(o, r.size, 0), r.FastMapTextureCoords(0), attrib);
|
||||||
vertices[nv + 1] = new Vertex(KLerp(o, r.size, 1), r.FastMapTextureCoords(1), attrib);
|
vertices[nv + 1] = new Vertex(KLerp(o, r.size, 1), r.FastMapTextureCoords(1), attrib);
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ namespace OpenRa.Game
|
|||||||
|
|
||||||
game.world.Add( new Actor( "mcv", new int2( 5, 5 ), game.players[ 3 ]) );
|
game.world.Add( new Actor( "mcv", new int2( 5, 5 ), game.players[ 3 ]) );
|
||||||
game.world.Add( new Actor( "mcv", new int2( 7, 5 ), game.players[ 2 ] ) );
|
game.world.Add( new Actor( "mcv", new int2( 7, 5 ), game.players[ 2 ] ) );
|
||||||
game.world.Add( new Actor( "mcv", new int2( 9, 5 ), game.players[ 1 ] ) );
|
game.world.Add( new Actor( "mcv", new int2( 9, 5 ), game.players[ 0 ] ) );
|
||||||
game.world.Add( new Actor( "jeep", new int2( 9, 7 ), game.players[ 1 ] ) );
|
game.world.Add( new Actor( "jeep", new int2( 9, 7 ), game.players[ 1 ] ) );
|
||||||
|
|
||||||
sidebar = new Sidebar(Race.Soviet, renderer, game);
|
sidebar = new Sidebar(Race.Soviet, renderer, game);
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Windows.Forms;
|
using System.Windows.Forms;
|
||||||
|
using OpenRa.Game.Graphics;
|
||||||
|
|
||||||
namespace OpenRa.Game
|
namespace OpenRa.Game
|
||||||
{
|
{
|
||||||
@@ -19,8 +20,6 @@ namespace OpenRa.Game
|
|||||||
|
|
||||||
int lastTime = Environment.TickCount + 2000;
|
int lastTime = Environment.TickCount + 2000;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public void Update()
|
public void Update()
|
||||||
{
|
{
|
||||||
int t = Environment.TickCount;
|
int t = Environment.TickCount;
|
||||||
@@ -30,7 +29,9 @@ namespace OpenRa.Game
|
|||||||
lastTime += 40;
|
lastTime += 40;
|
||||||
|
|
||||||
foreach( Actor a in actors )
|
foreach( Actor a in actors )
|
||||||
a.Tick( game, 40 );
|
a.Tick( game, 40 );
|
||||||
|
|
||||||
|
Renderer.waterFrame += 0.05f;
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (Action<World> a in frameEndActions) a(this);
|
foreach (Action<World> a in frameEndActions) a(this);
|
||||||
|
|||||||
20
sprite.fx
20
sprite.fx
@@ -6,6 +6,7 @@ shared texture DiffuseTexture, Palette;
|
|||||||
shared float2 Scroll;
|
shared float2 Scroll;
|
||||||
|
|
||||||
shared float2 r1, r2; // matrix elements
|
shared float2 r1, r2; // matrix elements
|
||||||
|
shared float palDist;
|
||||||
|
|
||||||
sampler s_DiffuseTexture = sampler_state {
|
sampler s_DiffuseTexture = sampler_state {
|
||||||
Texture = <DiffuseTexture>;
|
Texture = <DiffuseTexture>;
|
||||||
@@ -64,11 +65,28 @@ VertexOut Simple_vp(VertexIn v) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const float2 texelOffset = float2( 0, 1.0f/32.0f );
|
const float2 texelOffset = float2( 0, 1.0f/32.0f );
|
||||||
|
const float animBase = (96.0f/256.0f);
|
||||||
|
const float animLen = (7.0f/256.0f);
|
||||||
|
|
||||||
|
float DoPaletteAnimation( float x )
|
||||||
|
{
|
||||||
|
float a = (x - animBase) / animLen;
|
||||||
|
float b = (a >= 0 && a <= 1) ? 1.0f : 0.0f;
|
||||||
|
float _;
|
||||||
|
float c = modf(a + palDist, _);
|
||||||
|
|
||||||
|
return lerp( a, c, b ) * animLen + animBase;
|
||||||
|
}
|
||||||
|
|
||||||
|
float2 DoPaletteAnimation2( float2 x )
|
||||||
|
{
|
||||||
|
return float2( DoPaletteAnimation(x.x), x.y );
|
||||||
|
}
|
||||||
|
|
||||||
float4 Palette_fp(FragmentIn f) : COLOR0 {
|
float4 Palette_fp(FragmentIn f) : COLOR0 {
|
||||||
float4 x = tex2D(s_DiffuseTexture, f.Tex0.xy);
|
float4 x = tex2D(s_DiffuseTexture, f.Tex0.xy);
|
||||||
float2 p = float2( dot(x, f.ChannelMask), f.Tex0.z );
|
float2 p = float2( dot(x, f.ChannelMask), f.Tex0.z );
|
||||||
return tex2D(s_PaletteTexture, p + texelOffset);
|
return tex2D(s_PaletteTexture, DoPaletteAnimation2(p) + texelOffset);
|
||||||
}
|
}
|
||||||
|
|
||||||
technique low_quality {
|
technique low_quality {
|
||||||
|
|||||||
Reference in New Issue
Block a user