当前位置: 首页>>代码示例>>C#>>正文


C# WebGLRenderingContext.uniform1f方法代码示例

本文整理汇总了C#中WebGLRenderingContext.uniform1f方法的典型用法代码示例。如果您正苦于以下问题:C# WebGLRenderingContext.uniform1f方法的具体用法?C# WebGLRenderingContext.uniform1f怎么用?C# WebGLRenderingContext.uniform1f使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在WebGLRenderingContext的用法示例。


在下文中一共展示了WebGLRenderingContext.uniform1f方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Application


//.........这里部分代码省略.........
								Native.document.body.style.backgroundColor = "yellow";
								await Task.Delay(500);
							} while (await Native.window.async.onframe);
						}
					);



					// https://developer.mozilla.org/en/docs/Web/API/WebGLRenderingContext

					#region Paint_Image
					Paint_ImageDelegate Paint_Image =
					(mProgram, time, mouseOriX, mouseOriY, mousePosX, mousePosY) =>
					{


						var viewportxres = gl.canvas.width;
						var viewportyres = gl.canvas.height;

						#region Paint_Image
						//new IHTMLPre { "enter Paint_Image" }.AttachToDocument();

						// http://www.html5rocks.com/en/tutorials/webgl/webgl_fundamentals/
						//gl.blendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA);
						gl.viewport(0, 0, viewportxres, viewportyres);


						// alpha to zero will only hide the pixel if blending is enabled. 
						gl.useProgram(mProgram);

						// uniform4fv
						var mouse = new[] { mousePosX, mousePosY, mouseOriX, mouseOriY };

						var l2 = gl.getUniformLocation(mProgram, "iGlobalTime"); if (l2 != null) gl.uniform1f(l2, time);
						var l3 = gl.getUniformLocation(mProgram, "iResolution"); if (l3 != null) gl.uniform3f(l3, viewportxres, viewportyres, 1.0f);
						var l4 = gl.getUniformLocation(mProgram, "iMouse"); if (l4 != null) gl.uniform4fv(l4, mouse);
						//var l7 = gl.getUniformLocation(this.mProgram, "iDate"); if (l7 != null) gl.uniform4fv(l7, dates);
						//var l9 = gl.getUniformLocation(this.mProgram, "iSampleRate"); if (l9 != null) gl.uniform1f(l9, this.mSampleRate);

						var ich0 = gl.getUniformLocation(mProgram, "iChannel0"); if (ich0 != null) gl.uniform1i(ich0, 0);
						var ich1 = gl.getUniformLocation(mProgram, "iChannel1"); if (ich1 != null) gl.uniform1i(ich1, 1);
						var ich2 = gl.getUniformLocation(mProgram, "iChannel2"); if (ich2 != null) gl.uniform1i(ich2, 2);
						var ich3 = gl.getUniformLocation(mProgram, "iChannel3"); if (ich3 != null) gl.uniform1i(ich3, 3);




						//for (var i = 0; i < mInputs.Length; i++)
						//{
						//	var inp = mInputs[i];

						//	gl.activeTexture((uint)(gl.TEXTURE0 + i));

						//	if (inp == null)
						//	{
						//		gl.bindTexture(gl.TEXTURE_2D, null);
						//	}
						//}

						var times = new[] { 0.0f, 0.0f, 0.0f, 0.0f };
						var l5 = gl.getUniformLocation(mProgram, "iChannelTime");
						if (l5 != null) gl.uniform1fv(l5, times);

						var resos = new float[12] { 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f };
						var l8 = gl.getUniformLocation(mProgram, "iChannelResolution");
						if (l8 != null) gl.uniform3fv(l8, resos);
开发者ID:exaphaser,项目名称:JSC-Cross-Compiler,代码行数:67,代码来源:Application.cs

示例2: InitializeContent


//.........这里部分代码省略.........
                                }
                                lastTime = timeNow;
                            };
                            #endregion


                            var laptopScreenAspectRatio = 1.66f;

                            //Func<string, f> parseFloat = Convert.ToSingle;
                            Func<string, f> parseFloat = x => float.Parse(x);

                            var shaderProgram = currentProgram;

                            #region drawSceneOnLaptopScreen
                            Action drawSceneOnLaptopScreen =
                            delegate
                            {
                                gl.viewport(0, 0, rttFramebuffer_width, rttFramebuffer_height);
                                gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);

                                glMatrix.mat4.perspective(45, laptopScreenAspectRatio, 0.1f, 100.0f, pMatrix);

                                gl.uniform1i(shaderProgram.showSpecularHighlightsUniform, Convert.ToInt32(false));
                                gl.uniform3f(shaderProgram.ambientLightingColorUniform, 0.2f, 0.2f, 0.2f);
                                gl.uniform3f(shaderProgram.pointLightingLocationUniform, 0, 0, -5);
                                gl.uniform3f(shaderProgram.pointLightingDiffuseColorUniform, 0.8f, 0.8f, 0.8f);

                                gl.uniform1i(shaderProgram.showSpecularHighlightsUniform, Convert.ToInt32(false));
                                gl.uniform1i(shaderProgram.useTexturesUniform, Convert.ToInt32(true));

                                gl.uniform3f(shaderProgram.materialAmbientColorUniform, 1.0f, 1.0f, 1.0f);
                                gl.uniform3f(shaderProgram.materialDiffuseColorUniform, 1.0f, 1.0f, 1.0f);
                                gl.uniform3f(shaderProgram.materialSpecularColorUniform, 0.0f, 0.0f, 0.0f);
                                gl.uniform1f(shaderProgram.materialShininessUniform, 0);
                                gl.uniform3f(shaderProgram.materialEmissiveColorUniform, 0.0f, 0.0f, 0.0f);

                                glMatrix.mat4.identity(mvMatrix);

                                glMatrix.mat4.translate(mvMatrix, new f[] { 0, 0, -5 });
                                glMatrix.mat4.rotate(mvMatrix, degToRad(30), new f[] { 1, 0, 0 });

                                mvPushMatrix();
                                glMatrix.mat4.rotate(mvMatrix, degToRad(moonAngle), new f[] { 0, 1, 0 });
                                glMatrix.mat4.translate(mvMatrix, new f[] { 2, 0, 0 });
                                gl.activeTexture(gl.TEXTURE0);
                                gl.bindTexture(gl.TEXTURE_2D, moonTexture);
                                gl.uniform1i(shaderProgram.samplerUniform, 0);

                                gl.bindBuffer(gl.ARRAY_BUFFER, moonVertexPositionBuffer);
                                gl.vertexAttribPointer((uint)shaderProgram.vertexPositionAttribute, moonVertexPositionBuffer_itemSize, gl.FLOAT, false, 0, 0);

                                gl.bindBuffer(gl.ARRAY_BUFFER, moonVertexTextureCoordBuffer);
                                gl.vertexAttribPointer((uint)shaderProgram.textureCoordAttribute, moonVertexTextureCoordBuffer_itemSize, gl.FLOAT, false, 0, 0);

                                gl.bindBuffer(gl.ARRAY_BUFFER, moonVertexNormalBuffer);
                                gl.vertexAttribPointer((uint)shaderProgram.vertexNormalAttribute, moonVertexNormalBuffer_itemSize, gl.FLOAT, false, 0, 0);

                                gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, moonVertexIndexBuffer);
                                setMatrixUniforms();
                                gl.drawElements(gl.TRIANGLES, moonVertexIndexBuffer_numItems, gl.UNSIGNED_SHORT, 0);
                                mvPopMatrix();


                                mvPushMatrix();
                                glMatrix.mat4.rotate(mvMatrix, degToRad(cubeAngle), new f[] { 0, 1, 0 });
                                glMatrix.mat4.translate(mvMatrix, new f[] { 1.25f, 0, 0 });
开发者ID:exaphaser,项目名称:JSC-Cross-Compiler,代码行数:67,代码来源:Application.cs

示例3: Application


//.........这里部分代码省略.........
				//// http://stackoverflow.com/questions/20362023/webgl-why-does-transparent-canvas-show-clearcolor-color-component-when-alpha-is
				gl.clearColor(1, 1, 0, 1.0f);

				gl.viewport(0, 0, rttFramebuffer_width, rttFramebuffer_height);
				gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);


				#region Paint_Image
				ChromeShaderToyColumns.Library.ShaderToy.EffectPass.Paint_ImageDelegate Paint_Image = (time, mouseOriX, mouseOriY, mousePosX, mousePosY, zoom) =>
				{
					var mProgram = pass.xCreateShader.mProgram;


					var xres = rttFramebuffer_width;
					var yres = rttFramebuffer_height;

					#region Paint_Image

					//new IHTMLPre { "enter Paint_Image" }.AttachToDocument();

					// this is enough to do pip to bottom left, no need to adjust vertex positions even?
					//gl.viewport(0, 0, (int)xres, (int)yres);

					// useProgram: program not valid
					gl.useProgram(mProgram);

					// uniform4fv
					var mouse = new[] { mousePosX, mousePosY, mouseOriX, mouseOriY };

					// X:\jsc.svn\examples\glsl\future\GLSLShaderToyPip\GLSLShaderToyPip\Application.cs
					//gl.getUniformLocation(mProgram, "fZoom").With(fZoom => gl.uniform1f(fZoom, zoom));


					var l2 = gl.getUniformLocation(mProgram, "iGlobalTime"); if (l2 != null) gl.uniform1f(l2, time);
					var l3 = gl.getUniformLocation(mProgram, "iResolution"); if (l3 != null) gl.uniform3f(l3, xres, yres, 1.0f);
					var l4 = gl.getUniformLocation(mProgram, "iMouse"); if (l4 != null) gl.uniform4fv(l4, mouse);
					//var l7 = gl.getUniformLocation(this.mProgram, "iDate"); if (l7 != null) gl.uniform4fv(l7, dates);
					//var l9 = gl.getUniformLocation(this.mProgram, "iSampleRate"); if (l9 != null) gl.uniform1f(l9, this.mSampleRate);

					var ich0 = gl.getUniformLocation(mProgram, "iChannel0"); if (ich0 != null) gl.uniform1i(ich0, 0);
					var ich1 = gl.getUniformLocation(mProgram, "iChannel1"); if (ich1 != null) gl.uniform1i(ich1, 1);
					var ich2 = gl.getUniformLocation(mProgram, "iChannel2"); if (ich2 != null) gl.uniform1i(ich2, 2);
					var ich3 = gl.getUniformLocation(mProgram, "iChannel3"); if (ich3 != null) gl.uniform1i(ich3, 3);


					// what if there are other textures too?
					// X:\jsc.svn\examples\javascript\chrome\apps\WebGL\ChromeWebGLFrameBuffer\ChromeWebGLFrameBuffer\Application.cs

					//for (var i = 0; i < mInputs.Length; i++)
					//{
					//	var inp = mInputs[i];

					//	gl.activeTexture((uint)(gl.TEXTURE0 + i));

					//	if (inp == null)
					//	{
					//		gl.bindTexture(gl.TEXTURE_2D, null);
					//	}
					//}

					var times = new[] { 0.0f, 0.0f, 0.0f, 0.0f };
					var l5 = gl.getUniformLocation(mProgram, "iChannelTime");
					if (l5 != null) gl.uniform1fv(l5, times);

					var resos = new float[12] { 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f };
					var l8 = gl.getUniformLocation(mProgram, "iChannelResolution");
开发者ID:exaphaser,项目名称:JSC-Cross-Compiler,代码行数:67,代码来源:Application.cs

示例4: Application


//.........这里部分代码省略.........
                                            #region [uniform] uAmbientColor <- ambientR, ambientG, ambientB
                                            gl.uniform3f(
                                                shaderProgram.ambientColorUniform,
                                                parseFloat(toolbar.ambientR.value),
                                                parseFloat(toolbar.ambientG.value),
                                                parseFloat(toolbar.ambientB.value)
                                            );
                                            #endregion

                                            #region [uniform] uPointLightingLocation <- lightPositionX, lightPositionY, lightPositionZ
                                            gl.uniform3f(
                                                shaderProgram.pointLightingLocationUniform,
                                                parseFloat(toolbar.lightPositionX.value),
                                                parseFloat(toolbar.lightPositionY.value),
                                                parseFloat(toolbar.lightPositionZ.value)
                                            );
                                            #endregion

                                            #region [uniform] uPointLightingSpecularColor <- specularR, specularG, specularB
                                            gl.uniform3f(
                                                shaderProgram.pointLightingSpecularColorUniform,
                                                parseFloat(toolbar.specularR.value),
                                                parseFloat(toolbar.specularG.value),
                                                parseFloat(toolbar.specularB.value)
                                            );
                                            #endregion

                                            #region [uniform] uPointLightingDiffuseColor <- diffuseR, diffuseG, diffuseB
                                            gl.uniform3f(
                                                shaderProgram.pointLightingDiffuseColorUniform,
                                                parseFloat(toolbar.diffuseR.value),
                                                parseFloat(toolbar.diffuseG.value),
                                                parseFloat(toolbar.diffuseB.value)
                                            );
                                            #endregion

                                        }

                                        var texture = toolbar.texture[toolbar.texture.selectedIndex].value;
                                        gl.uniform1i(shaderProgram.useTexturesUniform, Convert.ToInt32(texture != "none"));

                                        glMatrix.mat4.identity(mvMatrix);

                                        glMatrix.mat4.translate(mvMatrix, new f[] { 0, 0, -40 });
                                        glMatrix.mat4.rotate(mvMatrix, degToRad(23.4f), new f[] { 1, 0, -1 });
                                        glMatrix.mat4.rotate(mvMatrix, degToRad(teapotAngle), new f[] { 0, 1, 0 });

                                        gl.activeTexture(gl.TEXTURE0);
                                        if (texture == "earth")
                                        {
                                            gl.bindTexture(gl.TEXTURE_2D, earthTexture);
                                        }
                                        else if (texture == "galvanized")
                                        {
                                            gl.bindTexture(gl.TEXTURE_2D, galvanizedTexture);
                                        }
                                        gl.uniform1i(shaderProgram.samplerUniform, 0);

                                        gl.uniform1f(shaderProgram.materialShininessUniform, parseFloat(toolbar.shininess.value));

                                        gl.bindBuffer(gl.ARRAY_BUFFER, teapotVertexPositionBuffer);
                                        gl.vertexAttribPointer((uint)shaderProgram.vertexPositionAttribute, teapotVertexPositionBuffer_itemSize, gl.FLOAT, false, 0, 0);

                                        gl.bindBuffer(gl.ARRAY_BUFFER, teapotVertexTextureCoordBuffer);
                                        gl.vertexAttribPointer((uint)shaderProgram.textureCoordAttribute, teapotVertexTextureCoordBuffer_itemSize, gl.FLOAT, false, 0, 0);

                                        gl.bindBuffer(gl.ARRAY_BUFFER, teapotVertexNormalBuffer);
                                        gl.vertexAttribPointer((uint)shaderProgram.vertexNormalAttribute, teapotVertexNormalBuffer_itemSize, gl.FLOAT, false, 0, 0);

                                        gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, teapotVertexIndexBuffer);
                                        setMatrixUniforms();
                                        gl.drawElements(gl.TRIANGLES, teapotVertexIndexBuffer_numItems, gl.UNSIGNED_SHORT, 0);


                                    };
                                    #endregion





                                    Native.window.onframe += delegate
                                    {
                                        if (IsDisposed)
                                            return;


                                        animate();
                                        drawScene();

                                    };


                                };

                        }
                    )

            );
        }
开发者ID:exaphaser,项目名称:JSC-Cross-Compiler,代码行数:101,代码来源:Application.cs

示例5: Application


//.........这里部分代码省略.........
            var prMatrix = new CanvasMatrix4();
            //prMatrix.perspective(45, 1, .1, 100);
            gl.uniformMatrix4fv(gl.getUniformLocation(prog, "prMatrix"),
               false, new Float32Array(prMatrix.getAsArray()));
            var mvMatrix = new CanvasMatrix4();
            var rotMat = new CanvasMatrix4();
            rotMat.makeIdentity();
            var mvMatLoc = gl.getUniformLocation(prog, "mvMatrix");
            var colorLoc = gl.getUniformLocation(prog, "color");
            var scaleLoc = gl.getUniformLocation(prog, "scale");

            gl.enable(gl.DEPTH_TEST);
            gl.depthFunc(gl.LEQUAL);
            gl.clearDepth(1.0f);
            gl.clearColor(0, 0, .8f, 1f);

            var xOffs = 0;
            var yOffs = 0;
            var drag = 0;
            var xRot = 0f;
            var yRot = 0f;
            var transl = -10.5f;

            #region drawBall
            Action<f, f, f, f, f, f, f> drawBall = (x, y, z, r, g, b, _scale) =>
            {
                var scale = _scale * 1f;

                mvMatrix.makeIdentity();
                mvMatrix.translate(x, y, z);
                mvMatrix.multRight(rotMat);
                mvMatrix.translate(0, 0, transl);
                gl.uniformMatrix4fv(mvMatLoc, false, new Float32Array(mvMatrix.getAsArray()));
                gl.uniform1f(scaleLoc, scale);
                gl.uniform3f(colorLoc, r, g, b);
                for (var i = 0; i < nTheta; i++)
                    gl.drawElements(gl.TRIANGLE_STRIP, 2 * (nPhi + 1), gl.UNSIGNED_SHORT,
                      4 * (nPhi + 1) * i);
            };
            #endregion

            Action<f, f, f, f> drawBall_white = (x, y, z, _scale) =>
                drawBall(x, y, z, 1, 1, 1, _scale);


            Action<f, f, f, f> drawBall_red = (x, y, z, _scale) =>
                drawBall(x, y, z, 1, 0, 0, _scale);


            #region drawScene
            Action drawScene = delegate
            {
                gl.viewport(0, 0, gl_viewportWidth, gl_viewportHeight);

                #region prMatrix
                gl.uniformMatrix4fv(gl.getUniformLocation(prog, "prMatrix"),
false, new Float32Array(prMatrix.getAsArray()));
                #endregion

                gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
                rotMat.rotate(xRot / 3, 1, 0, 0); rotMat.rotate(yRot / 3, 0, 1, 0);
                yRot = 0; xRot = 0;
                drawBall(0, 0, 0, .3f, .3f, .3f, 1.5f);
                drawBall(1, 1, 1, .3f, .3f, .3f, 1.5f);

                drawBall_white(2, 2, 0, 1);
开发者ID:exaphaser,项目名称:JSC-Cross-Compiler,代码行数:67,代码来源:Application.cs

示例6: Application


//.........这里部分代码省略.........
                        glMatrix.mat4.identity(mvMatrix);


                        glMatrix.mat4.translate(mvMatrix, new float[] { 0.0f, 0.0f, z });

                        glMatrix.mat4.rotate(mvMatrix, degToRad(xRot), new[] { 1f, 0f, 0f });
                        glMatrix.mat4.rotate(mvMatrix, degToRad(yRot), new[] { 0f, 1f, 0f });


                        gl.bindBuffer(gl.ARRAY_BUFFER, cubeVertexPositionBuffer);
                        gl.vertexAttribPointer((uint)shaderProgram_vertexPositionAttribute, cubeVertexPositionBuffer_itemSize, gl.FLOAT, false, 0, 0);

                        #region new in lesson 07
                        gl.bindBuffer(gl.ARRAY_BUFFER, cubeVertexNormalBuffer);
                        gl.vertexAttribPointer((uint)shaderProgram_vertexNormalAttribute, cubeVertexNormalBuffer_itemSize, gl.FLOAT, false, 0, 0);
                        #endregion

                        gl.bindBuffer(gl.ARRAY_BUFFER, cubeVertexTextureCoordBuffer);
                        gl.vertexAttribPointer((uint)shaderProgram_textureCoordAttribute, cubeVertexTextureCoordBuffer_itemSize, gl.FLOAT, false, 0, 0);


                        gl.activeTexture(gl.TEXTURE0);
                        gl.bindTexture(gl.TEXTURE_2D, textures[filter]);
                        gl.uniform1i(shaderProgram_samplerUniform, 0);

                        #region new in lesson 08

                        var blending = [email protected];
                        if (blending)
                        {
                            gl.blendFunc(gl.SRC_ALPHA, gl.ONE);
                            gl.enable(gl.BLEND);
                            gl.disable(gl.DEPTH_TEST);
                            gl.uniform1f(shaderProgram_alphaUniform, toolbar.alpha);
                        }
                        else
                        {
                            gl.disable(gl.BLEND);
                            gl.enable(gl.DEPTH_TEST);
                        }

                        #endregion


                        var lighting = [email protected];
                        gl.uniform1i(shaderProgram_useLightingUniform, lighting.ToInt32());
                        if (lighting)
                        {
                            gl.uniform3f(
                                shaderProgram_ambientColorUniform,
                                toolbar.ambientR,
                                toolbar.ambientG,
                                toolbar.ambientB
                            );

                            var lightingDirection = new float []{
                                toolbar.lightDirectionX,
                                toolbar.lightDirectionY,
                                toolbar.lightDirectionZ
                            };
                            var adjustedLD = glMatrix.vec3.create();
                            glMatrix.vec3.normalize(lightingDirection, adjustedLD);
                            glMatrix.vec3.scale(adjustedLD, new f[] {-1});
                            gl.uniform3fv(shaderProgram_lightingDirectionUniform, adjustedLD);

                            gl.uniform3f(
开发者ID:exaphaser,项目名称:JSC-Cross-Compiler,代码行数:67,代码来源:Application.cs


注:本文中的WebGLRenderingContext.uniform1f方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。