@willmotil wrote:
It seems i have a bigger problem then my original question i was about to ask.
im using gl on win7
Its saying a vertex shader must be set when trying to draw a custom vertex type ?
The shader compiles. I set the effect as soon as i loaded it and this is a pretty small test class.I had to add a VertexDeclaration to the draw call now, So im thinking im doing it wrong or something ?
My draw code looks like this im just drawing a single quad.
myEffect.Parameters["TextureA"].SetValue(wall00); myEffect.Parameters["TextureB"].SetValue(wall01); myEffect.CurrentTechnique = myEffect.Techniques["BlankTechniqueA"]; // GraphicsDevice.DrawUserIndexedPrimitives ( PrimitiveType.TriangleList ,qbItem.spriteVertices ,0 ,4 ,qbItem.triangleIndexList ,0 ,2 ,new VertexDeclaration(VertexPositionColorUvTexture.VertexElements) );
for the type
public struct VertexPositionColorUvTexture { public Vector3 Position; // 6 bytes public Color Color; // 4 bytes public Vector2 TextureCoordinate; // 4 bytes public Vector2 WhichTexture; // 4 bytes private static int currentByteSize = 0; public static int Offset(float n) { currentByteSize += 2; return currentByteSize - 2; } public static int Offset(Vector2 n) { currentByteSize += 4; return currentByteSize - 4; } public static int Offset(Color n) { currentByteSize += 4; return currentByteSize - 4; } public static int Offset(Vector3 n) { currentByteSize += 6; return currentByteSize - 6; } public static int Offset(Vector4 n) { currentByteSize += 8; return currentByteSize - 8; } public static VertexElement[] VertexElements = new VertexElement[] { new VertexElement( Offset(Vector3.Zero), VertexElementFormat.Vector3, VertexElementUsage.Position, 0 ), new VertexElement( Offset(Color.White), VertexElementFormat.Color, VertexElementUsage.Color, 0 ), new VertexElement( Offset(Vector2.Zero), VertexElementFormat.Vector2, VertexElementUsage.TextureCoordinate, 0 ), new VertexElement( Offset(Vector2.Zero), VertexElementFormat.Vector2, VertexElementUsage.TextureCoordinate, 1 ), }; }
here is the shader.
//_______________________________ based on lithiums basic shader // DirectBatch fx #if OPENGL #define SV_POSITION POSITION #define VS_SHADERMODEL vs_3_0 #define PS_SHADERMODEL ps_3_0 #else #define VS_SHADERMODEL vs_4_0_level_9_1 #define PS_SHADERMODEL ps_4_0_level_9_1 #endif Texture2D TextureA; sampler2D TextureSamplerA = sampler_state { Texture = <TextureA>; }; Texture2D TextureB; sampler2D TextureSamplerB = sampler_state { Texture = <TextureB>; }; struct VertexShaderInput { float4 Position : POSITION0; float4 Color : COLOR0; float2 TexureCoordinate : TEXCOORD0; float2 TexureCoordinateB : TEXCOORD1; }; struct VertexShaderOutput { float4 Position : SV_Position; float4 Color : COLOR0; float2 TexureCoordinate : TEXCOORD0; float2 TexureCoordinateB : TEXCOORD1; }; struct PixelShaderOutput { float4 Color : COLOR0; }; VertexShaderOutput VertexShaderFunction(VertexShaderInput input) { VertexShaderOutput output; output.Position = input.Position; output.Color = input.Color; output.TexureCoordinate = input.TexureCoordinate; output.TexureCoordinateB = input.TexureCoordinateB; return output; } // arrgg humm PixelShaderOutput PixelShaderFunction(VertexShaderOutput input) { PixelShaderOutput output; // test float4 A = tex2D(TextureSamplerA, input.TexureCoordinate) * input.Color; // cb is filled with zeros ? float4 B = tex2D(TextureSamplerB, input.TexureCoordinate) * input.Color; //if (B.a > .025) A.a = B.a; A.a = B.a; float4 C = tex2D(TextureSamplerA, input.TexureCoordinateB) * input.Color; float4 D = tex2D(TextureSamplerB, input.TexureCoordinateB) * input.Color; // secondary test custom format if (C.a < D.a) A.b = .50; output.Color = A; // return output; } //PixelShaderOutput PixelShaderFunction(VertexShaderOutput input) //{ // PixelShaderOutput output; // output.Color = tex2D(TextureSampler, input.TexureCoordinate) * input.Color; // return output; //} technique BlankTechniqueA { pass { VertexShader = compile VS_SHADERMODEL VertexShaderFunction(); PixelShader = compile PS_SHADERMODEL PixelShaderFunction(); } }
Here is the xnb data.
It looks like its in there to me ?
XNBd § zMicrosoft.Xna.Framework.Content.EffectReader, MonoGame.Framework, Version=3.6.0.1227, Culture=neutral, PublicKeyToken=null MGFX ¬\Õ #ifdef GL_ES precision mediump float; precision mediump int; #endif const vec4 ps_c0 = vec4(0.5, 0.0, 0.0, 0.0); vec4 ps_r0; vec4 ps_r1; uniform sampler2D ps_s0; uniform sampler2D ps_s1; varying vec4 vFrontColor; #define ps_v0 vFrontColor #define ps_oC0 gl_FragColor varying vec4 vTexCoord0; #define ps_v1 vTexCoord0 varying vec4 vTexCoord1; #define ps_v2 vTexCoord1 void main() { ps_r0 = texture2D(ps_s1, ps_v1.xy); ps_oC0.w = ps_r0.w * ps_v0.w; ps_r0 = texture2D(ps_s1, ps_v2.xy); ps_r0.x = ps_r0.w * ps_v0.w; ps_r1 = texture2D(ps_s0, ps_v2.xy); ps_r0.x = (ps_r1.w * ps_v0.w) + -ps_r0.x; ps_r1 = texture2D(ps_s0, ps_v1.xy); ps_r0.yzw = ps_r1.xyz * ps_v0.xyz; ps_oC0.z = ((ps_r0.x >= 0.0) ? ps_r0.w : ps_c0.x); ps_oC0.xy = ps_r0.yz; } ps_s0 ps_s1 s #ifdef GL_ES precision highp float; precision mediump int; #endif uniform vec4 posFixup; attribute vec4 vs_v0; #define vs_o0 gl_Position attribute vec4 vs_v1; varying vec4 vFrontColor; #define vs_o1 vFrontColor attribute vec4 vs_v2; varying vec4 vTexCoord0; #define vs_o2 vTexCoord0 attribute vec4 vs_v3; varying vec4 vTexCoord1; #define vs_o3 vTexCoord1 void main() { vs_o0 = vs_v0; vs_o1 = vs_v1; vs_o2.xy = vs_v2.xy; vs_o3.xy = vs_v3.xy; gl_Position.y = gl_Position.y * posFixup.y; gl_Position.xy += posFixup.zw * gl_Position.ww; gl_Position.z = gl_Position.z * 2.0 - gl_Position.w; } vs_v0 vs_v1 vs_v2 vs_v3 TextureA TextureB BlankTechniqueA
Posts: 3
Participants: 2