@willmotil wrote:
First Im using the crossplatform template on windows. Second really stink with shaders in monogame.
What im trying to do is draw a custom vertex quad and shade it with a simple effect Not a basic effect but one loaded in from the content manager.
Question while this builds, why wont it work.
im getting varying shades of blue depending on the value * .55 but no image at allsampler TextureSampler : register(s0);
Texture2D myTex2D;float4 PixelShaderFunction(float4 pos : SV_POSITION, float4 color1 : COLOR0, float2 texCoord : TEXCOORD0) : SV_TARGET0
{
float4 tex;
tex = myTex2D.Sample(TextureSampler, color1) *.55;
return tex;
}
technique Technique1
{
pass Pass1
{
PixelShader = compile ps_3_0 PixelShaderFunction();
}
}public void DrawShaded(GameTime gameTime) { // cant pass a texture to a regular effect ? //TestEffectB.Parameters["myTex2D"].SetValue(_tex2d); // 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); TestEffectB.CurrentTechnique.Passes[0].Apply(); _spriteBatch.Draw(_renderTarget, new Vector2(0, 0), Color.White); _spriteBatch.End(); base.Draw(gameTime); }
Now i can use a basic effect to draw the texture to a custom vertex quad but if i try to use a effect that i load in myself. I just can't get it to work. In the above if i change the code in the shader, my screen just alters the entire shade of blue blackground.
Further i can't seem to pass a texture using a parameter to a effect directly.
TestEffectB.Parameters["myTex2D"].SetValue(_tex2d); // errors out.
^ i could do this in xna.Which makes no sense because i can pass in a matrix.
Though even this monogame generated .fx has a problem, its drawing everything redpublic void DrawEffectA(GameTime gameTime)
{
//TestEffectA.Parameters["myTex2D"].SetValue(_tex2d);
TestEffectA.Parameters["WorldViewProjection"].SetValue(_worldviewprojection);
GraphicsDevice.Clear(Color.CornflowerBlue);
foreach (EffectPass pass in TestEffectA.CurrentTechnique.Passes)
{
pass.Apply();
GraphicsDevice.DrawUserIndexedPrimitives(PrimitiveType.TriangleList, _vertices, 0, 4, _indices, 0, 2);
}
base.Draw(gameTime);
}Where is a code sample when ya need one lol.
I never could get a effect to work on custom vertex data and it seems i cant even cheat my way around it by rendering to a target and then shading but
What i really want is to alter the custom vertex positions themselves in the vertex shader. Does anyone have a simple dumbed down example of how to do this with a quad.private VertexPositionNormalTexture[] _vertices; private int[] _indices; private RenderTarget2D _renderTarget; private void CreateQuad() { _vertices = new VertexPositionNormalTexture[4]; _vertices[0].Position = new Vector3(-0.5f, -0.5f, 0f); _vertices[0].TextureCoordinate = new Vector2(0f, 1f); _vertices[0].Normal = Vector3.Backward; _vertices[1].Position = new Vector3(-0.5f, 0.5f, 0f); _vertices[1].TextureCoordinate = new Vector2(0f, 0f); _vertices[1].Normal = Vector3.Backward; _vertices[2].Position = new Vector3(0.5f, -0.5f, 0f); _vertices[2].TextureCoordinate = new Vector2(1f, 1f); _vertices[2].Normal = Vector3.Backward; _vertices[3].Position = new Vector3(0.5f, 0.5f, 0f); _vertices[3].TextureCoordinate = new Vector2(1f, 0f); _vertices[3].Normal = Vector3.Backward; _indices = new int[6]; _indices[0] = 0; _indices[1] = 1; _indices[2] = 2; _indices[3] = 2; _indices[4] = 1; _indices[5] = 3; } }
Posts: 3
Participants: 3