Have compile error while importing shader from file. THREE.js + Vue.js + WebPack
Have error, searched for solution many hours, but found nothing(
Import shader code from file this way:
import {ColourShader} from '../shaders/ColourShader.js'
Here is my 'ColourShader.js' code:
export var ColourShader = {
vertexShader: [
'void main() {',
'gl_Position = vec4( position, 1.0 );',
'}'].join(),
fragmentShader: [
'uniform vec2 u_resolution;',
'uniform float u_time;',
'const int octaves = 6;',
'const float seed = 43758.5453123;',
'const float seed2 = 73156.8473192;',
'vec2 random2(vec2 st, float seed){',
'st = vec2( dot(st,vec2(127.1,311.7)),',
'dot(st,vec2(269.5,183.3)) );',
'return -1.0 + 2.0*fract(sin(st)*seed);',
'}',
'float noise(vec2 st, float seed) {',
'vec2 i = floor(st);',
'vec2 f = fract(st);',
'vec2 u = f*f*(3.0-2.0*f);',
'return mix( mix( dot( random2(i + vec2(0.0,0.0), seed ), f - vec2(0.0,0.0) ),' ,
'dot( random2(i + vec2(1.0,0.0), seed ), f - vec2(1.0,0.0) ), u.x),',
'mix( dot( random2(i + vec2(0.0,1.0), seed ), f - vec2(0.0,1.0) ),' ,
'dot( random2(i + vec2(1.0,1.0), seed ), f - vec2(1.0,1.0) ), u.x), u.y);',
'}',
'float fbm1(in vec2 _st, float seed) {',
'float v = 0.0;',
'float a = 0.5;',
'vec2 shift = vec2(100.0);',
'mat2 rot = mat2(cos(0.5), sin(0.5), -sin(0.5), cos(0.50));',
'for (int i = 0; i < octaves; ++i) {',
'v += a * noise(_st, seed);',
'_st = rot * _st * 2.0 + shift;',
'a *= 0.4;',
'}',
'return v;',
'}',
'float pattern(vec2 uv, float seed, float time, inout vec2 q, inout vec2 r) {',
'q = vec2( fbm1( uv + vec2(0.0,0.0), seed ), fbm1( uv + vec2(5.2,1.3), seed ) );',
'r = vec2( fbm1( uv + 4.0*q + vec2(1.7 - time / 2.,9.2), seed ), fbm1( uv + 4.0*q + vec2(8.3 - time / 2.,2.8), seed ) );',
'vec2 s = vec2( fbm1( uv + 4.0*r + vec2(21.7 - time / 2.,90.2), seed ), fbm1( uv + 4.0*r + vec2(80.3 - time / 2.,20.8), seed ) );',
'vec2 t = vec2( fbm1( uv + 4.0*s + vec2(121.7 - time / 2.,90.2), seed ), fbm1( uv + 4.0*s + vec2(180.3 - time / 2.,20.8), seed ) );',
'float rtn = fbm1( uv + 4.0*t, seed );',
' rtn = clamp(rtn, 0., .5);' ,
'return rtn;',
'}',
'void main() {',
'vec2 uv = (gl_FragCoord.xy - 0.5 * u_resolution.xy) / u_resolution.y;',
'uv *= 1. + dot(uv, uv)*.3;',
'float time = u_time / 20.;',
'mat2 rot = mat2(cos(time), sin(time), -sin(time), cos(time));',
'uv = rot * uv;',
'uv *= 1.4 + sin(time) * .3;',
'uv.x -= time;',
'vec2 q = vec2(0.,0.);',
'vec2 r = vec2(0.,0.);',
'vec3 colour = vec3(pattern(uv, seed, time, q, r));',
'float QR = clamp(dot(q, r), -1., 1.);',
'colour += vec3(',
'(q.x + q.y) + QR * 30.,',
'QR * 15.',
'r.x * r.y + QR * 5.',
');',
'colour += .1;',
'colour = clamp(colour, 0.05, 1.);',
'gl_FragColor = vec4(colour + (abs(colour) * .1), 1.);',
'}'].join('n')}
So, when I use this shader importing it via tag it works right, but if I try to import this shader into my Vue.js single file component that occurs many errors, such
THREE.WebGLShader: Shader couldn't compile.
THREE.WebGLProgram: shader error: 0 35715 false gl.getProgramInfoLog invalid shaders
javascript vue.js three.js webgl shader
add a comment |
Have error, searched for solution many hours, but found nothing(
Import shader code from file this way:
import {ColourShader} from '../shaders/ColourShader.js'
Here is my 'ColourShader.js' code:
export var ColourShader = {
vertexShader: [
'void main() {',
'gl_Position = vec4( position, 1.0 );',
'}'].join(),
fragmentShader: [
'uniform vec2 u_resolution;',
'uniform float u_time;',
'const int octaves = 6;',
'const float seed = 43758.5453123;',
'const float seed2 = 73156.8473192;',
'vec2 random2(vec2 st, float seed){',
'st = vec2( dot(st,vec2(127.1,311.7)),',
'dot(st,vec2(269.5,183.3)) );',
'return -1.0 + 2.0*fract(sin(st)*seed);',
'}',
'float noise(vec2 st, float seed) {',
'vec2 i = floor(st);',
'vec2 f = fract(st);',
'vec2 u = f*f*(3.0-2.0*f);',
'return mix( mix( dot( random2(i + vec2(0.0,0.0), seed ), f - vec2(0.0,0.0) ),' ,
'dot( random2(i + vec2(1.0,0.0), seed ), f - vec2(1.0,0.0) ), u.x),',
'mix( dot( random2(i + vec2(0.0,1.0), seed ), f - vec2(0.0,1.0) ),' ,
'dot( random2(i + vec2(1.0,1.0), seed ), f - vec2(1.0,1.0) ), u.x), u.y);',
'}',
'float fbm1(in vec2 _st, float seed) {',
'float v = 0.0;',
'float a = 0.5;',
'vec2 shift = vec2(100.0);',
'mat2 rot = mat2(cos(0.5), sin(0.5), -sin(0.5), cos(0.50));',
'for (int i = 0; i < octaves; ++i) {',
'v += a * noise(_st, seed);',
'_st = rot * _st * 2.0 + shift;',
'a *= 0.4;',
'}',
'return v;',
'}',
'float pattern(vec2 uv, float seed, float time, inout vec2 q, inout vec2 r) {',
'q = vec2( fbm1( uv + vec2(0.0,0.0), seed ), fbm1( uv + vec2(5.2,1.3), seed ) );',
'r = vec2( fbm1( uv + 4.0*q + vec2(1.7 - time / 2.,9.2), seed ), fbm1( uv + 4.0*q + vec2(8.3 - time / 2.,2.8), seed ) );',
'vec2 s = vec2( fbm1( uv + 4.0*r + vec2(21.7 - time / 2.,90.2), seed ), fbm1( uv + 4.0*r + vec2(80.3 - time / 2.,20.8), seed ) );',
'vec2 t = vec2( fbm1( uv + 4.0*s + vec2(121.7 - time / 2.,90.2), seed ), fbm1( uv + 4.0*s + vec2(180.3 - time / 2.,20.8), seed ) );',
'float rtn = fbm1( uv + 4.0*t, seed );',
' rtn = clamp(rtn, 0., .5);' ,
'return rtn;',
'}',
'void main() {',
'vec2 uv = (gl_FragCoord.xy - 0.5 * u_resolution.xy) / u_resolution.y;',
'uv *= 1. + dot(uv, uv)*.3;',
'float time = u_time / 20.;',
'mat2 rot = mat2(cos(time), sin(time), -sin(time), cos(time));',
'uv = rot * uv;',
'uv *= 1.4 + sin(time) * .3;',
'uv.x -= time;',
'vec2 q = vec2(0.,0.);',
'vec2 r = vec2(0.,0.);',
'vec3 colour = vec3(pattern(uv, seed, time, q, r));',
'float QR = clamp(dot(q, r), -1., 1.);',
'colour += vec3(',
'(q.x + q.y) + QR * 30.,',
'QR * 15.',
'r.x * r.y + QR * 5.',
');',
'colour += .1;',
'colour = clamp(colour, 0.05, 1.);',
'gl_FragColor = vec4(colour + (abs(colour) * .1), 1.);',
'}'].join('n')}
So, when I use this shader importing it via tag it works right, but if I try to import this shader into my Vue.js single file component that occurs many errors, such
THREE.WebGLShader: Shader couldn't compile.
THREE.WebGLProgram: shader error: 0 35715 false gl.getProgramInfoLog invalid shaders
javascript vue.js three.js webgl shader
1
And i use shader code after import this way: ColourShader.fragmentShader or ColourShader.vertexShader
– Александр Николаев
Nov 21 at 0:33
2
Might be easier for you to figure out if you switched to using multiline template literals instead of concatenated arrays of strings. In other words remove all the quotes and commas and[and]and.join()and just use backticks
– gman
Nov 21 at 8:34
It'd be nice if you showed us how you actually made yourShaderMaterial
– pailhead
Nov 21 at 20:42
add a comment |
Have error, searched for solution many hours, but found nothing(
Import shader code from file this way:
import {ColourShader} from '../shaders/ColourShader.js'
Here is my 'ColourShader.js' code:
export var ColourShader = {
vertexShader: [
'void main() {',
'gl_Position = vec4( position, 1.0 );',
'}'].join(),
fragmentShader: [
'uniform vec2 u_resolution;',
'uniform float u_time;',
'const int octaves = 6;',
'const float seed = 43758.5453123;',
'const float seed2 = 73156.8473192;',
'vec2 random2(vec2 st, float seed){',
'st = vec2( dot(st,vec2(127.1,311.7)),',
'dot(st,vec2(269.5,183.3)) );',
'return -1.0 + 2.0*fract(sin(st)*seed);',
'}',
'float noise(vec2 st, float seed) {',
'vec2 i = floor(st);',
'vec2 f = fract(st);',
'vec2 u = f*f*(3.0-2.0*f);',
'return mix( mix( dot( random2(i + vec2(0.0,0.0), seed ), f - vec2(0.0,0.0) ),' ,
'dot( random2(i + vec2(1.0,0.0), seed ), f - vec2(1.0,0.0) ), u.x),',
'mix( dot( random2(i + vec2(0.0,1.0), seed ), f - vec2(0.0,1.0) ),' ,
'dot( random2(i + vec2(1.0,1.0), seed ), f - vec2(1.0,1.0) ), u.x), u.y);',
'}',
'float fbm1(in vec2 _st, float seed) {',
'float v = 0.0;',
'float a = 0.5;',
'vec2 shift = vec2(100.0);',
'mat2 rot = mat2(cos(0.5), sin(0.5), -sin(0.5), cos(0.50));',
'for (int i = 0; i < octaves; ++i) {',
'v += a * noise(_st, seed);',
'_st = rot * _st * 2.0 + shift;',
'a *= 0.4;',
'}',
'return v;',
'}',
'float pattern(vec2 uv, float seed, float time, inout vec2 q, inout vec2 r) {',
'q = vec2( fbm1( uv + vec2(0.0,0.0), seed ), fbm1( uv + vec2(5.2,1.3), seed ) );',
'r = vec2( fbm1( uv + 4.0*q + vec2(1.7 - time / 2.,9.2), seed ), fbm1( uv + 4.0*q + vec2(8.3 - time / 2.,2.8), seed ) );',
'vec2 s = vec2( fbm1( uv + 4.0*r + vec2(21.7 - time / 2.,90.2), seed ), fbm1( uv + 4.0*r + vec2(80.3 - time / 2.,20.8), seed ) );',
'vec2 t = vec2( fbm1( uv + 4.0*s + vec2(121.7 - time / 2.,90.2), seed ), fbm1( uv + 4.0*s + vec2(180.3 - time / 2.,20.8), seed ) );',
'float rtn = fbm1( uv + 4.0*t, seed );',
' rtn = clamp(rtn, 0., .5);' ,
'return rtn;',
'}',
'void main() {',
'vec2 uv = (gl_FragCoord.xy - 0.5 * u_resolution.xy) / u_resolution.y;',
'uv *= 1. + dot(uv, uv)*.3;',
'float time = u_time / 20.;',
'mat2 rot = mat2(cos(time), sin(time), -sin(time), cos(time));',
'uv = rot * uv;',
'uv *= 1.4 + sin(time) * .3;',
'uv.x -= time;',
'vec2 q = vec2(0.,0.);',
'vec2 r = vec2(0.,0.);',
'vec3 colour = vec3(pattern(uv, seed, time, q, r));',
'float QR = clamp(dot(q, r), -1., 1.);',
'colour += vec3(',
'(q.x + q.y) + QR * 30.,',
'QR * 15.',
'r.x * r.y + QR * 5.',
');',
'colour += .1;',
'colour = clamp(colour, 0.05, 1.);',
'gl_FragColor = vec4(colour + (abs(colour) * .1), 1.);',
'}'].join('n')}
So, when I use this shader importing it via tag it works right, but if I try to import this shader into my Vue.js single file component that occurs many errors, such
THREE.WebGLShader: Shader couldn't compile.
THREE.WebGLProgram: shader error: 0 35715 false gl.getProgramInfoLog invalid shaders
javascript vue.js three.js webgl shader
Have error, searched for solution many hours, but found nothing(
Import shader code from file this way:
import {ColourShader} from '../shaders/ColourShader.js'
Here is my 'ColourShader.js' code:
export var ColourShader = {
vertexShader: [
'void main() {',
'gl_Position = vec4( position, 1.0 );',
'}'].join(),
fragmentShader: [
'uniform vec2 u_resolution;',
'uniform float u_time;',
'const int octaves = 6;',
'const float seed = 43758.5453123;',
'const float seed2 = 73156.8473192;',
'vec2 random2(vec2 st, float seed){',
'st = vec2( dot(st,vec2(127.1,311.7)),',
'dot(st,vec2(269.5,183.3)) );',
'return -1.0 + 2.0*fract(sin(st)*seed);',
'}',
'float noise(vec2 st, float seed) {',
'vec2 i = floor(st);',
'vec2 f = fract(st);',
'vec2 u = f*f*(3.0-2.0*f);',
'return mix( mix( dot( random2(i + vec2(0.0,0.0), seed ), f - vec2(0.0,0.0) ),' ,
'dot( random2(i + vec2(1.0,0.0), seed ), f - vec2(1.0,0.0) ), u.x),',
'mix( dot( random2(i + vec2(0.0,1.0), seed ), f - vec2(0.0,1.0) ),' ,
'dot( random2(i + vec2(1.0,1.0), seed ), f - vec2(1.0,1.0) ), u.x), u.y);',
'}',
'float fbm1(in vec2 _st, float seed) {',
'float v = 0.0;',
'float a = 0.5;',
'vec2 shift = vec2(100.0);',
'mat2 rot = mat2(cos(0.5), sin(0.5), -sin(0.5), cos(0.50));',
'for (int i = 0; i < octaves; ++i) {',
'v += a * noise(_st, seed);',
'_st = rot * _st * 2.0 + shift;',
'a *= 0.4;',
'}',
'return v;',
'}',
'float pattern(vec2 uv, float seed, float time, inout vec2 q, inout vec2 r) {',
'q = vec2( fbm1( uv + vec2(0.0,0.0), seed ), fbm1( uv + vec2(5.2,1.3), seed ) );',
'r = vec2( fbm1( uv + 4.0*q + vec2(1.7 - time / 2.,9.2), seed ), fbm1( uv + 4.0*q + vec2(8.3 - time / 2.,2.8), seed ) );',
'vec2 s = vec2( fbm1( uv + 4.0*r + vec2(21.7 - time / 2.,90.2), seed ), fbm1( uv + 4.0*r + vec2(80.3 - time / 2.,20.8), seed ) );',
'vec2 t = vec2( fbm1( uv + 4.0*s + vec2(121.7 - time / 2.,90.2), seed ), fbm1( uv + 4.0*s + vec2(180.3 - time / 2.,20.8), seed ) );',
'float rtn = fbm1( uv + 4.0*t, seed );',
' rtn = clamp(rtn, 0., .5);' ,
'return rtn;',
'}',
'void main() {',
'vec2 uv = (gl_FragCoord.xy - 0.5 * u_resolution.xy) / u_resolution.y;',
'uv *= 1. + dot(uv, uv)*.3;',
'float time = u_time / 20.;',
'mat2 rot = mat2(cos(time), sin(time), -sin(time), cos(time));',
'uv = rot * uv;',
'uv *= 1.4 + sin(time) * .3;',
'uv.x -= time;',
'vec2 q = vec2(0.,0.);',
'vec2 r = vec2(0.,0.);',
'vec3 colour = vec3(pattern(uv, seed, time, q, r));',
'float QR = clamp(dot(q, r), -1., 1.);',
'colour += vec3(',
'(q.x + q.y) + QR * 30.,',
'QR * 15.',
'r.x * r.y + QR * 5.',
');',
'colour += .1;',
'colour = clamp(colour, 0.05, 1.);',
'gl_FragColor = vec4(colour + (abs(colour) * .1), 1.);',
'}'].join('n')}
So, when I use this shader importing it via tag it works right, but if I try to import this shader into my Vue.js single file component that occurs many errors, such
THREE.WebGLShader: Shader couldn't compile.
THREE.WebGLProgram: shader error: 0 35715 false gl.getProgramInfoLog invalid shaders
javascript vue.js three.js webgl shader
javascript vue.js three.js webgl shader
asked Nov 21 at 0:30
Александр Николаев
33
33
1
And i use shader code after import this way: ColourShader.fragmentShader or ColourShader.vertexShader
– Александр Николаев
Nov 21 at 0:33
2
Might be easier for you to figure out if you switched to using multiline template literals instead of concatenated arrays of strings. In other words remove all the quotes and commas and[and]and.join()and just use backticks
– gman
Nov 21 at 8:34
It'd be nice if you showed us how you actually made yourShaderMaterial
– pailhead
Nov 21 at 20:42
add a comment |
1
And i use shader code after import this way: ColourShader.fragmentShader or ColourShader.vertexShader
– Александр Николаев
Nov 21 at 0:33
2
Might be easier for you to figure out if you switched to using multiline template literals instead of concatenated arrays of strings. In other words remove all the quotes and commas and[and]and.join()and just use backticks
– gman
Nov 21 at 8:34
It'd be nice if you showed us how you actually made yourShaderMaterial
– pailhead
Nov 21 at 20:42
1
1
And i use shader code after import this way: ColourShader.fragmentShader or ColourShader.vertexShader
– Александр Николаев
Nov 21 at 0:33
And i use shader code after import this way: ColourShader.fragmentShader or ColourShader.vertexShader
– Александр Николаев
Nov 21 at 0:33
2
2
Might be easier for you to figure out if you switched to using multiline template literals instead of concatenated arrays of strings. In other words remove all the quotes and commas and
[ and ] and .join() and just use backticks– gman
Nov 21 at 8:34
Might be easier for you to figure out if you switched to using multiline template literals instead of concatenated arrays of strings. In other words remove all the quotes and commas and
[ and ] and .join() and just use backticks– gman
Nov 21 at 8:34
It'd be nice if you showed us how you actually made your
ShaderMaterial– pailhead
Nov 21 at 20:42
It'd be nice if you showed us how you actually made your
ShaderMaterial– pailhead
Nov 21 at 20:42
add a comment |
1 Answer
1
active
oldest
votes
Your problem lies in your obfuscation from clarity, and this happened:
'colour += vec3(',
'(q.x + q.y) + QR * 30.,',
'QR * 15.', //// <------ Missing comma here
'r.x * r.y + QR * 5.',
');',
Using template literals would make your life easier, example with corrected code:
let fragmentShader = `
uniform vec2 u_resolution;
uniform float u_time;
const int octaves = 6;
const float seed = 43758.5453123;
const float seed2 = 73156.8473192;
vec2 random2(vec2 st, float seed){
st = vec2( dot(st,vec2(127.1,311.7)), dot(st,vec2(269.5,183.3)) );
return -1.0 + 2.0*fract(sin(st)*seed);
}
float noise(vec2 st, float seed) {
vec2 i = floor(st);
vec2 f = fract(st);
vec2 u = f*f*(3.0-2.0*f);
return mix( mix( dot( random2(i + vec2(0.0,0.0), seed ), f - vec2(0.0,0.0) ),
dot( random2(i + vec2(1.0,0.0), seed ), f - vec2(1.0,0.0) ), u.x),
mix( dot( random2(i + vec2(0.0,1.0), seed ), f - vec2(0.0,1.0) ),
dot( random2(i + vec2(1.0,1.0), seed ), f - vec2(1.0,1.0) ), u.x), u.y);
}
float fbm1(in vec2 _st, float seed) {
float v = 0.0;
float a = 0.5;
vec2 shift = vec2(100.0);
mat2 rot = mat2(cos(0.5), sin(0.5), -sin(0.5), cos(0.50));
for (int i = 0; i < octaves; ++i) {
v += a * noise(_st, seed);
_st = rot * _st * 2.0 + shift;
a *= 0.4;
}
return v;
}
float pattern(vec2 uv, float seed, float time, inout vec2 q, inout vec2 r) {
q = vec2( fbm1( uv + vec2(0.0,0.0), seed ), fbm1( uv + vec2(5.2,1.3), seed ) );
r = vec2( fbm1( uv + 4.0*q + vec2(1.7 - time / 2.,9.2), seed ), fbm1( uv + 4.0*q + vec2(8.3 - time / 2.,2.8), seed ) );
vec2 s = vec2( fbm1( uv + 4.0*r + vec2(21.7 - time / 2.,90.2), seed ), fbm1( uv + 4.0*r + vec2(80.3 - time / 2.,20.8), seed ) );
vec2 t = vec2( fbm1( uv + 4.0*s + vec2(121.7 - time / 2.,90.2), seed ), fbm1( uv + 4.0*s + vec2(180.3 - time / 2.,20.8), seed ) );
float rtn = fbm1( uv + 4.0*t, seed );
rtn = clamp(rtn, 0., .5);
return rtn;
}
void main() {
vec2 uv = (gl_FragCoord.xy - 0.5 * u_resolution.xy) / u_resolution.y;
uv *= 1. + dot(uv, uv)*.3;
float time = u_time / 20.;
mat2 rot = mat2(cos(time), sin(time), -sin(time), cos(time));
uv = rot * uv;
uv *= 1.4 + sin(time) * .3;
uv.x -= time;
vec2 q = vec2(0.,0.);
vec2 r = vec2(0.,0.);
vec3 colour = vec3(pattern(uv, seed, time, q, r));
float QR = clamp(dot(q, r), -1., 1.);
colour += vec3((q.x + q.y) + QR * 30.,
QR * 15.,
r.x * r.y + QR * 5.
);
colour += .1;
colour = clamp(colour, 0.05, 1.);
gl_FragColor = vec4(colour + (abs(colour) * .1), 1.);
}
`
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53403654%2fhave-compile-error-while-importing-shader-from-file-three-js-vue-js-webpack%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Your problem lies in your obfuscation from clarity, and this happened:
'colour += vec3(',
'(q.x + q.y) + QR * 30.,',
'QR * 15.', //// <------ Missing comma here
'r.x * r.y + QR * 5.',
');',
Using template literals would make your life easier, example with corrected code:
let fragmentShader = `
uniform vec2 u_resolution;
uniform float u_time;
const int octaves = 6;
const float seed = 43758.5453123;
const float seed2 = 73156.8473192;
vec2 random2(vec2 st, float seed){
st = vec2( dot(st,vec2(127.1,311.7)), dot(st,vec2(269.5,183.3)) );
return -1.0 + 2.0*fract(sin(st)*seed);
}
float noise(vec2 st, float seed) {
vec2 i = floor(st);
vec2 f = fract(st);
vec2 u = f*f*(3.0-2.0*f);
return mix( mix( dot( random2(i + vec2(0.0,0.0), seed ), f - vec2(0.0,0.0) ),
dot( random2(i + vec2(1.0,0.0), seed ), f - vec2(1.0,0.0) ), u.x),
mix( dot( random2(i + vec2(0.0,1.0), seed ), f - vec2(0.0,1.0) ),
dot( random2(i + vec2(1.0,1.0), seed ), f - vec2(1.0,1.0) ), u.x), u.y);
}
float fbm1(in vec2 _st, float seed) {
float v = 0.0;
float a = 0.5;
vec2 shift = vec2(100.0);
mat2 rot = mat2(cos(0.5), sin(0.5), -sin(0.5), cos(0.50));
for (int i = 0; i < octaves; ++i) {
v += a * noise(_st, seed);
_st = rot * _st * 2.0 + shift;
a *= 0.4;
}
return v;
}
float pattern(vec2 uv, float seed, float time, inout vec2 q, inout vec2 r) {
q = vec2( fbm1( uv + vec2(0.0,0.0), seed ), fbm1( uv + vec2(5.2,1.3), seed ) );
r = vec2( fbm1( uv + 4.0*q + vec2(1.7 - time / 2.,9.2), seed ), fbm1( uv + 4.0*q + vec2(8.3 - time / 2.,2.8), seed ) );
vec2 s = vec2( fbm1( uv + 4.0*r + vec2(21.7 - time / 2.,90.2), seed ), fbm1( uv + 4.0*r + vec2(80.3 - time / 2.,20.8), seed ) );
vec2 t = vec2( fbm1( uv + 4.0*s + vec2(121.7 - time / 2.,90.2), seed ), fbm1( uv + 4.0*s + vec2(180.3 - time / 2.,20.8), seed ) );
float rtn = fbm1( uv + 4.0*t, seed );
rtn = clamp(rtn, 0., .5);
return rtn;
}
void main() {
vec2 uv = (gl_FragCoord.xy - 0.5 * u_resolution.xy) / u_resolution.y;
uv *= 1. + dot(uv, uv)*.3;
float time = u_time / 20.;
mat2 rot = mat2(cos(time), sin(time), -sin(time), cos(time));
uv = rot * uv;
uv *= 1.4 + sin(time) * .3;
uv.x -= time;
vec2 q = vec2(0.,0.);
vec2 r = vec2(0.,0.);
vec3 colour = vec3(pattern(uv, seed, time, q, r));
float QR = clamp(dot(q, r), -1., 1.);
colour += vec3((q.x + q.y) + QR * 30.,
QR * 15.,
r.x * r.y + QR * 5.
);
colour += .1;
colour = clamp(colour, 0.05, 1.);
gl_FragColor = vec4(colour + (abs(colour) * .1), 1.);
}
`
add a comment |
Your problem lies in your obfuscation from clarity, and this happened:
'colour += vec3(',
'(q.x + q.y) + QR * 30.,',
'QR * 15.', //// <------ Missing comma here
'r.x * r.y + QR * 5.',
');',
Using template literals would make your life easier, example with corrected code:
let fragmentShader = `
uniform vec2 u_resolution;
uniform float u_time;
const int octaves = 6;
const float seed = 43758.5453123;
const float seed2 = 73156.8473192;
vec2 random2(vec2 st, float seed){
st = vec2( dot(st,vec2(127.1,311.7)), dot(st,vec2(269.5,183.3)) );
return -1.0 + 2.0*fract(sin(st)*seed);
}
float noise(vec2 st, float seed) {
vec2 i = floor(st);
vec2 f = fract(st);
vec2 u = f*f*(3.0-2.0*f);
return mix( mix( dot( random2(i + vec2(0.0,0.0), seed ), f - vec2(0.0,0.0) ),
dot( random2(i + vec2(1.0,0.0), seed ), f - vec2(1.0,0.0) ), u.x),
mix( dot( random2(i + vec2(0.0,1.0), seed ), f - vec2(0.0,1.0) ),
dot( random2(i + vec2(1.0,1.0), seed ), f - vec2(1.0,1.0) ), u.x), u.y);
}
float fbm1(in vec2 _st, float seed) {
float v = 0.0;
float a = 0.5;
vec2 shift = vec2(100.0);
mat2 rot = mat2(cos(0.5), sin(0.5), -sin(0.5), cos(0.50));
for (int i = 0; i < octaves; ++i) {
v += a * noise(_st, seed);
_st = rot * _st * 2.0 + shift;
a *= 0.4;
}
return v;
}
float pattern(vec2 uv, float seed, float time, inout vec2 q, inout vec2 r) {
q = vec2( fbm1( uv + vec2(0.0,0.0), seed ), fbm1( uv + vec2(5.2,1.3), seed ) );
r = vec2( fbm1( uv + 4.0*q + vec2(1.7 - time / 2.,9.2), seed ), fbm1( uv + 4.0*q + vec2(8.3 - time / 2.,2.8), seed ) );
vec2 s = vec2( fbm1( uv + 4.0*r + vec2(21.7 - time / 2.,90.2), seed ), fbm1( uv + 4.0*r + vec2(80.3 - time / 2.,20.8), seed ) );
vec2 t = vec2( fbm1( uv + 4.0*s + vec2(121.7 - time / 2.,90.2), seed ), fbm1( uv + 4.0*s + vec2(180.3 - time / 2.,20.8), seed ) );
float rtn = fbm1( uv + 4.0*t, seed );
rtn = clamp(rtn, 0., .5);
return rtn;
}
void main() {
vec2 uv = (gl_FragCoord.xy - 0.5 * u_resolution.xy) / u_resolution.y;
uv *= 1. + dot(uv, uv)*.3;
float time = u_time / 20.;
mat2 rot = mat2(cos(time), sin(time), -sin(time), cos(time));
uv = rot * uv;
uv *= 1.4 + sin(time) * .3;
uv.x -= time;
vec2 q = vec2(0.,0.);
vec2 r = vec2(0.,0.);
vec3 colour = vec3(pattern(uv, seed, time, q, r));
float QR = clamp(dot(q, r), -1., 1.);
colour += vec3((q.x + q.y) + QR * 30.,
QR * 15.,
r.x * r.y + QR * 5.
);
colour += .1;
colour = clamp(colour, 0.05, 1.);
gl_FragColor = vec4(colour + (abs(colour) * .1), 1.);
}
`
add a comment |
Your problem lies in your obfuscation from clarity, and this happened:
'colour += vec3(',
'(q.x + q.y) + QR * 30.,',
'QR * 15.', //// <------ Missing comma here
'r.x * r.y + QR * 5.',
');',
Using template literals would make your life easier, example with corrected code:
let fragmentShader = `
uniform vec2 u_resolution;
uniform float u_time;
const int octaves = 6;
const float seed = 43758.5453123;
const float seed2 = 73156.8473192;
vec2 random2(vec2 st, float seed){
st = vec2( dot(st,vec2(127.1,311.7)), dot(st,vec2(269.5,183.3)) );
return -1.0 + 2.0*fract(sin(st)*seed);
}
float noise(vec2 st, float seed) {
vec2 i = floor(st);
vec2 f = fract(st);
vec2 u = f*f*(3.0-2.0*f);
return mix( mix( dot( random2(i + vec2(0.0,0.0), seed ), f - vec2(0.0,0.0) ),
dot( random2(i + vec2(1.0,0.0), seed ), f - vec2(1.0,0.0) ), u.x),
mix( dot( random2(i + vec2(0.0,1.0), seed ), f - vec2(0.0,1.0) ),
dot( random2(i + vec2(1.0,1.0), seed ), f - vec2(1.0,1.0) ), u.x), u.y);
}
float fbm1(in vec2 _st, float seed) {
float v = 0.0;
float a = 0.5;
vec2 shift = vec2(100.0);
mat2 rot = mat2(cos(0.5), sin(0.5), -sin(0.5), cos(0.50));
for (int i = 0; i < octaves; ++i) {
v += a * noise(_st, seed);
_st = rot * _st * 2.0 + shift;
a *= 0.4;
}
return v;
}
float pattern(vec2 uv, float seed, float time, inout vec2 q, inout vec2 r) {
q = vec2( fbm1( uv + vec2(0.0,0.0), seed ), fbm1( uv + vec2(5.2,1.3), seed ) );
r = vec2( fbm1( uv + 4.0*q + vec2(1.7 - time / 2.,9.2), seed ), fbm1( uv + 4.0*q + vec2(8.3 - time / 2.,2.8), seed ) );
vec2 s = vec2( fbm1( uv + 4.0*r + vec2(21.7 - time / 2.,90.2), seed ), fbm1( uv + 4.0*r + vec2(80.3 - time / 2.,20.8), seed ) );
vec2 t = vec2( fbm1( uv + 4.0*s + vec2(121.7 - time / 2.,90.2), seed ), fbm1( uv + 4.0*s + vec2(180.3 - time / 2.,20.8), seed ) );
float rtn = fbm1( uv + 4.0*t, seed );
rtn = clamp(rtn, 0., .5);
return rtn;
}
void main() {
vec2 uv = (gl_FragCoord.xy - 0.5 * u_resolution.xy) / u_resolution.y;
uv *= 1. + dot(uv, uv)*.3;
float time = u_time / 20.;
mat2 rot = mat2(cos(time), sin(time), -sin(time), cos(time));
uv = rot * uv;
uv *= 1.4 + sin(time) * .3;
uv.x -= time;
vec2 q = vec2(0.,0.);
vec2 r = vec2(0.,0.);
vec3 colour = vec3(pattern(uv, seed, time, q, r));
float QR = clamp(dot(q, r), -1., 1.);
colour += vec3((q.x + q.y) + QR * 30.,
QR * 15.,
r.x * r.y + QR * 5.
);
colour += .1;
colour = clamp(colour, 0.05, 1.);
gl_FragColor = vec4(colour + (abs(colour) * .1), 1.);
}
`
Your problem lies in your obfuscation from clarity, and this happened:
'colour += vec3(',
'(q.x + q.y) + QR * 30.,',
'QR * 15.', //// <------ Missing comma here
'r.x * r.y + QR * 5.',
');',
Using template literals would make your life easier, example with corrected code:
let fragmentShader = `
uniform vec2 u_resolution;
uniform float u_time;
const int octaves = 6;
const float seed = 43758.5453123;
const float seed2 = 73156.8473192;
vec2 random2(vec2 st, float seed){
st = vec2( dot(st,vec2(127.1,311.7)), dot(st,vec2(269.5,183.3)) );
return -1.0 + 2.0*fract(sin(st)*seed);
}
float noise(vec2 st, float seed) {
vec2 i = floor(st);
vec2 f = fract(st);
vec2 u = f*f*(3.0-2.0*f);
return mix( mix( dot( random2(i + vec2(0.0,0.0), seed ), f - vec2(0.0,0.0) ),
dot( random2(i + vec2(1.0,0.0), seed ), f - vec2(1.0,0.0) ), u.x),
mix( dot( random2(i + vec2(0.0,1.0), seed ), f - vec2(0.0,1.0) ),
dot( random2(i + vec2(1.0,1.0), seed ), f - vec2(1.0,1.0) ), u.x), u.y);
}
float fbm1(in vec2 _st, float seed) {
float v = 0.0;
float a = 0.5;
vec2 shift = vec2(100.0);
mat2 rot = mat2(cos(0.5), sin(0.5), -sin(0.5), cos(0.50));
for (int i = 0; i < octaves; ++i) {
v += a * noise(_st, seed);
_st = rot * _st * 2.0 + shift;
a *= 0.4;
}
return v;
}
float pattern(vec2 uv, float seed, float time, inout vec2 q, inout vec2 r) {
q = vec2( fbm1( uv + vec2(0.0,0.0), seed ), fbm1( uv + vec2(5.2,1.3), seed ) );
r = vec2( fbm1( uv + 4.0*q + vec2(1.7 - time / 2.,9.2), seed ), fbm1( uv + 4.0*q + vec2(8.3 - time / 2.,2.8), seed ) );
vec2 s = vec2( fbm1( uv + 4.0*r + vec2(21.7 - time / 2.,90.2), seed ), fbm1( uv + 4.0*r + vec2(80.3 - time / 2.,20.8), seed ) );
vec2 t = vec2( fbm1( uv + 4.0*s + vec2(121.7 - time / 2.,90.2), seed ), fbm1( uv + 4.0*s + vec2(180.3 - time / 2.,20.8), seed ) );
float rtn = fbm1( uv + 4.0*t, seed );
rtn = clamp(rtn, 0., .5);
return rtn;
}
void main() {
vec2 uv = (gl_FragCoord.xy - 0.5 * u_resolution.xy) / u_resolution.y;
uv *= 1. + dot(uv, uv)*.3;
float time = u_time / 20.;
mat2 rot = mat2(cos(time), sin(time), -sin(time), cos(time));
uv = rot * uv;
uv *= 1.4 + sin(time) * .3;
uv.x -= time;
vec2 q = vec2(0.,0.);
vec2 r = vec2(0.,0.);
vec3 colour = vec3(pattern(uv, seed, time, q, r));
float QR = clamp(dot(q, r), -1., 1.);
colour += vec3((q.x + q.y) + QR * 30.,
QR * 15.,
r.x * r.y + QR * 5.
);
colour += .1;
colour = clamp(colour, 0.05, 1.);
gl_FragColor = vec4(colour + (abs(colour) * .1), 1.);
}
`
answered Nov 25 at 14:01
Karlsson
488
488
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53403654%2fhave-compile-error-while-importing-shader-from-file-three-js-vue-js-webpack%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
And i use shader code after import this way: ColourShader.fragmentShader or ColourShader.vertexShader
– Александр Николаев
Nov 21 at 0:33
2
Might be easier for you to figure out if you switched to using multiline template literals instead of concatenated arrays of strings. In other words remove all the quotes and commas and
[and]and.join()and just use backticks– gman
Nov 21 at 8:34
It'd be nice if you showed us how you actually made your
ShaderMaterial– pailhead
Nov 21 at 20:42