minor fixes
This commit is contained in:
@@ -143,9 +143,9 @@
|
|||||||
//vec3 lightColor = vec3(1.,1.,1.);
|
//vec3 lightColor = vec3(1.,1.,1.);
|
||||||
|
|
||||||
//gl_FragColor = vec4(mix(waterColor, vec3(1.,1.,1.),fresnel).xyz, 1.);
|
//gl_FragColor = vec4(mix(waterColor, vec3(1.,1.,1.),fresnel).xyz, 1.);
|
||||||
//gl_FragColor = vec4(result,1.0);
|
gl_FragColor = vec4(result,1.0);
|
||||||
//gl_FragColor = vec4(normal,1.0);
|
//gl_FragColor = vec4(normal,1.0);
|
||||||
gl_FragColor = vec4(displace.x,displace.x,displace.x,1.0); //Show Perlin Noise texture deactivate vertex distrotion before
|
//gl_FragColor = vec4(displace.x,displace.x,displace.x,1.0); //Show Perlin Noise texture deactivate vertex distrotion before
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
<script id="default-vs" type="x-shader/x-vertex">
|
<script id="default-vs" type="x-shader/x-vertex">
|
||||||
|
|||||||
34
src/main.ts
34
src/main.ts
@@ -1,4 +1,4 @@
|
|||||||
import { vec3, mat4, glMatrix } from 'gl-matrix'
|
import { vec3, mat4 } from 'gl-matrix'
|
||||||
|
|
||||||
var gl: WebGL2RenderingContext;
|
var gl: WebGL2RenderingContext;
|
||||||
var viewportWidth = 0;
|
var viewportWidth = 0;
|
||||||
@@ -21,12 +21,12 @@ function initGL(canvas: HTMLCanvasElement) {
|
|||||||
// Not the best error detection logic.
|
// Not the best error detection logic.
|
||||||
// Redirect to http://get.webgl.org in failure case.
|
// Redirect to http://get.webgl.org in failure case.
|
||||||
if (gltemp == null) {
|
if (gltemp == null) {
|
||||||
alert("Unable to initialize WebGL. Your browser or machine may not support it.");
|
alert("Unable to initialize WebGL2. Your browser or machine may not support it.");
|
||||||
}
|
}
|
||||||
gl = <WebGL2RenderingContext>gltemp;
|
gl = <WebGL2RenderingContext>gltemp;
|
||||||
//WebGL2 supports floating point textures by default but it does not support filtering them or rendering to them by default. Note: 16bit filtering is included
|
//WebGL2 supports floating point textures by default but it does not support filtering them or rendering to them by default. Note: 16bit filtering is included
|
||||||
if (!gl.getExtension('EXT_color_buffer_float')) {
|
if (!gl.getExtension('EXT_color_buffer_float')) {
|
||||||
console.log("32Bit render Buffers not available.")
|
alert("32Bit/16Bit single Color render Buffers not available.");
|
||||||
} //allow 32bit texture as framebuffer target
|
} //allow 32bit texture as framebuffer target
|
||||||
|
|
||||||
gl.enable(gl.DEPTH_TEST);
|
gl.enable(gl.DEPTH_TEST);
|
||||||
@@ -288,7 +288,7 @@ function drawScene() {
|
|||||||
gl.useProgram(perlinNoiseProgram);
|
gl.useProgram(perlinNoiseProgram);
|
||||||
let uTime = gl.getUniformLocation(<WebGLProgram>perlinNoiseProgram, "uTime");
|
let uTime = gl.getUniformLocation(<WebGLProgram>perlinNoiseProgram, "uTime");
|
||||||
gl.uniform1f(uTime, timeSpent);
|
gl.uniform1f(uTime, timeSpent);
|
||||||
gl.drawArrays(gl.TRIANGLES, 0, 6); // Draw quadr
|
gl.drawArrays(gl.TRIANGLES, 0, 6); // Draw fullscreen quad
|
||||||
}
|
}
|
||||||
|
|
||||||
//--- Second render pass -> Geomtry with displacement by perlin noise texture ---
|
//--- Second render pass -> Geomtry with displacement by perlin noise texture ---
|
||||||
@@ -298,35 +298,9 @@ function drawScene() {
|
|||||||
|
|
||||||
gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
|
gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
|
||||||
|
|
||||||
//--- Display perlin noise texture (For Debug)
|
|
||||||
/*{
|
|
||||||
//draw a fullscreen quad
|
|
||||||
gl.bindBuffer(gl.ARRAY_BUFFER, VBO);
|
|
||||||
|
|
||||||
// There are 7 floating-point values per vertex
|
|
||||||
let stride = 5 * Float32Array.BYTES_PER_ELEMENT;
|
|
||||||
|
|
||||||
// Set up position stream
|
|
||||||
gl.vertexAttribPointer(0, 3, gl.FLOAT, false, stride, 0);
|
|
||||||
gl.enableVertexAttribArray(0);
|
|
||||||
gl.vertexAttribPointer(1, 2, gl.FLOAT, false, stride, 3 * Float32Array.BYTES_PER_ELEMENT);
|
|
||||||
gl.enableVertexAttribArray(1);
|
|
||||||
|
|
||||||
gl.activeTexture(gl.TEXTURE0); //Binds the texture to 0
|
gl.activeTexture(gl.TEXTURE0); //Binds the texture to 0
|
||||||
gl.bindTexture(gl.TEXTURE_2D, textureFBO);
|
gl.bindTexture(gl.TEXTURE_2D, textureFBO);
|
||||||
|
|
||||||
gl.useProgram(textureProgram);
|
|
||||||
let mvp = mat4.create();
|
|
||||||
mat4.identity(mvp);
|
|
||||||
let mvp_loc = gl.getUniformLocation(<WebGLProgram>defaultProgram, "u_mvp");
|
|
||||||
gl.uniformMatrix4fv(mvp_loc, false, mvp);
|
|
||||||
gl.drawArrays(gl.TRIANGLES, 0, 6);
|
|
||||||
}*/
|
|
||||||
|
|
||||||
gl.activeTexture(gl.TEXTURE0); //Binds the texture to 0
|
|
||||||
gl.bindTexture(gl.TEXTURE_2D, textureFBO);
|
|
||||||
|
|
||||||
|
|
||||||
var projection = mat4.create();
|
var projection = mat4.create();
|
||||||
mat4.identity(projection);
|
mat4.identity(projection);
|
||||||
mat4.perspective(projection, 1.0, viewportWidth / viewportHeight, 0.1, 1000.);
|
mat4.perspective(projection, 1.0, viewportWidth / viewportHeight, 0.1, 1000.);
|
||||||
|
|||||||
Reference in New Issue
Block a user