Shader color upgrade+simple night shader.
Added in better color shader with nighttime support.
This commit is contained in:
parent
e545d4232d
commit
50f84167aa
|
@ -40,12 +40,47 @@ namespace ShaderExample
|
|||
|
||||
//StardewModdingAPI.Events.GraphicsEvents.OnPostRenderEvent += GraphicsEvents_OnPreRenderEvent1;
|
||||
effect = Helper.Content.Load<Effect>(Path.Combine("Content", "Shaders", "GreyScaleEffect.xnb"));
|
||||
}
|
||||
|
||||
|
||||
public void applyCurrentShader(bool ignoreOutdoorLight=false)
|
||||
{
|
||||
SetInstanceField(typeof(SpriteBatch), Game1.spriteBatch, effect, "customEffect");
|
||||
Class1.effect.CurrentTechnique.Passes[0].Apply();
|
||||
if (Game1.player.currentLocation != null && Game1.activeClickableMenu==null)
|
||||
{
|
||||
if (Game1.currentLocation.ignoreOutdoorLighting.Value == false&&ignoreOutdoorLight==false)
|
||||
{
|
||||
//Monitor.Log("WTF");
|
||||
Monitor.Log(Game1.outdoorLight.ToString());
|
||||
Matrix projection = Matrix.CreateOrthographicOffCenter(0,Game1.graphics.GraphicsDevice.Viewport.Width, Game1.graphics.GraphicsDevice.Viewport.Height, 0, 0, 1);
|
||||
Matrix halfPixelOffset = Matrix.CreateTranslation(-0.5f, -0.5f, 0);
|
||||
//effect.Parameters["MatrixTransform"].SetValue(halfPixelOffset * projection);
|
||||
effect.Parameters["ambientRed"].SetValue(Game1.outdoorLight.R);
|
||||
effect.Parameters["ambientGreen"].SetValue(Game1.outdoorLight.G);
|
||||
effect.Parameters["ambientBlue"].SetValue(Game1.outdoorLight.B);
|
||||
effect.Parameters["timeOfDay"].SetValue(Game1.timeOfDay);
|
||||
}
|
||||
else
|
||||
{
|
||||
//Set to 255 to symbolize a white effect.
|
||||
effect.Parameters["ambientRed"].SetValue(255f);
|
||||
effect.Parameters["ambientGreen"].SetValue(255f);
|
||||
effect.Parameters["ambientBlue"].SetValue(255f);
|
||||
effect.Parameters["timeOfDay"].SetValue(600f);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
effect.Parameters["ambientRed"].SetValue(255f);
|
||||
effect.Parameters["ambientGreen"].SetValue(255f);
|
||||
effect.Parameters["ambientBlue"].SetValue(255f);
|
||||
effect.Parameters["timeOfDay"].SetValue(600f);
|
||||
}
|
||||
}
|
||||
|
||||
private void GraphicsEvents_OnPreRenderEvent(object sender, EventArgs e)
|
||||
{
|
||||
|
||||
try
|
||||
{
|
||||
|
||||
|
@ -58,8 +93,7 @@ namespace ShaderExample
|
|||
if (Game1.activeClickableMenu != null)
|
||||
{
|
||||
Game1.spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.PointClamp, null, null);
|
||||
SetInstanceField(typeof(SpriteBatch), Game1.spriteBatch, effect, "customEffect");
|
||||
Class1.effect.CurrentTechnique.Passes[0].Apply();
|
||||
applyCurrentShader();
|
||||
Game1.activeClickableMenu.draw(Game1.spriteBatch);
|
||||
Game1.spriteBatch.End();
|
||||
}
|
||||
|
@ -102,15 +136,13 @@ namespace ShaderExample
|
|||
//The perfect map draw order.
|
||||
Game1.spriteBatch.Begin(SpriteSortMode.FrontToBack, BlendState.AlphaBlend, SamplerState.PointClamp, null, null);
|
||||
//drawMapPart2();
|
||||
SetInstanceField(typeof(SpriteBatch), Game1.spriteBatch, effect, "customEffect");
|
||||
Class1.effect.CurrentTechnique.Passes[0].Apply();
|
||||
applyCurrentShader();
|
||||
AHHHH();
|
||||
Game1.spriteBatch.End();
|
||||
|
||||
|
||||
Game1.spriteBatch.Begin(SpriteSortMode.FrontToBack, BlendState.AlphaBlend, SamplerState.PointClamp, null, null);
|
||||
SetInstanceField(typeof(SpriteBatch), Game1.spriteBatch, effect, "customEffect");
|
||||
Class1.effect.CurrentTechnique.Passes[0].Apply();
|
||||
applyCurrentShader();
|
||||
Game1.player.currentLocation.drawAboveFrontLayer(Game1.spriteBatch);
|
||||
if (Game1.currentLocation.Map.GetLayer("AlwaysFront") != null)
|
||||
{
|
||||
|
@ -120,19 +152,18 @@ namespace ShaderExample
|
|||
}
|
||||
//Game1.currentLocation.drawAboveAlwaysFrontLayer(Game1.spriteBatch);
|
||||
Game1.player.currentLocation.drawAboveAlwaysFrontLayer(Game1.spriteBatch);
|
||||
drawOverlays();
|
||||
|
||||
Game1.spriteBatch.End();
|
||||
|
||||
|
||||
if (Game1.activeClickableMenu != null)
|
||||
{
|
||||
Game1.spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.PointClamp, null, null);
|
||||
SetInstanceField(typeof(SpriteBatch), Game1.spriteBatch, effect, "customEffect");
|
||||
Class1.effect.CurrentTechnique.Passes[0].Apply();
|
||||
applyCurrentShader();
|
||||
Game1.activeClickableMenu.draw(Game1.spriteBatch);
|
||||
Game1.spriteBatch.End();
|
||||
Game1.spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.PointClamp, null, null);
|
||||
SetInstanceField(typeof(SpriteBatch), Game1.spriteBatch, effect, "customEffect");
|
||||
Class1.effect.CurrentTechnique.Passes[0].Apply();
|
||||
applyCurrentShader();
|
||||
if (Game1.activeClickableMenu is StardewValley.Menus.GameMenu)
|
||||
{
|
||||
if ((Game1.activeClickableMenu as StardewValley.Menus.GameMenu).currentTab == 3) return;
|
||||
|
@ -300,17 +331,27 @@ namespace ShaderExample
|
|||
//Game1.spriteBatch.End();
|
||||
|
||||
Game1.spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.PointClamp, null, null);
|
||||
SetInstanceField(typeof(SpriteBatch), Game1.spriteBatch, effect, "customEffect");
|
||||
Class1.effect.CurrentTechnique.Passes[0].Apply();
|
||||
applyCurrentShader(true);
|
||||
if(Game1.activeClickableMenu==null&& Game1.eventUp==false)getInvokeMethod(Program.gamePtr, "drawHUD", new object[] { });
|
||||
|
||||
if (Game1.hudMessages.Count > 0 && (!Game1.eventUp || Game1.isFestival()))
|
||||
{
|
||||
for (int i = Game1.hudMessages.Count - 1; i >= 0; --i)
|
||||
Game1.hudMessages[i].draw(Game1.spriteBatch, i);
|
||||
}
|
||||
|
||||
Game1.spriteBatch.End();
|
||||
|
||||
|
||||
Game1.spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.PointClamp, null, null);
|
||||
applyCurrentShader(true);
|
||||
drawMouse();
|
||||
Game1.spriteBatch.End();
|
||||
|
||||
|
||||
Game1.spriteBatch.Begin(SpriteSortMode.FrontToBack, BlendState.AlphaBlend, SamplerState.PointClamp, null, null);
|
||||
SetInstanceField(typeof(SpriteBatch), Game1.spriteBatch, effect, "customEffect");
|
||||
Class1.effect.CurrentTechnique.Passes[0].Apply();
|
||||
drawMouse();
|
||||
//applyCurrentShader();
|
||||
//drawMouse();
|
||||
}
|
||||
|
||||
|
||||
|
@ -327,7 +368,7 @@ namespace ShaderExample
|
|||
public void drawMapPart1()
|
||||
{
|
||||
//Game1.spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.PointClamp, null, null);
|
||||
SetInstanceField(typeof(SpriteBatch), Game1.spriteBatch, effect, "customEffect");
|
||||
applyCurrentShader();
|
||||
foreach (var layer in Game1.player.currentLocation.map.Layers)
|
||||
{
|
||||
//do back and buildings
|
||||
|
@ -421,7 +462,7 @@ namespace ShaderExample
|
|||
public void drawMapPart2()
|
||||
{
|
||||
//Game1.spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.PointClamp, null, null);
|
||||
SetInstanceField(typeof(SpriteBatch), Game1.spriteBatch, effect, "customEffect");
|
||||
applyCurrentShader();
|
||||
foreach (var layer in Game1.player.currentLocation.map.Layers)
|
||||
{
|
||||
//do front, and always front.
|
||||
|
@ -518,9 +559,8 @@ namespace ShaderExample
|
|||
protected void drawOverlays()
|
||||
{
|
||||
SpriteBatch spriteBatch = Game1.spriteBatch;
|
||||
// spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.PointClamp, (DepthStencilState)null, (RasterizerState)null);
|
||||
SetInstanceField(typeof(SpriteBatch), Game1.spriteBatch, effect, "customEffect");
|
||||
effect.CurrentTechnique.Passes[0].Apply();
|
||||
// spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.PointClamp, (DepthStencilState)null, (RasterizerState)null);
|
||||
applyCurrentShader(true);
|
||||
foreach(var v in Game1.onScreenMenus)
|
||||
{
|
||||
v.draw(spriteBatch);
|
||||
|
|
Binary file not shown.
Binary file not shown.
|
@ -10,30 +10,9 @@ namespace ShaderExample.Framework.Drawers
|
|||
{
|
||||
public class Characters
|
||||
{
|
||||
/// <summary>
|
||||
/// Draw the farmer.
|
||||
/// </summary>
|
||||
/// <param name="f"></param>
|
||||
public static void drawFarmer()
|
||||
{
|
||||
//Game1.spriteBatch.Begin(SpriteSortMode.FrontToBack, BlendState.AlphaBlend, SamplerState.PointClamp, null, null);
|
||||
Class1.SetInstanceField(typeof(SpriteBatch), Game1.spriteBatch, ShaderExample.Class1.effect, "customEffect");
|
||||
Class1.effect.CurrentTechnique.Passes[0].Apply();
|
||||
Game1.player.currentLocation.draw(Game1.spriteBatch);
|
||||
//Game1.spriteBatch.End();
|
||||
}
|
||||
|
||||
public static void drawCharacters()
|
||||
{
|
||||
//Game1.spriteBatch.Begin(SpriteSortMode.FrontToBack, BlendState.AlphaBlend, SamplerState.PointClamp, null, null);
|
||||
Class1.SetInstanceField(typeof(SpriteBatch), Game1.spriteBatch, ShaderExample.Class1.effect, "customEffect");
|
||||
Class1.effect.CurrentTechnique.Passes[0].Apply();
|
||||
foreach(var character in Game1.player.currentLocation.characters)
|
||||
{
|
||||
character.draw(Game1.spriteBatch);
|
||||
}
|
||||
//Game1.spriteBatch.End();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -9,4 +9,3 @@ C:\Users\iD Student\Desktop\Stardew\ShaderExample\ShaderExample\bin\Debug\Conten
|
|||
C:\Users\iD Student\Desktop\Stardew\ShaderExample\ShaderExample\bin\Debug\Netcode.dll
|
||||
C:\Users\iD Student\Desktop\Stardew\ShaderExample\ShaderExample\bin\Debug\Netcode.pdb
|
||||
C:\Users\iD Student\Desktop\Stardew\ShaderExample\ShaderExample\obj\Debug\ShaderExample.csproj.CopyComplete
|
||||
C:\Users\iD Student\Desktop\Stardew\ShaderExample\ShaderExample\obj\Debug\ShaderExample.csprojResolveAssemblyReference.cache
|
||||
|
|
Binary file not shown.
Binary file not shown.
|
@ -12,7 +12,7 @@
|
|||
<TargetFrameworkProfile>Client</TargetFrameworkProfile>
|
||||
<XnaFrameworkVersion>v4.0</XnaFrameworkVersion>
|
||||
<XnaPlatform>Windows</XnaPlatform>
|
||||
<XnaProfile>Reach</XnaProfile>
|
||||
<XnaProfile>HiDef</XnaProfile>
|
||||
<XnaCrossPlatformGroupID>6e015d12-6141-4a91-b036-a111000be29c</XnaCrossPlatformGroupID>
|
||||
<XnaOutputType>Game</XnaOutputType>
|
||||
<ApplicationIcon>Game.ico</ApplicationIcon>
|
||||
|
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -17,13 +17,13 @@
|
|||
<Processor>EffectProcessor</Processor>
|
||||
<Options>None</Options>
|
||||
<Output>C:\Users\iD Student\Desktop\Stardew\WindowsGame2\WindowsGame2\WindowsGame2\bin\x86\Debug\Content\GreyScaleEffect.xnb</Output>
|
||||
<Time>2018-07-18T22:20:40.2080638-07:00</Time>
|
||||
<Time>2018-07-19T21:12:39.9018516-07:00</Time>
|
||||
</Item>
|
||||
<BuildSuccessful>true</BuildSuccessful>
|
||||
<Settings>
|
||||
<ContentProjectGUID>{58C274AC-3DD6-4FC1-9E6B-9E2D8D885F08}</ContentProjectGUID>
|
||||
<TargetPlatform>Windows</TargetPlatform>
|
||||
<TargetProfile>Reach</TargetProfile>
|
||||
<TargetProfile>HiDef</TargetProfile>
|
||||
<BuildConfiguration>Debug</BuildConfiguration>
|
||||
<CompressContent>false</CompressContent>
|
||||
<RootDirectory>C:\Users\iD Student\Desktop\Stardew\WindowsGame2\WindowsGame2\WindowsGame2Content\</RootDirectory>
|
||||
|
|
|
@ -1 +1 @@
|
|||
Windows.v4.0.Reach
|
||||
Windows.v4.0.HiDef
|
||||
|
|
Binary file not shown.
Binary file not shown.
|
@ -1,15 +1,40 @@
|
|||
sampler s0;
|
||||
|
||||
float ambientRed;
|
||||
float ambientGreen;
|
||||
float ambientBlue;
|
||||
|
||||
float timeOfDay;
|
||||
|
||||
float4x4 MatrixTransform;
|
||||
|
||||
|
||||
|
||||
float4 PixelShaderFunction(float2 coords: TEXCOORD0) : COLOR0
|
||||
{
|
||||
float4 color = tex2D(s0, coords); //Get the default pixel color.
|
||||
float r = color.r;
|
||||
float g = color.g;
|
||||
float b = color.b;
|
||||
float a = color.a;
|
||||
float Gray = (r * 0.3 + g * 0.59 + b * 0.11);
|
||||
|
||||
color.rgb = Gray;
|
||||
return color;
|
||||
float4 color = tex2D(s0, coords); //Get the default pixel color.
|
||||
[flatten]if (timeOfDay < 2100) {
|
||||
float r = color.r*(ambientRed / 255);
|
||||
float g = color.g*(ambientGreen / 255);
|
||||
float b = color.b*(ambientBlue / 255);
|
||||
float a = color.a;
|
||||
float Gray = (r * 0.3 + g * 0.59 + b * 0.11); //.3,.59,.11
|
||||
|
||||
color.rgb = Gray;
|
||||
return color;
|
||||
}
|
||||
else {
|
||||
float r = color.r*(ambientRed / 255);
|
||||
float g = color.g*(ambientGreen / 255);
|
||||
float b = color.b*(ambientBlue / 255);
|
||||
float a = color.a;
|
||||
float Gray = (r * 0.11 + g * 0.11 + b * 0.78); //.3,.59,.11
|
||||
|
||||
color.rgb = Gray;
|
||||
return color;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
technique Technique1
|
||||
|
|
Loading…
Reference in New Issue