本文整理汇总了C#中WebGLRenderingContext.uniform1i方法的典型用法代码示例。如果您正苦于以下问题:C# WebGLRenderingContext.uniform1i方法的具体用法?C# WebGLRenderingContext.uniform1i怎么用?C# WebGLRenderingContext.uniform1i使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类WebGLRenderingContext
的用法示例。
在下文中一共展示了WebGLRenderingContext.uniform1i方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Application
//.........这里部分代码省略.........
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, (int)gl.NEAREST);
#endregion
gl.bindTexture(gl.TEXTURE_2D, null);
gl.clearColor(0.0f, 0.0f, 0.0f, 1.0f);
gl.enable(gl.DEPTH_TEST);
#region new in lesson 04
var xRot = 0.0f;
var yRot = 0.0f;
var zRot = 0.0f;
var lastTime = 0L;
Action animate = delegate
{
var timeNow = new IDate().getTime();
if (lastTime != 0)
{
var elapsed = timeNow - lastTime;
xRot += (90 * elapsed) / 1000.0f;
yRot += (90 * elapsed) / 1000.0f;
zRot += (90 * elapsed) / 1000.0f;
}
lastTime = timeNow;
};
Func<float, float> degToRad = (degrees) =>
{
return degrees * (f)Math.PI / 180f;
};
#endregion
#region drawScene
Action drawScene = delegate
{
gl.viewport(0, 0, gl_viewportWidth, gl_viewportHeight);
gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
glMatrix.mat4.perspective(45f, (float)gl_viewportWidth / (float)gl_viewportHeight, 0.1f, 100.0f, pMatrix);
glMatrix.mat4.identity(mvMatrix);
glMatrix.mat4.translate(mvMatrix, new float[] { 0.0f, 0.0f, -5.0f });
glMatrix.mat4.rotate(mvMatrix, degToRad(xRot), new[] { 1f, 0f, 0f });
glMatrix.mat4.rotate(mvMatrix, degToRad(yRot), new[] { 0f, 1f, 0f });
glMatrix.mat4.rotate(mvMatrix, degToRad(zRot), new[] { 0f, 0f, 1f });
gl.bindBuffer(gl.ARRAY_BUFFER, cubeVertexPositionBuffer);
gl.vertexAttribPointer((uint)shaderProgram_vertexPositionAttribute, cubeVertexPositionBuffer_itemSize, gl.FLOAT, false, 0, 0);
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, neheTexture);
gl.uniform1i(shaderProgram_samplerUniform, 0);
gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, cubeVertexIndexBuffer);
setMatrixUniforms();
gl.drawElements(gl.TRIANGLES, cubeVertexIndexBuffer_numItems, gl.UNSIGNED_SHORT, 0);
};
drawScene();
#endregion
var c = 0;
Native.window.onframe += delegate
{
c++;
Native.document.title = "" + c;
drawScene();
animate();
};
}
);
}
示例2: drawObject
void drawObject(WebGLRenderingContext gl, foo shader, bar @object)
{
gl.useProgram(shader.program);
gl.bindBuffer(gl.ARRAY_BUFFER, @object.vertex_buffer);
gl.vertexAttribPointer((uint)shader.aVertexPosition, 3, gl.FLOAT, false, 0, 0);
gl.bindBuffer(gl.ARRAY_BUFFER, @object.texturecoord_buffer);
gl.vertexAttribPointer((uint)shader.aTextureCoord, 2, gl.FLOAT, false, 0, 0);
gl.activeTexture(gl.TEXTURE0);
gl.bindTexture(gl.TEXTURE_2D, @object.t["texture1"]);
gl.uniform1i(shader.u["uSamplerDiffuse1"], 0);
gl.activeTexture(gl.TEXTURE1);
gl.bindTexture(gl.TEXTURE_2D, @object.t["texture2"]);
gl.uniform1i(shader.u["uSamplerDiffuse2"], 1);
gl.activeTexture(gl.TEXTURE2);
gl.bindTexture(gl.TEXTURE_2D, @object.t["texture3"]);
gl.uniform1i(shader.u["uSamplerDiffuse3"], 2);
gl.activeTexture(gl.TEXTURE3);
gl.bindTexture(gl.TEXTURE_2D, @object.t["texture4"]);
gl.uniform1i(shader.u["uSamplerDiffuse4"], 3);
gl.activeTexture(gl.TEXTURE4);
gl.bindTexture(gl.TEXTURE_2D, @object.t["texture5"]);
gl.uniform1i(shader.u["uSamplerDiffuse5"], 4);
gl.activeTexture(gl.TEXTURE5);
gl.bindTexture(gl.TEXTURE_2D, @object.t["texture6"]);
gl.uniform1i(shader.u["uSamplerDiffuse6"], 5);
gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, @object.index_buffer);
gl.uniformMatrix4fv(shader.u["uProjectionMatrix"], false, shader.PROJECTION_MATRIX);
gl.uniformMatrix4fv(shader.u["uModelViewMatrix"], false, shader.MV_MATRIX);
gl.drawElements(gl.TRIANGLES, @object.n_elements, gl.UNSIGNED_SHORT, 0);
}
示例3: Application
//.........这里部分代码省略.........
// 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);
// using ?
var l1 = (uint)gl.getAttribLocation(mProgram, "pos");
gl.bindBuffer(gl.ARRAY_BUFFER, quadVBO);
示例4: Application
//.........这里部分代码省略.........
canvas.height = gl_viewportHeight;
};
Native.window.onresize +=
e =>
{
AtResize();
};
AtResize();
#endregion
new HTML.Images.FromAssets.star().InvokeOnComplete(
texture_image =>
{
var starTexture = gl.createTexture();
#region handleLoadedTexture
gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, 1);
gl.bindTexture(gl.TEXTURE_2D, starTexture);
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, texture_image);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, (int)gl.LINEAR);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, (int)gl.LINEAR);
gl.bindTexture(gl.TEXTURE_2D, null);
#endregion
#region drawStar
Action drawStar = () =>
{
gl.activeTexture(gl.TEXTURE0);
gl.bindTexture(gl.TEXTURE_2D, starTexture);
gl.uniform1i(shaderProgram_samplerUniform, 0);
gl.bindBuffer(gl.ARRAY_BUFFER, starVertexTextureCoordBuffer);
gl.vertexAttribPointer((uint)shaderProgram_textureCoordAttribute, starVertexTextureCoordBuffer_itemSize, gl.FLOAT, false, 0, 0);
gl.bindBuffer(gl.ARRAY_BUFFER, starVertexPositionBuffer);
gl.vertexAttribPointer((uint)shaderProgram_vertexPositionAttribute, starVertexPositionBuffer_itemSize, gl.FLOAT, false, 0, 0);
setMatrixUniforms();
gl.drawArrays(gl.TRIANGLE_STRIP, 0, starVertexPositionBuffer_numItems);
};
#endregion
#region drawScene
Action drawScene = delegate
{
gl.viewport(0, 0, gl_viewportWidth, gl_viewportHeight);
gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
glMatrix.mat4.perspective(45, gl_viewportWidth / gl_viewportHeight, 0.1f, 100.0f, pMatrix);
gl.blendFunc(gl.SRC_ALPHA, gl.ONE);
gl.enable(gl.BLEND);
glMatrix.mat4.identity(mvMatrix);
glMatrix.mat4.translate(mvMatrix, new f[] {0.0f, 0.0f, zoom});
glMatrix.mat4.rotate(mvMatrix, degToRad(tilt),new f[] { 1.0f, 0.0f, 0.0f});
//var twinkle = document.getElementById("twinkle").checked;
var twinkle = false;
foreach (var star in stars)
{
示例5: Application
//.........这里部分代码省略.........
var lastTime = 0L;
// Used to make us "jog" up and down as we move forward.
var joggingAngle = 0f;
#region animate
Action animate = () =>
{
var timeNow = new IDate().getTime();
if (lastTime != 0)
{
var elapsed = timeNow - lastTime;
if (speed != 0)
{
xPos -= (f)Math.Sin(degToRad(yaw)) * speed * elapsed;
zPos -= (f)Math.Cos(degToRad(yaw)) * speed * elapsed;
joggingAngle += elapsed * 0.6f; // 0.6 "fiddle factor" - makes it feel more realistic :-)
yPos = (f)Math.Sin(degToRad(joggingAngle)) / 20 + 0.4f;
}
else
{
joggingAngle += elapsed * 0.06f; // 0.6 "fiddle factor" - makes it feel more realistic :-)
yPos = (f)Math.Sin(degToRad(joggingAngle)) / 200 + 0.4f;
}
yaw += yawRate * elapsed;
pitch += pitchRate * elapsed;
}
lastTime = timeNow;
};
#endregion
#region drawScene
Action drawScene = () =>
{
gl.viewport(0, 0, gl_viewportWidth, gl_viewportHeight);
gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
glMatrix.mat4.perspective(45, (float)Native.window.aspect, 0.1f, 100.0f, pMatrix);
glMatrix.mat4.identity(mvMatrix);
if (__pointer_y != 0)
pitch = radToDeg(__pointer_y * -0.01f);
if (__pointer_x != 0)
yaw = radToDeg(__pointer_x * -0.01f);
glMatrix.mat4.rotate(mvMatrix, degToRad(-pitch), new f[] { 1, 0, 0 });
glMatrix.mat4.rotate(mvMatrix, degToRad(-yaw), new f[] { 0, 1, 0 });
//glMatrix.mat4.rotate(mvMatrix, __pointer_y * 0.01f, 1, 0, 0);
//glMatrix.mat4.rotate(mvMatrix, __pointer_x * 0.01f, 0, 1, 0);
glMatrix.mat4.translate(mvMatrix, new[] { -xPos, -yPos, -zPos });
gl.activeTexture(gl.TEXTURE0);
gl.bindTexture(gl.TEXTURE_2D, mudTexture);
gl.uniform1i(shaderProgram_samplerUniform, 0);
gl.bindBuffer(gl.ARRAY_BUFFER, worldVertexTextureCoordBuffer);
gl.vertexAttribPointer((uint)shaderProgram_textureCoordAttribute, worldVertexTextureCoordBuffer_itemSize, gl.FLOAT, false, 0, 0);
gl.bindBuffer(gl.ARRAY_BUFFER, worldVertexPositionBuffer);
gl.vertexAttribPointer((uint)shaderProgram_vertexPositionAttribute, worldVertexPositionBuffer_itemSize, gl.FLOAT, false, 0, 0);
setMatrixUniforms();
gl.drawArrays(gl.TRIANGLES, 0, worldVertexPositionBuffer_numItems);
};
#endregion
Native.window.onframe +=
delegate
{
if (IsDisposed)
return;
handleKeys();
drawScene();
animate();
};
}
);
}
示例6: Application
//.........这里部分代码省略.........
#region drawScene
Action drawScene = delegate
{
gl.viewport(0, 0, gl_viewportWidth, gl_viewportHeight);
gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
glMatrix.mat4.perspective(45f, (float)gl_viewportWidth / (float)gl_viewportHeight, 0.1f, 100.0f, pMatrix);
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 07
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(
shaderProgram_directionalColorUniform,
toolbar.directionalR,
toolbar.directionalG,
toolbar.directionalB
);
}
#endregion
示例7: InitializeContent
//.........这里部分代码省略.........
Action animate = () =>
{
var timeNow = new IDate().getTime();
if (lastTime != 0)
{
var elapsed = timeNow - lastTime;
moonAngle += 0.05f * elapsed;
cubeAngle += 0.05f * elapsed;
laptopAngle -= 0.005f * elapsed;
}
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);
示例8: Application
//.........这里部分代码省略.........
{
glMatrix.mat4.perspective(45f, (float)gl_viewportWidth / (float)gl_viewportHeight, 0.1f, 100.0f, pMatrix);
glMatrix.mat4.identity(mvMatrix);
var u1 = f.trackBar1.Value * 0.1f;
glMatrix.mat4.translate(mvMatrix, new float[] { 0.0f, 0.0f, u1 });
//glMatrix.mat4.rotate(mvMatrix, degToRad(xRot), new[] { 1f, 0f, 0f });
if (Anonymous_LogosSingleNoWings_Checked)
glMatrix.mat4.rotate(mvMatrix, degToRad(yRot), new[] { 0f, 1f, 0f });
else
glMatrix.mat4.rotate(mvMatrix, degToRad(f.trackBar3.Value), new[] { 0f, 1f, 0f });
var u2 = f.trackBar2.Value * 0.1f;
glMatrix.mat4.translate(mvMatrix, new float[] { 0.0f, 0.0f, u2 });
Native.document.title = new { u1, u2 }.ToString();
//glMatrix.mat4.rotate(mvMatrix, degToRad(zRot), new[] { 0f, 0f, 1f });
gl.bindBuffer(gl.ARRAY_BUFFER, cubeVertexPositionBuffer);
gl.vertexAttribPointer((uint)shaderProgram_vertexPositionAttribute, cubeVertexPositionBuffer_itemSize, gl.FLOAT, false, 0, 0);
gl.bindBuffer(gl.ARRAY_BUFFER, cubeVertexTextureCoordBuffer);
gl.vertexAttribPointer((uint)shaderProgram_textureCoordAttribute, cubeVertexTextureCoordBuffer_itemSize, gl.FLOAT, false, 0, 0);
if (Anonymous_LogosSingleNoWings_Checked)
{
gl.activeTexture(gl.TEXTURE0);
gl.bindTexture(gl.TEXTURE_2D, tex0);
gl.uniform1i(shaderProgram_samplerUniform, 0);
}
else
{
gl.activeTexture(gl.TEXTURE0);
gl.bindTexture(gl.TEXTURE_2D, tex1);
gl.uniform1i(shaderProgram_samplerUniform, 0);
}
gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, cubeVertexIndexBuffer);
setMatrixUniforms();
gl.drawElements(gl.TRIANGLES, cubeVertexIndexBuffer_numItems, gl.UNSIGNED_SHORT, 0);
gl.bindTexture(gl.TEXTURE_2D, null);
};
var c = 0;
Native.window.onframe += delegate
{
c++;
if (page == null)
{
gl_viewportWidth = canvas.clientWidth;
gl_viewportHeight = canvas.clientHeight;
canvas.style.SetLocation(0, 0, gl_viewportWidth, gl_viewportHeight);
canvas.width = gl_viewportWidth;
canvas.height = gl_viewportHeight;
}
gl.viewport(0, 0, gl_viewportWidth, gl_viewportHeight);
gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
if (f.Anonymous_LogosSingleNoWings.Checked)
drawScene(false);
if (f.Anonymous_LogosSingleWings.Checked)
drawScene(true);
animate();
};
}
);
}
);
}
示例9: Application
//.........这里部分代码省略.........
#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");
if (l8 != null) gl.uniform3fv(l8, resos);
// using ?
示例10: Application
//.........这里部分代码省略.........
var lastTime = 0L;
#region animate
Action animate = () =>
{
var timeNow = new IDate().getTime();
if (lastTime != 0)
{
var elapsed = timeNow - lastTime;
moonAngle += 0.05f * elapsed;
cubeAngle += 0.05f * elapsed;
}
lastTime = timeNow;
};
#endregion
//Func<string, f> parseFloat = Convert.ToSingle;
Func<string, f> parseFloat = x => float.Parse(x);
#region drawScene
Action drawScene = () =>
{
gl.viewport(0, 0, gl_viewportWidth, gl_viewportHeight);
gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
glMatrix.mat4.perspective(45, gl_viewportWidth / gl_viewportHeight, 0.1f, 100.0f, pMatrix);
var lighting = [email protected];
#region [uniform] bool uUseLighting <- lighting
gl.uniform1i(shaderProgram_useLightingUniform, Convert.ToInt32(lighting));
#endregion
if (lighting)
{
#region [uniform] vec3 uAmbientColor <- (f ambientR, f ambientG, f ambientB)
gl.uniform3f(
shaderProgram_ambientColorUniform,
parseFloat(toolbar.ambientR.value),
parseFloat(toolbar.ambientG.value),
parseFloat(toolbar.ambientB.value)
);
#endregion
#region [uniform] vec3 uPointLightingLocation <- (f lightPositionX, f lightPositionY, f lightPositionZ)
gl.uniform3f(
shaderProgram_pointLightingLocationUniform,
parseFloat(toolbar.lightPositionX.value),
parseFloat(toolbar.lightPositionY.value),
parseFloat(toolbar.lightPositionZ.value)
);
#endregion
#region [uniform] vec3 uPointLightingColor <- (f pointR, f pointG, f pointB)
gl.uniform3f(
shaderProgram_pointLightingColorUniform,
parseFloat(toolbar.pointR.value),
parseFloat(toolbar.pointG.value),
parseFloat(toolbar.pointB.value)
);
#endregion
}
示例11: Application
//.........这里部分代码省略.........
var elapsed = timeNow - lastTime;
teapotAngle += 0.05f * elapsed;
}
lastTime = timeNow;
};
#endregion
//Func<string, f> parseFloat = Convert.ToSingle;
Func<string, f> parseFloat = x => float.Parse(x);
#region drawScene
Action drawScene = () =>
{
gl.useProgram(currentProgram.program);
gl.viewport(0, 0, gl_viewportWidth, gl_viewportHeight);
gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
//if (teapotVertexPositionBuffer == null || teapotVertexNormalBuffer == null || teapotVertexTextureCoordBuffer == null || teapotVertexIndexBuffer == null) {
// return;
//}
glMatrix.mat4.perspective(45, gl_viewportWidth / gl_viewportHeight, 0.1f, 100.0f, pMatrix);
var shaderProgram = currentProgram;
var specularHighlights = [email protected];
#region [uniform] bool uShowSpecularHighlights <- [email protected]
gl.uniform1i(shaderProgram.showSpecularHighlightsUniform, Convert.ToInt32(specularHighlights));
#endregion
var lighting = [email protected];
#region [uniform] bool uUseLighting <- [email protected]
gl.uniform1i(shaderProgram.useLightingUniform, Convert.ToInt32(lighting));
#endregion
if (lighting)
{
#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,
示例12: Application
//.........这里部分代码省略.........
Action animate = () =>
{
var timeNow = new IDate().getTime();
if (lastTime != 0)
{
var elapsed = timeNow - lastTime;
earthAngle += 0.05f * elapsed;
}
lastTime = timeNow;
};
#endregion
//Func<string, f> parseFloat = Convert.ToSingle;
//Func<string, f> parseFloat = x => float.Parse(x);
#region drawScene
Action drawScene = () =>
{
var shaderProgram = currentProgram;
gl.useProgram(shaderProgram.program);
gl.viewport(0, 0, gl_viewportWidth, gl_viewportHeight);
gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
glMatrix.mat4.perspective(45, gl_viewportWidth / gl_viewportHeight, 0.1f, 100.0f, pMatrix);
#region [uniform] uUseColorMap <- color_map
var useColorMap = [email protected];
gl.uniform1i(shaderProgram.useColorMapUniform, Convert.ToInt32(useColorMap));
#endregion
#region [uniform] uUseSpecularMap <- specular_map
var useSpecularMap = [email protected];
gl.uniform1i(shaderProgram.useSpecularMapUniform, Convert.ToInt32(useSpecularMap));
#endregion
#region [uniform] uUseLighting <- lighting
var lighting = [email protected];
gl.uniform1i(shaderProgram.useLightingUniform, Convert.ToInt32(lighting));
#endregion
if (lighting)
{
#region [uniform] uAmbientColor <- ambientR, ambientG, ambientB
gl.uniform3f(
shaderProgram.ambientColorUniform,
float.Parse(toolbar.ambientR.value),
float.Parse(toolbar.ambientG.value),
float.Parse(toolbar.ambientB.value)
);
#endregion
#region [uniform] uPointLightingLocation <- lightPositionX, lightPositionY, lightPositionZ
gl.uniform3f(
shaderProgram.pointLightingLocationUniform,
float.Parse(toolbar.lightPositionX.value),
float.Parse(toolbar.lightPositionY.value),
float.Parse(toolbar.lightPositionZ.value)
);
示例13: Application
//.........这里部分代码省略.........
var textureLocation = default(WebGLUniformLocation);
#region resize
Action resize = delegate
{
canvas.style.SetLocation(0, 0);
canvas.width = Native.window.Width;
canvas.height = Native.window.Height;
parameters_screenWidth = canvas.width;
parameters_screenHeight = canvas.height;
gl.viewport(0, 0, canvas.width, canvas.height);
};
Native.window.onresize +=
delegate
{
if (IsDisposed)
return;
resize();
};
resize();
#endregion
Native.window.onframe +=
delegate
{
if (IsDisposed)
return;
if (program == null) return;
gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
// Load program into GPU
// Get var locations
vertexPositionLocation = gl.getAttribLocation(program, "position");
textureLocation = gl.getUniformLocation(program, "texture");
// Set values to program variables
var program_uniforms = program.Uniforms(gl);
var resolution = new __vec2 { x = parameters_screenWidth, y = parameters_screenHeight };
program_uniforms.time = time.ElapsedMilliseconds / 1000f;
// could the uniform accept anonymous type and infer vec2 based on x and y?
program_uniforms.resolution = resolution;
//gl.uniform1f(gl.getUniformLocation(program, "time"), parameters_time / 1000);
//gl.uniform2f(gl.getUniformLocation(program, "resolution"), parameters_screenWidth, parameters_screenHeight);
gl.uniform1i(textureLocation, 0);
gl.activeTexture(gl.TEXTURE0);
gl.bindTexture(gl.TEXTURE_2D, texture);
// Render geometry
gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
gl.vertexAttribPointer((uint)vertexPositionLocation, 2, gl.FLOAT, false, 0, 0);
gl.enableVertexAttribArray((uint)vertexPositionLocation);
gl.drawArrays(gl.TRIANGLES, 0, 6);
gl.disableVertexAttribArray((uint)vertexPositionLocation);
};
#region requestFullscreen
Native.document.body.ondblclick +=
delegate
{
if (IsDisposed)
return;
// http://tutorialzine.com/2012/02/enhance-your-website-fullscreen-api/
Native.document.body.requestFullscreen();
};
#endregion
}
示例14: Application
//.........这里部分代码省略.........
var moonTexture = gl.createTexture();
gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, 1);
gl.bindTexture(gl.TEXTURE_2D, moonTexture);
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, mud);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, (int)gl.LINEAR);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, (int)gl.LINEAR_MIPMAP_NEAREST);
gl.generateMipmap(gl.TEXTURE_2D);
gl.bindTexture(gl.TEXTURE_2D, null);
gl.clearColor(0.0f, 0.0f, 0.0f, 1.0f);
gl.enable(gl.DEPTH_TEST);
#region drawScene
Action drawScene = () =>
{
gl.viewport(0, 0, gl_viewportWidth, gl_viewportHeight);
gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
glMatrix.mat4.perspective(45, gl_viewportWidth / gl_viewportHeight, 0.1f, 100.0f, pMatrix);
var lighting = [email protected];
#region [uniform] bool uUseLighting <- lighting
gl.uniform1i(shaderProgram_useLightingUniform, Convert.ToInt32(lighting));
#endregion
if (lighting)
{
#region [uniform] vec3 uAmbientColor <- (f ambientR, f ambientG, f ambientB)
gl.uniform3f(
shaderProgram_ambientColorUniform,
float.Parse(toolbar.ambientR.value),
float.Parse(toolbar.ambientG.value),
float.Parse(toolbar.ambientB.value)
);
#endregion
var lightingDirection = new[]{
float.Parse(toolbar.lightDirectionX.value),
float.Parse(toolbar.lightDirectionY.value),
float.Parse(toolbar.lightDirectionZ.value)
};
var adjustedLD = glMatrix.vec3.create();
glMatrix.vec3.normalize(lightingDirection, adjustedLD);
glMatrix.vec3.scale(adjustedLD, new f[] { -1 });
#region [uniform] vec3 uLightingDirection <- vec3
gl.uniform3fv(shaderProgram_lightingDirectionUniform, adjustedLD);
#endregion
#region [uniform] vec3 uDirectionalColor <- (f directionalR, f directionalG, f directionalB)
gl.uniform3f(
shaderProgram_directionalColorUniform,
float.Parse(toolbar.directionalR.value),
float.Parse(toolbar.directionalG.value),