XNA remove shader effects - c#

I am new to XNA 4.0 and I'm using a shader for my background texture that creates a glow effects on white objects. When I try to add sprites to the background image it also creates the glow on my sprites, how can I remove my shader on the sprites I add on top of my background?

Use 2 seperate SpriteBatch.Begin() ... SpriteBatch.End() sections.
In the first use the Effect that wraps your shader and draw your background.
In the second draw anything you want without applying the shader.

Related

tiled draw mode in Sprite Renderer component

Illustrating Image:
Ok so my goal is to fill up the sky with blue. I used the tiled draw mode in Sprite Renderer component but it doesn't seem to be a good choice. I thought of creating a blue square and then put it on top of the sky but is there any way to do it automatically? ( I found something called border but I couldn't understand what these green lines mean? )
You first have to set up the image to tile correctly. In the inspector for the image you want to tile, open the Sprite Editor, and move the border (green box) to select the SKY portion of your image. For example:
After doing this, your sprite should tile correctly:
Do Note:
If you're filling in a solid color for the sky, use the Sliced mode instead of Tiled to reduce polygon counts. (Tiled mode will make new quads for each repeated section, while Sliced will stretch the solid color in only one quad):
(Left is Tiled, right is Sliced)

Unity - paint a texture with alpha to make it dissapear partially

I am trying to achieve this effect, I want to "paint" the image with alpha, like erasing part of the image exactly where the user touches or uses the mouse.
I don't know where to start.
You could put each image on a separate Layer and tell your "eraser brush" to ignore the layer behind the one you want to erase using a LayerMask. When the user clicks on the image, it erases part of the image on the first layer, but leaves the image behind it alone.
Credit to Statement from here:
LayerMask, or any "Mask" in Computer Science, is an integer which uses
its 32 bits to represent different flags. While it is an integer, the
value doesn't mean anything useful numerically. What matters is which
flags are turned on or off.
In the case of LayerMask, each flag (each bit) represents one layer.
The layers are selectable at the top of the inspector for each GameObject, you can add and name layers there, and also choose to view different combinations of them (see pic).
If you want to have 2 textures on asingle plane:
- Make a custom shader with 3 textures (background, foreground, mask)
- Then you can paint into that mask texture with grayscale color and shader fades the 2 textures based on the mask color (example, if color is full white, only foreground is visible)
Or if you want to have 3D object behind a separate texture plane (and you only need to erase the existing texture, not draw the same pattern back)
- Could use any default texture which supports alpha
- Just paint into the MainTexture in the material, painting with color alpha 0 makes the area transparent
- Texture needs to have [x] read/write enabled in the importer settings to allow drawing on it
Some related links:
Basic pixel drawing example from unity docs: http://docs.unity3d.com/ScriptReference/RaycastHit-textureCoord.html
Old demo scene, painting to texture and using dissolve shader : http://unitycoder.com/blog/2011/08/10/painting-holes-with-shader-v2-0/
And search for unity blend 2 textures with mask, unity draw to texture etc. to find more examples & shaders.

Lighting covering up sky

I have a 2D tile-based lighting system which is drawn onto a Render Target.
I am also drawing a background which involves mountains, sun/moon, and clouds.
There is also the unlit game; blocks, character, etc.
Here is the order in which everything is drawn:
1. Background
2. Game World
3. Lighting
The problem is that the LIGHTING is covering up the BACKGROUND when it's dark:
Although it's perfectly fine in the day because the light is full:
You might ask, well, why don't you just blend each block, not drawing the lighting on a RenderTarget?
Because that would prevent me from performing smooth lighting, as seen in the pictures. To produce the smooth lighting, I draw squares of light onto a RenderTarget, perform a Gaussian blur and then draw that RenderTarget.
How about not drawing a square of light in empty spaces?
The light blurs onto any adjacent blocks, and not all objects in my game affected by lighting are square, so they would look like a sprite with a blurry square on top of it.
Light NOT being drawn in empty spaces:
Light being drawn everywhere:
Is there any way to keep the background visible, or something else that would help my predicament?
I'd suggest you do the following:
Render lighting to rendertarget
Render scene to rendertarget (leave the background transparent)
Multiply scene with the lighting rendertarget
Render background to screen
Render scene (with the lighting already applied) to the screen
Because the background is added after applying the lighting, it will not be affected.

Erase part of RenderTarget when drawing primitives?

I'm creating a paint like application using XNA.
I have a render target which acts as a canvas. When the user draws something I draw corresponding triangles using DrawUserPrimitives and triangle strips to make lines and other curves.
I want to implement an eraser in the application, so that the user can erase the triangles from the texture. I've used OpenGL in the past and there I would just use a blend function like so: glBlendFunc(GL_ZERO, GL_ONE_MINUS_SRC_ALPHA);
How would I do this in XNA? I tried setting the GraphicsDevice blend mode to AlphaBlend, Additive, etc.. but it did not work. Any ideas?
If you change your code to use a Texture2D instead of a RenderTarget2D, you can use RenderTarget2D.GetTexture() to get the pixel data from the RenderTarget2D.
Of course, there will probably be a performance hit, but if you can optimize the code in a way that cuts down on the number of times this is done, like temporarily drawing the background color instead of actually erasing, and then iterating through the pixels after the mouse is released, you could make it work.
There may be a better way, but I couldn't find it.

C# MDX drawing transparent rectangle over a sprite

I want to make a "Pausemenu" in a Tetrisgame, when I hit Esc, the Menu pops up and that the user clearly is aware of that the game isnt running, I want to draw a transparent black rectangle over the whole game sprite, I´m using C# Managed DirectX 9.0c on .Net Framework 3.5. (I could achieve the same effect with a texture, but since in the settings the Board Width/Height can be changed, this would be an ugly solution)
Is there an easy way to achieve this?
You can simple create a small PNG, make it black and 75% opaque.
In your Game just use the Sprite Class (with alpha enabled) and scale it (with transform) to the dimensions of your viewport.
You could also use the Sprite Class to modify the Color of the Sprite when drawing, so you can make it fade in or out or give it another color.
Hope that helps!

Categories

Resources