Exemplo n.º 1
0
 public static void Apply(vec4 cameraPos, float cameraAspect, Texture2D Current, RenderTarget2D Output)
 {
     GridHelper.GraphicsDevice.SetRenderTarget(Output);
     GridHelper.GraphicsDevice.Clear(Color.Transparent);
     Using(cameraPos, cameraAspect, Current);
     GridHelper.DrawGrid();
 }
Exemplo n.º 2
0
        protected virtual vec4 GetResult(vec4 baseColor, vec4 blend)
        {
            vec4 result = blend + baseColor;
            result = clamp(result, 0, 1);

            return result;
        }
Exemplo n.º 3
0
 public DragParam(mat4 projectionMatrix, mat4 viewMatrix, vec4 viewport, Point lastMousePositionOnScreen)
 {
     this.projectionMatrix = projectionMatrix;
     this.viewMatrix = viewMatrix;
     this.lastMousePositionOnScreen = lastMousePositionOnScreen;
     this.viewport = viewport;
 }
        /// <summary>
        /// Move vertexes' position accroding to difference on screen.
        /// <para>根据<paramref name="differenceOnScreen"/>来修改指定索引处的顶点位置。</para>
        /// </summary>
        /// <param name="differenceOnScreen"></param>
        /// <param name="viewMatrix"></param>
        /// <param name="projectionMatrix"></param>
        /// <param name="viewport"></param>
        /// <param name="positionIndexes"></param>
        public override void MovePositions(Point differenceOnScreen,
            mat4 viewMatrix, mat4 projectionMatrix, vec4 viewport, params uint[] positionIndexes)
        {
            base.MovePositions(differenceOnScreen, viewMatrix, projectionMatrix, viewport, positionIndexes);

            this.needsUpdating = true;
        }
Exemplo n.º 5
0
 /// <summary>
 /// Initializes a new instance of the <see cref="mat4"/> struct.
 /// The matrix is initialised with the <paramref name="cols"/>.
 /// </summary>
 /// <param name="cols">The colums of the matrix.</param>
 public mat4(vec4[] cols)
 {
     this.col0 = cols[0];
     this.col1 = cols[1];
     this.col2 = cols[2];
     this.col3 = cols[3];
 }
Exemplo n.º 6
0
 /// <summary>
 /// Initializes a new instance of the <see cref="mat4"/> struct.
 /// This matrix is the identity matrix scaled by <paramref name="scale"/>.
 /// </summary>
 /// <param name="scale">The scale.</param>
 public mat4(float scale)
 {
     this.col0 = new vec4(scale, 0, 0, 0);
     this.col1 = new vec4(0, scale, 0, 0);
     this.col2 = new vec4(0, 0, scale, 0);
     this.col3 = new vec4(0, 0, 0, scale);
 }
Exemplo n.º 7
0
 public mat4(vec4 col0, vec4 col1, vec4 col2, vec4 col3)
 {
     this.col0 = col0;
     this.col1 = col1;
     this.col2 = col2;
     this.col3 = col3;
 }
Exemplo n.º 8
0
        public override void main()
        {
            float real = Position.x * Zoom + Xcenter;
            float imag = Position.y * Zoom + Ycenter;
            float Creal = real;     // change this line...
            float Cimag = imag;     // ...and this one to get a Julia Set

            // Julia Set
                //float Creal = -1.36f;
                //float Cimag = 0.11f;

            float r2 = 0;
            float iter;

            for (iter = 0.0f; iter < MaxIterations && r2 < 4.0f; ++iter)
            {
                float tempreal = real;
                real = (tempreal * tempreal) - (imag * imag) + Creal;
                imag = 2.0f * tempreal * imag + Cimag;
                r2 = (real * real) + (imag * imag);
            }

            // Base the color on the number of iterations
            vec3 color;

            if (r2 < 4.0f)
                color = InnerColor;
            else
                color = mix(OuterColor1, OuterColor2, fract(iter * 0.05f));

            color *= LightIntensity;

            FragColor = new vec4(color, 1.0f);
        }
Exemplo n.º 9
0
        protected override void DoInitialize()
        {
            base.DoInitialize();

            {
                // velocity
                var buffer = VertexBuffer.Create(typeof(vec4), ParticleModel.particleCount, VBOConfig.Vec4, "empty", BufferUsage.DynamicCopy);
                unsafe
                {
                    var random = new Random();
                    var array = (vec4*)buffer.MapBuffer(MapBufferAccess.WriteOnly);
                    for (int i = 0; i < ParticleModel.particleCount; i++)
                    {
                        array[i] = new vec4(
                            (float)(random.NextDouble() - 0.5) * 0.2f,
                            (float)(random.NextDouble() - 0.5) * 0.2f,
                            (float)(random.NextDouble() - 0.5) * 0.2f,
                            0);
                    }
                    buffer.UnmapBuffer();
                }
                this.VelocityBuffer = buffer;
            }

            this.PositionBuffer = this.DataSource.GetVertexAttributeBuffer(ParticleModel.strPosition, null);
        }
Exemplo n.º 10
0
        protected override vec4 GetResult(vec4 baseColor, vec4 blend)
        {
            float noise = (noise1(new vec2(TexCoord * noiseScale)) + 1.0f) * 0.5f;
            vec4 result = (noise < Opacity) ? blend : baseColor;

            return result;
        }
        /// <summary>
        /// Move vertexes' position accroding to difference on screen.
        /// <para>根据<paramref name="differenceOnScreen"/>来修改指定索引处的顶点位置。</para>
        /// </summary>
        /// <param name="differenceOnScreen"></param>
        /// <param name="viewMatrix"></param>
        /// <param name="projectionMatrix"></param>
        /// <param name="viewport"></param>
        /// <param name="positionIndexes"></param>
        public virtual void MovePositions(Point differenceOnScreen,
            mat4 viewMatrix, mat4 projectionMatrix, vec4 viewport, params uint[] positionIndexes)
        {
            if (positionIndexes == null) { return; }
            if (positionIndexes.Length == 0) { return; }

            this.innerPickableRenderer.MovePositions(differenceOnScreen, viewMatrix, projectionMatrix, viewport, positionIndexes);
        }
Exemplo n.º 12
0
        protected override vec4 GetResult(vec4 baseColor, vec4 blend)
        {
            vec4 white = new vec4(1, 1, 1, 1);

            vec4 r = white - ((white - blend) * (white - baseColor));

            return r;
        }
Exemplo n.º 13
0
        protected override vec4 GetResult(vec4 baseColor, vec4 blend)
        {
            vec4 result = new vec4();
            result.rgb = baseColor.rgb;
            result.a = 0;

            return result;
        }
Exemplo n.º 14
0
 public mat4(vec4 r0, vec4 r1, vec4 r2, vec4 r3)
     :base(4)
 {
     this[0, 0] = r0.x; this[1, 0] = r0.y; this[2, 0] = r0.z; this[3, 0] = r0.w;
     this[0, 1] = r1.x; this[1, 1] = r1.y; this[2, 1] = r1.z; this[3, 1] = r1.w;
     this[0, 2] = r2.x; this[1, 2] = r2.y; this[2, 2] = r2.z; this[3, 2] = r2.w;
     this[0, 3] = r3.x; this[1, 3] = r3.y; this[2, 3] = r3.z; this[3, 3] = r3.w;
 }
        /// <summary>
        /// Move vertexes' position accroding to difference on screen.
        /// <para>根据<paramref name="differenceOnScreen"/>来修改指定索引处的顶点位置。</para>
        /// </summary>
        /// <param name="differenceOnScreen"></param>
        /// <param name="viewMatrix"></param>
        /// <param name="projectionMatrix"></param>
        /// <param name="viewport"></param>
        /// <param name="positionIndexes"></param>
        public virtual void MovePositions(Point differenceOnScreen,
            mat4 viewMatrix, mat4 projectionMatrix, vec4 viewport, IEnumerable<uint> positionIndexes)
        {
            if (positionIndexes == null) { return; }
            if (positionIndexes.Count() == 0) { return; }

            this.innerPickableRenderer.MovePositions(differenceOnScreen, viewMatrix, projectionMatrix, viewport, positionIndexes);
        }
Exemplo n.º 16
0
 public static mat4 Translate(ref vec4 t)
 {
     return new mat4(
         1, 0, 0, 0,
         0, 1, 0, 0,
         0, 0, 1, 0,
         t.x, t.y, t.z, 1
         );
 }
Exemplo n.º 17
0
        static float GaussianMixture( float lambda, ref vec4 Data0, ref vec4 Data1, ref vec4 Data2)
        {
            float t = (lambda - 0.380f) / (0.780f - 0.380f);
            float g0 = Gaussian(Data0.y, Data0.z, Data0.w, t);
            float g1 = Gaussian(Data1.y, Data1.z, Data1.w, t);
            float g2 = Gaussian(Data2.y, Data2.z, Data2.w, t);

            return Math.Min(Math.Max(g0 + g1 + g2 + Data0.x, Data1.x), Data2.x);
        }
Exemplo n.º 18
0
 public static void Using(vec4 cameraPos, float cameraAspect, Texture2D Current)
 {
     CompiledEffect.Parameters["vs_param_cameraPos"].SetValue(FragSharpMarshal.Marshal(cameraPos));
     CompiledEffect.Parameters["vs_param_cameraAspect"].SetValue(FragSharpMarshal.Marshal(cameraAspect));
     CompiledEffect.Parameters["fs_param_Current_Texture"].SetValue(FragSharpMarshal.Marshal(Current));
     CompiledEffect.Parameters["fs_param_Current_size"].SetValue(FragSharpMarshal.Marshal(vec(Current.Width, Current.Height)));
     CompiledEffect.Parameters["fs_param_Current_dxdy"].SetValue(FragSharpMarshal.Marshal(1.0f / vec(Current.Width, Current.Height)));
     CompiledEffect.CurrentTechnique.Passes[0].Apply();
 }
Exemplo n.º 19
0
        public override void main()
        {
            vec4 color = texture(texture1, pass_UV) * percent + texture(texture2, pass_UV) * (1.0f - percent);
			if (color.a < 0.1)
			{
				discard();
			}
            out_Color = color;
        }
Exemplo n.º 20
0
 public static mat4 Scale(ref vec4 s)
 {
     return new mat4(
         s.x, 0, 0, 0,
         0, s.y, 0, 0,
         0, 0, s.z, 0,
         0, 0, 0, 1
         );
 }
Exemplo n.º 21
0
        public static mat4 inverse(mat4 m)
        {
            float Coef00 = m[2][2] * m[3][3] - m[3][2] * m[2][3];
            float Coef02 = m[1][2] * m[3][3] - m[3][2] * m[1][3];
            float Coef03 = m[1][2] * m[2][3] - m[2][2] * m[1][3];

            float Coef04 = m[2][1] * m[3][3] - m[3][1] * m[2][3];
            float Coef06 = m[1][1] * m[3][3] - m[3][1] * m[1][3];
            float Coef07 = m[1][1] * m[2][3] - m[2][1] * m[1][3];

            float Coef08 = m[2][1] * m[3][2] - m[3][1] * m[2][2];
            float Coef10 = m[1][1] * m[3][2] - m[3][1] * m[1][2];
            float Coef11 = m[1][1] * m[2][2] - m[2][1] * m[1][2];

            float Coef12 = m[2][0] * m[3][3] - m[3][0] * m[2][3];
            float Coef14 = m[1][0] * m[3][3] - m[3][0] * m[1][3];
            float Coef15 = m[1][0] * m[2][3] - m[2][0] * m[1][3];

            float Coef16 = m[2][0] * m[3][2] - m[3][0] * m[2][2];
            float Coef18 = m[1][0] * m[3][2] - m[3][0] * m[1][2];
            float Coef19 = m[1][0] * m[2][2] - m[2][0] * m[1][2];

            float Coef20 = m[2][0] * m[3][1] - m[3][0] * m[2][1];
            float Coef22 = m[1][0] * m[3][1] - m[3][0] * m[1][1];
            float Coef23 = m[1][0] * m[2][1] - m[2][0] * m[1][1];

            vec4 Fac0 = new vec4(Coef00, Coef00, Coef02, Coef03);
            vec4 Fac1 = new vec4(Coef04, Coef04, Coef06, Coef07);
            vec4 Fac2 = new vec4(Coef08, Coef08, Coef10, Coef11);
            vec4 Fac3 = new vec4(Coef12, Coef12, Coef14, Coef15);
            vec4 Fac4 = new vec4(Coef16, Coef16, Coef18, Coef19);
            vec4 Fac5 = new vec4(Coef20, Coef20, Coef22, Coef23);

            vec4 Vec0 = new vec4(m[1][0], m[0][0], m[0][0], m[0][0]);
            vec4 Vec1 = new vec4(m[1][1], m[0][1], m[0][1], m[0][1]);
            vec4 Vec2 = new vec4(m[1][2], m[0][2], m[0][2], m[0][2]);
            vec4 Vec3 = new vec4(m[1][3], m[0][3], m[0][3], m[0][3]);

            vec4 Inv0 = new vec4(Vec1 * Fac0 - Vec2 * Fac1 + Vec3 * Fac2);
            vec4 Inv1 = new vec4(Vec0 * Fac0 - Vec2 * Fac3 + Vec3 * Fac4);
            vec4 Inv2 = new vec4(Vec0 * Fac1 - Vec1 * Fac3 + Vec3 * Fac5);
            vec4 Inv3 = new vec4(Vec0 * Fac2 - Vec1 * Fac4 + Vec2 * Fac5);

            vec4 SignA = new vec4(+1, -1, +1, -1);
            vec4 SignB = new vec4(-1, +1, -1, +1);
            mat4 Inverse = new mat4(Inv0 * SignA, Inv1 * SignB, Inv2 * SignA, Inv3 * SignB);

            vec4 Row0 = new vec4(Inverse[0][0], Inverse[1][0], Inverse[2][0], Inverse[3][0]);

            vec4 Dot0 = new vec4(m[0] * Row0);
            float Dot1 = (Dot0.x + Dot0.y) + (Dot0.z + Dot0.w);

            float OneOverDeterminant = (1f) / Dot1;

            return Inverse * OneOverDeterminant;
        }
Exemplo n.º 22
0
        public static vec4 radians(vec4 degrees)
        {
            vec4 r;

            r.x = degrees.x * degToRad;
            r.y = degrees.y * degToRad;
            r.z = degrees.z * degToRad;
            r.w = degrees.w * degToRad;

            return r;

        }
Exemplo n.º 23
0
        public override void main()
        {
            vec4 baseColor = texture(BaseImage, TexCoord.xy);
            vec4 blend = texture(BlendImage, TexCoord.xy);


            // Get the result of the operation
            vec4 color = ColorOp(baseColor, blend);

            // Deal with the opacity
            vec4 finalColor = mix(baseColor, color, Opacity);

            FragColor = finalColor;
        }
Exemplo n.º 24
0
        VertexOut SimpleVertexShader(Vertex data, vec4 cameraPos, float cameraAspect)
        {
            VertexOut Output = VertexOut.Zero;

            Output.Position.w = 1;

            Output.Position.x = (data.Position.x - cameraPos.x) / cameraAspect * cameraPos.z;
            Output.Position.y = (data.Position.y - cameraPos.y) * cameraPos.w;

            Output.TexCoords = data.TextureCoordinate;
            Output.Color = data.Color;

            return Output;
        }
Exemplo n.º 25
0
        /// <summary>
        /// Concatenates every value in this matrix with it's corresponding value in the other one.
        /// </summary>
        /// <param name="m">This matrix</param>
        /// <param name="m2">Other matrix</param>
        /// <returns>The concatenated result.</returns>
        public static mat4 Concat(this mat4 m, mat4 m2)
        {
            vec4[] vecs = new vec4[4];

            for (int i = 0; i < vecs.Length; i++)
            {
                vecs[i] = new vec4();
                for (int j = 0; j < vecs.Length; j++)
                {
                    vecs[i][j] = m[i][j] + m2[i][j];
                }
            }

            return new mat4(vecs);
        }
Exemplo n.º 26
0
        public override void main()
        {
            vec4 noisevec = texture(Noise, MCPosition);

            float intensity = abs(noisevec[0] - 0.25f) +
                abs(noisevec[1] - 0.125f) +
                abs(noisevec[2] - 0.0625f) +
                abs(noisevec[3] - 0.03125f);

            float sineval = sin(MCPosition.y * 6.0f + intensity * 12.0f) * 0.5f + 0.5f;

            vec3 color = mix(VeinColor, MarbleColor, sineval) * LightIntensity;

            FragColor = new vec4(color, 1.0f);
        }
Exemplo n.º 27
0
        public override void main()
        {
            float scaledT = fract(TexCoord * Scale);

            float frac1 = clamp(scaledT / Fuzz, 0, 1);
            float frac2 = clamp((scaledT - Width) / Fuzz, 0, 1);

            frac1 = frac1 * (1.0f - frac2);
            frac1 = frac1 * frac1 * (3.0f - (2.0f * frac1));    // Smoothing

            vec3 finalColor = mix(BackColor, StripeColor, frac1);
            finalColor = finalColor * DiffuseColor + SpecularColor;

            FragColor = new vec4(finalColor, 1);
        }
Exemplo n.º 28
0
        private string AsString(uint[] indices, vec4[] verts)
        {
            var sb = new StringBuilder();

            foreach (var idx in indices)
            {
                var v = verts[idx];
                var signs = v.x < 0 ? "-" : "+";
                signs += v.y < 0 ? "-" : "+";
                signs += v.z < 0 ? "-" : "+";
                sb.Append(idx + " : " + signs + "\n");
            }

            return sb.ToString();
        }
Exemplo n.º 29
0
        public void DirectionalLight(int i, vec3 normal, ref vec4 ambient, ref vec4 diffuse, ref vec4 specular)
        {
            float nDotVP;   // normal . light direction
            float nDotHV;   // normal . light half vector
            float pf;       // power factor

            nDotVP = max(0.0f, dot(normal,
                normalize(new vec3(LightSource[i].position))));
            nDotHV = max(0.0f, dot(normal, new vec3(LightSource[i].halfVector)));

            if (nDotVP == 0.0f)
                pf = 0.0f;
            else
                pf = pow(nDotHV, FrontMaterial.shininess);

            ambient += LightSource[i].ambient;
            diffuse += LightSource[i].diffuse * nDotVP;
            specular += LightSource[i].specular * pf;
        }
Exemplo n.º 30
0
        public override void main()
        {
            vec3 color;
            vec2 position;
            vec2 useBrick;

            position = MCPosition / BrickSize;

            if (fract(position.y * 0.5f) > 0.5f)
                position.x += 0.5f;

            position = fract(position);

            useBrick = step(position, BrickPct);

            color = mix(MortarColor, BrickColor, useBrick.x * useBrick.y);
            color *= LightIntensity;

            FragColor = new vec4(color, 1.0f);
        }
Exemplo n.º 31
0
            public Ztorfield(int start, int stop)
            {
                framedelta = T2 - T1;
                this.start = sync(start);
                this.stop  = stop;

                ms = new M[] {
                    // cba to generate this rn
                    new M(v3(1f, 1f, 0f), sin, cos, eq_linear),
                    new M(v3(1f, 1f, 0f), cos, sin, eq_linear),
                    new M(v3(1f, -1f, 0f), sin, cos, eq_linear),
                    new M(v3(1f, -1f, 0f), cos, sin, eq_linear),
                    new M(v3(1f, 0f, 1f), sin, eq_linear, cos),
                    new M(v3(1f, 0f, 1f), cos, eq_linear, sin),
                    new M(v3(1f, 0f, -1f), sin, eq_linear, cos),
                    new M(v3(1f, 0f, -1f), cos, eq_linear, sin),
                    new M(v3(-1f, 1f, 0f), sin, cos, eq_linear),
                    new M(v3(-1f, 1f, 0f), cos, sin, eq_linear),
                    new M(v3(-1f, -1f, 0f), sin, cos, eq_linear),
                    new M(v3(-1f, -1f, 0f), cos, sin, eq_linear),
                    new M(v3(-1f, 0f, 1f), sin, eq_linear, cos),
                    new M(v3(-1f, 0f, 1f), cos, eq_linear, sin),
                    new M(v3(-1f, 0f, -1f), sin, eq_linear, cos),
                    new M(v3(-1f, 0f, -1f), cos, eq_linear, sin),
                    new M(v3(0f, 1f, 1f), eq_linear, cos, sin),
                    new M(v3(0f, 1f, 1f), eq_linear, sin, cos),
                    new M(v3(0f, 1f, -1f), eq_linear, cos, sin),
                    new M(v3(0f, 1f, -1f), eq_linear, sin, cos),
                    new M(v3(0f, -1f, 1f), eq_linear, cos, sin),
                    new M(v3(0f, -1f, 1f), eq_linear, sin, cos),
                    new M(v3(0f, -1f, -1f), eq_linear, cos, sin),
                    new M(v3(0f, -1f, -1f), eq_linear, sin, cos),
                };
                for (int i = 0; i < ms.Length; i++)
                {
                    int a = 0;
                    for (int j = 1; j < 3; j++)
                    {
                        if (ms[i].eqs[j] == cos)
                        {
                            a = j;
                            break;
                        }
                    }
                    int count = 0;
                    for (int j = 0; j < ms.Length; j++)
                    {
                        if (i == j)
                        {
                            continue;
                        }
                        if (ms[j].dir[a] == ms[i].dir[a] &&
                            ms[j].eqs[a] == sin)
                        {
                            ms[i].t[count++] = ms[j];
                        }
                    }
                }

                Random rand = new Random("ztorfield".GetHashCode());

                movs = new MOV[stop - start / MOVETIME];
                MOV __m;

                __m.time = T3;
                __m.m    = ms[23];
                movs[0]  = __m;
                for (int i = 1; i < movs.Length; i++)
                {
                    MOV mov;
                    mov.m    = __m.m.t[rand.Next(4)];
                    mov.time = T3 + i * MOVETIME;
                    movs[i]  = mov;
                    __m      = mov;
                }

                vec3[]      templatepoints = new vec3[DIVH * DIVV];
                int[]       templatelines  = new int[templatepoints.Length * 4];
                const float INTH           = 360f / DIVH;
                const float INTV           = 360f / DIVV;

                for (int a = 0; a < DIVH; a++)
                {
                    vec3  p1   = v3(campos);
                    float anga = rad(INTH * a);
                    for (int b = 0; b < DIVV; b++)
                    {
                        int   idx  = a * DIVV + b;
                        float angb = rad(INTV * b);
                        float dist = RH - RV * cos(angb);
                        vec3  p    = campos + v3(dist * cos(anga), dist * sin(anga), RV * sin(angb));
                        templatepoints[idx] = p;

                        int a_ = (a + 1) % DIVH;
                        int b_ = (b + 1) % DIVV;

                        int _1 = a * DIVV + b;
                        int _2 = a_ * DIVV + b;
                        int _3 = a * DIVV + b_;
                        int _4 = a_ * DIVV + b_;

                        templatelines[idx * 4 + 0] = _1;
                        templatelines[idx * 4 + 1] = _2;
                        templatelines[idx * 4 + 2] = _3;
                        templatelines[idx * 4 + 3] = _4;
                    }
                }

                points  = new vec3[templatepoints.Length * FIELDSIZE * FIELDSIZE * FIELDSIZE * 3];
                _points = new vec3[points.Length];
                lines   = new Oline[points.Length * 2];

                for (int i = 0; i < FIELDSIZE; i++)
                {
                    for (int j = 0; j < FIELDSIZE; j++)
                    {
                        for (int k = 0; k < FIELDSIZE; k++)
                        {
                            vec3 off = v3(0f);
                            vec4 rot = quat(0f, PI2, 0f);
                            mk(templatepoints, templatelines, i, j, k, 0, off, rot);
                            off = v3(-SPACING2, -SPACING2, 0f);
                            rot = quat(PI2, 0f, 0f);
                            mk(templatepoints, templatelines, i, j, k, 1, off, rot);
                            off = v3(0f, -SPACING2, -SPACING2);
                            rot = quat(0f, 0f, 0f);
                            mk(templatepoints, templatelines, i, j, k, 2, off, rot);
                        }
                    }
                }
            }
Exemplo n.º 32
0
 /// <summary>
 /// Returns a bvec4 from component-wise application of IsFinite (!float.IsNaN(v) &amp;&amp; !float.IsInfinity(v)).
 /// </summary>
 public static bvec4 IsFinite(vec4 v) => vec4.IsFinite(v);
Exemplo n.º 33
0
 public void update(int time, vec4 col, vec4 c)
 {
     update(time, col, c, Sprite.Size(spritename));
 }
Exemplo n.º 34
0
 public override void main()
 {
     // TODO: this is where you should start with fragment shader. Only ASCII code are welcome.
     out_Color = pass_Color;
     // this is where your fragment shader ends.
 }
Exemplo n.º 35
0
 public Vertex(vec4 v, uint?idx = null, vec3 normal = new vec3())
     : this(new vec3(v.x, v.y, v.z), idx, normal)
 {
 }
Exemplo n.º 36
0
 public vec4 abs(vec4 v)
 {
     return(new vec4(abs(v.x), abs(v.y), abs(v.z), abs(v.w)));
 }
Exemplo n.º 37
0
 public DragParam(mat4 projectionMatrix, mat4 viewMatrix, vec4 viewport, ivec2 lastMousePositionOnScreen,
                  params uint[] indexes)
     : this(projectionMatrix, viewMatrix, viewport, lastMousePositionOnScreen)
 {
     this.pickedVertexIds.AddRange(indexes);
 }
Exemplo n.º 38
0
 public vec4 Apply(vec4 v)
 => ModelMatrix * v;
Exemplo n.º 39
0
 public void main()
 {
     gl_Position = new vec4(positions[gl_VertexIndex], 0.0f, 1.0f);
     fragColor   = colors[gl_VertexIndex];
 }
Exemplo n.º 40
0
 public virtual void mainImage(out vec4 fragColor, vec2 fragCoord)
 {
     fragColor = new vec4();
 }
Exemplo n.º 41
0
        public VertexAttributeBufferPtr GetVertexAttributeBufferPtr(string bufferName, string varNameInShader)
        {
            if (bufferName == strPosition)
            {
                if (positionBufferPtr == null)
                {
                    using (var buffer = new VertexAttributeBuffer <vec4>(
                               varNameInShader, VertexAttributeConfig.Vec4, BufferUsage.DynamicCopy))
                    {
                        buffer.Create(particleCount);
                        unsafe
                        {
                            var array = (vec4 *)buffer.Header.ToPointer();
                            for (int i = 0; i < particleCount; i++)
                            {
                                array[i] = new vec4(
                                    (float)(random.NextDouble() - 0.5) * 20,
                                    (float)(random.NextDouble() - 0.5) * 20,
                                    (float)(random.NextDouble() - 0.5) * 20,
                                    (float)(random.NextDouble())
                                    );
                            }
                        }

                        positionBufferPtr = buffer.GetBufferPtr();
                    }
                }

                return(positionBufferPtr);
            }
            else if (bufferName == strVelocity)
            {
                if (velocityBufferPtr == null)
                {
                    using (var buffer = new VertexAttributeBuffer <vec4>(
                               varNameInShader, VertexAttributeConfig.Vec4, BufferUsage.DynamicCopy))
                    {
                        buffer.Create(particleCount);
                        unsafe
                        {
                            var array = (vec4 *)buffer.Header.ToPointer();
                            for (int i = 0; i < particleCount; i++)
                            {
                                array[i] = new vec4(
                                    (float)(random.NextDouble() - 0.5) * 0.2f,
                                    (float)(random.NextDouble() - 0.5) * 0.2f,
                                    (float)(random.NextDouble() - 0.5) * 0.2f,
                                    0
                                    );
                            }
                        }

                        velocityBufferPtr = buffer.GetBufferPtr();
                    }
                }

                return(velocityBufferPtr);
            }
            else
            {
                throw new ArgumentException();
            }
        }
Exemplo n.º 42
0
 /// <summary>
 /// Returns a bvec4 from component-wise application of GreaterThanEqual (lhs &gt;= rhs).
 /// </summary>
 public static bvec4 GreaterThanEqual(vec4 lhs, vec4 rhs) => vec4.GreaterThanEqual(lhs, rhs);
Exemplo n.º 43
0
 /// <summary>
 /// Returns a bvec4 from component-wise application of IsNegativeInfinity (float.IsNegativeInfinity(v)).
 /// </summary>
 public static bvec4 IsNegativeInfinity(vec4 v) => vec4.IsNegativeInfinity(v);
Exemplo n.º 44
0
 /// <summary>
 /// Returns a bvec4 from component-wise application of IsNaN (float.IsNaN(v)).
 /// </summary>
 public static bvec4 IsNaN(vec4 v) => vec4.IsNaN(v);
Exemplo n.º 45
0
            public override void draw(SCENE scene)
            {
                copy(_points, points);

                vec3 dp = v3(0f);

                for (int i = 0; i < movs.Length; i++)
                {
                    if (scene.time < movs[i].time)
                    {
                        break;
                    }
                    if (scene.time > movs[i].time + MOVETIME)
                    {
                        dp += movs[i].m.dir * SPACING2;
                        continue;
                    }
                    float x = progress(movs[i].time, movs[i].time + MOVETIME, scene.time);
                    for (int j = 0; j < 3; j++)
                    {
                        Eq    eq  = movs[i].m.eqs[j];
                        float mod = eq(x * PI2);
                        if (eq == cos)
                        {
                            mod = 1f - mod;
                        }
                        dp[j] += mod * movs[i].m.dir[j] * SPACING2;
                    }
                    break;
                }
                move(_points, dp);
                turn(_points, campos, quat(0f, rad(mouse.y), rad(mouse.x)));

                if (scene.time >= T3)
                {
                    phantomframedelta = framedelta = 50;
                    float reltime = scene.time - T3;
                    reltime *= .5f;
                    vec4  lquatx = quat(0f, 0f, reltime * PI2 / MOVETIME);
                    vec4  lquaty = quat(0f, -reltime * PI / MOVETIME, 0f);
                    float x      = progress(0, 400, reltime / 30f);
                    vec4  lquatz = quat(rad(sin(x) * TWOPI), 0f, 0f);
                    turn(_points, campos, lquatx);
                    turn(_points, campos, lquaty);
                    turn(_points, campos, lquatz);
                }
                else if (scene.time >= T2)
                {
                    phantomframedelta = framedelta = T3 - T2;
                }
                else
                {
                    phantomframedelta = framedelta = T2 - T1;
                }
                int idx = 0;

                foreach (Oline o in lines)
                {
                    if (scene.time < T2)
                    {
                        int c = DIVV * DIVH * 2;
                        if (idx++ % (c * 2) >= c)
                        {
                            continue;
                        }
                    }
                    float dist = ((o.pts[o.a] + o.pts[o.b]) / 2 - campos).length();
                    float a    = 1f - progressx(400, 450, dist);
                    o.update(scene.time, v4(v3(1f), a));
                    o.draw(scene.g);
                }
            }
Exemplo n.º 46
0
        private static bool hasObjectIntersection(Dictionary <int, ObjectType> objectList, List <AABB> aabbGrpups, Ray ray, out vec4 intersecPoint, out vec4 normal, out MaterialProperty materialProperty, out KeyValuePair <int, ObjectType> kvp)
        {
            float closestT = Constants.Max_camera_distance;

            intersecPoint    = new vec4();
            normal           = new vec4();
            materialProperty = new MaterialProperty();
            kvp = new KeyValuePair <int, ObjectType>();
            bool hasFound = false;

            //Erst AABB gruppen durchsuchen
            foreach (var aabb in aabbGrpups)
            {
                if (!aabb.hitAABB(ray))
                {
                    continue;
                }
                foreach (var _obj in aabb.ElementList)
                {
                    vec4             _current_intersec = new vec4();
                    vec4             _current_normal   = new vec4();
                    MaterialProperty _props            = new MaterialProperty();
                    float            t;

                    if (_obj.hasIntersectionPoint(ray, out _current_intersec, out _current_normal, out t, out _props))
                    {
                        if (t > 0 && t < closestT)
                        {
                            intersecPoint    = _current_intersec;
                            normal           = _current_normal;
                            closestT         = t;
                            materialProperty = _props;
                            kvp      = new KeyValuePair <int, ObjectType>(_obj.IdNumber, _obj);
                            hasFound = true;
                        }
                    }
                }
            }
            //Dann restliche Objekte

            foreach (var _kvp in objectList)
            {
                if (_kvp.Value.PartOfGroup)
                {
                    continue;
                }
                vec4             _current_intersec = new vec4();
                vec4             _current_normal   = new vec4();
                MaterialProperty _props            = new MaterialProperty();
                ObjectType       obj = _kvp.Value;
                float            t;

                if (obj.hasIntersectionPoint(ray, out _current_intersec, out _current_normal, out t, out _props))
                {
                    if (t > 0 && t < closestT)
                    {
                        intersecPoint    = _current_intersec;
                        normal           = _current_normal;
                        closestT         = t;
                        materialProperty = _props;
                        kvp      = _kvp;
                        hasFound = true;
                    }
                }
            }
            return(hasFound);
        }
Exemplo n.º 47
0
            private void mk(vec3[] templatepoints, int[] templatelines, int i, int j, int k, int m, vec3 off, vec4 rot)
            {
                vec3[] pts = new vec3[templatepoints.Length];
                copy(pts, templatepoints);
                int idx = (i * FIELDSIZE * FIELDSIZE + j * FIELDSIZE + k) * 3 + m;

                idx *= pts.Length;
                turn(pts, campos, rot);
                vec3      offset = v3(i, j, k);
                const int F2     = FIELDSIZE / 2;

                offset -= F2;
                move(pts, offset * SPACING);
                move(pts, off);
                copy(points, idx, pts, 0, pts.Length);
                for (int z = 0; z < pts.Length; z++)
                {
                    int _1 = templatelines[z * 4 + 0] + idx;
                    int _2 = templatelines[z * 4 + 1] + idx;
                    int _3 = templatelines[z * 4 + 2] + idx;
                    int _4 = templatelines[z * 4 + 3] + idx;
                    lines[(idx + z) * 2 + 0] = new Oline(_points, _1, _3);
                    lines[(idx + z) * 2 + 1] = new Oline(_points, _4, _3);
                }
            }
Exemplo n.º 48
0
 public override void main()
 {
     outColor = texture(textureMap, passUV);
 }
Exemplo n.º 49
0
 void main()
 {
     gl_Position = uPMatrix * uMVMatrix * vec4(aVertexPosition, 1.0f);
     vColor      = aVertexColor;
 }
Exemplo n.º 50
0
            public void update(int time, vec4 col, vec4 c, float size)
            {
                if (c != null && (c.z < 0.2f || size < 1f || col.w == 0f))
                {
                    update(time, null, null, 0f);
                    return;
                }

                this.col  = col;
                this.pos  = c == null ? null : c.xy;
                this.size = size;

                if (!rendering)
                {
                    return;
                }

                if (c == null)
                {
                    if (size != SIZE_KEEP_LOOB_TIME)
                    {
                        // yuk!
                        loob_time = -1;
                    }
                    sprite = null;
                    return;
                }

                if (isOnScreen(pos, size))
                {
                    if (wasOOB && loob_time != -1 && (spritesettings & Sprite.INTERPOLATE_MOVE) > 0)
                    {
                        sprite = null;
                        supdate(loob_time, loob_pos, 0f, loob_col, 1f, v2(loob_size));
                        loob_time = -1;
                    }
                    wasOOB = false;
                }
                else
                {
                    // last-out-of-bounds data, if movement is interpolated
                    // a dot can suddenly appear onscreen because the last
                    // known pos was oob, so save the latest oob pos and
                    // use that before the first inbounds pos
                    loob_time = time;
                    loob_col  = v4(col);
                    loob_pos  = v2(c.xy);
                    loob_size = size;

                    // this check is to allow one frame offscreen
                    // so if it's interpolated it will move oob
                    // instead of disappear just before going oob
                    // TODO: YUK this depends on state D:
                    if (wasOOB || (spritesettings & Sprite.INTERPOLATE_MOVE) == 0)
                    {
                        update(time, null, null, SIZE_KEEP_LOOB_TIME);
                        return;
                    }
                    wasOOB = true;
                }

                supdate(time, c.xy, 0f, col, 1f, v2(size));
            }
Exemplo n.º 51
0
 public override void main()
 {
     gl_Position  = mvp * vec4(position, 0.0f, 1.0f);
     passColor    = color;
     passTexCoord = texCoord;
 }
Exemplo n.º 52
0
        //////////////////////////////////////////////////////////////////////////
        // Methods
        //////////////////////////////////////////////////////////////////////////

        public float dot(vec4 vec)
        {
            return(this.x * vec.x + this.y + vec.y + this.z * vec.z + this.w * vec.w);
        }
Exemplo n.º 53
0
 public override void main()
 {
     // TODO: this is where you should start with fragment shader. Only ASCII code are welcome.
     outColor = vec4(lineColor, 1.0f);
     // this is where your fragment shader ends.
 }
        private void InitVAO()
        {
            this.axisPrimitiveMode = DrawMode.QuadStrip;
            GLColor[] colors = this.ColorPalette.Colors;
            float[]   coords = this.ColorPalette.Coords;
            this.numbers     = new PointSpriteStringElement[coords.Length];
            this.vertexCount = coords.Length * 2;
            this.vao         = new uint[1];

            float coordLength = coords[coords.Length - 1] - coords[0];
            {
                GL.GenVertexArrays(1, vao);

                GL.BindVertexArray(vao[0]);

                //  Create a vertex buffer for the vertex data.
                {
                    UnmanagedArray <vec3> positionArray = new UnmanagedArray <vec3>(this.vertexCount);
                    positionArray[0] = new vec3(-0.5f, -0.5f, 0);
                    positionArray[1] = new vec3(-0.5f, 0.5f, 0);
                    for (int i = 1; i < coords.Length; i++)
                    {
                        float x = (coords[i] - coords[0]) / coordLength - 0.5f;
                        positionArray[i * 2 + 0] = new vec3(x, -0.5f, 0);
                        positionArray[i * 2 + 1] = new vec3(x, 0.5f, 0);
                    }

                    uint[] ids = new uint[1];
                    GL.GenBuffers(1, ids);
                    GL.BindBuffer(BufferTarget.ArrayBuffer, ids[0]);
                    GL.BufferData(BufferTarget.ArrayBuffer, positionArray, BufferUsage.StaticDraw);
                    GL.VertexAttribPointer(in_PositionLocation, 3, GL.GL_FLOAT, false, 0, IntPtr.Zero);
                    GL.EnableVertexAttribArray(in_PositionLocation);

                    positionArray.Dispose();
                }

                //  Now do the same for the colour data.
                {
                    var colorArray = new UnmanagedArray <vec4>(this.vertexCount);
                    for (int i = 0; i < colors.Length; i++)
                    {
                        GLColor color = colors[i];
                        colorArray[i * 2 + 0] = new vec4(color.R, color.G, color.B, color.A);
                        colorArray[i * 2 + 1] = new vec4(color.R, color.G, color.B, color.A);
                    }

                    uint[] ids = new uint[1];
                    GL.GenBuffers(1, ids);
                    GL.BindBuffer(BufferTarget.ArrayBuffer, ids[0]);
                    GL.BufferData(BufferTarget.ArrayBuffer, colorArray, BufferUsage.StaticDraw);
                    GL.VertexAttribPointer(in_ColorLocation, 4, GL.GL_FLOAT, false, 0, IntPtr.Zero);
                    GL.EnableVertexAttribArray(in_ColorLocation);

                    colorArray.Dispose();
                }

                //  Unbind the vertex array, we've finished specifying data for it.
                GL.BindVertexArray(0);
            }

            // prepare numbers
            {
                const float numberPosY = -0.6f;
                this.numbers[0] = new PointSpriteStringElement(
                    this.Min.ToShortString(), new vec3(-0.5f, numberPosY, 0));
                this.numbers[0].Initialize();
                for (int i = 1; i < coords.Length; i++)
                {
                    float x = (coords[i] - coords[0]) / coordLength - 0.5f;
                    if (i + 1 == coords.Length)
                    {
                        this.numbers[i] = new PointSpriteStringElement(
                            (this.Min + i * this.Step).ToShortString(), new vec3(x, numberPosY, 0));
                    }
                    else
                    {
                        this.numbers[i] = new PointSpriteStringElement(
                            this.Max.ToShortString(), new vec3(x, numberPosY, 0));
                    }
                    this.numbers[i].Initialize();
                }
            }
        }
Exemplo n.º 55
0
 /// <summary>
 /// Returns the derivative in y for the input argument p
 /// </summary>
 /// <param name="p"></param>
 /// <returns></returns>
 public static vec4 dFdy(vec4 p)
 {
     return(null);
 }
Exemplo n.º 56
0
 /// <summary>
 /// Returns the sum of the absolute derivative in x and y for
 /// the input argument p, i.e.,
 /// return = abs( dFdx( p ) ) + abs( dFdy( p ) );
 /// </summary>
 /// <param name="p"></param>
 /// <returns></returns>
 public static vec4 fwidth(vec4 p)
 {
     return(null);
 }
Exemplo n.º 57
0
 /// <summary>
 /// Returns a bvec4 from component-wise application of LesserThanEqual (lhs &lt;= rhs).
 /// </summary>
 public static bvec4 LesserThanEqual(vec4 lhs, vec4 rhs) => vec4.LesserThanEqual(lhs, rhs);
Exemplo n.º 58
0
    public virtual void Start()
    {
        bmp = new System.Drawing.Bitmap((int)iResolution.x, (int)iResolution.y);

        iMouse = new vec4();
    }
Exemplo n.º 59
0
 /// <summary>
 /// Returns a bvec4 from component-wise application of IsInfinity (float.IsInfinity(v)).
 /// </summary>
 public static bvec4 IsInfinity(vec4 v) => vec4.IsInfinity(v);
Exemplo n.º 60
0
 public override void main()
 {
     out_Color = pass_Color;
 }