Ejemplo n.º 1
0
 public void Render()
 {
     PlatformRenderer.SetTexture(0, Texture1);
     PlatformRenderer.SetTexture(1, Texture2);
     for (int i = 0; i < Material.PassCount; i++)
     {
         Material.Apply(i);
         Mesh.DrawIndexed(StartIndex, LastIndex - StartIndex);
     }
 }
Ejemplo n.º 2
0
 public void Apply(int pass)
 {
     shaderParams.Set(radiusKey, Radius);
     shaderParams.Set(brightnessKey, Brightness);
     shaderParams.Set(colorKey, Color);
     PlatformRenderer.SetTexture(1, MaskTexture);
     PlatformRenderer.SetBlendState(Blending.GetBlendState());
     PlatformRenderer.SetShaderProgram(AlphaIntensityShaderProgram.Instance);
     PlatformRenderer.SetShaderParams(shaderParamsArray);
 }
Ejemplo n.º 3
0
 public void Apply(int pass)
 {
     shaderParams.Set(brightnessKey, Brightness);
     shaderParams.Set(rangeKey, Range);
     shaderParams.Set(colorKey, Color);
     PlatformRenderer.SetTexture(1, MaskTexture);
     PlatformRenderer.SetBlendState(Blending.GetBlendState());
     PlatformRenderer.SetShaderProgram(DissolveMaterialShaderProgram.Instance);
     PlatformRenderer.SetShaderParams(shaderParamsArray);
 }
Ejemplo n.º 4
0
        public void Apply(int pass)
        {
            PlatformRenderer.SetBlending(Blending);
            PrepareShaderProgram();
            program.Use();
            program.LoadMatrix(program.WorldViewProjUniformId, Renderer.FixupWVP(Renderer.WorldViewProjection));
            program.LoadColor(program.DiffuseColorUniformId, DiffuseColor);
            program.LoadMatrix(program.WorldUniformId, Renderer.World);

            if (processLightning && lightSource != null)
            {
                program.LoadColor(program.LightColorUniformId, lightSource.Color);
                program.LoadVector3(program.LightDirectionUniformId, lightSource.Position.Normalized);
                program.LoadFloat(program.LightIntensityUniformId, lightSource.Intensity);
                program.LoadFloat(program.LightStrengthUniformId, lightSource.Strength);
                program.LoadFloat(program.AmbientLightUniformId, lightSource.Ambient);

                if (recieveShadows)
                {
                    var lightWVP = Renderer.World * lightSource.ViewProjection * Matrix44.CreateScale(new Vector3(1, -1, 1));
                    program.LoadMatrix(program.LightWorldViewProjectionUniformId, lightWVP);
                    program.LoadColor(program.ShadowColorUniformId, lightSource.ShadowColor);
                    PlatformRenderer.SetTexture(lightSource.ShadowMap, CommonMaterialProgram.ShadowMapTextureStage);
                }
            }

            if (skinEnabled)
            {
                program.LoadMatrixArray(program.BonesUniformId, boneTransforms, boneCount);
            }

            if (fogMode != FogMode.None)
            {
                program.LoadMatrix(program.WorldViewUniformId, Renderer.WorldView);
                program.LoadColor(program.FogColorUniformId, FogColor);
                if (fogMode == FogMode.Linear)
                {
                    program.LoadFloat(program.FogStartUniformId, FogStart);
                    program.LoadFloat(program.FogEndUniformId, FogEnd);
                }
                else
                {
                    program.LoadFloat(program.FogDensityUniformId, FogDensity);
                }
            }

            if (diffuseTexture != null)
            {
                PlatformRenderer.SetTexture(diffuseTexture, CommonMaterialProgram.DiffuseTextureStage);
            }
        }
Ejemplo n.º 5
0
 public void Apply(int pass)
 {
     PlatformRenderer.SetTexture(Texture1, 0);
     PlatformRenderer.SetTexture(Texture2, 1);
     if (PassCount == 2 && pass == 0)
     {
         PlatformRenderer.SetBlending(Blending.Alpha, PremulAlpha);
     }
     else
     {
         PlatformRenderer.SetBlending(Blending, PremulAlpha);
     }
     PlatformRenderer.SetShaderProgram(ShaderProgram);
 }
Ejemplo n.º 6
0
 public void Apply(int pass)
 {
     PlatformRenderer.SetTexture(Texture, 0);
     PlatformRenderer.SetTexture(null, 1);
     if (pass == 0)
     {
         PlatformRenderer.SetBlending(Blending.LcdTextFirstPass, false);
         PlatformRenderer.SetShaderProgram(shaderProgramPass1);
     }
     else
     {
         PlatformRenderer.SetBlending(Blending.LcdTextSecondPass, false);
         PlatformRenderer.SetShaderProgram(shaderProgramPass2);
     }
 }
Ejemplo n.º 7
0
        public void UpdateTexture()
        {
            if (HasNewTexture)
            {
                HasNewTexture = false;
                var sample      = currentVideoSample;
                var pinnedArray = GCHandle.Alloc(sample.Data, GCHandleType.Pinned);
                var pointer     = pinnedArray.AddrOfPinnedObject();
                lumaTexture.LoadImage(pointer, width, height, Format.R8_UNorm);

                chromaTexture.LoadImage(pointer + width * height, width / 2, height / 2, Format.R8G8_UNorm);
                pinnedArray.Free();

                RendererWrapper.Current.PushState(RenderState.Viewport | RenderState.Shader | RenderState.Blending);
                RendererWrapper.Current.Viewport = new Viewport(0, 0, texture.ImageSize.Width, texture.ImageSize.Height);
                RendererWrapper.Current.PushRenderTarget(texture);
                PlatformRenderer.SetTexture(0, lumaTexture);
                PlatformRenderer.SetTexture(1, chromaTexture);
                material.Apply(0);
                mesh.DrawIndexed(0, mesh.Indices.Length);
                RendererWrapper.Current.PopRenderTarget();
                RendererWrapper.Current.PopState();
            }
        }
Ejemplo n.º 8
0
        public void Render(Widget parentWidget)
        {
            Renderer.Flush();
            var animationTime = parentWidget.AnimationTime;
            // Find the morph targets to interpolate in between.
            MorphTarget target0, target1;

            if (MorphTargets.Count == 1)
            {
                target0 = target1 = MorphTargets[0];
            }
            else
            {
                while (true)
                {
                    target0 = MorphTargets[currentTarget];
                    target1 = MorphTargets[currentTarget + 1];
                    if (animationTime < target0.Timestamp)
                    {
                        if (currentTarget == 0)
                        {
                            break;
                        }
                        currentTarget--;
                    }
                    else if (animationTime <= target1.Timestamp)
                    {
                        break;
                    }
                    else if (currentTarget >= MorphTargets.Count - 2)
                    {
                        // We got across the rightmost target.
                        target0 = target1;
                        break;
                    }
                    else
                    {
                        currentTarget++;
                    }
                }
            }
            // Create the mesh if there is no any.
            if (target0.Mesh == null)
            {
                target0.Mesh = new Mesh {
                    VertexBuffers = new IVertexBuffer[] { UVBuffer, target0.PosColorBuffer, target1.PosColorBuffer },
                    Attributes    = new[] {
                        new[] { ShaderPrograms.Attributes.UV1 },
                        new[] { ShaderPrograms.Attributes.Pos1, ShaderPrograms.Attributes.Color1 },
                        new[] { ShaderPrograms.Attributes.Pos2, ShaderPrograms.Attributes.Color2 }
                    },
                    IndexBuffer = IndexBuffer
                };
            }
            // Calculate the interpolation koefficient.
            float t;

            if (animationTime <= target0.Timestamp)
            {
                t = 0;
            }
            else if (animationTime >= target1.Timestamp)
            {
                t = 1;
            }
            else
            {
                t = (float)((animationTime - target0.Timestamp) / (target1.Timestamp - target0.Timestamp));
            }
            // Render all of it.
            if (shaderProgram == null)
            {
                var options = ShaderOptions.VertexAnimation;
                shaderProgram      = ShaderPrograms.Instance.GetShaderProgram(ShaderId.Diffuse, 1, options);
                morphKoeffUid      = shaderProgram.GetUniformId("morphKoeff");
                globalColorUid     = shaderProgram.GetUniformId("globalColor");
                globalTransformUid = shaderProgram.GetUniformId("globalTransform");
            }
            PlatformRenderer.SetBlending(Blending.Alpha);
            PlatformRenderer.SetShaderProgram(shaderProgram);
            var globalColor = parentWidget.GlobalColor;

            shaderProgram.LoadFloat(morphKoeffUid, t);
            if (loadedGlobalColor.ABGR != globalColor.ABGR)
            {
                loadedGlobalColor = globalColor;
                var globalColorVec4 = (globalColor.ABGR == 0xFFFFFFFF) ?
                                      Vector4.One : new Vector4(
                    globalColor.R / 255f,
                    globalColor.G / 255f,
                    globalColor.B / 255f,
                    globalColor.A / 255f);
                shaderProgram.LoadVector4(globalColorUid, globalColorVec4);
            }
            shaderProgram.LoadMatrix(globalTransformUid, (Matrix44)parentWidget.LocalToWorldTransform);
            foreach (var sm in Batches)
            {
                PlatformRenderer.SetTexture(sm.Texture, 0);
                PlatformRenderer.DrawTriangles(target0.Mesh, sm.StartIndex, sm.IndexCount);
            }
        }