improved shader performance
This commit is contained in:
parent
be8e56cf27
commit
24b773d845
3 changed files with 160 additions and 38 deletions
|
@ -11,6 +11,7 @@ int BorderSize;
|
||||||
float R;
|
float R;
|
||||||
float G;
|
float G;
|
||||||
float B;
|
float B;
|
||||||
|
float2 ImageSize;
|
||||||
|
|
||||||
sampler2D SpriteTextureSampler = sampler_state
|
sampler2D SpriteTextureSampler = sampler_state
|
||||||
{
|
{
|
||||||
|
@ -25,46 +26,156 @@ struct VertexShaderOutput
|
||||||
|
|
||||||
float4 MainPS(VertexShaderOutput input) : COLOR
|
float4 MainPS(VertexShaderOutput input) : COLOR
|
||||||
{
|
{
|
||||||
float4 color = tex2D(SpriteTextureSampler, input.TextureCoordinates);
|
// float4 color = tex2Dlod(SpriteTextureSampler, float4 (input.TextureCoordinates.x, input.TextureCoordinates.y, 0,0));
|
||||||
|
|
||||||
if (color.a > 0)
|
// if (color.a > 0)
|
||||||
{
|
// {
|
||||||
return color;
|
// return color;
|
||||||
}
|
// }
|
||||||
|
|
||||||
float2 offsetX = float2(TexelSize.x, 0);
|
// float2 pixelSize.x = float2(pixelSize.x, 0);
|
||||||
float2 offsetY = float2( 0, TexelSize.y );
|
// float2 pixelSize.y = float2( 0, pixelSize.y );
|
||||||
|
|
||||||
for (int i = 1; i < 10; i++)
|
// for (int i = 1; i < 10; i++)
|
||||||
{
|
// {
|
||||||
if (i<=BorderSize)
|
// if (i<=BorderSize)
|
||||||
{
|
// {
|
||||||
float4 c1 = tex2D(SpriteTextureSampler, input.TextureCoordinates + offsetX*i);
|
// float4 c1 = tex2Dlod(SpriteTextureSampler, float4((input.TextureCoordinates + pixelSize.x*i).x, (input.TextureCoordinates + pixelSize.x*i).y,0,0));
|
||||||
float4 c2 = tex2D(SpriteTextureSampler, input.TextureCoordinates - offsetX*i);
|
// float4 c2 = tex2Dlod(SpriteTextureSampler, float4((input.TextureCoordinates - pixelSize.x*i).x,(input.TextureCoordinates - pixelSize.x*i ).y ,0,0));
|
||||||
float4 c3 = tex2D(SpriteTextureSampler, input.TextureCoordinates + offsetY*i);
|
// float4 c3 = tex2Dlod(SpriteTextureSampler, float4((input.TextureCoordinates + pixelSize.y*i ).x,(input.TextureCoordinates + pixelSize.y*i ).y ,0,0));
|
||||||
float4 c4 = tex2D(SpriteTextureSampler, input.TextureCoordinates - offsetY*i);
|
// float4 c4 = tex2Dlod(SpriteTextureSampler, float4((input.TextureCoordinates - pixelSize.y*i ).x,(input.TextureCoordinates - pixelSize.y*i ).y ,0,0));
|
||||||
float4 d1 = tex2D(SpriteTextureSampler, input.TextureCoordinates - (offsetX+offsetY)*i);
|
// float4 d1 = tex2Dlod(SpriteTextureSampler, float4((input.TextureCoordinates - (pixelSize.x+pixelSize.y)*i ).x,(input.TextureCoordinates - (pixelSize.x+pixelSize.y)*i ).y ,0,0));
|
||||||
float4 d2 = tex2D(SpriteTextureSampler, input.TextureCoordinates + (offsetX+offsetY)*i);
|
// float4 d2 = tex2Dlod(SpriteTextureSampler, float4((input.TextureCoordinates + (pixelSize.x+pixelSize.y)*i).x,(input.TextureCoordinates + (pixelSize.x+pixelSize.y)*i).y ,0,0));
|
||||||
float4 d3 = tex2D(SpriteTextureSampler, input.TextureCoordinates - (offsetX-offsetY)*i);
|
// float4 d3 = tex2Dlod(SpriteTextureSampler, float4((input.TextureCoordinates - (pixelSize.x-pixelSize.y)*i ).x,(input.TextureCoordinates - (pixelSize.x-pixelSize.y)*i ).y ,0,0));
|
||||||
float4 d4 = tex2D(SpriteTextureSampler, input.TextureCoordinates - (-offsetX+offsetY)*i);
|
// float4 d4 = tex2Dlod(SpriteTextureSampler, float4((input.TextureCoordinates - (-pixelSize.x+pixelSize.y)*i).x,(input.TextureCoordinates - (-pixelSize.x+pixelSize.y)*i).y ,0,0));
|
||||||
|
|
||||||
if (color.a != c1.a || color.a != c2.a|| color.a != c3.a|| color.a != c4.a
|
// if (color.a != c1.a || color.a != c2.a|| color.a != c3.a|| color.a != c4.a
|
||||||
|| color.a != d1.a
|
// || color.a != d1.a
|
||||||
|| color.a != d2.a
|
// || color.a != d2.a
|
||||||
|| color.a != d3.a
|
// || color.a != d3.a
|
||||||
|| color.a != d4.a
|
// || color.a != d4.a
|
||||||
)
|
// )
|
||||||
{
|
// {
|
||||||
color.r=R;
|
// color.r=R;
|
||||||
color.g=G;
|
// color.g=G;
|
||||||
color.b=B;
|
// color.b=B;
|
||||||
color.a=1;
|
// color.a=1;
|
||||||
}
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
// return color;
|
||||||
|
//float pixelSize.x = float(1/ImageSize.x);
|
||||||
|
//float pixelSize.y = float(1/ImageSize.y );
|
||||||
|
|
||||||
|
// ###########################################################################
|
||||||
|
|
||||||
|
|
||||||
|
// float2 pixelSize = 1/ float2((float) ImageSize.x, (float) ImageSize.y);
|
||||||
|
|
||||||
|
// float4 color = tex2D(SpriteTextureSampler, input.TextureCoordinates);
|
||||||
|
// if(color.a==1) {return color;}
|
||||||
|
|
||||||
|
// // float2 offsets[8] = {float2(-1,0), float2(1,0), float2(0,1), float2(0,-1), float2(-1,1), float2(1,1), float2(1,-1), float2(-1,-1)};
|
||||||
|
// float2 offsets[8] = {float2(-pixelSize.x,0),
|
||||||
|
// float2(pixelSize.x,0),
|
||||||
|
// float2(0,pixelSize.y),
|
||||||
|
// float2(0,-pixelSize.y),
|
||||||
|
// float2(-pixelSize.x,pixelSize.y),
|
||||||
|
// float2(pixelSize.x,pixelSize.y),
|
||||||
|
// float2(pixelSize.x,-pixelSize.y),
|
||||||
|
// float2(-pixelSize.x,-pixelSize.y)};
|
||||||
|
// int i, j = 0;
|
||||||
|
|
||||||
|
// while(i < 10)
|
||||||
|
// {
|
||||||
|
// i++;
|
||||||
|
// j=0;
|
||||||
|
// while (j < 8)
|
||||||
|
// {
|
||||||
|
// // float2 curUV = input.TextureCoordinates + ((offsets[j] * pixelSize.x + offsets[j] *pixelSize.y)* i);
|
||||||
|
// float curUVx = input.TextureCoordinates.x + offsets[j].x * (float)i;
|
||||||
|
// float curUVy = input.TextureCoordinates.y + offsets[j].y * (float)i;
|
||||||
|
// float4 offsetsample = tex2Dlod(SpriteTextureSampler, float4(curUVx, curUVy,0,0));
|
||||||
|
|
||||||
|
// if(
|
||||||
|
// offsetsample.a==1
|
||||||
|
|
||||||
|
// )
|
||||||
|
// {
|
||||||
|
// return float4(
|
||||||
|
// R,
|
||||||
|
// G,
|
||||||
|
// B,
|
||||||
|
// 1);
|
||||||
|
|
||||||
|
// }
|
||||||
|
|
||||||
|
// j++;
|
||||||
|
// }
|
||||||
|
|
||||||
|
|
||||||
|
// }
|
||||||
|
|
||||||
|
// return color;
|
||||||
|
|
||||||
|
//##############################################################
|
||||||
|
|
||||||
|
float2 pixelSize = 1/ float2((float) ImageSize.x, (float) ImageSize.y);
|
||||||
|
int px = (int) input.TextureCoordinates.x*ImageSize.x;
|
||||||
|
int py = (int) input.TextureCoordinates.y*ImageSize.y;
|
||||||
|
float4 color = tex2D(SpriteTextureSampler, input.TextureCoordinates);
|
||||||
|
|
||||||
|
if(color.a==1) {return color;}
|
||||||
|
|
||||||
|
// float2 offsets[8] = {float2(-1,0), float2(1,0), float2(0,1), float2(0,-1), float2(-1,1), float2(1,1), float2(1,-1), float2(-1,-1)};
|
||||||
|
float2 offsets[8] = {float2(-1,0),
|
||||||
|
float2(1,0),
|
||||||
|
float2(0,1),
|
||||||
|
float2(0,-1),
|
||||||
|
float2(-1,1),
|
||||||
|
float2(1,1),
|
||||||
|
float2(1,-1),
|
||||||
|
float2(-1,-1)};
|
||||||
|
int i, j = 0;
|
||||||
|
|
||||||
|
// while(i < 10)
|
||||||
|
// {
|
||||||
|
// i++;
|
||||||
|
// j=0;
|
||||||
|
|
||||||
|
while (j < 8)
|
||||||
|
{
|
||||||
|
// float2 curUV = input.TextureCoordinates + ((offsets[j] * pixelSize.x + offsets[j] *pixelSize.y)* i);
|
||||||
|
float checkpx=(float)px+0.5+(float)10*offsets[j].x;
|
||||||
|
float checkpy=(float)py+0.5+(float)10*offsets[j].y;
|
||||||
|
|
||||||
|
float curUVx = input.TextureCoordinates.x + (float)checkpx/(float)ImageSize.x;
|
||||||
|
float curUVy = input.TextureCoordinates.y + (float)checkpy/(float)ImageSize.y;
|
||||||
|
float4 offsetsample = tex2Dlod(SpriteTextureSampler, float4(curUVx, curUVy,0,0));
|
||||||
|
|
||||||
|
if(
|
||||||
|
offsetsample.a==1
|
||||||
|
|
||||||
|
)
|
||||||
|
{
|
||||||
|
return float4(
|
||||||
|
R,
|
||||||
|
G,
|
||||||
|
B,
|
||||||
|
1);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
j++;
|
||||||
}
|
}
|
||||||
|
|
||||||
return color;
|
|
||||||
}
|
// }
|
||||||
|
|
||||||
|
return color;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
technique SpriteDrawing
|
technique SpriteDrawing
|
||||||
{
|
{
|
||||||
|
|
|
@ -11,6 +11,7 @@ namespace Sledgemapper
|
||||||
public Color GridColor { get; set; }
|
public Color GridColor { get; set; }
|
||||||
public Color NoteColor { get; set; }
|
public Color NoteColor { get; set; }
|
||||||
public string MachineName { get; set; }
|
public string MachineName { get; set; }
|
||||||
|
public int TileDeleteDivider { get; set; }
|
||||||
|
|
||||||
public Settings()
|
public Settings()
|
||||||
{
|
{
|
||||||
|
@ -18,7 +19,7 @@ namespace Sledgemapper
|
||||||
GridColor = Color.Black;
|
GridColor = Color.Black;
|
||||||
NoteColor = Color.DarkRed;
|
NoteColor = Color.DarkRed;
|
||||||
OverlayTintColor = new Color(24, 118, 157);
|
OverlayTintColor = new Color(24, 118, 157);
|
||||||
|
TileDeleteDivider=8;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
MachineName = Environment.MachineName;
|
MachineName = Environment.MachineName;
|
||||||
|
|
|
@ -601,7 +601,7 @@ namespace Sledgemapper
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//DrawWalls();
|
//
|
||||||
|
|
||||||
_spriteBatch.End();
|
_spriteBatch.End();
|
||||||
|
|
||||||
|
@ -609,7 +609,7 @@ namespace Sledgemapper
|
||||||
|
|
||||||
Vector2 texelSize = new Vector2((float)(1 / (double)rendertarget.Width), (float)(1 / (double)rendertarget.Height));
|
Vector2 texelSize = new Vector2((float)(1 / (double)rendertarget.Width), (float)(1 / (double)rendertarget.Height));
|
||||||
outlineShader.Parameters["TexelSize"].SetValue(texelSize);
|
outlineShader.Parameters["TexelSize"].SetValue(texelSize);
|
||||||
outlineShader.Parameters["BorderSize"].SetValue(_state.TileSize / 8);
|
outlineShader.Parameters["BorderSize"].SetValue((int)(_state.TileSize / 100f *20f));
|
||||||
|
|
||||||
outlineShader.Parameters["R"].SetValue(_settings.OverlayTintColor.R / 255.0f);
|
outlineShader.Parameters["R"].SetValue(_settings.OverlayTintColor.R / 255.0f);
|
||||||
outlineShader.Parameters["G"].SetValue(_settings.OverlayTintColor.G / 255.0f);
|
outlineShader.Parameters["G"].SetValue(_settings.OverlayTintColor.G / 255.0f);
|
||||||
|
@ -627,6 +627,7 @@ namespace Sledgemapper
|
||||||
transformMatrix: Matrix.CreateTranslation(_viewportCenter),
|
transformMatrix: Matrix.CreateTranslation(_viewportCenter),
|
||||||
sortMode: SpriteSortMode.Deferred);
|
sortMode: SpriteSortMode.Deferred);
|
||||||
|
|
||||||
|
DrawWalls();
|
||||||
DrawOverlays();
|
DrawOverlays();
|
||||||
DrawNotes();
|
DrawNotes();
|
||||||
DrawGrid(visibleTilesX, visibleTilesY);
|
DrawGrid(visibleTilesX, visibleTilesY);
|
||||||
|
@ -825,7 +826,12 @@ namespace Sledgemapper
|
||||||
|
|
||||||
var endposX = _state.SelectedSnapPoint.X * _state.TileSize;
|
var endposX = _state.SelectedSnapPoint.X * _state.TileSize;
|
||||||
var endposY = _state.SelectedSnapPoint.Y * _state.TileSize;
|
var endposY = _state.SelectedSnapPoint.Y * _state.TileSize;
|
||||||
|
if (_state.InsertMode == InsertMode.NewDelete)
|
||||||
|
{
|
||||||
|
var ww = _state.TileSize / _settings.TileDeleteDivider;
|
||||||
|
if (posX == endposX) { endposX += ww; posX -= ww; }
|
||||||
|
if (posY == endposY) { endposY += ww; posY -= ww; }
|
||||||
|
}
|
||||||
switch (_state.LineStart.Index)
|
switch (_state.LineStart.Index)
|
||||||
{
|
{
|
||||||
case 1:
|
case 1:
|
||||||
|
@ -1297,7 +1303,7 @@ namespace Sledgemapper
|
||||||
}
|
}
|
||||||
Effect outlineShader; // Outline shader effect
|
Effect outlineShader; // Outline shader effect
|
||||||
|
|
||||||
private void DrawDelete(Room tile)
|
private void DrawDelete(Room tile)
|
||||||
{
|
{
|
||||||
var posX = tile.Start.X * _state.TileSize;
|
var posX = tile.Start.X * _state.TileSize;
|
||||||
var posY = tile.Start.Y * _state.TileSize;
|
var posY = tile.Start.Y * _state.TileSize;
|
||||||
|
@ -1305,6 +1311,10 @@ namespace Sledgemapper
|
||||||
var endposX = tile.End.X * _state.TileSize;
|
var endposX = tile.End.X * _state.TileSize;
|
||||||
var endposY = tile.End.Y * _state.TileSize;
|
var endposY = tile.End.Y * _state.TileSize;
|
||||||
|
|
||||||
|
|
||||||
|
var ww = _state.TileSize / _settings.TileDeleteDivider;
|
||||||
|
if (posX == endposX) { endposX += ww; posX -= ww; }
|
||||||
|
if (posY == endposY) { endposY += ww; posY -= ww; }
|
||||||
switch (tile.Start.Index)
|
switch (tile.Start.Index)
|
||||||
{
|
{
|
||||||
case 1:
|
case 1:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue