Commit c769a391 authored by Tomi Korpipää's avatar Tomi Korpipää Committed by Pasi Keränen
Browse files

Use proper multiline strings for shader strings


Added to the rest of the examples. Causes crashing on Qt5.4 Beta without
them.

Change-Id: I7b060ccdfd5458057dd3053ca40d8569aef89dd2
Reviewed-by: default avatarPasi Keränen <pasi.keranen@digia.com>
Showing with 73 additions and 73 deletions
...@@ -162,17 +162,17 @@ function initShaders() { ...@@ -162,17 +162,17 @@ function initShaders() {
log(" Initializing shaders..."); log(" Initializing shaders...");
vertexShader = getShader(gl, "attribute highp vec3 aVertexPosition; \ vertexShader = getShader(gl, "attribute highp vec3 aVertexPosition; \
attribute highp vec4 aVertexColor; \ attribute highp vec4 aVertexColor; \
uniform highp mat4 uMVMatrix; \ uniform highp mat4 uMVMatrix; \
uniform highp mat4 uPMatrix; \ uniform highp mat4 uPMatrix; \
varying highp vec4 vColor; \ varying highp vec4 vColor; \
void main(void) { \ void main(void) { \
gl_Position = uPMatrix * uMVMatrix * vec4(aVertexPosition, 1.0); \ gl_Position = uPMatrix * uMVMatrix * vec4(aVertexPosition, 1.0); \
vColor = aVertexColor; \ vColor = aVertexColor; \
}", gl.VERTEX_SHADER); }", gl.VERTEX_SHADER);
fragmentShader = getShader(gl, "varying highp vec4 vColor; \ fragmentShader = getShader(gl, "varying highp vec4 vColor; \
void main(void) { \ void main(void) { \
gl_FragColor = vColor; \ gl_FragColor = vColor; \
}", gl.FRAGMENT_SHADER); }", gl.FRAGMENT_SHADER);
shaderProgram = gl.createProgram(); shaderProgram = gl.createProgram();
......
...@@ -73,12 +73,12 @@ function renderGL(canvas) { ...@@ -73,12 +73,12 @@ function renderGL(canvas) {
function initShaders() function initShaders()
{ {
// setup a GLSL program // setup a GLSL program
vertexShader = compileShader("attribute vec2 a_position; \ vertexShader = compileShader("attribute vec2 a_position; \
void main() { \ void main() { \
gl_Position = vec4(a_position, 0.0, 1.0); \ gl_Position = vec4(a_position, 0.0, 1.0); \
}", gl.VERTEX_SHADER); }", gl.VERTEX_SHADER);
fragmentShader = compileShader("void main() { \ fragmentShader = compileShader("void main() { \
gl_FragColor = vec4(0.0, 0.0, 1.0, 1.0); \ gl_FragColor = vec4(0.0, 0.0, 1.0, 1.0); \
}", gl.FRAGMENT_SHADER); }", gl.FRAGMENT_SHADER);
shaderProgram = gl.createProgram(); shaderProgram = gl.createProgram();
......
...@@ -374,41 +374,41 @@ function initBuffers() ...@@ -374,41 +374,41 @@ function initBuffers()
function initShaders() function initShaders()
{ {
var vertexShader = getShader(gl, var vertexShader = getShader(gl,
"attribute highp vec3 aVertexNormal; "attribute highp vec3 aVertexNormal; \
attribute highp vec3 aVertexPosition; attribute highp vec3 aVertexPosition; \
attribute mediump vec4 aVertexColor; attribute mediump vec4 aVertexColor; \
attribute highp vec2 aTextureCoord; attribute highp vec2 aTextureCoord; \
uniform highp mat4 uNormalMatrix; uniform highp mat4 uNormalMatrix; \
uniform mat4 uMVMatrix; uniform mat4 uMVMatrix; \
uniform mat4 uPMatrix; uniform mat4 uPMatrix; \
varying mediump vec4 vColor; varying mediump vec4 vColor; \
varying highp vec2 vTextureCoord; varying highp vec2 vTextureCoord; \
varying highp vec3 vLighting; varying highp vec3 vLighting; \
void main(void) { void main(void) { \
gl_Position = uPMatrix * uMVMatrix * vec4(aVertexPosition, 1.0); gl_Position = uPMatrix * uMVMatrix * vec4(aVertexPosition, 1.0); \
vColor = aVertexColor; vColor = aVertexColor; \
vTextureCoord = aTextureCoord; vTextureCoord = aTextureCoord; \
highp vec3 ambientLight = vec3(0.5, 0.5, 0.5); highp vec3 ambientLight = vec3(0.5, 0.5, 0.5); \
highp vec3 directionalLightColor = vec3(0.75, 0.75, 0.75); highp vec3 directionalLightColor = vec3(0.75, 0.5, 0.75); \
highp vec3 directionalVector = vec3(0.85, 0.8, 0.75); highp vec3 directionalVector = vec3(0.85, 0.8, 0.75); \
highp vec4 transformedNormal = uNormalMatrix * vec4(aVertexNormal, 1.0); highp vec4 transformedNormal = uNormalMatrix * vec4(aVertexNormal, 1.0); \
highp float directional = max(dot(transformedNormal.xyz, directionalVector), 0.0); highp float directional = max(dot(transformedNormal.xyz, directionalVector), 0.0); \
vLighting = ambientLight + (directionalLightColor * directional); vLighting = ambientLight + (directionalLightColor * directional); \
}", gl.VERTEX_SHADER); }", gl.VERTEX_SHADER);
var fragmentShader = getShader(gl, var fragmentShader = getShader(gl,
"varying mediump vec4 vColor; "varying mediump vec4 vColor; \
varying highp vec2 vTextureCoord; varying highp vec2 vTextureCoord; \
varying highp vec3 vLighting; varying highp vec3 vLighting; \
uniform sampler2D uSampler; uniform sampler2D uSampler; \
void main(void) { void main(void) { \
mediump vec4 texelColor = texture2D(uSampler, vec2(vTextureCoord.s, vTextureCoord.t)); mediump vec4 texelColor = texture2D(uSampler, vec2(vTextureCoord.s, vTextureCoord.t)); \
mediump vec3 blendColor = mix(vColor.rgb, texelColor.rgb, texelColor.a); mediump vec3 blendColor = mix(vColor.rgb, texelColor.rgb, texelColor.a); \
gl_FragColor = vec4(blendColor * vLighting, 1.0); gl_FragColor = vec4(blendColor * vLighting, 1.0); \
}", gl.FRAGMENT_SHADER); }", gl.FRAGMENT_SHADER);
var shaderProgram = gl.createProgram(); var shaderProgram = gl.createProgram();
......
...@@ -654,39 +654,39 @@ function initShaders() ...@@ -654,39 +654,39 @@ function initShaders()
log(" initShaders...") log(" initShaders...")
vertexShader = getShader(gl, vertexShader = getShader(gl,
"attribute highp vec3 aVertexNormal; "attribute highp vec3 aVertexNormal; \
attribute highp vec3 aVertexPosition; attribute highp vec3 aVertexPosition; \
attribute highp vec2 aTextureCoord; attribute highp vec2 aTextureCoord; \
uniform highp mat4 uNormalMatrix; uniform highp mat4 uNormalMatrix; \
uniform mat4 uMVMatrix; uniform mat4 uMVMatrix; \
uniform mat4 uPMatrix; uniform mat4 uPMatrix; \
uniform vec3 eyePos; uniform vec3 eyePos; \
varying highp vec2 vTextureCoord; varying highp vec2 vTextureCoord; \
varying highp vec4 vLighting; varying highp vec4 vLighting; \
void main(void) { void main(void) { \
gl_Position = uPMatrix * uMVMatrix * vec4(aVertexPosition, 1.0); gl_Position = uPMatrix * uMVMatrix * vec4(aVertexPosition, 1.0); \
vTextureCoord = aTextureCoord; vTextureCoord = aTextureCoord; \
highp vec4 ambientLight = vec4(0.5, 0.5, 0.5, 1.0); highp vec4 ambientLight = vec4(0.5, 0.5, 0.5, 1.0); \
highp vec4 directionalLightColor = vec4(1.0, 1.0, 1.0, 1.0); highp vec4 directionalLightColor = vec4(1.0, 1.0, 1.0, 1.0); \
highp vec3 directionalVector = eyePos; highp vec3 directionalVector = eyePos; \
highp vec4 transformedNormal = uNormalMatrix * vec4(aVertexNormal, 1.0); highp vec4 transformedNormal = uNormalMatrix * vec4(aVertexNormal, 1.0); \
highp float directional = max(dot(transformedNormal.xyz, directionalVector), 0.0); highp float directional = max(dot(transformedNormal.xyz, directionalVector), 0.0); \
vLighting = ambientLight + (directionalLightColor * directional); vLighting = ambientLight + (directionalLightColor * directional); \
}", gl.VERTEX_SHADER); }", gl.VERTEX_SHADER);
fragmentShader = getShader(gl, fragmentShader = getShader(gl,
"varying highp vec2 vTextureCoord; "varying highp vec2 vTextureCoord; \
varying highp vec4 vLighting; varying highp vec4 vLighting; \
uniform sampler2D uSampler; uniform sampler2D uSampler; \
void main(void) { void main(void) { \
mediump vec4 texelColor = texture2D(uSampler, vTextureCoord); mediump vec4 texelColor = texture2D(uSampler, vTextureCoord); \
gl_FragColor = vec4(texelColor * vLighting); gl_FragColor = vec4(texelColor * vLighting); \
}", gl.FRAGMENT_SHADER); }", gl.FRAGMENT_SHADER);
texturedShaderProgram = gl.createProgram(); texturedShaderProgram = gl.createProgram();
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment