本文整理汇总了C#中SFML.Graphics.Shader类的典型用法代码示例。如果您正苦于以下问题:C# Shader类的具体用法?C# Shader怎么用?C# Shader使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Shader类属于SFML.Graphics命名空间,在下文中一共展示了Shader类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: RenderStates
////////////////////////////////////////////////////////////
/// <summary>
/// Construct a set of render states with all its attributes
/// </summary>
/// <param name="blendMode">Blend mode to use</param>
/// <param name="transform">Transform to use</param>
/// <param name="texture">Texture to use</param>
/// <param name="shader">Shader to use</param>
////////////////////////////////////////////////////////////
public RenderStates(BlendMode blendMode, Transform transform, Texture texture, Shader shader)
{
BlendMode = blendMode;
Transform = transform;
Texture = texture;
Shader = shader;
}
示例2: Initialize
public void Initialize()
{
SelectedShader = new Shader(null, "Shader/SelectedShader.frag");
SelectedState = new RenderStates(SelectedShader);
AddControls();
}
示例3: 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);
}
示例4: WaterRefractionEffect
/// <summary>
/// Initializes the <see cref="WaterRefractionEffect"/> class.
/// </summary>
static WaterRefractionEffect()
{
// Set the default values
DefaultWaterAlpha = _defaultWaterAlpha;
DefaultWaveSpeed = _defaultWaveSpeed;
DefaultWaveIntensity = _defaultWaveIntensity;
DefaultMagnification = _defaultMagnification;
// Check if shaders are supported
if (!Shader.IsAvailable)
{
const string msg =
"Unable to construct shader for `WaterRefractionEffect` - shaders are not supported on this system.";
if (log.IsInfoEnabled)
log.InfoFormat(msg);
return;
}
// Try to create the default shader
try
{
var code = Resources.WaterRefractionEffectShader;
_defaultShader = ShaderExtensions.LoadFromMemory(code);
}
catch (LoadingFailedException ex)
{
const string errmsg = "Failed to load the default Shader for WaterRefractionEffect. Exception: {0}";
if (log.IsErrorEnabled)
log.ErrorFormat(errmsg, ex);
Debug.Fail(string.Format(errmsg, ex));
}
}
示例5: ExplosionRefractionEffect
/// <summary>
/// Initializes the <see cref="ExplosionRefractionEffect"/> class.
/// </summary>
static ExplosionRefractionEffect()
{
// Set the default values
DefaultLifeSpan = _defaultLifeSpan;
DefaultExpansionRate = new Vector2(1.5f, 1.5f);
DefaultIntensity = _defaultIntensity;
// Check if shaders are supported
if (!Shader.IsAvailable)
{
const string msg =
"Unable to construct shader for `ExplosionRefractionEffect` - shaders are not supported on this system.";
if (log.IsInfoEnabled)
log.InfoFormat(msg);
return;
}
// Try to create the default shader
try
{
var code = Resources.ExplosionRefractionEffectShader;
_defaultShader = ShaderExtensions.LoadFromMemory(code);
}
catch (LoadingFailedException ex)
{
const string errmsg = "Failed to load the default Shader for ExplosionRefractionEffect. Exception: {0}";
if (log.IsErrorEnabled)
log.ErrorFormat(errmsg, ex);
Debug.Fail(string.Format(errmsg, ex));
}
}
示例6: 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);
}
示例7: 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, null, "resources/pixelate.frag");
myShader.SetUniform("texture", Shader.CurrentTexture);
}
示例8: PointLight
public PointLight(Color color, float power, float radius, Vector2f position)
{
Position = position;
Color = color;
Power = power;
Radius = radius;
VisMap = new VisbilityMap(Position, Radius);
_shader = new Shader("shaders/lightShader.vert", "shaders/lightShader.frag");
}
示例9: 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);
}
示例10: 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);
}
示例11: Game
public Game()
{
win = win = new RenderWindow(new SFML.Window.VideoMode(800, 670), "Shader^^");
win.Closed += (sender, e) => { ((RenderWindow)sender).Close(); };
BackgroundGrayScale = new Sprite(new Texture("bg.png"));
BackgroundMult = new Sprite(new Texture("wall.png"));
Overlay = new Sprite(new Texture("lightMask.png"));
t = new GameTime();
GrayScaleShader = new Shader(null, "GrayScale.frag");
GrayScaleState = new RenderStates(GrayScaleShader);
MultTexture = new RenderTexture(800, 670);
MultShader = new Shader(null, "Mult.frag");
MultState = new RenderStates(MultShader);
Add = new RenderStates(BlendMode.Add);
}
示例12: 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;
}
示例13: load_batch_shaders
public static void load_batch_shaders(string folder)
{
//Debug.Log("Loading shaders from folder " + folder);
Debug.StartLogGroup();
DirectoryInfo dir = new DirectoryInfo(folder);
if (dir.Exists)
{
FileInfo[] files = dir.GetFiles("*.sfx", System.IO.SearchOption.AllDirectories);
for (int f = 0; f < files.Length; f++)
{
Debug.Log("Loading " + files[f].FullName);
bool succeeded = true;
Shader shader = null;
try
{
shader = new Shader(files[f].FullName);
}
catch (SFML.LoadingFailedException e)
{
succeeded = false;
throw;
}
if (succeeded)
{
Debug.Log("Success!");
var temp = files[f].Name;
var identifier = files[f].Name.Remove(files[f].Name.LastIndexOf('.'));
shaders.Add(identifier, shader);
}
else
{
Debug.Log("Shader loading failed");
}
}
}
Debug.EndLogGroup();
}
示例14: Draw
/// <summary>
/// Draws a raw <see cref="SFML.Graphics.Sprite"/>. Recommended to avoid using when possible, but when needed,
/// can provide a slight performance boost when drawing a large number of sprites with identical state.
/// </summary>
/// <param name="sprite">The <see cref="SFML.Graphics.Sprite"/> to draw.</param>
/// <param name="shader">The <see cref="Shader"/> to use while drawing.</param>
public virtual void Draw(SFML.Graphics.Sprite sprite, Shader shader = null)
{
if (sprite == null || !IsAssetValid(sprite.Image))
return;
_rt.Draw(sprite, shader);
}
示例15: Main
/// <summary>
/// The main entry point for the application.
/// </summary>
static void Main()
{
// Create the main window
RenderWindow window = new RenderWindow(new VideoMode(800, 600), "SFML.Net Shader");
// Setup event handlers
window.Closed += new EventHandler(OnClosed);
window.KeyPressed += new EventHandler<KeyEventArgs>(OnKeyPressed);
// Check that the system can use shaders
if (Shader.IsAvailable == false)
{
DisplayError(window);
return;
}
// Create the render image
RenderImage image = new RenderImage(window.Width, window.Height);
// Load a background image to display
Sprite background = new Sprite(new Image("resources/background.jpg"));
background.Image.Smooth = false;
// Load a sprite which we'll move into the scene
Sprite entity = new Sprite(new Image("resources/sprite.png"));
// Load the text font
Font font = new Font("resources/arial.ttf");
// Load the image needed for the wave effect
Image waveImage = new Image("resources/wave.jpg");
// Load all effects
shaders = new Dictionary<string, Shader>();
shaders["nothing"] = new Shader("resources/nothing.sfx");
shaders["blur"] = new Shader("resources/blur.sfx");
shaders["colorize"] = new Shader("resources/colorize.sfx");
shaders["fisheye"] = new Shader("resources/fisheye.sfx");
shaders["wave"] = new Shader("resources/wave.sfx");
shaders["pixelate"] = new Shader("resources/pixelate.sfx");
backgroundShader = new ShaderSelector(shaders);
entityShader = new ShaderSelector(shaders);
globalShader = new ShaderSelector(shaders);
// Do specific initializations
shaders["nothing"].SetTexture("texture", Shader.CurrentTexture);
shaders["blur"].SetTexture("texture", Shader.CurrentTexture);
shaders["blur"].SetParameter("offset", 0.0F);
shaders["colorize"].SetTexture("texture", Shader.CurrentTexture);
shaders["colorize"].SetParameter("color", 1.0F, 1.0F, 1.0F);
shaders["fisheye"].SetTexture("texture", Shader.CurrentTexture);
shaders["wave"].SetTexture("texture", Shader.CurrentTexture);
shaders["wave"].SetTexture("wave", waveImage);
shaders["pixelate"].SetTexture("texture", Shader.CurrentTexture);
// Define a string for displaying current effect description
shaderText = new Text();
shaderText.Font = font;
shaderText.Size = 20;
shaderText.Position = new Vector2(5.0F, 0.0F);
shaderText.Color = new Color(250, 100, 30);
shaderText.DisplayedString = "Background shader: \"" + backgroundShader.Name + "\"\n" +
"Flower shader: \"" + entityShader.Name + "\"\n" +
"Global shader: \"" + globalShader.Name + "\"\n";
// Define a string for displaying help
Text infoText = new Text();
infoText.Font = font;
infoText.Size = 20;
infoText.Position = new Vector2(5.0F, 500.0F);
infoText.Color = new Color(250, 100, 30);
infoText.DisplayedString = "Move your mouse to change the shaders' parameters\n" +
"Press numpad 1 to change the background shader\n" +
"Press numpad 2 to change the flower shader\n" +
"Press numpad 3 to change the global shader";
// Start the game loop
float time = 0.0F;
while (window.IsOpened())
{
// Process events
window.DispatchEvents();
// TOFIX -- using window.Input together with image.Draw apparently causes a memory corruption
// Get the mouse position in the range [0, 1]
//float x = window.Input.GetMouseX() / (float)window.Width;
//float y = window.Input.GetMouseY() / (float)window.Height;
float x = (float)(Math.Cos(time * 1.3) + 1) * 0.5F;
float y = (float)(Math.Sin(time * 0.8) + 1) * 0.5F;
// Update the shaders
backgroundShader.Update(x, y);
entityShader.Update(x, y);
globalShader.Update(x, y);
// Animate the sprite
time += window.GetFrameTime();
//.........这里部分代码省略.........