示例#1
0
        public override void Render(SSRenderConfig renderConfig)
        {
            if (Mesh != null)
            {
                base.Render(renderConfig);

                Matrix4 modelView = this.worldMat * renderConfig.invCameraViewMatrix;
                modelView = OpenTKHelper.BillboardMatrix(ref modelView);
                GL.MatrixMode(MatrixMode.Modelview);
                GL.LoadMatrix(ref modelView);

                if (isOcclusionQueueryEnabled)
                {
                    GL.BeginQuery(QueryTarget.SamplesPassed, GL_query_id);
                }

                Mesh.renderMesh(renderConfig);

                if (isOcclusionQueueryEnabled)
                {
                    GL.EndQuery(QueryTarget.SamplesPassed);
                }
            }
        }
示例#2
0
        public virtual void Render(SSRenderConfig renderConfig)
        {
            // compute and set the modelView matrix, by combining the cameraViewMat
            // with the object's world matrix
            //    ... http://www.songho.ca/opengl/gl_transform.html
            //    ... http://stackoverflow.com/questions/5798226/3d-graphics-processing-how-to-calculate-modelview-matrix
            renderBoundingSphereMesh(renderConfig);

            Matrix4 modelViewMat = this.worldMat * renderConfig.invCameraViewMatrix;

            if (this.renderState.matchScaleToScreenPixels)
            {
                Matrix4 scaleCompenstaion = OpenTKHelper.ScaleToScreenPxViewMat(
                    this.Pos, this.Scale.X, ref renderConfig.invCameraViewMatrix, ref renderConfig.projectionMatrix);
                modelViewMat = scaleCompenstaion * modelViewMat;
            }
            if (this.renderState.doBillboarding)
            {
                modelViewMat = OpenTKHelper.BillboardMatrix(ref modelViewMat);
            }
            GL.MatrixMode(MatrixMode.Modelview);
            GL.LoadMatrix(ref modelViewMat);

            resetTexturingState();

            if (renderConfig.drawingShadowMap)
            {
                if (renderConfig.drawingPssm && renderConfig.pssmShader != null)
                {
                    renderConfig.pssmShader.Activate();
                    renderConfig.pssmShader.UniObjectWorldTransform = this.worldMat;
                }
                else
                {
                    SSShaderProgram.DeactivateAll();
                }
            }
            else
            {
                if (renderState.noShader)
                {
                    SSShaderProgram.DeactivateAll();
                }
                else
                {
                    setDefaultShaderState(renderConfig.mainShader, renderConfig);
                }
                setMaterialState();

                if (this.alphaBlendingEnabled)
                {
                    GL.Enable(EnableCap.Blend);
                    GL.BlendEquation(renderState.blendEquationMode);
                    GL.BlendFunc(renderState.blendFactorSrc, renderState.blendFactorDest);
                }
                else
                {
                    GL.Disable(EnableCap.Blend);
                }

                if (this.renderState.lighted)
                {
                    GL.Enable(EnableCap.Lighting);
                    GL.ShadeModel(ShadingModel.Flat);
                }
                else
                {
                    GL.Disable(EnableCap.Lighting);
                }
            }

            if (this.renderState.alphaTest)
            {
                GL.Enable(EnableCap.AlphaTest);
            }
            else
            {
                GL.Disable(EnableCap.AlphaTest);
            }

            if (this.renderState.depthTest)
            {
                GL.Enable(EnableCap.DepthTest);
                GL.DepthFunc(renderState.depthFunc);
            }
            else
            {
                GL.Disable(EnableCap.DepthTest);
            }
            GL.DepthMask(this.renderState.depthWrite);

            GL.Disable(EnableCap.LineStipple);

            if (preRenderHook != null)
            {
                preRenderHook(this, renderConfig);
            }
        }
        public override void Render(SSRenderConfig renderConfig)
        {
            Matrix4 modelView = this.worldMat * renderConfig.invCameraViewMatrix;

            // allow particle system to react to camera/worldview
            particleSystem.updateCamera(ref modelView, ref renderConfig.projectionMatrix);

            // do we have anything to draw?
            if (particleSystem.activeBlockLength <= 0)
            {
                return;
            }

            base.Render(renderConfig);

            // select either instance shader or instance pssm shader
            ISSInstancableShaderProgram instanceShader = renderConfig.instanceShader;

            if (renderConfig.drawingShadowMap)
            {
                if (renderConfig.drawingPssm)
                {
                    renderConfig.instancePssmShader.Activate();
                    renderConfig.instancePssmShader.UniObjectWorldTransform = this.worldMat;
                    instanceShader = renderConfig.instancePssmShader;
                }
            }
            else
            {
                if (!globalBillboarding && base.alphaBlendingEnabled)
                {
                    // Must be called before updating buffers
                    particleSystem.sortByDepth(ref modelView);

                    // Fixes flicker issues for particles with "fighting" view depth values
                    // Also assumes the particle system is the last to be drawn in a scene
                    GL.DepthFunc(DepthFunction.Lequal);
                }
                if (depthRead)
                {
                    GL.Enable(EnableCap.DepthTest);
                }
                else
                {
                    GL.Disable(EnableCap.DepthTest);
                }
                GL.DepthMask(depthWrite);

                // texture binding setup
                renderConfig.instanceShader.Activate();
                renderConfig.instanceShader.UniObjectWorldTransform = this.worldMat;
                if (base.textureMaterial != null)
                {
                    renderConfig.instanceShader.SetupTextures(base.textureMaterial);
                }
            }

            if (globalBillboarding)
            {
                // Setup "global" billboarding. (entire particle system is rendered as a camera-facing
                // billboard and will show the same position of particles from all angles)
                modelView = OpenTKHelper.BillboardMatrix(ref modelView);
                GL.MatrixMode(MatrixMode.Modelview);
                GL.LoadMatrix(ref modelView);
            }

            instanceShader.Activate();

            // prepare attribute arrays for draw
            GL.PushClientAttrib(ClientAttribMask.ClientAllAttribBits);
            prepareAttribute(_posBuffer, instanceShader.AttrInstancePos,
                             particleSystem.positions);
            prepareAttribute(_orientationXYBuffer, instanceShader.AttrInstanceOrientationXY,
                             particleSystem.orientationsXY);
            prepareAttribute(_orientationZBuffer, instanceShader.AttrInstanceOrientationZ,
                             particleSystem.orientationsZ);
            prepareAttribute(_masterScaleBuffer, instanceShader.AttrInstanceMasterScale,
                             particleSystem.masterScales);
            prepareAttribute(_componentScaleXYBuffer, instanceShader.AttrInstanceComponentScaleXY,
                             particleSystem.componentScalesXY);
            prepareAttribute(_componentScaleZBuffer, instanceShader.AttrInstanceComponentScaleZ,
                             particleSystem.componentScalesZ);
            prepareAttribute(_colorBuffer, instanceShader.AttrInstanceColor,
                             particleSystem.colors);

            //prepareAttribute(m_spriteIndexBuffer, instanceShader.AttrInstanceSpriteIndex, m_ps.SpriteIndices);
            prepareAttribute(_spriteOffsetUBuffer, instanceShader.AttrInstanceSpriteOffsetU,
                             particleSystem.spriteOffsetsU);
            prepareAttribute(_spriteOffsetVBuffer, instanceShader.AttrInstanceSpriteOffsetV,
                             particleSystem.SpriteOffsetsV);
            prepareAttribute(_spriteSizeUBuffer, instanceShader.AttrInstanceSpriteSizeU,
                             particleSystem.SpriteSizesU);
            prepareAttribute(_spriteSizeVBuffer, instanceShader.AttrInstanceSpriteSizeV,
                             particleSystem.SpriteSizesV);

            // do the draw
            mesh.renderInstanced(renderConfig, particleSystem.activeBlockLength, PrimitiveType.Triangles);

            GL.PopClientAttrib();
            //this.boundingSphere.Render(ref renderConfig);
        }