diff --git a/examples/canvas3d/interaction/qml/interaction/interaction.js b/examples/canvas3d/interaction/qml/interaction/interaction.js index 90c2159769a2561de6f04d68d3cc0f1e98a08d0d..84bd11de79565df8f38467bdb521bbb99b212200 100644 --- a/examples/canvas3d/interaction/qml/interaction/interaction.js +++ b/examples/canvas3d/interaction/qml/interaction/interaction.js @@ -276,38 +276,38 @@ function initShaders() log(" initShaders ENTER...") vertexShader = getShader(gl, - "attribute highp vec3 aVertexNormal; - attribute highp vec3 aVertexPosition; - attribute highp vec2 aTextureCoord; - - uniform highp mat4 uNormalMatrix; - uniform mat4 uMVMatrix; - uniform mat4 uPMatrix; - - varying highp vec2 vTextureCoord; - varying highp vec3 vLighting; - - void main(void) { - gl_Position = uPMatrix * uMVMatrix * vec4(aVertexPosition, 1.0); - vTextureCoord = aTextureCoord; - highp vec3 ambientLight = vec3(0.5, 0.5, 0.5); - highp vec3 directionalLightColor = vec3(0.75, 0.75, 0.75); - highp vec3 directionalVector = vec3(0.85, 0.8, 0.75); - highp vec4 transformedNormal = uNormalMatrix * vec4(aVertexNormal, 1.0); - - highp float directional = max(dot(transformedNormal.xyz, directionalVector), 0.0); - vLighting = ambientLight + (directionalLightColor * directional); + "attribute highp vec3 aVertexNormal; \ + attribute highp vec3 aVertexPosition; \ + attribute highp vec2 aTextureCoord; \ + \ + uniform highp mat4 uNormalMatrix; \ + uniform mat4 uMVMatrix; \ + uniform mat4 uPMatrix; \ + \ + varying highp vec2 vTextureCoord; \ + varying highp vec3 vLighting; \ + \ + void main(void) { \ + gl_Position = uPMatrix * uMVMatrix * vec4(aVertexPosition, 1.0); \ + vTextureCoord = aTextureCoord; \ + highp vec3 ambientLight = vec3(0.5, 0.5, 0.5); \ + highp vec3 directionalLightColor = vec3(0.75, 0.75, 0.75); \ + highp vec3 directionalVector = vec3(0.85, 0.8, 0.75); \ + highp vec4 transformedNormal = uNormalMatrix * vec4(aVertexNormal, 1.0); \ + \ + highp float directional = max(dot(transformedNormal.xyz, directionalVector), 0.0); \ + vLighting = ambientLight + (directionalLightColor * directional); \ }", gl.VERTEX_SHADER); fragmentShader = getShader(gl, - "varying highp vec2 vTextureCoord; - varying highp vec3 vLighting; - - uniform sampler2D uSampler; - - void main(void) { - mediump vec4 texelColor = texture2D(uSampler, vec2(vTextureCoord.s, vTextureCoord.t)); - gl_FragColor = vec4(texelColor.rgb * vLighting, 1.0); + "varying highp vec2 vTextureCoord; \ + varying highp vec3 vLighting; \ + \ + uniform sampler2D uSampler; \ + \ + void main(void) { \ + mediump vec4 texelColor = texture2D(uSampler, vec2(vTextureCoord.s, vTextureCoord.t)); \ + gl_FragColor = vec4(texelColor.rgb * vLighting, 1.0); \ }", gl.FRAGMENT_SHADER); texturedShaderProgram = gl.createProgram(); diff --git a/examples/canvas3d/plasmaeffects/qml/plasmaeffects/plasmaeffects.js b/examples/canvas3d/plasmaeffects/qml/plasmaeffects/plasmaeffects.js index 99683a4f29399b8ed85c9092e39bf20ae8c29255..a0c788963b5493a404e24c8ff386851160f821d2 100644 --- a/examples/canvas3d/plasmaeffects/qml/plasmaeffects/plasmaeffects.js +++ b/examples/canvas3d/plasmaeffects/qml/plasmaeffects/plasmaeffects.js @@ -385,51 +385,51 @@ function initShaders() log(" initShaders ENTER...") var cubeVertexShader = getShader(gl, - "attribute highp vec3 aVertexPosition; - attribute mediump vec4 aVertexColor; - attribute highp vec2 aTextureCoord; - - uniform mat4 uMVMatrix; - uniform mat4 uPMatrix; - - varying mediump vec4 vColor; - varying highp vec2 vTextureCoord; - varying highp vec4 vPos; - - void main(void) { - vPos = uPMatrix * uMVMatrix * vec4(aVertexPosition, 1.0); - gl_Position = uPMatrix * uMVMatrix * vec4(aVertexPosition, 1.0); - vColor = aVertexColor; - vTextureCoord = aTextureCoord; + "attribute highp vec3 aVertexPosition; \ + attribute mediump vec4 aVertexColor; \ + attribute highp vec2 aTextureCoord; \ + \ + uniform mat4 uMVMatrix; \ + uniform mat4 uPMatrix; \ + \ + varying mediump vec4 vColor; \ + varying highp vec2 vTextureCoord; \ + varying highp vec4 vPos; \ + \ + void main(void) { \ + vPos = uPMatrix * uMVMatrix * vec4(aVertexPosition, 1.0); \ + gl_Position = uPMatrix * uMVMatrix * vec4(aVertexPosition, 1.0); \ + vColor = aVertexColor; \ + vTextureCoord = aTextureCoord; \ }", gl.VERTEX_SHADER); var cubeFragmentShader = getShader(gl, - "#define PI 3.1415926535897932384626433832795 - uniform highp float uTime; - - varying mediump vec4 vColor; - varying highp vec2 vTextureCoord; - varying highp vec4 vPos; - - uniform sampler2D uSampler; - - void main(void) { - highp vec4 volScale = vec4(3.0, 3.0, 3.0, 2.0); - highp vec4 volume = vPos * volScale - volScale/2.0; - - highp vec2 scaling = vec2(20.0,20.0); - highp vec2 coord = vTextureCoord * scaling - scaling/2.0; - highp float value = sin(volume.x+coord.x+uTime); - value += sin((volume.y+coord.y+uTime)/1.5); - value += sin((volume.z+coord.y+uTime)/1.5); - - coord += scaling/2.0 * vec2(sin(uTime/3.0), cos(uTime/2.0)); - value += sin(sqrt(coord.x*coord.x + coord.y*coord.y + 1.0) + uTime); - value = value/2.0; - value = sin(PI*value); - highp vec4 col = vec4(value, value, value, 1.0); - highp vec4 textureColor = texture2D(uSampler, vec2(vTextureCoord.s, vTextureCoord.t)); - gl_FragColor = vec4(col.rgb * vColor.rgb * textureColor.rgb, textureColor.a); - }", gl.FRAGMENT_SHADER); + " \ + uniform highp float uTime; \ + \ + varying mediump vec4 vColor; \ + varying highp vec2 vTextureCoord; \ + varying highp vec4 vPos; \ + \ + uniform sampler2D uSampler; \ + \ + void main(void) { \ + highp vec4 volScale = vec4(3.0, 3.0, 3.0, 2.0); \ + highp vec4 volume = vPos * volScale - volScale/2.0; \ + \ + highp vec2 scaling = vec2(20.0,20.0); \ + highp vec2 coord = vTextureCoord * scaling - scaling/2.0; \ + highp float value = sin(volume.x+coord.x+uTime); \ + value += sin((volume.y+coord.y+uTime)/1.5); \ + value += sin((volume.z+coord.y+uTime)/1.5); \ + \ + coord += scaling/2.0 * vec2(sin(uTime/3.0), cos(uTime/2.0)); \ + value += sin(sqrt(coord.x*coord.x + coord.y*coord.y + 1.0) + uTime); \ + value = value/2.0; \ + value = sin(3.14*value); \ + highp vec4 col = vec4(value, value, value, 1.0); \ + highp vec4 textureColor = texture2D(uSampler, vec2(vTextureCoord.s, vTextureCoord.t)); \ + gl_FragColor = vec4(col.rgb * vColor.rgb * textureColor.rgb, textureColor.a); \ + }", gl.FRAGMENT_SHADER); //! [0] cubeShaderProgram = gl.createProgram(); @@ -461,51 +461,51 @@ function initShaders() //! [2] // BACKGROUND SHADER var bkgVertexShader = getShader(gl, - "attribute highp vec2 aVertexPosition; - attribute highp vec2 aTextureCoord; - - varying highp vec2 vTextureCoord; - - void main(void) { - gl_Position = vec4(aVertexPosition, 0.0, 1.0); - vTextureCoord = aTextureCoord; + "attribute highp vec2 aVertexPosition; \ + attribute highp vec2 aTextureCoord; \ + \ + varying highp vec2 vTextureCoord; \ + \ + void main(void) { \ + gl_Position = vec4(aVertexPosition, 0.0, 1.0); \ + vTextureCoord = aTextureCoord; \ }", gl.VERTEX_SHADER); var bkgFragmentShader = getShader(gl, - "uniform highp float uTime; - varying highp vec2 vTextureCoord; - - void main(void) { - highp vec2 position = vTextureCoord.xy; - - highp float centerX = position.x - 0.5 + sin(uTime / 2.0) * 0.1; - highp float centerY = position.y - 0.5 + cos(uTime / 2.0) * 0.1; - - highp float x = log(sqrt(centerX*centerX + centerY*centerY)); - highp float y = atan(centerX, centerY); - - highp float color = cos(x * cos(uTime / 30.0) * 80.0) + cos(x * cos(uTime / 30.0) * 10.0) + - cos(y * cos(uTime / 20.0) * 40.0) + cos(y * sin(uTime / 50.0) * 40.0); - color *= 0.5; - - gl_FragColor = vec4(color * sin(uTime / 10.0) * 0.5, color * (1.0 - sin(uTime / 10.0)) * 0.5, sin( color + uTime / 3.0 ) * 0.3, 1.0 ); + "uniform highp float uTime; \ + varying highp vec2 vTextureCoord; \ + \ + void main(void) { \ + highp vec2 position = vTextureCoord.xy; \ + \ + highp float centerX = position.x - 0.5 + sin(uTime / 2.0) * 0.1; \ + highp float centerY = position.y - 0.5 + cos(uTime / 2.0) * 0.1; \ + \ + highp float x = log(sqrt(centerX*centerX + centerY*centerY)); \ + highp float y = atan(centerX, centerY); \ + \ + highp float color = cos(x * cos(uTime / 30.0) * 80.0) + cos(x * cos(uTime / 30.0) * 10.0) + \ + cos(y * cos(uTime / 20.0) * 40.0) + cos(y * sin(uTime / 50.0) * 40.0); \ + color *= 0.5; \ + \ + gl_FragColor = vec4(color * sin(uTime / 10.0) * 0.5, color * (1.0 - sin(uTime / 10.0)) * 0.5, sin( color + uTime / 3.0 ) * 0.3, 1.0 ); \ }", gl.FRAGMENT_SHADER); var bkgFragmentShaderBW = getShader(gl, - "uniform highp float uTime; - varying highp vec2 vTextureCoord; - - void main(void) { - highp vec2 position = vTextureCoord.xy; - - highp float centerX = position.x - 0.5 + sin(uTime / 3.0) * 0.1; - highp float centerY = position.y - 0.5 + cos(uTime / 3.0) * 0.1; - - highp float x = log(sqrt(centerX*centerX + centerY*centerY)); - highp float y = atan(centerX, centerY); - - highp float color = cos(x * cos(uTime / 30.0) * 80.0) + cos(x * cos(uTime / 30.0) * 10.0); - color += cos(y * cos(uTime / 20.0) * 40.0) + cos(y * sin(uTime / 50.0) * 40.0); - color *= 0.2; - gl_FragColor = vec4(color, color, color, 1.0 ); + "uniform highp float uTime; \ + varying highp vec2 vTextureCoord; \ + \ + void main(void) { \ + highp vec2 position = vTextureCoord.xy; \ + \ + highp float centerX = position.x - 0.5 + sin(uTime / 3.0) * 0.1; \ + highp float centerY = position.y - 0.5 + cos(uTime / 3.0) * 0.1; \ + \ + highp float x = log(sqrt(centerX*centerX + centerY*centerY)); \ + highp float y = atan(centerX, centerY); \ + \ + highp float color = cos(x * cos(uTime / 30.0) * 80.0) + cos(x * cos(uTime / 30.0) * 10.0); \ + color += cos(y * cos(uTime / 20.0) * 40.0) + cos(y * sin(uTime / 50.0) * 40.0); \ + color *= 0.2; \ + gl_FragColor = vec4(color, color, color, 1.0 ); \ }", gl.FRAGMENT_SHADER); //! [1] diff --git a/examples/canvas3d/textureandlight/qml/textureandlight/textureandlight.js b/examples/canvas3d/textureandlight/qml/textureandlight/textureandlight.js index 62f0bb7d3ec1dbf763a78645992896bbe98992af..1e52d0c1a18a318e75b21c51cbd150de7e199d40 100644 --- a/examples/canvas3d/textureandlight/qml/textureandlight/textureandlight.js +++ b/examples/canvas3d/textureandlight/qml/textureandlight/textureandlight.js @@ -292,43 +292,43 @@ function initShaders() { //! [3] var vertexShader = getShader(gl, - "attribute highp vec3 aVertexNormal; - attribute highp vec3 aVertexPosition; - attribute mediump vec4 aVertexColor; - attribute highp vec2 aTextureCoord; - - uniform highp mat4 uNormalMatrix; - uniform mat4 uMVMatrix; - uniform mat4 uPMatrix; - - varying mediump vec4 vColor; - varying highp vec2 vTextureCoord; - varying highp vec3 vLighting; - - void main(void) { - gl_Position = uPMatrix * uMVMatrix * vec4(aVertexPosition, 1.0); - vColor = aVertexColor; - vTextureCoord = aTextureCoord; - highp vec3 ambientLight = vec3(0.5, 0.5, 0.5); - highp vec3 directionalLightColor = vec3(0.75, 0.75, 0.75); - highp vec3 directionalVector = vec3(0.85, 0.8, 0.75); - highp vec4 transformedNormal = uNormalMatrix * vec4(aVertexNormal, 1.0); - highp float directional = max(dot(transformedNormal.xyz, directionalVector), 0.0); - vLighting = ambientLight + (directionalLightColor * directional); + "attribute highp vec3 aVertexNormal; \ + attribute highp vec3 aVertexPosition; \ + attribute mediump vec4 aVertexColor; \ + attribute highp vec2 aTextureCoord; \ + \ + uniform highp mat4 uNormalMatrix; \ + uniform mat4 uMVMatrix; \ + uniform mat4 uPMatrix; \ + \ + varying mediump vec4 vColor; \ + varying highp vec2 vTextureCoord; \ + varying highp vec3 vLighting; \ + \ + void main(void) { \ + gl_Position = uPMatrix * uMVMatrix * vec4(aVertexPosition, 1.0); \ + vColor = aVertexColor; \ + vTextureCoord = aTextureCoord; \ + highp vec3 ambientLight = vec3(0.5, 0.5, 0.5); \ + highp vec3 directionalLightColor = vec3(0.75, 0.75, 0.75); \ + highp vec3 directionalVector = vec3(0.85, 0.8, 0.75); \ + highp vec4 transformedNormal = uNormalMatrix * vec4(aVertexNormal, 1.0); \ + highp float directional = max(dot(transformedNormal.xyz, directionalVector), 0.0); \ + vLighting = ambientLight + (directionalLightColor * directional); \ }", gl.VERTEX_SHADER); //! [3] //! [4] var fragmentShader = getShader(gl, - "varying mediump vec4 vColor; - varying highp vec2 vTextureCoord; - varying highp vec3 vLighting; - - uniform sampler2D uSampler; - - void main(void) { - mediump vec4 texelColor = texture2D(uSampler, vec2(vTextureCoord.s, vTextureCoord.t)); - mediump vec3 blendColor = mix(vColor.rgb, texelColor.rgb, texelColor.a); - gl_FragColor = vec4(blendColor * vLighting, 1.0); + "varying mediump vec4 vColor; \ + varying highp vec2 vTextureCoord; \ + varying highp vec3 vLighting; \ + \ + uniform sampler2D uSampler; \ + \ + void main(void) { \ + mediump vec4 texelColor = texture2D(uSampler, vec2(vTextureCoord.s, vTextureCoord.t)); \ + mediump vec3 blendColor = mix(vColor.rgb, texelColor.rgb, texelColor.a); \ + gl_FragColor = vec4(blendColor * vLighting, 1.0); \ }", gl.FRAGMENT_SHADER); //! [4] //! [5] diff --git a/examples/canvas3d/texturedcube/qml/texturedcube/texturedcube.js b/examples/canvas3d/texturedcube/qml/texturedcube/texturedcube.js index 559f8656c7dbf1151937f722de330014921a540c..6d93bfb9eeaf16f55759297337999e9b76726e69 100644 --- a/examples/canvas3d/texturedcube/qml/texturedcube/texturedcube.js +++ b/examples/canvas3d/texturedcube/qml/texturedcube/texturedcube.js @@ -252,33 +252,33 @@ function initBuffers() function initShaders() { log(" initShaders ENTER {") - var vertexShader = getShader(gl," - attribute highp vec3 aVertexPosition; - attribute mediump vec4 aVertexColor; - attribute highp vec2 aTextureCoord; - - uniform mat4 uMVMatrix; - uniform mat4 uPMatrix; - - varying mediump vec4 vColor; - varying highp vec2 vTextureCoord; - varying highp vec4 vPos; - - void main(void) { - vPos = uPMatrix * uMVMatrix * vec4(aVertexPosition, 1.0); - gl_Position = uPMatrix * uMVMatrix * vec4(aVertexPosition, 1.0); - vColor = aVertexColor; - vTextureCoord = aTextureCoord; + var vertexShader = getShader(gl, + "attribute highp vec3 aVertexPosition; \ + attribute mediump vec4 aVertexColor; \ + attribute highp vec2 aTextureCoord; \ + \ + uniform mat4 uMVMatrix; \ + uniform mat4 uPMatrix; \ + \ + varying mediump vec4 vColor; \ + varying highp vec2 vTextureCoord; \ + varying highp vec4 vPos; \ + \ + void main(void) { \ + vPos = uPMatrix * uMVMatrix * vec4(aVertexPosition, 1.0); \ + gl_Position = uPMatrix * uMVMatrix * vec4(aVertexPosition, 1.0); \ + vColor = aVertexColor; \ + vTextureCoord = aTextureCoord; \ }", gl.VERTEX_SHADER); - var fragmentShader = getShader(gl," - varying mediump vec4 vColor; - varying highp vec2 vTextureCoord; - varying highp vec4 vPos; - - uniform sampler2D uSampler; - - void main(void) { - gl_FragColor = vColor * texture2D(uSampler, vec2(vTextureCoord.s, vTextureCoord.t)); + var fragmentShader = getShader(gl, + "varying mediump vec4 vColor; \ + varying highp vec2 vTextureCoord; \ + varying highp vec4 vPos; \ + \ + uniform sampler2D uSampler; \ + \ + void main(void) { \ + gl_FragColor = vColor * texture2D(uSampler, vec2(vTextureCoord.s, vTextureCoord.t)); \ }", gl.FRAGMENT_SHADER); var shaderProgram = gl.createProgram();