本文整理汇总了C#中SFML.Graphics.Shader.SetParameter方法的典型用法代码示例。如果您正苦于以下问题:C# Shader.SetParameter方法的具体用法?C# Shader.SetParameter怎么用?C# Shader.SetParameter使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SFML.Graphics.Shader
的用法示例。
在下文中一共展示了Shader.SetParameter方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: BloomTest
public BloomTest(RenderTexture target_tex, RenderTarget target)
{
_target = target;
_bloom = new Shader(null, "bloom.glsl");
_texture = new RenderTexture((uint)GlobalProps.Width, (uint)GlobalProps.Height);
_states.BlendMode = BlendMode.Alpha;
_states.Shader = _bloom;
_states.Transform = Transform.Identity;
_states.Texture = target_tex.Texture;
_bloom.SetParameter("referenceTex", Shader.CurrentTexture);
_bloom.SetParameter("pixelWidth", 4);
_bloom.SetParameter("pixelHeight", 4);
int w = GlobalProps.Width, h = GlobalProps.Height;
Vector2f v0 = new Vector2f(0, 0);
Vector2f v1 = new Vector2f(w, 0);
Vector2f v2 = new Vector2f(w, h);
Vector2f v3 = new Vector2f(0, h);
_verts = new Vertex[4];
_verts[0] = new Vertex(v0, Color.White, v0);
_verts[1] = new Vertex(v1, Color.White, v1);
_verts[2] = new Vertex(v2, Color.White, v2);
_verts[3] = new Vertex(v3, Color.White, v3);
}
示例2: Edge
public Edge()
: base("edge post-effect")
{
// Create the off-screen surface
mySurface = new RenderTexture(800, 600);
mySurface.Smooth = true;
// Load the textures
myBackgroundTexture = new Texture("resources/sfml.png");
myBackgroundTexture.Smooth = true;
myEntityTexture = new Texture("resources/devices.png");
myEntityTexture.Smooth = true;
// Initialize the background sprite
myBackgroundSprite = new Sprite(myBackgroundTexture);
myBackgroundSprite.Position = new Vector2f(135, 100);
// Load the moving entities
myEntities = new Sprite[6];
for (int i = 0; i < myEntities.Length; ++i)
{
myEntities[i] = new Sprite(myEntityTexture, new IntRect(96 * i, 0, 96, 96));
}
// Load the shader
myShader = new Shader(null, "resources/edge.frag");
myShader.SetParameter("texture", Shader.CurrentTexture);
}
示例3: GraphicsDisplay
public GraphicsDisplay(uint width, uint height)
{
Width = width;
Height = height;
_data = new Image(width, height, Color.Black);
_dataTexture = new Texture(_data);
_palette = new Image("Data/palette.png");
_paletteTexture = new Texture(_palette);
_display = new Sprite(_dataTexture);
_renderer = new Shader("Data/display.vert", "Data/display.frag");
_renderer.SetParameter("data", _dataTexture);
_renderer.SetParameter("dataSize", width, height);
_renderer.SetParameter("palette", _paletteTexture);
}
示例4: Pixelate
public Pixelate() : base("pixelate")
{
// Load the texture and initialize the sprite
myTexture = new Texture("resources/background.jpg");
mySprite = new Sprite(myTexture);
// Load the shader
myShader = new Shader(null, "resources/pixelate.frag");
myShader.SetParameter("texture", Shader.CurrentTexture);
}
示例5: LightLayer
public LightLayer(Vector2u gameRez, Vector2u windowRez)
{
Lights = new List<Light>();
Polygons = new List<Polygon>();
renText = new RenderTexture(gameRez.X, gameRez.Y);
lightMap = new RenderTexture(gameRez.X, gameRez.Y);
lightMap.Smooth = true;
scene = new Texture(windowRez.X, windowRez.Y);
lightShader = new Shader(null, "Content/shaders/light.frag");
lightShader.SetParameter("screenHeight", gameRez.Y);
lightState = new RenderStates(BlendMode.Add, Transform.Identity, renText.Texture, lightShader);
shadowShader = new Shader(null, "Content/shaders/shadows.frag");
//shadowState = new RenderStates(shadowShader);
shadowState = new RenderStates(BlendMode.Multiply);
}
示例6: LightEffectManager
public LightEffectManager(Map parent)
{
Parent = parent;
DynamicEffects = new List<LightEffect>();
StaticEffects = new List<LightEffect>();
GlobalColor = DEFAUT_GLOBAL_COLOR;
IsRefreshed = false;
RenderTexture = new RenderTexture(GameData.WINDOW_WIDTH, GameData.WINDOW_HEIGHT);
BlurEffect = new Shader(GameData.DATAS_DEFAULT_PATH + "gfx/blur.sfx");
BlurEffect.SetCurrentTexture("texture");
BlurEffect.SetParameter("offset", 0.005F * SMOOTHNESS);
Walls = null;
OpacityBoxes = null;
}
示例7: Start
public void Start()
{
System.Drawing.Rectangle r = System.Windows.Forms.Screen.PrimaryScreen.Bounds;
RenderWindow window = new RenderWindow(new VideoMode(1024, 786), "One Bullet", Styles.Titlebar | Styles.Close, settings);
window.LostFocus += (s, e) => { focus = false; };
window.GainedFocus += (s, e) => { focus = true; };
Width = (int)window.Size.X;
Height = (int)window.Size.Y;
window.Closed += window_Closed;
window.KeyPressed += window_KeyPressed;
window.KeyReleased += window_KeyReleased;
Finish();
player.OnShoot += Shoot;
window.SetFramerateLimit(60);
Font font = new Font("Content/consolas.ttf");
Text healthText = new Text("", font, 72);
healthText.Color = Color.Red;
Text dialog = new Text("", font, 48);
dialog.Color = new Color(128, 128, 128);
Texture bulletUI = new Texture("Content/bulletUI.png");
RectangleShape bulletRect = new RectangleShape();
bulletRect.Size = new Vector2f(72, 108);
bulletRect.Origin = new Vector2f(72, 108);
bulletRect.Texture = bulletUI;
light = new RenderTexture(window.Size.X, window.Size.Y);
lightCircle = new CircleShape(0, 20);
RectangleShape lightDisplay = new RectangleShape();
lightDisplay.Size = new Vector2f(window.Size.X, window.Size.Y);
lightDisplay.Position = new Vector2f();
blur = new Shader("Content/blur.vs", "Content/blur.fs");
blur.SetParameter("rad", 0.004f);
RenderStates blurStates = new RenderStates(RenderStates.Default);
blurStates.Shader = blur;
RectangleShape imageFrame = new RectangleShape();
imageFrame.Position = new Vector2f(Width / 2 - 400, 16);
imageFrame.Size = new Vector2f(800, 600);
Texture white = new Texture(1, 1);
Texture blood = new Texture("Content/bloodOverlay.png");
Text startBtn = new Text("START GAME", font, 100);
startBtn.Position = new Vector2f(Width / 2 - startBtn.GetGlobalBounds().Width / 2, Height / 5);
bloodSystem = new ParticleSystem(new Texture("Content/bloodParticle.png"));
Texture aimImage = new Texture("Content/finalScene.png");
Text copyright = new Text("Game by WebFreak001. Made for Ludum Dare 28", font, 48);
copyright.Position = new Vector2f(Width / 2 - copyright.GetLocalBounds().Width / 2, 32);
bool mouseOld = false;
#region Achivements
if (!File.Exists("ach.txt"))
{
File.WriteAllText("ach.txt", "0:0\n1:0\n2:0");
}
achivements = new Dictionary<int, Achivement>();
string[] achs = File.ReadAllLines("ach.txt");
bool done1 = false;
bool done2 = false;
bool done3 = false;
if (achs.Length > 2)
{
if (achs[0].StartsWith("0"))
{
char c = achs[0].Last();
if (c == '1') done1 = true;
}
if (achs[1].StartsWith("1"))
{
char c = achs[1].Last();
if (c == '1') done2 = true;
}
if (achs[2].StartsWith("1"))
{
char c = achs[2].Last();
if (c == '1') done3 = true;
}
}
achivements.Add(0, new Achivement() { Done = done1, Text = "Start the game" });
achivements.Add(1, new Achivement() { Done = done2, Text = "You Missed" });
achivements.Add(2, new Achivement() { Done = done3, Text = "Finish the Game" });
//.........这里部分代码省略.........
示例8: TextDisplay
/// <summary>
/// Constructs a text display.
/// </summary>
/// <param name="width">Width in characters</param>
/// <param name="height">Height in characters</param>
/// <param name="fontFile">Font texture</param>
/// <param name="convertFont">Enable support for masked fonts</param>
/// <param name="paletteFile">Palette texture</param>
public TextDisplay(uint width, uint height, string fontFile = "font.png", bool convertFont = true, string paletteFile = "palette.png")
{
if (string.IsNullOrEmpty(fontFile))
throw new ArgumentNullException("fontFile");
if (string.IsNullOrEmpty(paletteFile))
throw new ArgumentNullException("paletteFile");
Width = width;
Height = height;
_data = new Image(width, height, Color.Black);
_dataTexture = new Texture(_data);
var fontImage = new Image(Path.Combine(DataFolder, fontFile));
CharacterWidth = fontImage.Size.X / 16;
CharacterHeight = fontImage.Size.Y / 16;
if (convertFont)
{
var fontWidth = fontImage.Size.X;
var fontHeight = fontImage.Size.Y;
var fontPixels = fontImage.Pixels;
fontImage.Dispose();
// use top left pixel of space as mask color
var maskX = (32 % 16) * CharacterWidth;
var maskY = (32 / 16) * CharacterHeight * (fontWidth * 4);
var maskI = maskX + maskY;
var maskR = fontPixels[maskI + 0];
var maskG = fontPixels[maskI + 1];
var maskB = fontPixels[maskI + 2];
var maskA = fontPixels[maskI + 3];
for (int i = 0; i < fontPixels.Length; i += 4)
{
var r = fontPixels[i + 0];
var g = fontPixels[i + 1];
var b = fontPixels[i + 2];
var a = fontPixels[i + 3];
if (r == maskR && g == maskG && b == maskB && a == maskA)
{
// mask color, set to transparent
fontPixels[i + 3] = 0;
}
else
{
// set alpha channel to average of rgb
var level = (r + b + g) / 3f;
var alpha = a / 256f;
fontPixels[i + 3] = (byte)(level * alpha);
}
}
fontImage = new Image(fontWidth, fontHeight, fontPixels);
//fontImage.SaveToFile("result.png");
}
_fontTexture = new Texture(fontImage);
_palette = new Image(Path.Combine(DataFolder, paletteFile));
_paletteTexture = new Texture(_palette);
_display = new VertexArray(PrimitiveType.Quads, 4);
_display[0] = new Vertex(new Vector2f(0, 0), new Vector2f(0, 0));
_display[1] = new Vertex(new Vector2f(width * CharacterWidth, 0), new Vector2f(1, 0));
_display[2] = new Vertex(new Vector2f(width * CharacterWidth, height * CharacterHeight), new Vector2f(1, 1));
_display[3] = new Vertex(new Vector2f(0, height * CharacterHeight), new Vector2f(0, 1));
var displayVertexSource = File.ReadAllText(Path.Combine(DataFolder, "texter.vert"));
var displayFragmentSource = File.ReadAllText(Path.Combine(DataFolder, "texter.frag"))
.Replace("#W#", CharacterWidth.ToString("D"))
.Replace("#H#", CharacterHeight.ToString("D"));
_renderer = Shader.FromString(displayVertexSource, displayFragmentSource);
_renderer.SetParameter("data", _dataTexture);
_renderer.SetParameter("dataSize", width, height);
_renderer.SetParameter("font", _fontTexture);
_renderer.SetParameter("palette", _paletteTexture);
}