Пример #1
0
            //private UniformSampler2D UniformSampler2DValue;
            //private UniformSamplerCube UniformSamplerCubeValue;

            public Uniform(int index, string name, uint type, WebGLUniformLocation location)
            {
                Index    = index;
                Name     = name;
                Type     = type;
                Location = location;
            }
Пример #2
0
        private async Task <WebGLProgram> InitProgramAsync(WebGLContext gl, string vsSource, string fsSource)
        {
            var vertexShader = await this.LoadShaderAsync(gl, ShaderType.VERTEX_SHADER, vsSource);

            var fragmentShader = await this.LoadShaderAsync(gl, ShaderType.FRAGMENT_SHADER, fsSource);

            var program = await gl.CreateProgramAsync();

            await gl.AttachShaderAsync(program, vertexShader);

            await gl.AttachShaderAsync(program, fragmentShader);

            await gl.LinkProgramAsync(program);

            await gl.DeleteShaderAsync(vertexShader);

            await gl.DeleteShaderAsync(fragmentShader);

            if (!await gl.GetProgramParameterAsync <bool>(program, ProgramParameter.LINK_STATUS))
            {
                string info = await gl.GetProgramInfoLogAsync(program);

                throw new Exception("An error occured while linking the program: " + info);
            }

            u_matrix_location = await _context.GetUniformLocationAsync(program, "u_matrix");

            return(program);
        }
Пример #3
0
        internal async Task UseAsync(WebGLUniformLocation uniform, int binding)
        {
            await _gl.ActiveTextureAsync((Blazor.Extensions.Canvas.WebGL.Texture) Enum.Parse(typeof(Blazor.Extensions.Canvas.WebGL.Texture), "TEXTURE" + binding));

            await _gl.BindTextureAsync(TextureType.TEXTURE_2D, _texture);

            await _gl.UniformAsync(uniform, binding);
        }
Пример #4
0
        public static void Init(RenderContext renderContext)
        {
            GL gl = renderContext.gl;

            String fragShaderText =
                " precision highp float;                                                              \n" +
                " uniform vec4 lineColor;                                                               \n" +
                "                                                                                       \n" +
                "   void main(void) {                                                                   \n" +
                "   gl_FragColor = lineColor;         \n" +
                "   }                                                                                   \n";


            String vertexShaderText =
                "     attribute vec3 aVertexPosition;                                              \n" +
                "                                                                                  \n" +
                "     uniform mat4 uMVMatrix;                                                      \n" +
                "     uniform mat4 uPMatrix;                                                       \n" +
                "                                                                                  \n" +
                "                                                                                  \n" +
                "                                                                                  \n" +
                "     void main(void) {                                                            \n" +
                "         gl_Position = uPMatrix * uMVMatrix * vec4(aVertexPosition, 1.0);         \n" +
                "     }                                                                            \n" +
                "                                                                                  \n";

            frag = gl.createShader(GL.FRAGMENT_SHADER);
            gl.shaderSource(frag, fragShaderText);
            gl.compileShader(frag);

            object stat = gl.getShaderParameter(frag, GL.COMPILE_STATUS);


            vert = gl.createShader(GL.VERTEX_SHADER);
            gl.shaderSource(vert, vertexShaderText);
            gl.compileShader(vert);
            object stat1 = gl.getShaderParameter(vert, GL.COMPILE_STATUS);

            prog = gl.createProgram();

            gl.attachShader(prog, vert);
            gl.attachShader(prog, frag);
            gl.linkProgram(prog);
            object errcode = gl.getProgramParameter(prog, GL.LINK_STATUS);


            gl.useProgram(prog);

            vertLoc      = gl.getAttribLocation(prog, "aVertexPosition");
            lineColorLoc = gl.getUniformLocation(prog, "lineColor");
            projMatLoc   = gl.getUniformLocation(prog, "uPMatrix");
            mvMatLoc     = gl.getUniformLocation(prog, "uMVMatrix");

            gl.enable(GL.BLEND);
            gl.blendFunc(GL.SRC_ALPHA, GL.ONE_MINUS_SRC_ALPHA);
            initialized = true;
        }
        public void uniform3f(WebGLUniformLocation location, double x, double y, double z)
        {
#if _DEBUG
            Log.Info(string.Format("uniform3f {0} {1} {2} {3}", location.Value, x, y, z));
#endif
#if GLEW_STATIC
            Gl.glUniform3f((int)location.Value, (float)x, (float)y, (float)z);
#else
            Gl.__glewUniform3f((int)location.Value, (float)x, (float)y, (float)z);
#endif
            this.ErrorTest();
        }
Пример #6
0
        public void compile(WebGLRenderingContext webgl)
        {
            this.vs = webgl.CreateShader(webgl.VERTEX_SHADER);
            this.fs = webgl.CreateShader(webgl.FRAGMENT_SHADER);

            //分别编译shader
            webgl.ShaderSource(this.vs, this.vscode);
            webgl.CompileShader(this.vs);
            var r1 = webgl.GetShaderParameter(this.vs, webgl.COMPILE_STATUS);

            if (r1.As <bool>() == false)
            {
                alert(webgl.GetShaderInfoLog(this.vs));
            }
            //
            webgl.ShaderSource(this.fs, this.fscode);
            webgl.CompileShader(this.fs);
            var r2 = webgl.GetShaderParameter(this.fs, webgl.COMPILE_STATUS);

            if (r2.As <bool>() == false)
            {
                alert(webgl.GetShaderInfoLog(this.fs));
            }

            //program link
            this.program = webgl.CreateProgram().As <WebGLProgram>();

            webgl.AttachShader(this.program, this.vs);
            webgl.AttachShader(this.program, this.fs);

            webgl.LinkProgram(this.program);
            var r3 = webgl.GetProgramParameter(this.program, webgl.LINK_STATUS);

            if (r3.As <bool>() == false)
            {
                alert(webgl.GetProgramInfoLog(this.program));
            }


            //绑定vbo和shader顶点格式,这部分应该要区分材质改变与参数改变,可以少切换一些状态
            this.posPos    = webgl.GetAttribLocation(this.program, "position");
            this.posColor  = webgl.GetAttribLocation(this.program, "color");
            this.posColor2 = webgl.GetAttribLocation(this.program, "color2");

            this.posUV = webgl.GetAttribLocation(this.program, "uv");

            this.uniMatrix = webgl.GetUniformLocation(this.program, "matrix");
            this.uniTex0   = webgl.GetUniformLocation(this.program, "tex0");
            this.uniTex1   = webgl.GetUniformLocation(this.program, "tex1");
            this.uniCol0   = webgl.GetUniformLocation(this.program, "col0");
            this.uniCol1   = webgl.GetUniformLocation(this.program, "col1");
        }
        public void uniform1i(WebGLUniformLocation location, int x)
        {
#if _DEBUG
            Log.Info(string.Format("uniform1i {0} {1}", location.Value, x));
#endif

#if GLEW_STATIC
            Gl.glUniform1i(location.Value, x);
#else
            Gl.__glewUniform1i(location.Value, x);
#endif
            this.ErrorTest();
        }
Пример #8
0
        public static void SetUniform(ref ShaderFieldInfo field, WebGLUniformLocation location, params float[] data)
        {
            if (field.Scope != ShaderFieldScope.Uniform)
            {
                return;
            }
            if (location == null)
            {
                return;
            }
            switch (field.Type)
            {
            case ShaderFieldType.Bool:
            case ShaderFieldType.Int:
                int[] arrI = new int[field.ArrayLength];
                for (int j = 0; j < arrI.Length; j++)
                {
                    arrI[j] = (int)data[j];
                }
                GraphicsBackend.GL.Uniform1iv(location, new Span <int>(arrI));
                break;

            case ShaderFieldType.Float:
                GraphicsBackend.GL.Uniform1fv(location, new Span <float>(data));
                break;

            case ShaderFieldType.Vec2:
                GraphicsBackend.GL.Uniform2fv(location, new Span <float>(data));
                break;

            case ShaderFieldType.Vec3:
                GraphicsBackend.GL.Uniform3fv(location, new Span <float>(data));
                break;

            case ShaderFieldType.Vec4:
                GraphicsBackend.GL.Uniform4fv(location, new Span <float>(data));
                break;

            case ShaderFieldType.Mat2:
                GraphicsBackend.GL.UniformMatrix2fv(location, false, new Span <float>(data));
                break;

            case ShaderFieldType.Mat3:
                GraphicsBackend.GL.UniformMatrix3fv(location, false, new Span <float>(data));
                break;

            case ShaderFieldType.Mat4:
                GraphicsBackend.GL.UniformMatrix4fv(location, false, new Span <float>(data));
                break;
            }
        }
            public void onSurfaceCreated(GL10 glUnused, javax.microedition.khronos.egl.EGLConfig config)
            {
                // and now we still need redux?

                // Set the background clear color to gray.
                gl.clearColor(0.5f, 0.5f, 0.5f, 0.5f);

                // Position the eye behind the origin.
                const float eyeX = 0.0f;
                const float eyeY = 0.0f;
                const float eyeZ = 1.5f;

                // We are looking toward the distance
                const float lookX = 0.0f;
                const float lookY = 0.0f;
                const float lookZ = -5.0f;

                // Set our up vector. This is where our head would be pointing were we holding the camera.
                const float upX = 0.0f;
                const float upY = 1.0f;
                const float upZ = 0.0f;

                // Set the view matrix. This matrix can be said to represent the camera position.
                // NOTE: In OpenGL 1, a ModelView matrix is used, which is a combination of a model and
                // view matrix. In OpenGL 2, we can keep track of these matrices separately if we choose.
                Matrix.setLookAtM(mViewMatrix, 0, eyeX, eyeY, eyeZ, lookX, lookY, lookZ, upX, upY, upZ);



                // Create a program object and store the handle to it.


                var programHandle = gl.createProgram(
                    new Shaders.TriangleVertexShader(),
                    new Shaders.TriangleFragmentShader()
                    );

                gl.bindAttribLocation(programHandle, 0, "a_Position");
                gl.bindAttribLocation(programHandle, 1, "a_Color");

                gl.linkProgram(programHandle);

                // Set program handles. These will later be used to pass in values to the program.
                mMVPMatrixHandle = gl.getUniformLocation(programHandle, "u_MVPMatrix");
                mPositionHandle  = gl.getAttribLocation(programHandle, "a_Position");
                mColorHandle     = gl.getAttribLocation(programHandle, "a_Color");

                // Tell OpenGL to use this program when rendering.
                gl.useProgram(programHandle);
            }
Пример #10
0
        public void PlatformApply(GraphicsDevice device, ShaderProgram program)
        {
            // NOTE: We assume here the program has
            // already been set on the device.

            // If the program changed then lookup the
            // uniform again and apply the state.
            if (_shaderProgram != program)
            {
                var location = program.GetUniformLocation(_name);
                if (location == null)
                {
                    return;
                }

                _shaderProgram = program;
                _location      = location;
                _dirty         = true;
            }

            // If the shader program is the same, the effect may still be different and have different values in the buffer
            if (!Object.ReferenceEquals(this, _lastConstantBufferApplied))
            {
                _dirty = true;
            }

            // If the buffer content hasn't changed then we're
            // done... use the previously set uniform state.
            if (!_dirty)
            {
                return;
            }

            // TODO: We need to know the type of buffer float/int/bool
            // and cast this correctly... else it doesn't work as i guess
            // GL is checking the type of the uniform.

            gl.uniform4fv(_location, _buffer.As <double[]>());

            GraphicsExtensions.CheckGLError();

            // Clear the dirty flag.
            _dirty = false;

            _lastConstantBufferApplied = this;
        }
Пример #11
0
        public async void Build(WebGLContext gl)
        {
            await InitProgramAsync(gl, VertexProgramString, FragmentProgramString);

            ViewProjectionLocation = await gl.GetUniformLocationAsync(ShaderProgram, "ViewProjection");

            AnchorLocation = await gl.GetUniformLocationAsync(ShaderProgram, "in_anchor");

            ColorLocation = await gl.GetUniformLocationAsync(ShaderProgram, "in_color");

            FilpLocation = await gl.GetUniformLocationAsync(ShaderProgram, "in_flip");

            ModelLocation = await gl.GetUniformLocationAsync(ShaderProgram, "in_model");

            PositionAttributeLocaltion = (uint)await gl.GetAttribLocationAsync(ShaderProgram, "in_pos");

            TexturePositionAttributeLocaltion = (uint)await gl.GetAttribLocationAsync(ShaderProgram, "in_texPos");
        }
Пример #12
0
        private void InitializeShaders()
        {
            WebGLProgram shaderProgram;

            using (var vertexShaderStream = EmbeddedResourceHelper.Load("GLTFVertexShader.essl"))
                using (var fragmentShaderStream = EmbeddedResourceHelper.Load("GLTFFragmentShader.essl"))
                    using (var vertexShaderReader = new StreamReader(vertexShaderStream))
                        using (var fragmentShaderReader = new StreamReader(fragmentShaderStream))
                        {
                            var vertexShader   = vertexShaderReader.ReadToEnd();
                            var fragmentShader = fragmentShaderReader.ReadToEnd();
                            shaderProgram = gl.InitializeShaders(vertexShader, fragmentShader);
                        }

            inVarNormalAttribute   = (uint)gl.GetAttribLocation(shaderProgram, "in_var_NORMAL");
            inVarPositionAttribute = (uint)gl.GetAttribLocation(shaderProgram, "in_var_POSITION");

            worldViewProjectionUniformLocation = gl.GetUniformLocation(shaderProgram, "worldViewProj");
        }
Пример #13
0
        public void InitShaders()
        {
            var fragmentShader = this.GetShader(gl, "shader-fs");
            var vertexShader   = this.GetShader(gl, "shader-vs");
            var shaderProgram  = gl.CreateProgram().As <WebGLProgram>();

            if (shaderProgram.Is <int>())
            {
                Global.Alert("Could not initialise program");
            }

            gl.AttachShader(shaderProgram, vertexShader);
            gl.AttachShader(shaderProgram, fragmentShader);
            gl.LinkProgram(shaderProgram);

            if (!gl.GetProgramParameter(shaderProgram, gl.LINK_STATUS).As <bool>())
            {
                Global.Alert("Could not initialise shaders");
            }

            gl.UseProgram(shaderProgram);

            this.vertexPositionAttribute = gl.GetAttribLocation(shaderProgram, "aVertexPosition");
            this.vertexNormalAttribute   = gl.GetAttribLocation(shaderProgram, "aVertexNormal");
            this.textureCoordAttribute   = gl.GetAttribLocation(shaderProgram, "aTextureCoord");

            gl.EnableVertexAttribArray(this.vertexPositionAttribute);
            gl.EnableVertexAttribArray(this.vertexNormalAttribute);
            gl.EnableVertexAttribArray(this.textureCoordAttribute);

            this.pMatrixUniform           = gl.GetUniformLocation(shaderProgram, "uPMatrix");
            this.mvMatrixUniform          = gl.GetUniformLocation(shaderProgram, "uMVMatrix");
            this.nMatrixUniform           = gl.GetUniformLocation(shaderProgram, "uNMatrix");
            this.samplerUniform           = gl.GetUniformLocation(shaderProgram, "uSampler");
            this.useLightingUniform       = gl.GetUniformLocation(shaderProgram, "uUseLighting");
            this.ambientColorUniform      = gl.GetUniformLocation(shaderProgram, "uAmbientColor");
            this.lightingDirectionUniform = gl.GetUniformLocation(shaderProgram, "uLightingDirection");
            this.directionalColorUniform  = gl.GetUniformLocation(shaderProgram, "uDirectionalColor");
            this.alphaUniform             = gl.GetUniformLocation(shaderProgram, "uAlpha");

            this.program = shaderProgram;
        }
Пример #14
0
        public void UniformMatrix(WebGLUniformLocation location, bool transpose, float[] value)
        {
            switch (value.Length)
            {
            case 2 * 2:
                this.CallMethod <object>(UNIFORM_MATRIX + "2fv", location, transpose, value);
                break;

            case 3 * 3:
                this.CallMethod <object>(UNIFORM_MATRIX + "3fv", location, transpose, value);
                break;

            case 4 * 4:
                this.CallMethod <object>(UNIFORM_MATRIX + "4fv", location, transpose, value);
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(value), value.Length, "Value array has incorrect size");
            }
        }
        public void uniformMatrix4fv(WebGLUniformLocation location, bool transpose, float[] value)
        {
#if _DEBUG
            Log.Info(string.Format("uniformMatrix4fv {0} {1} {2} {3} {4} {5} {6} {7} {8} {9} {10} {11} {12} {13} {14} {15} {16}", location.Value, transpose
                                   , value[0], value[1], value[2], value[3], value[4], value[5], value[6], value[7], value[8], value[9], value[10], value[11], value[12], value[13], value[14], value[15]));
#endif

            unsafe
            {
                fixed(float *pvalue = &value[0])
                {
#if GLEW_STATIC
                    Gl.glUniformMatrix4fv((int)location.Value, value.Length / 16, (byte)(transpose ? 1 : 0), pvalue);
#else
                    Gl.__glewUniformMatrix4fv((int)location.Value, value.Length / 16, (byte)(transpose ? 1 : 0), pvalue);
#endif
                }
            }

            this.ErrorTest();
        }
        protected override async Task BindDataToProgramAsync(WebGLProgram program)
        {
            _vertexBuffer = new GLVertexBuffer(_context, program);
            await _vertexBuffer.ConsumeAndBindBufferAsync(
                await ResourceLoader.LoadAsJsonAsync <VertexBufferModel>(
                    "BlazorFFT.Components.WebGL.JSON.BoxVertexBuffer.json"));

            _vertexBuffer.ThrowIfNotValid();

            _indexBuffer = new GLIndexbuffer(_context);
            await _indexBuffer.ConsumeAndBindBufferAsync(
                await ResourceLoader.LoadAsJsonAsync <IndexBufferModel>(
                    "BlazorFFT.Components.WebGL.JSON.BoxIndexBuffer.json"));

            _indexBuffer.ThrowIfNotValid();

            _matLocWorld = await _context.GetUniformLocationAsync(program, "mWorld");

            _matLocView = await _context.GetUniformLocationAsync(program, "mView");

            _matLocProj = await _context.GetUniformLocationAsync(program, "mProj");
        }
Пример #17
0
        public void Uniform(WebGLUniformLocation location, params int[] value)
        {
            switch (value.Length)
            {
            case 1:
                this.CallMethod <object>(UNIFORM + "1iv", location, value);
                break;

            case 2:
                this.CallMethod <object>(UNIFORM + "2iv", location, value);
                break;

            case 3:
                this.CallMethod <object>(UNIFORM + "3iv", location, value);
                break;

            case 4:
                this.CallMethod <object>(UNIFORM + "4iv", location, value);
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(value), value.Length, "Value array is empty or too long");
            }
        }
Пример #18
0
 public void uniform3f(WebGLUniformLocation location, float x, float y, float z) { }
Пример #19
0
 public void uniform2f(WebGLUniformLocation location, float x, float y) { }
Пример #20
0
 public void uniform1f(WebGLUniformLocation location, float x) { }
            public void onDrawFrame(GL10 glUnused)
            {
                gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);

                // Do a complete rotation every 10 seconds.
                long time = SystemClock.uptimeMillis() % 10000L;
                float angleInDegrees = (360.0f / 10000.0f) * ((int)time);

                // Set our per-vertex lighting program.
                gl.useProgram(mPerVertexProgramHandle);

                // Set program handles for cube drawing.
                mMVPMatrixHandle = gl.getUniformLocation(mPerVertexProgramHandle, "u_MVPMatrix");
                mMVMatrixHandle = gl.getUniformLocation(mPerVertexProgramHandle, "u_MVMatrix");
                mLightPosHandle = gl.getUniformLocation(mPerVertexProgramHandle, "u_LightPos");

                mPositionHandle = gl.getAttribLocation(mPerVertexProgramHandle, "a_Position");
                mColorHandle = gl.getAttribLocation(mPerVertexProgramHandle, "a_Color");
                mNormalHandle = gl.getAttribLocation(mPerVertexProgramHandle, "a_Normal");

                // Calculate position of the light. Rotate and then push into the distance.
                Matrix.setIdentityM(mLightModelMatrix, 0);
                Matrix.translateM(mLightModelMatrix, 0, 0.0f, 0.0f, -5.0f);
                Matrix.rotateM(mLightModelMatrix, 0, angleInDegrees, 0.0f, 1.0f, 0.0f);
                Matrix.translateM(mLightModelMatrix, 0, 0.0f, 0.0f, 2.0f);

                Matrix.multiplyMV(mLightPosInWorldSpace, 0, mLightModelMatrix, 0, mLightPosInModelSpace, 0);
                Matrix.multiplyMV(mLightPosInEyeSpace, 0, mViewMatrix, 0, mLightPosInWorldSpace, 0);

                #region drawCube 
                Action drawCube =
                    delegate
                    {
                        // Pass in the position information
                        mCubePositions.position(0);

                        opengl.glVertexAttribPointer(mPositionHandle, mPositionDataSize, (int)gl.FLOAT, false,
                                0, mCubePositions);

                        gl.enableVertexAttribArray((uint)mPositionHandle);

                        // Pass in the color information
                        mCubeColors.position(0);
                        opengl.glVertexAttribPointer(mColorHandle, mColorDataSize, (int)gl.FLOAT, false,
                                0, mCubeColors);

                        gl.enableVertexAttribArray((uint)mColorHandle);

                        // Pass in the normal information
                        mCubeNormals.position(0);
                        opengl.glVertexAttribPointer(mNormalHandle, mNormalDataSize, (int)gl.FLOAT, false,
                                0, mCubeNormals);

                        gl.enableVertexAttribArray((uint)mNormalHandle);

                        // This multiplies the view matrix by the model matrix, and stores the result in the MVP matrix
                        // (which currently contains model * view).
                        Matrix.multiplyMM(mMVPMatrix, 0, mViewMatrix, 0, mModelMatrix, 0);

                        // Pass in the modelview matrix.
                        gl.uniformMatrix4fv(mMVMatrixHandle, false, mMVPMatrix);

                        // This multiplies the modelview matrix by the projection matrix, and stores the result in the MVP matrix
                        // (which now contains model * view * projection).
                        Matrix.multiplyMM(mMVPMatrix, 0, mProjectionMatrix, 0, mMVPMatrix, 0);

                        // Pass in the combined matrix.
                        gl.uniformMatrix4fv(mMVPMatrixHandle, false, mMVPMatrix);

                        // Pass in the light position in eye space.        
                        gl.uniform3f(mLightPosHandle, mLightPosInEyeSpace[0], mLightPosInEyeSpace[1], mLightPosInEyeSpace[2]);

                        // Draw the cube.
                        gl.drawArrays(gl.TRIANGLES, 0, 36);
                    };
                #endregion


                // Draw some cubes.        
                Matrix.setIdentityM(mModelMatrix, 0);
                Matrix.translateM(mModelMatrix, 0, 4.0f, 0.0f, -7.0f);
                Matrix.rotateM(mModelMatrix, 0, angleInDegrees, 1.0f, 0.0f, 0.0f);
                drawCube();

                Matrix.setIdentityM(mModelMatrix, 0);
                Matrix.translateM(mModelMatrix, 0, -4.0f, 0.0f, -7.0f);
                Matrix.rotateM(mModelMatrix, 0, angleInDegrees, 0.0f, 1.0f, 0.0f);
                drawCube();

                Matrix.setIdentityM(mModelMatrix, 0);
                Matrix.translateM(mModelMatrix, 0, 0.0f, 4.0f, -7.0f);
                Matrix.rotateM(mModelMatrix, 0, angleInDegrees, 0.0f, 0.0f, 1.0f);
                drawCube();

                Matrix.setIdentityM(mModelMatrix, 0);
                Matrix.translateM(mModelMatrix, 0, 0.0f, -4.0f, -7.0f);
                drawCube();

                Matrix.setIdentityM(mModelMatrix, 0);
                Matrix.translateM(mModelMatrix, 0, 0.0f, 0.0f, -5.0f);
                Matrix.rotateM(mModelMatrix, 0, angleInDegrees, 1.0f, 1.0f, 0.0f);
                drawCube();

                #region drawLight
                Action drawLight =
                    delegate
                    {
                        var pointMVPMatrixHandle = gl.getUniformLocation(mPointProgramHandle, "u_MVPMatrix");
                        var pointPositionHandle = gl.getAttribLocation(mPointProgramHandle, "a_Position");

                        // Pass in the position.
                        gl.vertexAttrib3f((uint)pointPositionHandle, mLightPosInModelSpace[0], mLightPosInModelSpace[1], mLightPosInModelSpace[2]);

                        // Since we are not using a buffer object, disable vertex arrays for this attribute.
                        gl.disableVertexAttribArray((uint)pointPositionHandle);

                        // Pass in the transformation matrix.
                        Matrix.multiplyMM(mMVPMatrix, 0, mViewMatrix, 0, mLightModelMatrix, 0);
                        Matrix.multiplyMM(mMVPMatrix, 0, mProjectionMatrix, 0, mMVPMatrix, 0);
                        
                        gl.uniformMatrix4fv(pointMVPMatrixHandle, false, mMVPMatrix);

                        // Draw the point.
                        gl.drawArrays(gl.POINTS, 0, 1);
                    };
                #endregion

                // Draw a point to indicate the light.
                gl.useProgram(mPointProgramHandle);
                drawLight();
            }
Пример #22
0
 public void uniformMatrix4fv(WebGLUniformLocation location, bool transpose, Float32Array array)
 {
 }
Пример #23
0
 public void uniform4i(WebGLUniformLocation location, int x, int y, int z, int w)
 {
 }
Пример #24
0
        public void draw(f tilt, f spin, bool twinkle, Action mvPushMatrix, Action mvPopMatrix, Float32Array mvMatrix, Action drawStar, WebGLUniformLocation shaderProgram_colorUniform, WebGLRenderingContext gl)
        {
            #region degToRad
            Func<float, float> degToRad = (degrees) =>
            {
                return degrees * (f)Math.PI / 180f;
            };
            #endregion

            mvPushMatrix();

            // Move to the star's position
            glMatrix.mat4.rotate(mvMatrix, degToRad(this.angle), new f[] { 0.0f, 1.0f, 0.0f });
            glMatrix.mat4.translate(mvMatrix, new f[] { this.dist, 0.0f, 0.0f });

            // Rotate back so that the star is facing the viewer
            glMatrix.mat4.rotate(mvMatrix, degToRad(-this.angle), new f[] { 0.0f, 1.0f, 0.0f });
            glMatrix.mat4.rotate(mvMatrix, degToRad(-tilt), new f[] { 1.0f, 0.0f, 0.0f });

            //if (twinkle) {
            //    // Draw a non-rotating star in the alternate "twinkling" color
            //    gl.uniform3f(shaderProgram_colorUniform, this.twinkleR, this.twinkleG, this.twinkleB);
            //    drawStar();
            //}

            // All stars spin around the Z axis at the same rate
            glMatrix.mat4.rotate(mvMatrix, degToRad(spin), new f[] { 0.0f, 0.0f, 1.0f });

            // Draw the star in its main color
            gl.uniform3f(shaderProgram_colorUniform, this.r, this.g, this.b);
            drawStar();

            mvPopMatrix();
        }
 /// <summary>
 /// Assigns two dimensional integer value to a uniform variable for the current program object.
 /// If the location is null, no uniforms are updated and no error code is generated.
 ///
 /// Errors:
 ///     gl.INVALID_OPERATION    The location doesn't belong to the current program.
 ///                             There is no current program object.
 ///                             If location is an invalid location for the current program object and location isn't equal to -1.
 /// </summary>
 /// <param name="location">The location of the uniform variable to be updated.</param>
 /// <param name="x">Horizontal value to assign.</param>
 /// <param name="y">Vertical value to assign.</param>
 public virtual void Uniform2i(WebGLUniformLocation location, int x, int y) { }
 /// <summary>
 /// Assigns two dimensional floating point values to a uniform variable for the current program object.
 ///
 /// Errors:
 ///     gl.INVALID_OPERATION    The location doesn't belong to the current program.
 ///                             There is no current program object.
 ///                             If location is an invalid location for the current program object and location isn't equal to -1.
 /// </summary>
 /// <param name="location">The location of the uniform variable to be updated. </param>
 /// <param name="x">Horizontal value to assign.</param>
 /// <param name="y">Vertical value to assign.</param>
 public virtual void Uniform2f(WebGLUniformLocation location, double x, double y) { }
 /// <summary>
 /// Assigns a boolean value to a uniform variable for the current program object.
 /// Uniform1i can be used to set texture samplers. If location is a texture sampler, then value refers to an offset into the array of active textures.
 ///
 /// Errors:
 ///     gl.INVALID_OPERATION    The location doesn't belong to the current program.
 ///                             There is no current program object.
 ///                             If location is an invalid location for the current program object and location isn't equal to -1.
 /// </summary>
 /// <param name="location">Specifies the location of the uniform to modify.</param>
 /// <param name="value">The new value for the uniform variable. </param>
 public virtual void Uniform1i(WebGLUniformLocation location, bool value) { }
 /// <summary>
 /// Assigns a floating point value to a uniform variable for the current program object.
 ///
 /// Errors:
 ///     gl.INVALID_OPERATION    There's no active program object.
 ///                             The size and type of the uniform variable doesn't match the size and type of the value loaded.
 /// </summary>
 /// <param name="location">The location:
 ///     null        Data passed will fail silently, no uniform variables will be changed.
 ///     location    Specifies the location of the uniform to modify. WebGLUniformLocation instance returned by getUniformLocation.
 /// </param>
 /// <param name="x">The new floating point value for the uniform variable. </param>
 public virtual void Uniform1f(WebGLUniformLocation location, double x) { }
 /// <summary>
 /// Gets the uniform value for a specific location in a program.
 ///
 /// Errors:
 ///     gl.INVALID_VALUE    If program is not generated by WebGL.
 ///
 ///     gl.INVALID_OPERATION        If location isn't a valid uniform variable location for program
 ///                                 If program is not a program object.
 ///                                 if program isn't successfully linked.
 /// </summary>
 /// <param name="program">The program to query.</param>
 /// <param name="location">The location of the uniform variable.</param>
 /// <returns>The uniform value or null if a WebGL error is generated.</returns>
 public virtual object GetUniform(WebGLProgram program, WebGLUniformLocation location)
 {
     return null;
 }
Пример #30
0
 public void uniform4f(WebGLUniformLocation location, float x, float y, float z, float w) { }
Пример #31
0
 public void uniform4fv(WebGLUniformLocation location, float[] v) { }
 /// <summary>
 /// Assigns four dimensional floating point values to a uniform variable for the current program object.
 /// If the location is null, no uniforms are updated and no error code is generated.
 ///
 /// Errors:
 ///     gl.INVALID_OPERATION    The location doesn't belong to the current program.
 ///                             There is no active program.
 ///                             Uniform specified by location isn't a float type.
 /// </summary>
 /// <param name="location">The location of the uniform variable to be updated.</param>
 /// <param name="x">Horizontal value to assign.</param>
 /// <param name="y">Vertical value to assign.</param>
 /// <param name="z">Depth value to assign.</param>
 /// <param name="w">Scaling value to assign.</param>
 public virtual void Uniform4f(WebGLUniformLocation location, double x, double y, double z, double w) { }
Пример #33
0
 public void uniform4fv(WebGLUniformLocation location, Float32Array v)
 {
 }
Пример #34
0
        public override void Run()
        {
            base.Run();

            var vertices = new float[]
            {
                -1, -1, -1,
                1, -1, -1,
                1, 1, -1,

                -1, 1, -1,
                -1, -1, 1,
                1, -1, 1,

                1, 1, 1,
                -1, 1, 1,
                -1, -1, -1,

                -1, 1, -1,
                -1, 1, 1,
                -1, -1, 1,

                1, -1, -1,
                1, 1, -1,
                1, 1, 1,

                1, -1, 1,
                -1, -1, -1,
                -1, -1, 1,

                1, -1, 1,
                1, -1, -1,
                -1, 1, -1,

                -1, 1, 1,
                1, 1, 1,
                1, 1, -1
            };

            vertexBuffer = gl.CreateArrayBuffer(vertices);

            indices = new ushort[]
            {
                0, 1, 2,
                0, 2, 3,

                4, 5, 6,
                4, 6, 7,

                8, 9, 10,
                8, 10, 11,

                12, 13, 14,
                12, 14, 15,

                16, 17, 18,
                16, 18, 19,

                20, 21, 22,
                20, 22, 23
            };
            indexBuffer = gl.CreateElementArrayBuffer(indices);

            var colors = new float[]
            {
                1, 0, 0,
                1, 0, 0,
                1, 0, 0,
                1, 0, 0,

                0, 1, 0,
                0, 1, 0,
                0, 1, 0,
                0, 1, 0,

                0, 0, 1,
                0, 0, 1,
                0, 0, 1,
                0, 0, 1,

                1, 1, 0,
                1, 1, 0,
                1, 1, 0,
                1, 1, 0,

                0, 1, 1,
                0, 1, 1,
                0, 1, 1,
                0, 1, 1,

                1, 1, 1,
                1, 1, 1,
                1, 1, 1,
                1, 1, 1
            };

            colorBuffer = gl.CreateArrayBuffer(colors);

            var shaderProgram = InitShaders();

            pMatrixUniform = gl.GetUniformLocation(shaderProgram, "pMatrix");
            vMatrixUniform = gl.GetUniformLocation(shaderProgram, "vMatrix");
            wMatrixUniform = gl.GetUniformLocation(shaderProgram, "wMatrix");

            gl.BindBuffer(WebGLRenderingContextBase.ARRAY_BUFFER, vertexBuffer);
            var positionAttribute = (uint)gl.GetAttribLocation(shaderProgram, "position");

            gl.VertexAttribPointer(positionAttribute, 3, WebGLRenderingContextBase.FLOAT, false, 0, 0);
            gl.EnableVertexAttribArray(positionAttribute);

            gl.BindBuffer(WebGLRenderingContextBase.ARRAY_BUFFER, colorBuffer);
            var colorAttribute = (uint)gl.GetAttribLocation(shaderProgram, "color");

            gl.VertexAttribPointer(colorAttribute, 3, WebGLRenderingContextBase.FLOAT, false, 0, 0);
            gl.EnableVertexAttribArray(colorAttribute);

            gl.BindBuffer(WebGLRenderingContextBase.ELEMENT_ARRAY_BUFFER, indexBuffer);

            worldMatrix = Matrix.Identity;
        }
Пример #35
0
 public void uniform4iv(WebGLUniformLocation location, Int32Array v)
 {
 }
Пример #36
0
        public void InitShaders()
        {
            var fragmentShader = this.GetShader(gl, "shader-fs");
            var vertexShader = this.GetShader(gl, "shader-vs");
            var shaderProgram = gl.CreateProgram().As<WebGLProgram>();

            if (shaderProgram.Is<int>())
            {
                Global.Alert("Could not initialise program");
            }

            gl.AttachShader(shaderProgram, vertexShader);
            gl.AttachShader(shaderProgram, fragmentShader);
            gl.LinkProgram(shaderProgram);

            if (!gl.GetProgramParameter(shaderProgram, gl.LINK_STATUS).As<bool>())
            {
                Global.Alert("Could not initialise shaders");
            }

            gl.UseProgram(shaderProgram);

            this.vertexPositionAttribute = gl.GetAttribLocation(shaderProgram, "aVertexPosition");
            this.vertexNormalAttribute = gl.GetAttribLocation(shaderProgram, "aVertexNormal");
            this.textureCoordAttribute = gl.GetAttribLocation(shaderProgram, "aTextureCoord");

            gl.EnableVertexAttribArray(this.vertexPositionAttribute);
            gl.EnableVertexAttribArray(this.vertexNormalAttribute);
            gl.EnableVertexAttribArray(this.textureCoordAttribute);

            this.pMatrixUniform = gl.GetUniformLocation(shaderProgram, "uPMatrix");
            this.mvMatrixUniform = gl.GetUniformLocation(shaderProgram, "uMVMatrix");
            this.nMatrixUniform = gl.GetUniformLocation(shaderProgram, "uNMatrix");
            this.samplerUniform = gl.GetUniformLocation(shaderProgram, "uSampler");
            this.useLightingUniform = gl.GetUniformLocation(shaderProgram, "uUseLighting");
            this.ambientColorUniform = gl.GetUniformLocation(shaderProgram, "uAmbientColor");
            this.lightingDirectionUniform = gl.GetUniformLocation(shaderProgram, "uLightingDirection");
            this.directionalColorUniform = gl.GetUniformLocation(shaderProgram, "uDirectionalColor");
            this.alphaUniform = gl.GetUniformLocation(shaderProgram, "uAlpha");

            this.program = shaderProgram;
        }
Пример #37
0
        public override void Run()
        {
            base.Run();

            var shaderProgram = gl.InitializeShaders(
                vertexShaderCode:
                @"attribute vec2 position;
attribute vec2 textureCoordinate;

uniform vec2 resolution;

varying vec2 v_texCoord;

void main() {
   vec2 zeroToOne = position / resolution;
   vec2 zeroToTwo = zeroToOne * 2.0;
   vec2 clipSpace = zeroToTwo - 1.0;
   gl_Position = vec4(clipSpace * vec2(1.0, -1.0), 0.0, 1.0);

   v_texCoord = textureCoordinate;
}",
                fragmentShaderCode:
                @"precision mediump float;

uniform sampler2D u_image;

varying vec2 v_texCoord;

void main() {
   gl_FragColor = texture2D(u_image, v_texCoord);
}");

            var positionAttribute          = (uint)gl.GetAttribLocation(shaderProgram, "position");
            var textureCoordinateAttribute = (uint)gl.GetAttribLocation(shaderProgram, "textureCoordinate");

            var x1        = 0;
            var x2        = DemoImage.Width;
            var y1        = 0;
            var y2        = DemoImage.Height;
            var positions = new float[]
            {
                x1, y1,
                x2, y1,
                x1, y2,
                x1, y2,
                x2, y1,
                x2, y2
            };
            var positionBuffer = gl.CreateArrayBuffer(positions);

            var textureCoordinateBuffer = gl.CreateArrayBuffer(new float[]
            {
                0, 0,
                0, 1,
                1, 0,
                1, 0,
                0, 1,
                1, 1
            });

            var texture = gl.CreateTexture();

            gl.BindTexture(WebGLRenderingContextBase.TEXTURE_2D, texture);

            gl.TexParameteri(
                WebGLRenderingContextBase.TEXTURE_2D,
                WebGLRenderingContextBase.TEXTURE_WRAP_S,
                (int)WebGLRenderingContextBase.CLAMP_TO_EDGE);
            gl.TexParameteri(
                WebGLRenderingContextBase.TEXTURE_2D,
                WebGLRenderingContextBase.TEXTURE_WRAP_T,
                (int)WebGLRenderingContextBase.CLAMP_TO_EDGE);
            gl.TexParameteri(
                WebGLRenderingContextBase.TEXTURE_2D,
                WebGLRenderingContextBase.TEXTURE_MIN_FILTER,
                (int)WebGLRenderingContextBase.NEAREST);
            gl.TexParameteri(
                WebGLRenderingContextBase.TEXTURE_2D,
                WebGLRenderingContextBase.TEXTURE_MAG_FILTER,
                (int)WebGLRenderingContextBase.NEAREST);

            var imageData = new ImageData(DemoImage.ARGBColors, DemoImage.Width, DemoImage.Height);

            gl.TexImage2D(
                WebGLRenderingContextBase.TEXTURE_2D,
                0,
                WebGLRenderingContextBase.RGB,
                WebGLRenderingContextBase.RGB,
                WebGLRenderingContextBase.UNSIGNED_BYTE,
                imageData);

            this.resolutionUniform = gl.GetUniformLocation(shaderProgram, "resolution");

            gl.EnableVertexAttribArray(positionAttribute);
            gl.BindBuffer(WebGLRenderingContextBase.ARRAY_BUFFER, positionBuffer);
            gl.VertexAttribPointer(positionAttribute, 2, WebGLRenderingContextBase.FLOAT, false, 0, 0);

            gl.EnableVertexAttribArray(textureCoordinateAttribute);
            gl.BindBuffer(WebGLRenderingContextBase.ARRAY_BUFFER, textureCoordinateBuffer);
            gl.VertexAttribPointer(textureCoordinateAttribute, 2, WebGLRenderingContextBase.FLOAT, false, 0, 0);
        }
Пример #38
0
        public static void Init(RenderContext renderContext)
        {
            GL gl = renderContext.gl;

            String fragShaderText =
                " precision mediump float;                                                              \n" +
                "                                                                                       \n" +
                "   varying vec2 vTextureCoord;                                                         \n" +
                "                                                                                       \n" +
                "   uniform sampler2D uSampler;                                                         \n" +
                "                                                                                       \n" +
                "   void main(void) {                                                                   \n" +
                "   gl_FragColor = texture2D(uSampler, vec2(vTextureCoord.s, vTextureCoord.t));         \n" +
                "   }                                                                                   \n";


            String vertexShaderText =
                "     attribute vec3 aVertexPosition;                                              \n" +
                "     attribute vec2 aTextureCoord;                                                \n" +
                "                                                                                  \n" +
                "     uniform mat4 uMVMatrix;                                                      \n" +
                "     uniform mat4 uPMatrix;                                                       \n" +
                "                                                                                  \n" +
                "     varying vec2 vTextureCoord;                                                  \n" +
                "                                                                                  \n" +
                "                                                                                  \n" +
                "     void main(void) {                                                            \n" +
                "         gl_Position = uPMatrix * uMVMatrix * vec4(aVertexPosition, 1.0);         \n" +
                "         vTextureCoord = aTextureCoord;                                           \n" +
                "     }                                                                            \n" +
                "                                                                                  \n";

            frag = gl.createShader(GL.FRAGMENT_SHADER);
            gl.shaderSource(frag, fragShaderText);
            gl.compileShader(frag);

            object stat = gl.getShaderParameter(frag, GL.COMPILE_STATUS);


            vert = gl.createShader(GL.VERTEX_SHADER);
            gl.shaderSource(vert, vertexShaderText);
            gl.compileShader(vert);
            object stat1 = gl.getShaderParameter(vert, GL.COMPILE_STATUS);

            prog = gl.createProgram();

            gl.attachShader(prog, vert);
            gl.attachShader(prog, frag);
            gl.linkProgram(prog);
            object errcode = gl.getProgramParameter(prog, GL.LINK_STATUS);


            gl.useProgram(prog);

            vertLoc    = gl.getAttribLocation(prog, "aVertexPosition");
            textureLoc = gl.getAttribLocation(prog, "aTextureCoord");
            projMatLoc = gl.getUniformLocation(prog, "uPMatrix");
            mvMatLoc   = gl.getUniformLocation(prog, "uMVMatrix");
            sampLoc    = gl.getUniformLocation(prog, "uSampler");

            Tile.uvMultiple = 1;
            Tile.DemEnabled = true;

            gl.enable(GL.BLEND);
            gl.blendFunc(GL.SRC_ALPHA, GL.ONE_MINUS_SRC_ALPHA);
            initialized = true;
        }
 /// <summary>
 /// Assigns four dimensional floating point vector array values to a uniform variable for the current program object.
 /// If the location is null, no uniforms are updated and no error code is generated.
 ///
 /// Errors:
 ///     gl.INVALID_OPERATION    The location doesn't belong to the current program.
 ///                             There is no active program.
 ///                             value references a typed array instance other than Float32Array.
 ///                             Uniform specified by location isn't a float type.
 ///
 ///     gl.INVALID_VALUE        The length of value array isn't a multiple of the number of required components.
 /// </summary>
 /// <param name="location">The location of the uniform variable to be updated.</param>
 /// <param name="value">Four dimensional floating point array to assign.</param>
 public virtual void Uniform4fv(WebGLUniformLocation location, double[][][][] value) { }
 private void InitShaders()
 {
     // create our shaders
     WebGLShader vertexShader = LoadShader(VERTEX_SHADER, @"
 attribute vec4 a_position;
 attribute vec4 a_color;
 attribute vec2 a_texCoord0;
 attribute vec2 a_texCoord1;
 uniform mat4 u_mvpMatrix;
 varying vec4 v_color;
 varying vec2 v_texCoord0;
 varying vec2 v_texCoord1;
 void main()
 {
     gl_Position = u_mvpMatrix * a_position;
     v_color = a_color;
     v_texCoord0 = a_texCoord0;
     v_texCoord1 = a_texCoord1;
 }");
     WebGLShader fragmentShader = LoadShader(FRAGMENT_SHADER, @"
 #ifdef GL_ES
 precision mediump float;
 #endif
 uniform sampler2D s_texture0;
 uniform sampler2D s_texture1;
 uniform int s_texEnv0;
 uniform int s_texEnv1;
 uniform int u_enable_texture_0;
 uniform int u_enable_texture_1;
 varying vec4 v_color;
 varying vec2 v_texCoord0;
 varying vec2 v_texCoord1;
 vec4 finalColor;
 void main()
 {
     finalColor = v_color;
     if (u_enable_texture_0 == 1)
     {
         vec4 texel = texture2D(s_texture0, v_texCoord0);
         if (s_texEnv0 == 1) {
             finalColor = finalColor * texel;
         } else if (s_texEnv0 == 2) {
             finalColor = vec4(texel.r, texel.g, texel.b, finalColor.a);
         } else {
             finalColor = texel;
         }
     }
     if (u_enable_texture_1 == 1) {
         vec4 texel = texture2D(s_texture1, v_texCoord1);
         if (s_texEnv1 == 1) {
             finalColor = finalColor * texel;
         } else if (s_texEnv1 == 2) {
             finalColor = vec4(texel.r, texel.g, texel.b, finalColor.a);
         } else {
             finalColor = texel;
         }
     }
     // simple alpha check
     if (finalColor.a == 0.0) {
         discard;
     }
     float gamma = 1.5;
     float igamma = 1.0 / gamma;
     gl_FragColor = vec4(pow(finalColor.r, igamma), pow(finalColor.g, igamma), pow(finalColor.b, igamma), finalColor.a);
 }");
     if ((vertexShader == null) || (fragmentShader == null))
         throw new Exception("RuntimeException: shader error");
     // Create the program object
     WebGLProgram programObject = gl.CreateProgram();
     if ((programObject == null) || (gl.GetError() != NO_ERROR))
         throw new Exception("RuntimeException: program error");
     // Attach our two shaders to the program
     gl.AttachShader(programObject, vertexShader);
     gl.AttachShader(programObject, fragmentShader);
     // Bind "vPosition" to attribute 0
     gl.BindAttribLocation(programObject, ARRAY_POSITION, "a_position");
     gl.BindAttribLocation(programObject, ARRAY_COLOR, "a_color");
     gl.BindAttribLocation(programObject, ARRAY_TEXCOORD_0, "a_texCoord0");
     gl.BindAttribLocation(programObject, ARRAY_TEXCOORD_1, "a_texCoord1");
     // Link the program
     gl.LinkProgram(programObject);
     // TODO(haustein) get position, color from the linker, too
     _uMvpMatrix = gl.GetUniformLocation(programObject, "u_mvpMatrix");
     _uSampler0 = gl.GetUniformLocation(programObject, "s_texture0");
     _uSampler1 = gl.GetUniformLocation(programObject, "s_texture1");
     _uTexEnv0 = gl.GetUniformLocation(programObject, "s_texEnv0");
     _uTexEnv1 = gl.GetUniformLocation(programObject, "s_texEnv1");
     _uEnableTexture0 = gl.GetUniformLocation(programObject, "u_enable_texture_0");
     _uEnableTexture1 = gl.GetUniformLocation(programObject, "u_enable_texture_1");
     // Check the link status
     bool linked = (bool)gl.GetProgramParameter(programObject, LINK_STATUS);
     if (!linked)
         throw new Exception("RuntimeException: linker Error: " + gl.GetProgramInfoLog(programObject));
     gl.UseProgram(programObject);
     gl.Uniform1i(_uSampler0, 0);
     gl.Uniform1i(_uSampler1, 1);
     gl.ActiveTexture(TEXTURE0);
 }
Пример #41
0
        public static void Init(RenderContext renderContext)
        {
            GL gl = renderContext.gl;

            String fragShaderText =
                "    precision highp float;                                                              \n" +
                "    uniform vec4 lineColor;                                                             \n" +
                "    varying lowp vec4 vColor;                                                           \n" +
                "    void main(void)                                                                     \n" +
                "    {                                                                                   \n" +
                "        gl_FragColor = lineColor * vColor;                                              \n" +
                "    }                                                                                   \n";


            String vertexShaderText =
                "    attribute vec3 aVertexPosition;                                                     \n" +
                "    attribute vec4 aVertexColor;                                                        \n" +
                "    attribute vec2 aTime;                                                               \n" +
                "    uniform mat4 uMVMatrix;                                                             \n" +
                "    uniform mat4 uPMatrix;                                                              \n" +
                "    uniform float jNow;                                                                 \n" +
                "    uniform float decay;                                                                \n" +
                "                                                                                        \n" +
                "    varying lowp vec4 vColor;                                                           \n" +
                "                                                                                        \n" +
                "    void main(void)                                                                     \n" +
                "    {                                                                                   \n" +
                "        gl_Position = uPMatrix * uMVMatrix * vec4(aVertexPosition, 1.0);                \n" +
                "        float dAlpha = 1.0;                                                             \n" +
                "        if ( decay > 0.0)                                                               \n" +
                "        {                                                                               \n" +
                "             dAlpha = 1.0 - ((jNow - aTime.y) / decay);                                 \n " +
                "             if (dAlpha > 1.0 )                                                         \n" +
                "             {                                                                          \n" +
                "                  dAlpha = 1.0;                                                         \n" +
                "             }                                                                          \n" +
                "        }                                                                               \n" +
                "     if (jNow < aTime.x && decay > 0.0)                                                 \n" +
                "     {                                                                                  \n" +
                //"         vColor = vec4(0.0, 0.0, 0.0, 0.0);                                             \n" +
                "         vColor = vec4(1, 1, 1, 1);                                                    \n" +
                "     }                                                                                  \n" +
                "     else                                                                               \n" +
                "     {                                                                                  \n" +
                "        vColor = vec4(aVertexColor.r, aVertexColor.g, aVertexColor.b, dAlpha * aVertexColor.a);          \n" +
                //"         vColor = vec4(1, 1, 1, 1);                                                    \n" +

                "     }                                                                                  \n" +
                "    }                                                                                   \n" +
                "                                                                                        \n";


            frag = gl.createShader(GL.FRAGMENT_SHADER);
            gl.shaderSource(frag, fragShaderText);
            gl.compileShader(frag);

            object stat = gl.getShaderParameter(frag, GL.COMPILE_STATUS);


            vert = gl.createShader(GL.VERTEX_SHADER);
            gl.shaderSource(vert, vertexShaderText);
            gl.compileShader(vert);
            object stat1 = gl.getShaderParameter(vert, GL.COMPILE_STATUS);

            prog = gl.createProgram();

            gl.attachShader(prog, vert);
            gl.attachShader(prog, frag);
            gl.linkProgram(prog);
            object errcode = gl.getProgramParameter(prog, GL.LINK_STATUS);


            gl.useProgram(prog);

            vertLoc      = gl.getAttribLocation(prog, "aVertexPosition");
            colorLoc     = gl.getAttribLocation(prog, "aVertexColor");
            timeLoc      = gl.getAttribLocation(prog, "aTime");
            lineColorLoc = gl.getUniformLocation(prog, "lineColor");
            projMatLoc   = gl.getUniformLocation(prog, "uPMatrix");
            mvMatLoc     = gl.getUniformLocation(prog, "uMVMatrix");
            jNowLoc      = gl.getUniformLocation(prog, "jNow");
            decayLoc     = gl.getUniformLocation(prog, "decay");

            gl.enable(GL.BLEND);
            gl.blendFunc(GL.SRC_ALPHA, GL.ONE_MINUS_SRC_ALPHA);
            initialized = true;
        }
 /// <summary>
 /// Assigns four dimensional integer values to a uniform variable for the current program object.
 /// If the location is null, no uniforms are updated and no error code is generated.
 ///
 /// Errors:
 ///     gl.INVALID_OPERATION    The location doesn't belong to the current program.
 ///                             There is no active program.
 ///                             Uniform specified by location isn't an integer type.
 /// </summary>
 /// <param name="location">The location of the uniform variable to be updated.</param>
 /// <param name="x">Horizontal value to assign.</param>
 /// <param name="y">Vertical value to assign.</param>
 /// <param name="z">Depth value to assign.</param>
 /// <param name="w">Scaling value to assign.</param>
 public virtual void Uniform4i(WebGLUniformLocation location, int x, int y, int z, int w) { }
Пример #43
0
        public static void Init(RenderContext renderContext)
        {
            GL gl = renderContext.gl;

            String fragShaderText =
                "    precision mediump float;                                                            \n" +
                "    uniform vec4 lineColor;                                                             \n" +
                "    varying lowp vec4 vColor;                                                           \n" +
                "    uniform sampler2D uSampler;                                                         \n" +
                "    void main(void)                                                                     \n" +
                "    {                                                                                   \n" +
                "        vec4 texColor;                                                                  \n" +
                "        texColor = texture2D(uSampler, gl_PointCoord);                                  \n" +
                "                                                                                        \n" +
                "                                                                                        \n" +
                "        gl_FragColor = lineColor * vColor * texColor;                                   \n" +
                "    }                                                                                   \n";


            String vertexShaderText =
                "    attribute vec3 aVertexPosition;                                                     \n" +
                "    attribute vec4 aVertexColor;                                                        \n" +
                "    attribute vec2 aTime;                                                               \n" +
                "    attribute float aPointSize;                                                         \n" +
                "    uniform mat4 uMVMatrix;                                                             \n" +
                "    uniform mat4 uPMatrix;                                                              \n" +
                "    uniform float jNow;                                                                 \n" +
                "    uniform vec3 cameraPosition;                                                        \n" +
                "    uniform float decay;                                                                \n" +
                "    uniform float scale;                                                                \n" +
                "                                                                                        \n" +
                "    varying lowp vec4 vColor;                                                           \n" +
                "                                                                                        \n" +
                "    void main(void)                                                                     \n" +
                "    {                                                                                   \n" +
                "        float dist = distance(aVertexPosition, cameraPosition);                                \n" +
                "        gl_Position = uPMatrix * uMVMatrix * vec4(aVertexPosition, 1.0);                \n" +
                "        float dAlpha = 1.0;                                                             \n" +
                "        if ( decay > 0.0)                                                               \n" +
                "        {                                                                               \n" +
                "             dAlpha = 1.0 - ((jNow - aTime.y) / decay);                                 \n " +
                "             if (dAlpha > 1.0 )                                                         \n" +
                "             {                                                                          \n" +
                "                  dAlpha = 1.0;                                                         \n" +
                "             }                                                                          \n" +
                "        }                                                                               \n" +
                "        if (jNow < aTime.x && decay > 0.0)                                              \n" +
                "        {                                                                               \n" +
                "            vColor = vec4(0.0, 0.0, 0.0, 0.0);                                          \n" +
                "        }                                                                               \n" +
                "        else                                                                            \n" +
                "        {                                                                               \n" +
                //  "           vColor = vec4(aVertexColor.r, aVertexColor.g, aVertexColor.b, dAlpha);       \n" +
                "           vColor = vec4(1,1,1,1);       \n" +

                "        }                                                                               \n" +
                "        gl_PointSize = max(1.0, (scale * ( aPointSize ) / dist));                     \n" +
                "    }                                                                                   \n" +
                "                                                                                        \n";


            frag = gl.createShader(GL.FRAGMENT_SHADER);
            gl.shaderSource(frag, fragShaderText);
            gl.compileShader(frag);

            object stat = gl.getShaderParameter(frag, GL.COMPILE_STATUS);


            vert = gl.createShader(GL.VERTEX_SHADER);
            gl.shaderSource(vert, vertexShaderText);
            gl.compileShader(vert);
            object stat1          = gl.getShaderParameter(vert, GL.COMPILE_STATUS);
            object compilationLog = gl.getShaderInfoLog(vert);

            prog = gl.createProgram();

            gl.attachShader(prog, vert);
            gl.attachShader(prog, frag);
            gl.linkProgram(prog);
            object errcode = gl.getProgramParameter(prog, GL.LINK_STATUS);


            gl.useProgram(prog);

            vertLoc      = gl.getAttribLocation(prog, "aVertexPosition");
            colorLoc     = gl.getAttribLocation(prog, "aVertexColor");
            pointSizeLoc = gl.getAttribLocation(prog, "aPointSize");
            timeLoc      = gl.getAttribLocation(prog, "aTime");
            projMatLoc   = gl.getUniformLocation(prog, "uPMatrix");
            mvMatLoc     = gl.getUniformLocation(prog, "uMVMatrix");
            sampLoc      = gl.getUniformLocation(prog, "uSampler");
            jNowLoc      = gl.getUniformLocation(prog, "jNow");
            decayLoc     = gl.getUniformLocation(prog, "decay");
            lineColorLoc = gl.getUniformLocation(prog, "lineColor");
            cameraPosLoc = gl.getUniformLocation(prog, "cameraPosition");
            scaleLoc     = gl.getUniformLocation(prog, "scale");
            gl.enable(GL.BLEND);

            initialized = true;
        }
 /// <summary>
 /// Assigns four dimensional integer vector array values to a uniform variable for the current program object.
 /// If the location is null, no uniforms are updated and no error code is generated.
 ///
 /// Errors:
 ///     gl.INVALID_OPERATION    The location doesn't belong to the current program.
 ///                             There is no active program.
 ///                             value references a typed array instance other than Int32Array.
 ///                             Uniform specified by location isn't an integer type.
 ///
 ///     gl.INVALID_VALUE        The length of value array isn't a multiple of the number of required components.
 /// </summary>
 /// <param name="location">The location of the uniform variable to be updated.</param>
 /// <param name="value">Four dimensional integer array to assign.</param>
 public virtual void Uniform4iv(WebGLUniformLocation location, int[][][][] value) { }
Пример #45
0
 public object getUniform(WebGLProgram program, WebGLUniformLocation location) { return default(object); }
 /// <summary>
 /// Sets values for a 4x4 floating point vector matrix into a uniform location as a matrix or a matrix array.
 /// If the location is null, no uniforms are updated and no error code is generated.
 ///
 /// Errors:
 ///     gl.INVALID_OPERATION    The location doesn't belong to the current program.
 ///                             There is no active program.
 ///                             The passed in uniform location isn't a matrix of the required dimensions.
 ///
 ///     gl.INVALID_VALUE        The length of value array isn't a multiple of the required matrix element count.
 ///                             If transpose equals gl.TRUE.
 /// </summary>
 /// <param name="location">The location of uniform variable to be updated. Locate set by getUniformLocation.</param>
 /// <param name="transpose">Sets whether to transpose the matrix as the values are loaded into the uniform variable. Must be set to gl.FALSE.</param>
 /// <param name="value">An array of float values representing one or more 3x3 matrices.</param>
 public virtual void UniformMatrix4fv(WebGLUniformLocation location, bool transpose, Array value) { }
Пример #47
0
 public void uniform1i(WebGLUniformLocation location, int x) { }
Пример #48
0
 public void uniform4iv(WebGLUniformLocation location, WebGLIntArray v) { }
Пример #49
0
 public void uniform2i(WebGLUniformLocation location, int x, int y) { }
Пример #50
0
 public void uniformMatrix4fv(WebGLUniformLocation location, bool transpose, WebGLFloatArray value) { }
Пример #51
0
 public void uniform3i(WebGLUniformLocation location, int x, int y, int z) { }
Пример #52
0
 public void uniform3i(WebGLUniformLocation location, int x, int y, int z)
 {
 }
Пример #53
0
 public void uniform4fv(WebGLUniformLocation location, WebGLFloatArray v) { }
Пример #54
0
 public void uniform4f(WebGLUniformLocation location, double x, double y, double z, double w)
 {
 }
Пример #55
0
 public void uniform4i(WebGLUniformLocation location, int x, int y, int z, int w) { }
Пример #56
0
 public void UniformMatrix4fv(WebGLUniformLocation location, bool transpose, Float32Array array) { }
Пример #57
0
 public void uniform4iv(WebGLUniformLocation location, int[] v) { }
Пример #58
0
 public void uniform2i(WebGLUniformLocation location, int x, int y)
 {
 }
Пример #59
0
 public void uniformMatrix4fv(WebGLUniformLocation location, bool transpose, float[] value) { }
Пример #60
0
 public void uniform3f(WebGLUniformLocation location, double x, double y, double z)
 {
 }