Beispiel #1
0
 bool IShader.SetAttribute(Xen.Graphics.ShaderSystem.IShaderSystem state, int name_uid, Matrix[] value)
 {
     throw new NotImplementedException();
 }
Beispiel #2
0
        public void Bind(Xen.Graphics.ShaderSystem.IShaderSystem state)
        {
            bool tc, ic;
            int  deviceID = state.Begin(this, 4, 0, out tc, out ic);

            if (device != deviceID)
            {
                if (vs != null)
                {
                    vs.Dispose();
                }
                if (ps != null)
                {
                    ps.Dispose();
                }

                device = deviceID;

                //internally, the code is smart enough to not duplicate creating the pixel shader
                state.CreateShaders(out vs, out ps, vsb, psb, 0, 0, 0, 0);
            }

            float randX = (float)(random.NextDouble());
            float randY = (float)(random.NextDouble());

            this.psConstants[4].Z = randX;
            this.psConstants[4].W = randY;

            //random texture is limited in size, so randomly offset by a tiny amount
            randX = (float)((random.NextDouble() * 2 - 1) / 256.0);
            randY = (float)((random.NextDouble() * 2 - 1) / 256.0);

            this.psConstants[5].X = randX;
            this.psConstants[5].Y = randY;

            state.SetShaders(this.vs, this.ps);

            TextureSamplerState point = TextureSamplerState.PointFiltering;

            state.SetPixelShaderSampler(0, randTexture, point);

            if (positionSize != null)
            {
                state.SetPixelShaderSampler(1, positionSize, point);
            }
            if (velocityRotation != null)
            {
                state.SetPixelShaderSampler(2, velocityRotation, point);
            }

            if (this.colourSamplerIndex != -1)
            {
                state.SetPixelShaderSampler(this.colourSamplerIndex, colourValues, point);
            }

            if (this.userSamplerIndex != -1)
            {
                state.SetPixelShaderSampler(this.userSamplerIndex, userValues, point);
            }

            if (this.lifeSamplerIndex != -1)
            {
                state.SetPixelShaderSampler(this.lifeSamplerIndex, lifeTexture, point);
            }


            state.SetWorldViewProjectionMatrix(this.vreg.Matrix4Transpose(0), ref this.world);

            const float randTextureSize    = (float)RandomValueTexture.Resolution;
            const float invRandTextureSize = 1.0f / randTextureSize;

            if (enabledMoveVS || enabledAddVS)
            {
                for (int i = 0; i < 4; i++)                 //copy the WVP matrix
                {
                    this.vsMoveConstants[i] = this.vreg.array[i];
                }

                vsMoveConstants[6] = new Vector4(randTextureSize, invRandTextureSize, 0, 0);

                state.SetShaderConstants(this.vsMoveConstants, psConstants);
            }
            else
            {
                state.SetWindowSizeVector2(this.vreg.Vector2(4), ref this.viewsize);
                this.vreg.array[6] = new Vector4(randTextureSize, invRandTextureSize, 0, 0);

                state.SetShaderConstants(this.vreg.array, psConstants);
            }
        }