Exemplo n.º 1
0
        private void RenderTessellator(RenderingContext rc)
        {
            //Vector4 lightPosition = new Vector4(0.25f, 0.25f, 1f, 0f);
            var shader = CurrentShader;

            //shader.SetFieldValue("normalmatrix", ref NormalMatrix);
            //GL.UniformMatrix3(parentShape.Uniforms.NormalMatrix, false, ref parentShape.NormalMatrix);
            //GL.Uniform3(Uniforms.LightPosition, 1, ref lightPosition.X);
            //GL.Uniform3(Uniforms.AmbientMaterial, X3DTypeConverters.ToVec3(OpenTK.Graphics.Color4.Aqua)); // 0.04f, 0.04f, 0.04f
            //GL.Uniform3(Uniforms.DiffuseMaterial, 0.0f, 0.75f, 0.75f);

            int PatchMatrix           = GL.GetUniformLocation(CurrentShader.ShaderHandle, "B");
            int TransposedPatchMatrix = GL.GetUniformLocation(CurrentShader.ShaderHandle, "BT");

            Matrix4 bezier = new Matrix4
                                 (-1, 3, -3, 1,
                                 3, -6, 3, 0,
                                 -3, 3, 0, 0,
                                 1, 0, 0, 0);

            GL.UniformMatrix4(PatchMatrix, false, ref bezier);
            GL.UniformMatrix4(TransposedPatchMatrix, true, ref bezier);

            if (_handle.NumVerticies3 > 0)
            {
                GL.UseProgram(shader.ShaderHandle);

                shader.SetFieldValue("size", size);
                shader.SetFieldValue("scale", scale);

                GL.PatchParameter(PatchParameterInt.PatchVertices, 3);
                GL.BindBuffer(BufferTarget.ArrayBuffer, _handle.vbo3);
                Buffering.ApplyBufferPointers(shader);
                GL.DrawArrays(PrimitiveType.Patches, 0, _handle.NumVerticies3);
            }


            if (_handle.NumVerticies4 > 0)
            {
                shader = quadShader;

                GL.UseProgram(shader.ShaderHandle);

                shader.SetFieldValue("size", size);
                shader.SetFieldValue("scale", scale);

                GL.PatchParameter(PatchParameterInt.PatchVertices, 16);
                GL.BindBuffer(BufferTarget.ArrayBuffer, _handle.vbo4);
                Buffering.ApplyBufferPointers(shader);
                GL.DrawArrays(PrimitiveType.Patches, 0, _handle.NumVerticies4);
            }
        }
Exemplo n.º 2
0
        private void RenderSkybox(RenderingContext rc)
        {
            rc.PushMatricies();

            // Inner cubemapped skybox
            //this._shapeInnerCube.Render(rc);

            _shaderInnerCube.Use();
#if APPLY_BACKDROP
            Matrix4 mat4 = rc.cam.GetWorldOrientation();
            _shaderInnerCube.SetFieldValue("modelview", ref mat4);
#endif
            _shaderInnerCube.SetFieldValue("scale", scaleCube);
            _shaderInnerCube.SetFieldValue("size", size);
            _shaderInnerCube.SetFieldValue("coloringEnabled", 0);
            _shaderInnerCube.SetFieldValue("texturingEnabled", 1);
            _shaderInnerCube.SetFieldValue("lightingEnabled", 0);

            _shaderInnerCube.SetFieldValue("projection", ref rc.matricies.projection);
            _shaderInnerCube.SetFieldValue("camscale", rc.cam.Scale.X);
            _shaderInnerCube.SetFieldValue("X3DScale", rc.matricies.Scale);


            texture2d = GL.IsEnabled(EnableCap.Texture2D);

            if (!texture2d)
            {
                GL.Enable(EnableCap.Texture2D);
            }

#if APPLY_BACKDROP
            GL.DepthMask(false);
#endif

            GL.ActiveTexture(TextureUnit.Texture0);
            GL.BindTexture(TextureTarget.TextureCubeMap, tex_cube);
            GL.BindBuffer(BufferTarget.ArrayBuffer, cubeHandle.vbo3);
            Buffering.ApplyBufferPointers(_shaderInnerCube);
            GL.DrawArrays(PrimitiveType.Triangles, 0, cubeHandle.NumVerticies3);

#if APPLY_BACKDROP
            GL.DepthMask(true);
#endif

            if (!texture2d)
            {
                GL.Disable(EnableCap.Texture2D);
            }

            rc.PopMatricies();
        }
        public override void Render(RenderingContext rc)
        {
            base.Render(rc);
            this._shape.Render(rc);

            var size  = new Vector3(1, 1, 1);
            var scale = new Vector3(1, 1, 1);

            _shape.CurrentShader.Use();
#if APPLY_BACKDROP
            Matrix4 mat4 = rc.cam.GetWorldOrientation();
            _shape.CurrentShader.SetFieldValue("modelview", ref mat4);
#endif
            _shape.CurrentShader.SetFieldValue("scale", scale);
            _shape.CurrentShader.SetFieldValue("size", size);

            bool texture2d = GL.IsEnabled(EnableCap.Texture2D);

            if (!texture2d)
            {
                GL.Enable(EnableCap.Texture2D);
            }

#if APPLY_BACKDROP
            GL.DepthMask(false);
#endif
#if CULL_FACE
            GL.Enable(EnableCap.CullFace);
            GL.CullFace(CullFaceMode.Back);
#endif

            //GL.FrontFace(FrontFaceDirection.Cw);
            GL.ActiveTexture(TextureUnit.Texture0);
            GL.BindTexture(TextureTarget.TextureCubeMap, tex_cube);
            GL.BindBuffer(BufferTarget.ArrayBuffer, _handle.vbo3);
            Buffering.ApplyBufferPointers(_shape.CurrentShader);
            //Buffering.ApplyBufferPointers(_shape.uniforms);
            GL.DrawArrays(PrimitiveType.Triangles, 0, _handle.NumVerticies3);
#if APPLY_BACKDROP
            GL.DepthMask(true);
#endif
#if CULL_FACE
            GL.Disable(EnableCap.CullFace);
#endif
            //GL.FrontFace(FrontFaceDirection.Ccw);

            if (!texture2d)
            {
                GL.Disable(EnableCap.Texture2D);
            }
        }
Exemplo n.º 4
0
        public void Render(Shape transform_context, RenderingContext rc)
        {
            if (!renderingEnabled)
            {
                return;
            }

            var shader = bboxShader;

            Matrix4 modelview;
            Vector3 x3dScale = new Vector3(0.06f, 0.06f, 0.06f);

            modelview = calculateModelview(transform_context, rc);

            //const float bbscale = 0.0329999961f; // (rc.cam.calibTrans.X* 0.1f)
            //float bbscale = (rc.cam.calibTrans.X * 0.1f);

            GL.UseProgram(shader.ShaderHandle);
            //rc.matricies.Scale = new Vector3(this.Width, this.Height, this.Depth);
            shader.SetFieldValue("size", new Vector3(this.Width, this.Height, this.Depth) * (x3dScale / 2.0f));
            shader.SetFieldValue("scale", Vector3.One);
            shader.SetFieldValue("modelview", ref modelview);
            shader.SetFieldValue("projection", ref rc.matricies.projection);
            shader.SetFieldValue("camscale", 1.0f);
            shader.SetFieldValue("X3DScale", Vector3.One);
            shader.SetFieldValue("coloringEnabled", 1);
            shader.SetFieldValue("texturingEnabled", 0);
            shader.SetFieldValue("lightingEnabled", 0);


            // BOUNDARY LINES
            GL.BindBuffer(BufferTarget.ArrayBuffer, _handle.vbo3);
            Buffering.ApplyBufferPointers(bboxShader);
            GL.DrawArrays(PrimitiveType.LineLoop, 0, _handle.NumVerticies3);


            // BOUNDARY POINTS
            GL.BindBuffer(BufferTarget.ArrayBuffer, _handle.vbo3);
            Buffering.ApplyBufferPointers(bboxShader);
            GL.DrawArrays(PrimitiveType.Points, 0, _handle.NumVerticies3);

            // MAX-MIN POINTS
            //GL.PointSize(8.0f);
            //GL.BindBuffer(BufferTarget.ArrayBuffer, _handlepb.vbo3);
            //Buffering.ApplyBufferPointers(bboxShader);
            //GL.DrawArrays(PrimitiveType.Points, 0, _handlepb.NumVerticies3);

            PostRender();
        }
Exemplo n.º 5
0
        private void RenderTriangles(RenderingContext rc)
        {
            if (_handle.NumVerticies3 > 0)
            {
                GL.UseProgram(CurrentShader.ShaderHandle);

                CurrentShader.SetFieldValue("size", size);
                CurrentShader.SetFieldValue("scale", scale);

                GL.BindBuffer(BufferTarget.ArrayBuffer, _handle.vbo3);
                Buffering.ApplyBufferPointers(CurrentShader);
                GL.DrawArrays(PrimitiveType.Triangles, 0, _handle.NumVerticies3);

                GL.UseProgram(0);
            }
        }
Exemplo n.º 6
0
        private void RenderQuads(RenderingContext rc)
        {
            if (_handle.NumVerticies4 > 0)
            {
                GL.UseProgram(quadShader.ShaderHandle);

                if (depthMask)
                {
                    ApplyGeometricTransformations(rc, quadShader, this);
                }
                else
                {
                    //REFACTOR!!
                    Matrix4 mat4 = Matrix4.Identity;
                    //Quaternion qRotFix = QuaternionExtensions.EulerToQuat(rc.cam.calibOrient.X, rc.cam.calibOrient.Y, rc.cam.calibOrient.Z);
                    //mat4 *= Matrix4.CreateTranslation(rc.cam.calibTrans) * Matrix4.CreateFromQuaternion(qRotFix);
                    Quaternion qRotFix = QuaternionExtensions.EulerToQuat(0.15f, 3.479997f, 0f);
                    mat4 *= Matrix4.CreateTranslation(new Vector3(0f, 0f, -0.29f)) * Matrix4.CreateFromQuaternion(qRotFix);

                    // test weapon/gun rendering fixed in front of player
                    //TODO: port this to X3D

                    quadShader.SetFieldValue("modelview", ref mat4);

                    RefreshDefaultUniforms(quadShader);

                    quadShader.SetFieldValue("bbox_x", bbox.Width);
                    quadShader.SetFieldValue("bbox_y", bbox.Height);
                    quadShader.SetFieldValue("bbox_z", bbox.Depth);
                    quadShader.SetFieldValue("projection", ref rc.matricies.projection);
                    quadShader.SetFieldValue("camscale", rc.cam.Scale.X);                   //GL.Uniform1(uniformCameraScale, rc.cam.Scale.X);
                    quadShader.SetFieldValue("X3DScale", rc.matricies.Scale);               //GL.Uniform3(uniformX3DScale, rc.matricies.Scale);
                    quadShader.SetFieldValue("coloringEnabled", coloring ? 1 : 0);
                    quadShader.SetFieldValue("texturingEnabled", texturingEnabled ? 1 : 0); //GL.Uniform1(uniforms.a_texturingEnabled, this.texturingEnabled ? 1 : 0);
                }
                quadShader.SetFieldValue("size", size);
                quadShader.SetFieldValue("scale", scale);

                ApplyMaterials(quadShader);

                GL.BindBuffer(BufferTarget.ArrayBuffer, _handle.vbo4);
                Buffering.ApplyBufferPointers(quadShader);
                GL.DrawArrays(PrimitiveType.Quads, 0, _handle.NumVerticies4);

                GL.UseProgram(0);
            }
        }
        public void Render(RenderingContext rc)
        {
            CurrentShader.Use();
            CurrentShader.SetFieldValue("scale", scale);
            CurrentShader.SetFieldValue("size", size);

            var identity = Matrix4.Identity;

            CurrentShader.SetFieldValue("modelview", ref identity);

            GL.Enable(EnableCap.Texture2D);
            GL.DepthMask(false);
            GL.BindTexture(TextureTarget.Texture2D, _crosshair.Index);
            GL.BindBuffer(BufferTarget.ArrayBuffer, vbo);
            Buffering.ApplyBufferPointers(CurrentShader);
            GL.DrawArrays(PrimitiveType.Quads, 0, NumVerticies);
            GL.DepthMask(true);
            GL.BindTexture(TextureTarget.Texture2D, 0);
        }
Exemplo n.º 8
0
        private void RenderLines(RenderingContext rc)
        {
            if (_handle.NumVerticies3 > 0)
            {
                PrimitiveType prim;

                GL.UseProgram(CurrentShader.ShaderHandle);

                CurrentShader.SetFieldValue("lightingEnabled", 0);
                CurrentShader.SetFieldValue("headlightEnabled", 0);

                CurrentShader.SetFieldValue("size", size);
                CurrentShader.SetFieldValue("scale", scale);

                GL.LineWidth(8.0f); // todo: LineProperties

                prim = PrimitiveType.Lines;

                if (typeof(IndexedLineSet).IsInstanceOfType(geometry))
                {
                    IndexedLineSet ils = (IndexedLineSet)geometry;
                    prim = ils.PrimativeType;
                }
                if (typeof(LineSet).IsInstanceOfType(geometry))
                {
                    LineSet ls = (LineSet)geometry;
                    prim = ls.PrimativeType;
                }

                GL.BindBuffer(BufferTarget.ArrayBuffer, _handle.vbo3);
                Buffering.ApplyBufferPointers(CurrentShader);
                GL.DrawArrays(prim, 0, _handle.NumVerticies3);


                GL.UseProgram(0);
                GL.LineWidth(1.0f);
            }
        }
Exemplo n.º 9
0
        private void RenderPoints(RenderingContext rc)
        {
            if (_handle.NumVerticies3 > 0)
            {
                GL.UseProgram(CurrentShader.ShaderHandle);

                CurrentShader.SetFieldValue("lightingEnabled", 0);
                CurrentShader.SetFieldValue("headlightEnabled", 0);

                CurrentShader.SetFieldValue("size", size);
                CurrentShader.SetFieldValue("scale", scale);

                GL.PointSize(8.0f); // todo:  point properties

                GL.BindBuffer(BufferTarget.ArrayBuffer, _handle.vbo3);
                Buffering.ApplyBufferPointers(CurrentShader);
                GL.DrawArrays(PrimitiveType.Points, 0, _handle.NumVerticies3);


                GL.UseProgram(0);
                GL.PointSize(1.0f);
            }
        }
Exemplo n.º 10
0
        public Bitmap GenerateHeightMap(RenderingContext rc)
        {
            GL.BindTexture(TextureTarget.Texture2D, 0);

            Bitmap b = TakeRenderingContextScreenshot(0, 0, 800, 600, () =>
            {

                GL.Enable(EnableCap.Texture2D);

                Vector3 size = new Vector3(1, 1, 1);
                Vector3 scale = new Vector3(1, 1, 1);

                //GL.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha);
                CurrentShader.Use();
                CurrentShader.SetFieldValue("scale", scale);
                CurrentShader.SetFieldValue("size", size);
                CurrentShader.SetFieldValue("seed", (float)seed.NextDouble()); //  (float)rc.Time * 0.001f

                var identity = Matrix4.Identity;
                CurrentShader.SetFieldValue("modelview", ref identity);

                GL.DepthMask(false);
                GL.BindBuffer(BufferTarget.ArrayBuffer, vbo);
                Buffering.ApplyBufferPointers(CurrentShader);
                GL.DrawArrays(PrimitiveType.Quads, 0, NumVerticies);
                GL.DepthMask(true);

            });

            GL.BindTexture(TextureTarget.Texture2D, 0);
            GL.UseProgram(0);

            this.Image = b;

            return b;
        }
Exemplo n.º 11
0
        private void RenderSkydome(RenderingContext rc)
        {
            rc.PushMatricies();

            texture2d = GL.IsEnabled(EnableCap.Texture2D);

            if (texture2d)
            {
                GL.Disable(EnableCap.Texture2D);
            }

            Matrix4 mat4;

            // Outer sky Sphere
            //this._shapeOuter.Render(rc);

            _shaderOuter.Use();



#if APPLY_BACKDROP
            mat4 = rc.cam.GetWorldOrientation();
            _shaderOuter.SetFieldValue("modelview", ref mat4);
#endif
            //_shaderOuter.SetFieldValue("scale", scaleSky);
            _shaderOuter.SetFieldValue("scale", size);
            _shaderOuter.SetFieldValue("size", size);
            if (skydomeColors != null && skydomeColors.Length > 0)
            {
                _shaderOuter.SetFieldValue("skyColors", this.skydomeColors.Length);//_shaderOuter.SetFieldValue("skyColors", this.colors.Length);
                _shaderOuter.SetFieldValue("skyColor", this.skydomeColors, 255 * 3);
            }
            //_shaderOuter.SetFieldValue("skyColor", this.colors, 255 * 3);
            _shaderOuter.SetFieldValue("skyAngle", this.angles, 255);

            _shaderOuter.SetFieldValue("isGround", 0);
            _shaderOuter.SetFieldValue("bbox", bboxOuter);
            _shaderOuter.SetFieldValue("max", max);
            _shaderOuter.SetFieldValue("min", min);

            _shaderOuter.SetFieldValue("projection", ref rc.matricies.projection);
            _shaderOuter.SetFieldValue("camscale", rc.cam.Scale.X);
            _shaderOuter.SetFieldValue("X3DScale", rc.matricies.Scale);

#if APPLY_BACKDROP
            GL.DepthMask(false);
#endif
            if (skydomeComputed)
            {
                GL.BindTexture(TextureTarget.Texture2D, skydomeTexture);
            }

            GL.BindBuffer(BufferTarget.ArrayBuffer, outerHandle.vbo4);
            Buffering.ApplyBufferPointers(_shaderOuter);
            GL.DrawArrays(PrimitiveType.Quads, 0, outerHandle.NumVerticies4);

            if (skydomeComputed)
            {
                GL.BindTexture(TextureTarget.Texture2D, 0);
            }

#if APPLY_BACKDROP
            GL.DepthMask(true);
#endif
            rc.PopMatricies();


            //            rc.PushMatricies();

            //            // Inner ground Hemisphere
            //            //RenderCube(rc);

            //            _shaderInner.Use();
            //#if APPLY_BACKDROP
            //            mat4 = rc.cam.GetWorldOrientation();
            //            _shaderInner.SetFieldValue("modelview", ref mat4);
            //#endif
            //            _shaderInner.SetFieldValue("scale", scaleGround);
            //            _shaderInner.SetFieldValue("size", size);
            //            _shaderOuter.SetFieldValue("skyColor", this.skydomeColors, 255 * 3);
            //            //_shaderInner.SetFieldValue("skyColor", this.colors, 255 * 3);
            //            _shaderInner.SetFieldValue("skyAngle", this.angles, 255);
            //            _shaderInner.SetFieldValue("skyColors", this.colors.Length);
            //            _shaderInner.SetFieldValue("isGround", 1);
            //            _shaderInner.SetFieldValue("bbox", bboxInner);

            //            _shaderInner.SetFieldValue("projection", ref rc.matricies.projection);
            //            _shaderInner.SetFieldValue("camscale", rc.cam.Scale.X);
            //            _shaderInner.SetFieldValue("X3DScale", rc.matricies.Scale);

            //#if APPLY_BACKDROP
            //            GL.DepthMask(false);
            //#endif
            //            GL.BindBuffer(BufferTarget.ArrayBuffer, innerHandle.vbo4);
            //            Buffering.ApplyBufferPointers(_shaderInner);
            //            GL.DrawArrays(PrimitiveType.Quads, 0, innerHandle.NumVerticies4);

            //#if APPLY_BACKDROP
            //            GL.DepthMask(true);
            //#endif


            //            rc.PopMatricies();

            if (texture2d)
            {
                GL.Enable(EnableCap.Texture2D);
            }
        }