ill try that
oh wait, wouldn’t that mess up the non spritebatch rendertarget draw?
Would i have to switch cameras between the rendertarget draw and the spritebatch ?
Though i suppose its kinda non sequitur if i can do it all with the first call now.
Re: It works on dx for both. Well with a little fov aspect ratio rigging i can get the non-rt call to look the same as the rt call (though its not close to properly mimicing it i just sort of spliced it in like that.) bout to test Gl now.
Edit Acckk The RenderTarget draw call version on GL only gives off a cornflower blue screen of death, the other one works though.
The primary topic objective problem is fulfilled solved, unless anyone knows why that isn’t working ill stop and take the opportunity to say
thanks for all your guys help.
Here’s the full game1 code. For Reference.
//using System;
//using System.Text;
//using System.Collections.Generic;
//using System.Linq;
//using Microsoft.Xna.Framework;
//using Microsoft.Xna.Framework.Graphics;
//using Microsoft.Xna.Framework.Input;
//namespace CustomVertexExperimentDX_dec_23_16
//{
public class Game1 : Game
{
public const float PI = (float)(Math.PI);
public const float PI2 = (float)(Math.PI * 2.0d);
public const float TODEGREES = 360.0f / PI2;
public const float TORADIANS = PI2 / 360.0f;
GraphicsDeviceManager graphics;
SpriteBatch spriteBatch;
private Texture2D tex2d;
private Matrix view, projection;
private Matrix worldviewprojection;
private Matrix worldviewprojectionorthagonal;
private VertexPositionColorTexture[] vertices;
//private VertexPositionNormalTexture[] _vertices;
private int[] indices;
private RenderTarget2D renderTarget;
private BasicEffect basicEffect;
Effect TestEffectA;
Vector3 offset = Vector3.Zero;
public Game1()
{
graphics = new GraphicsDeviceManager(this);
Content.RootDirectory = "Content";
}
protected override void Initialize()
{
base.Initialize();
}
protected override void LoadContent()
{
spriteBatch = new SpriteBatch(GraphicsDevice);
SetCameraOrientation3D();
SetCameraOrientationOrthagonal();
CreateQuad();
tex2d = Content.Load<Texture2D>("a_lookingood19");
TestEffectA = Content.Load<Effect>("TestEffect");
basicEffect = new BasicEffect(GraphicsDevice);
SetupBasicEffect(basicEffect);
renderTarget = new RenderTarget2D(GraphicsDevice,
GraphicsDevice.PresentationParameters.BackBufferWidth,
GraphicsDevice.PresentationParameters.BackBufferHeight,
false,
GraphicsDevice.PresentationParameters.BackBufferFormat,
DepthFormat.Depth24);
}
protected override void UnloadContent()
{
}
private void SetCameraOrientation3D() // just a hack for the test
{
view = Matrix.CreateLookAt(new Vector3(0, 0, 2), Vector3.Forward, Vector3.Up);
projection = Matrix.CreatePerspectiveFieldOfView(TORADIANS * 28, GraphicsDevice.PresentationParameters.BackBufferWidth / GraphicsDevice.PresentationParameters.BackBufferHeight, 1, 500);
//projection = Matrix.CreatePerspectiveFieldOfView(MathHelper.PiOver2, graphics.GraphicsDevice.DisplayMode.AspectRatio, 1f, 500);
worldviewprojection = Matrix.Identity * view * projection;
}
private void SetCameraOrientationOrthagonal()
{
view = Matrix.Identity;
projection = Matrix.CreateOrthographicOffCenter(0, GraphicsDevice.Viewport.Width, GraphicsDevice.Viewport.Height, 0, 0, -1f);
worldviewprojectionorthagonal = Matrix.Identity * view * projection;
}
private void SetupBasicEffect(BasicEffect f)
{
f.World = Matrix.Identity;
f.View = view;
f.Projection = projection;
f.TextureEnabled = true;
f.Texture = tex2d;
}
//private void SetupEffect(Effect f)
//{
//f.Parameters["Texture"].SetValue(tex2d);
//f.Parameters["WorldViewProjection"].SetValue(worldviewprojection);
//}
protected override void Update(GameTime gameTime)
{
if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape))
Exit();
base.Update(gameTime);
}
protected override void Draw(GameTime gameTime)
{
GraphicsDevice.Clear(Color.CornflowerBlue);
//DrawEffectA(gameTime);
DrawEffectAWithRT(gameTime);
base.Draw(gameTime);
}
public void DrawEffectA(GameTime gameTime)
{
SetCameraOrientation3D();
TestEffectA.Parameters["Texture"].SetValue(tex2d);
TestEffectA.Parameters["WorldViewProjection"].SetValue(worldviewprojection);
GraphicsDevice.Clear(Color.CornflowerBlue);
foreach (EffectPass pass in TestEffectA.CurrentTechnique.Passes)
{
pass.Apply();
// VertexPositionNormalTexture VertexPositionColorTexture bah dont need either
GraphicsDevice.DrawUserIndexedPrimitives(PrimitiveType.TriangleList, vertices, 0, 4, indices, 0, 2);
}
base.Draw(gameTime);
}
public void DrawEffectAWithRT(GameTime gameTime)
{
SetCameraOrientationOrthagonal();
TestEffectA.Parameters["Texture"].SetValue(tex2d);
TestEffectA.Parameters["WorldViewProjection"].SetValue(worldviewprojectionorthagonal);
// set the render target clear it
GraphicsDevice.SetRenderTarget(renderTarget);
GraphicsDevice.Clear(Color.CornflowerBlue);
// draw quad
foreach (EffectPass pass in basicEffect.CurrentTechnique.Passes)
{
pass.Apply();
GraphicsDevice.DrawUserIndexedPrimitives(PrimitiveType.TriangleList, vertices, 0, 4, indices, 0, 2);
}
// set and clear the screen target
GraphicsDevice.SetRenderTarget(null);
GraphicsDevice.Clear(Microsoft.Xna.Framework.Color.CornflowerBlue);
// alter it with spritebatch and the effect shader
//_spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.AlphaBlend);
spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.NonPremultiplied, SamplerState.PointClamp, DepthStencilState.Default, RasterizerState.CullNone, TestEffectA, worldviewprojection);
TestEffectA.CurrentTechnique.Passes[0].Apply();
//test
spriteBatch.Draw(renderTarget, new Vector2(0, 0), Color.White);
spriteBatch.End();
base.Draw(gameTime);
}
private void CreateQuad()
{
//_vertices = new VertexPositionNormalTexture[4];
vertices = new VertexPositionColorTexture[4];
vertices[0].Position = new Vector3(-0.5f, -0.5f, 0f);
//_vertices[0].Normal = Vector3.Backward;
vertices[0].Color = Color.White;
vertices[0].TextureCoordinate = new Vector2(0f, 1f);
vertices[1].Position = new Vector3(-0.5f, 0.5f, 0f);
//_vertices[1].Normal = Vector3.Backward;
vertices[1].Color = Color.White;
vertices[1].TextureCoordinate = new Vector2(0f, 0f);
vertices[2].Position = new Vector3(0.5f, -0.5f, 0f);
//_vertices[2].Normal = Vector3.Backward;
vertices[2].Color = Color.White;
vertices[2].TextureCoordinate = new Vector2(1f, 1f);
vertices[3].Position = new Vector3(0.5f, 0.5f, 0f);
//_vertices[3].Normal = Vector3.Backward;
vertices[3].Color = Color.White;
vertices[3].TextureCoordinate = new Vector2(1f, 0f);
indices = new int[6];
indices[0] = 0;
indices[1] = 1;
indices[2] = 2;
indices[3] = 2;
indices[4] = 1;
indices[5] = 3;
}
}`
Lithiums testing shader
> // Lithiums shader Example
> #if OPENGL
> #define SV_POSITION POSITION
> #define VS_SHADERMODEL vs_2_0
> #define PS_SHADERMODEL ps_2_0
> #else
> #define VS_SHADERMODEL vs_4_0_level_9_1
> #define PS_SHADERMODEL ps_4_0_level_9_1
> #endif
> float4x4 WorldViewProjection;
> Texture2D Texture : register(t0);
> sampler TextureSampler : register(s0)
> {
> Texture = (Texture);
> };
> struct VertexShaderInput
> {
> float4 Position : POSITION0;
> float4 Color : COLOR0;
> float2 TexureCoordinate : TEXCOORD0;
> };
> struct VertexShaderOutput
> {
> float4 Position : SV_Position;
> float4 Color : COLOR0;
> float2 TexureCoordinate : TEXCOORD0;
> };
> struct PixelShaderOutput
> {
> float4 Color : COLOR0;
> };
> VertexShaderOutput VertexShaderFunction(VertexShaderInput input)
> {
> VertexShaderOutput output;
> output.Position = mul(input.Position, WorldViewProjection);
> output.Color = input.Color;
> output.TexureCoordinate = input.TexureCoordinate;
> return output;
> }
> PixelShaderOutput PixelShaderFunction(VertexShaderOutput input)
> {
> PixelShaderOutput output;
> output.Color = tex2D(TextureSampler, input.TexureCoordinate) * input.Color;
> return output;
> }
> technique
> {
> pass
> {
> VertexShader = compile VS_SHADERMODEL VertexShaderFunction();
> PixelShader = compile PS_SHADERMODEL PixelShaderFunction();
> }
> }