Skip to content
This repository has been archived by the owner on Jan 4, 2023. It is now read-only.

Commit

Permalink
Cleaned up shader.
Browse files Browse the repository at this point in the history
  • Loading branch information
jessefreeman committed May 25, 2020
1 parent 1c3f655 commit db0c070
Show file tree
Hide file tree
Showing 7 changed files with 95 additions and 139 deletions.
16 changes: 8 additions & 8 deletions Disks/PixelVisionOS/System/Tools/SpriteTool/saves.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
"GameChip":
{
"savedData":{
"spriteSize": "1",
"editing": "undefined",
"selectedPalettePage": "1",
"selectedSpritePage": "1",
"sessionID": "202005051245326336",
"rootDirectory": "/Workspace/NewProject/",
"selectedColor": "-1",
"selectedSprite": "0",
"selectedPalette": "-1",
"selectedSprite": "0"
"selectedColor": "-1",
"rootDirectory": "/Workspace/NewProject/",
"sessionID": "202005051245326336",
"selectedSpritePage": "1",
"selectedPalettePage": "1",
"editing": "undefined",
"spriteSize": "1"
}
}
}
6 changes: 3 additions & 3 deletions Disks/PixelVisionOS/System/Tools/WorkspaceTool/saves.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
"GameChip":
{
"savedData":{
"sessionID": "202005242133137514",
"sessionID": "202005250939179820",
"scrollPos": "0",
"selection": "9",
"lastPath": "/Workspace/DragonSweeper/"
"selection": "0",
"lastPath": "/Workspace/"
}
}
}
8 changes: 4 additions & 4 deletions Effects/QuickDraw.fx
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ float4 PixelShaderFunction(float2 coords: TEXCOORD0) : COLOR0
{
float4 inColor = tex2D(screen, coords);

if (inColor.b == 1 && inColor.g == 1 && inColor.r == 1)
return maskColor;
else
//if (inColor.b == 1 && inColor.g == 1 && inColor.r == 1)
// return maskColor;
//else
// After 256, the color wraps over to green
return tex2D(colorPallete, float2(inColor.r, inColor.g * 256));
return tex2D(colorPallete, float2(inColor.r, inColor.g * 256));

}

Expand Down
53 changes: 16 additions & 37 deletions Effects/crt-lottes-mg.fx
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,14 @@ struct VertexShaderOutput
// Please take and use, change, or whatever.
//

#define hardPix -10.0

#define hardScan -10.0
#define hardBloomPix -4.0
#define hardBloomScan -3
#define bloomAmount 0.15
float2 warp = float2(0.008, 0.01);

float2 warp = float2(0.008, 0.01);
float hardPix = - 10.0;
sampler2D screen: register(s0);
sampler colorPallete: register(s1);

Expand All @@ -45,45 +46,21 @@ float2 textureSize;
float2 videoSize;
float2 outputSize;
float crtOn = 0;
float4 maskColor;

//Uncomment to reduce instructions with simpler linearization
//(fixes HD3000 Sandy Bridge IGP)
#define SIMPLE_LINEAR_GAMMA 2
#define DO_BLOOM 1

// ------------- //


//------------------------------------------------------------------------

// sRGB to Linear.
// Assuing using sRGB typed textures this should not be needed.
float3 ToSrgb(float3 c)
{
return sqrt(c);
}

// Nearest emulated sample given floating point position and texel offset.
// Also zero's off screen.
float3 Fetch(float2 pos, float2 off, float2 texture_size){

// Smooths out the distortion
pos=(floor(pos*texture_size.xy+off*crtOn)+float2(0.5,0.5))/texture_size.xy;
pos=(floor(pos*texture_size.xy+off)+float2(0.5,0.5))/texture_size.xy;

// find the color on the scren texture
float4 inColor = tex2D(screen, pos);

float4 outColor;

if (inColor.b == 1 && inColor.g == 1 && inColor.r == 1)
outColor = maskColor;
else
// After 256, the color wraps over to green
outColor = tex2D(colorPallete, float2(inColor.r, inColor.g * 256));
float4 outColor = tex2D(colorPallete, float2(inColor.r, inColor.g * 256));

// Convert the color to a palette color and brighten it
return brightboost * pow(outColor.rgb, 2);
return outColor.rgb;
}

// Distance in emulated pixels to nearest texel.
Expand Down Expand Up @@ -149,7 +126,7 @@ float3 Horz7(float2 pos, float off, float2 texture_size){
// Return scanline weight.
float Scan(float2 pos, float off, float2 texture_size) {
float dst = Dist(pos, texture_size).y;
return Gaus(dst + off, hardScan) * crtOn;
return Gaus(dst + off, hardScan);
}

// Return scanline weight for bloom.
Expand Down Expand Up @@ -189,16 +166,18 @@ float2 Warp(float2 pos){

float4 crt_lottes(float2 texture_size, float2 video_size, float2 tex)
{

if (crtOn == 0)
return float4(Fetch(tex, 0, texture_size),1);

float2 pos=Warp(tex.xy*(texture_size.xy/video_size.xy))*(video_size.xy/texture_size.xy);
float3 outColor = Tri(pos, texture_size);

#ifdef DO_BLOOM
//Add Bloom
outColor.rgb+=Bloom(pos, textureSize)*bloomAmount;
#endif

return float4(ToSrgb(outColor.rgb),1.0);
float3 outColor = Tri(pos, texture_size) ;

//Add Bloom
outColor.rgb+=Bloom(pos, textureSize)*bloomAmount;

return float4(outColor.rgb,1.0) * brightboost;
}

float4 main_fragment(VertexShaderOutput VOUT) : COLOR0
Expand Down
Binary file modified Effects/crt-lottes-mg.ogl.mgfxo
Binary file not shown.
118 changes: 59 additions & 59 deletions MonoGame/MonoGame.Framework/Graphics/SpriteBatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -192,58 +192,58 @@ void CheckValid(Texture2D texture)
item.Texture = texture;

// set SortKey based on SpriteSortMode.
switch ( _sortMode )
{
// Comparison of Texture objects.
case SpriteSortMode.Texture:
item.SortKey = texture.SortingKey;
break;
// Comparison of Depth
case SpriteSortMode.FrontToBack:
item.SortKey = layerDepth;
break;
// Comparison of Depth in reverse
case SpriteSortMode.BackToFront:
item.SortKey = -layerDepth;
break;
}
// switch ( _sortMode )
// {
// // Comparison of Texture objects.
// case SpriteSortMode.Texture:
// item.SortKey = texture.SortingKey;
// break;
// // Comparison of Depth
// case SpriteSortMode.FrontToBack:
// item.SortKey = layerDepth;
// break;
// // Comparison of Depth in reverse
// case SpriteSortMode.BackToFront:
// item.SortKey = -layerDepth;
// break;
// }

origin = origin * scale;
// origin = origin * scale;

float w, h;
if (sourceRectangle.HasValue)
{
// float w, h;
// if (sourceRectangle.HasValue)
// {
var srcRect = sourceRectangle.GetValueOrDefault();
w = srcRect.Width * scale.X;
h = srcRect.Height * scale.Y;
var w = srcRect.Width * scale.X;
var h = srcRect.Height * scale.Y;
_texCoordTL.X = srcRect.X * texture.TexelWidth;
_texCoordTL.Y = srcRect.Y * texture.TexelHeight;
_texCoordBR.X = (srcRect.X + srcRect.Width) * texture.TexelWidth;
_texCoordBR.Y = (srcRect.Y + srcRect.Height) * texture.TexelHeight;
}
else
{
w = texture.Width * scale.X;
h = texture.Height * scale.Y;
_texCoordTL = Vector2.Zero;
_texCoordBR = Vector2.One;
}
// }
// else
// {
// w = texture.Width * scale.X;
// h = texture.Height * scale.Y;
// _texCoordTL = Vector2.Zero;
// _texCoordBR = Vector2.One;
// }

if ((effects & SpriteEffects.FlipVertically) != 0)
{
var temp = _texCoordBR.Y;
_texCoordBR.Y = _texCoordTL.Y;
_texCoordTL.Y = temp;
}
if ((effects & SpriteEffects.FlipHorizontally) != 0)
{
var temp = _texCoordBR.X;
_texCoordBR.X = _texCoordTL.X;
_texCoordTL.X = temp;
}
// if ((effects & SpriteEffects.FlipVertically) != 0)
// {
// var temp = _texCoordBR.Y;
// _texCoordBR.Y = _texCoordTL.Y;
// _texCoordTL.Y = temp;
// }
// if ((effects & SpriteEffects.FlipHorizontally) != 0)
// {
// var temp = _texCoordBR.X;
// _texCoordBR.X = _texCoordTL.X;
// _texCoordTL.X = temp;
// }

if (rotation == 0f)
{
// if (rotation == 0f)
// {
item.Set(position.X - origin.X,
position.Y - origin.Y,
w,
Expand All @@ -252,22 +252,22 @@ void CheckValid(Texture2D texture)
_texCoordTL,
_texCoordBR,
layerDepth);
}
else
{
item.Set(position.X,
position.Y,
-origin.X,
-origin.Y,
w,
h,
(float)Math.Sin(rotation),
(float)Math.Cos(rotation),
color,
_texCoordTL,
_texCoordBR,
layerDepth);
}
// }
// else
// {
// item.Set(position.X,
// position.Y,
// -origin.X,
// -origin.Y,
// w,
// h,
// (float)Math.Sin(rotation),
// (float)Math.Cos(rotation),
// color,
// _texCoordTL,
// _texCoordBR,
// layerDepth);
// }

FlushIfNeeded();
}
Expand Down
33 changes: 5 additions & 28 deletions SDK/Runner/Data/DisplayTarget.cs
Original file line number Diff line number Diff line change
Expand Up @@ -140,14 +140,11 @@ public void ResetResolution(int gameWidth, int gameHeight, int overScanX = 0, in
{
if (renderTexture == null || renderTexture.Width != gameWidth || renderTexture.Height != gameHeight)
{
renderTexture = new Texture2D(graphicManager.GraphicsDevice, gameWidth, gameHeight, false, SurfaceFormat.Color);
renderTexture = new Texture2D(graphicManager.GraphicsDevice, gameWidth, gameHeight);

crtShader?.Parameters["textureSize"].SetValue(new Vector2(gameWidth, gameHeight));
crtShader?.Parameters["videoSize"].SetValue(new Vector2(gameWidth, gameHeight));
// crtShader?.Parameters["crtOn"].SetValue(useCRT ? 1f : 0f);

// Set the new number of pixels
// totalPixels = renderTexture.Width * renderTexture.Height;
}

// Calculate the game's resolution
Expand Down Expand Up @@ -189,7 +186,6 @@ public void ResetResolution(int gameWidth, int gameHeight, int overScanX = 0, in
offset.Y = 0;
}


// Apply changes
graphicManager.IsFullScreen = fullscreen;

Expand All @@ -200,37 +196,18 @@ public void ResetResolution(int gameWidth, int gameHeight, int overScanX = 0, in
graphicManager.PreferredBackBufferHeight = displayHeight;
graphicManager.ApplyChanges();
}
}

// public void Render(Color[] pixels)
// {
// // TODO didn't have to check length before service refactoring
// // if (totalPixels != pixels.Length) return;
//
// renderTexture.SetData(pixels);
//
// spriteBatch.Begin(samplerState: SamplerState.PointClamp, effect: useCRT ? shaderEffect : null);
//
// spriteBatch.Draw(renderTexture, offset, visibleRect, Color.White, 0f, Vector2.Zero, scale,
// SpriteEffects.None, 1f);
//
// spriteBatch.End();
// }
}

private Texture2D _colorPalette;

private readonly int paletteWidth = 256;
public void RebuildColorPalette(ColorChip colorChip)
{

var colors = ColorUtils.ConvertColors(colorChip.hexColors, colorChip.maskColor, colorChip.debugMode,
colorChip.backgroundColor);

// Create color palette texture
// var cachedColors = colors;//pngReader.colorPalette.ToArray();

// spriteBatch = new SpriteBatch(graphicManager.GraphicsDevice);

var width = 256;
var width = paletteWidth;
var height = (int)Math.Ceiling(colors.Length / (double)width);

_colorPalette = new Texture2D(graphicManager.GraphicsDevice, width, height);
Expand All @@ -243,7 +220,7 @@ public void RebuildColorPalette(ColorChip colorChip)
colorChip.ResetValidation();

// Set palette total
crtShader.Parameters["maskColor"].SetValue(Color.Magenta.ToVector4());
// crtShader.Parameters["maskColor"].SetValue(Color.Magenta.ToVector4());

}

Expand Down

0 comments on commit db0c070

Please sign in to comment.