//shader name , model type public static void Get(ShaderName shaderName, IShape shape) { //add to the base shapea additional stuff defined by Vector Structure indices = shape.Indexes; shaderEffect = ShaderFactory.Create(shaderName); modelShader = ModelShaderFactory.Create(shaderEffect.VertexType, shape.Vertexes); //var model = new Modelf.Model(); //model.LoadModel("Cube"); //modelShader = ModelShaderFactory.Create(shaderEffect.VertexType, model.Data); }
public Bitmap(Device device, IShaderEffect shaderEffect, ShaderName shader, SystemConfiguration winCfg, Vector2 bitmapDimensions) { screenHeight = winCfg.Height; screenWidth = winCfg.Width; bitmapWidth = bitmapDimensions.X; bitmapHeight = bitmapDimensions.Y; previousLocation.X = -1; previousLocation.Y = -1; this.device = device; InitializeBuffers(); //loadTexture //new D3DShader(); }
public static void Render(ModelX model, IShaderEffect effect, Vector3 ambientColor, int materialsSet) { GraphicsDevice device = model.VertexBuffer.GraphicsDevice; Material[] materials = model.Materials(materialsSet); device.SetVertexBuffer(model.VertexBuffer); for (int steps = 0; steps < 2; ++steps) { for (int idx = 0; idx < model.Subsets.Length; ++idx) { var subset = model.Subsets[idx]; Material material = materials[subset.Material]; if (steps == 0) { if (material.Opacity < 1) { continue; } } if (steps == 1) { if (material.Opacity == 1) { continue; } } device.Indices = subset.IndexBuffer; //// Draw the triangle. effect.DiffuseColor = material.Diffuse; effect.AmbientLightColor = ambientColor * material.Ambient; effect.SpecularColor = material.Specular; effect.EmissiveColor = material.Emissive; effect.Alpha = material.Opacity; MaterialTextures textures = material.Textures; effect.SpecularPower = material.SpecularExponent; Texture2D texture = textures != null ? textures.Diffuse : null; effect.Texture = texture; effect.TextureEnabled = texture != null; effect.Apply(0); int startIndex = 0; while (startIndex < subset.Indices.Length) { int primitiveCount = Math.Min((subset.Indices.Length - startIndex) / 3, 30000); device.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, model.Vertices.Length, startIndex, primitiveCount); startIndex += primitiveCount * 3; } } } }
public void Render(IShaderEffect effect, Vector3 ambientColor, int materialsSet) { ModelXRenderer.Render(this, effect, ambientColor, materialsSet); }
public D3DShader(Device device, IShaderEffect shaderEffect, ShaderName shader) { this.device = device; this.shader = shader; try { vertexShaderByteCode = ShaderBytecode.CompileFromFile(shaderEffect.EffectShaderFileName, shaderEffect.VsFunctionName, shaderEffect.VsVersion.ToString()); } catch (Exception ex) { throw new Exception("vertexShaderByteCode: " + ex); } try { pixelShaderByteCode = ShaderBytecode.CompileFromFile(shaderEffect.EffectShaderFileName, shaderEffect.PsFunctionName, shaderEffect.PsVersion.ToString()); } catch (Exception ex) { throw new Exception("vertexShaderByteCode: " + ex); } try { vertexShader = new VertexShader(device, vertexShaderByteCode); } catch (Exception ex) { throw new Exception("vertexShader: " + ex); } try { pixelShader = new PixelShader(device, pixelShaderByteCode); } catch (Exception ex) { throw new Exception("pixelShader: " + ex); } // Now setup the layout of the data that goes into the shader. // It needs to match the VertexType structure in the Model and in the shader. InputElement[] inputElementDesc = InputLayoutFactory.Create(shaderEffect.VertexType); CreateInputLayout(inputElementDesc); vertexShaderByteCode.Dispose(); pixelShaderByteCode.Dispose(); constantMatrixBuffer = GetConstantMatrixBuffer <BufferTypes.WorldViewProj>(device); //is there any differnece between loading one shader wih multiple effects //and more shaders with only one effect? if (shader != ShaderName.Color) { LoadTextureShader(); } //shader.GetPerObjectBufferType<DiffuseLightBufferType> if (shader == ShaderName.ParallaxMapping || shader == ShaderName.Diffuse || shader == ShaderName.Bumpmaping || shader == ShaderName.LightingEffect) { constantLightBuffer = GetConstantMatrixBuffer <BufferTypes.DiffuseLightBufferType>(device); } if (shader == ShaderName.Ambient) { constantLightBuffer = GetConstantMatrixBuffer <BufferTypes.AmbientLightBufferType>(device); } if (shader == ShaderName.Specular || shader == ShaderName.DirectionalLightingParallaxMapping) { constantLightBuffer = GetConstantMatrixBuffer <BufferTypes.SpecularLightBufferType>(device); } if (shader == ShaderName.ParallaxMapping || shader == ShaderName.Bumpmaping || shader == ShaderName.Specular || shader == ShaderName.ParallaxMapping || shader == ShaderName.DirectionalLightingParallaxMapping) { constantCameraBuffer = GetConstantMatrixBuffer <BufferTypes.CameraBufferType>(device); } }