Hello.

Began studying shaders in DirectX. I understand that there are a lot of shader source codes in the network, but I just can’t cross the threshold of entry. Wrote a shader based on several examples, compiled without errors, but the object to which it is applied is not drawn.

I suppose that the joint is somewhere in the technique (it was not described in the examples).

Here is the shader code:

/* ========== ВЕРШИННЫЙ ШЕЙДЕР ========== */ float4x4 world_matrix; // мировая матрица float4x4 view_matrix; // матрица вида float4x4 proj_matrix; // матрица проекции float4 light_position; // положение источника света struct VS_INPUT // Входящие данные { float4 Position: POSITION; float3 Normal: NORMAL; }; struct VS_OUTPUT // Исходящие данные { float4 Position: POSITION; float3 Light: TEXCOORD0; float3 Normal: TEXCOORD1; }; VS_OUTPUT VS_Main(VS_INPUT vs_input) { VS_OUTPUT OUTPUT = (VS_OUTPUT)0; // Произведение мировой, видовой и проекционной матриц float4x4 worldViewProj_matrix = mul(world_matrix, view_matrix); worldViewProj_matrix = mul(worldViewProj_matrix, proj_matrix); // Вычисляем позицию вершины OUTPUT.Position = mul(worldViewProj_matrix, vs_input.Position); //Сохраняем позицию источника света для передачи в пиксельный шейдер OUTPUT.Light = light_position; //Рассчитываем нормаль поверхности и сохраняем для пиксельного шейдера OUTPUT.Normal = normalize(mul(world_matrix, vs_input.Normal)); return OUTPUT; } /* ========== ПИКСЕЛЬНЫЙ ШЕЙДЕР ========== */ float Diffuse_intens; float4 Diffuse_color; float4 PS_Main(float3 Light: TEXCOORD0, float3 Normal : TEXCOORD1) :COLOR0 { return Diffuse_color * Diffuse_intens * dot(Normal, Light); } /* =============== ТЕХНИКА =============== */ technique technique0 { pass p0 { VertexShader = compile vs_2_0 VS_Main(); PixelShader = compile ps_2_0 PS_Main(); } } 

Draw method:

  Material material = new Material(); material.Diffuse = Color.White; material.Ambient = Color.FromArgb(60, 60, 60); device.Material = material; device.Transform.World = Matrix.Identity; device.Transform.World = Matrix.Translation(OffsetVector) * RotationMatrix; device.VertexFormat = CustomVertex.PositionNormalTextured.Format; device.SetTexture(0, MainTexture); #region Параметры шейдера effect.Technique = "technique0"; effect.SetValue("world_matrix", device.Transform.World); effect.SetValue("view_matrix", device.Transform.View); effect.SetValue("proj_matrix", device.Transform.Projection); effect.SetValue("light_position", new float[3] { device.Lights[0].Position.X, device.Lights[0].Position.Y, device.Lights[0].Position.Z }); effect.SetValue("Diffuse_intens", 1); effect.SetValue("Diffuse_color", device.Material.DiffuseColor); #endregion int numPasses = effect.Begin(0); for (int i = 0; i < numPasses; i++) { effect.BeginPass(i); device.DrawUserPrimitives(PrimitiveType.TriangleList, PrimitivesCount, Verts); effect.EndPass(); } effect.End(); device.SetTexture(0, null); device.Transform.World = Matrix.Identity; 

    0

    Protected by spirit community member Jul 28 '16 at 21:05 .

    Thank you for your interest in this issue. Since he collected a large number of low-quality and spam responses, which had to be deleted, now it’s necessary to have 10 reputation points on the site (the bonus for account association is not counted ).

    Maybe you want to answer one of the unanswered questions ?