stevensona / shader-toy Goto Github PK
View Code? Open in Web Editor NEWShadertoy-like live preview for GLSL shaders in Visual Studio Code
Home Page: https://marketplace.visualstudio.com/items?itemName=stevensona.shader-toy
License: MIT License
Shadertoy-like live preview for GLSL shaders in Visual Studio Code
Home Page: https://marketplace.visualstudio.com/items?itemName=stevensona.shader-toy
License: MIT License
my glsl code is :
void main()
{
gl_FragColor = texture2D(iChannel0, gl_FragCoord.xy);
}
and my folder is:
.vscode
test.glsl
normalmap_2.png
my settings.json is:
{
"shader-toy.textures": {
"0": "./normalmap_2.png"
}
}
BUT, I can't see the image anywhere! and the image is power of two...
please help me...
Hi Adam
This is not a SPAM message.
Kind Regards,
Nick Gorbikoff
IT Director
AJR International
300 Regency Drive
Glendale Heights, IL 60139
t: (630) 832-0222 x 242
f: (630) 832-0333
e: [email protected]
w: www.ajrintl.com
The line number mentioned in the error is not the same line where the error actually is.
Example:
#ifdef GL_ES
precision mediump float;
#endif
#define PI 3.14159265359
void main() {
vec2 st = gl_FragCoord.xy/iResolution.xy;
vec2 origin = vec2(0.5, 0.5);
vec2 d = distance(st, origin);
float r = d;
float g = r;
float b = r;
vec3 color = vec3(r, g, b);
gl_FragColor = vec4(color,1.0);
}
Error:
Shader failed to compile
Line 97: '=' : dimension mismatch
Line 97: '=' : cannot convert from 'mediump float' to 'mediump 2-component vector of float'
Line 99: '=' : dimension mismatch
Line 99: '=' : cannot convert from 'mediump 2-component vector of float' to 'mediump float'
We're using vscode.previewHtml
, but that has been deprecated. One can see it every time one launches a debug session of the extension.
So instead we should use the Webview API. Some more details are here: https://go.microsoft.com/fwlink/?linkid=2039309
I haven't taken a closer look yet, so I don't know what kind of refactor would be required.
I'm trying to force the aspect ratio to be 16:9 (with "shader-toy.forceAspectRatio": [16, 9]
), but I get the warning
Incorrect type. Expected one of number, number.
Edit: Shader still works fine, this is a very minor issue
Restart of VS Code is required to reset the preview with the current shader file.
If I open the shader preview with a working shader (no errors), it's not possible to open another glsl-file for the preview. The preview still shows the first shader.
Reproduce:
Result: The preview does not switch to the selected file. Also after closing the tab and reopen with command. It does only work if I restart VS Code.
Summary, the preview does only work for the first previewed file.
Extension Version: 0.8.3
Version: 1.33.1 (user setup)
Commit: 51b0b28134d51361cf996d2f0a1c698247aeabd8
Date: 2019-04-11T08:27:14.102Z
Electron: 3.1.6
Chrome: 66.0.3359.181
Node.js: 10.2.0
V8: 6.6.346.32
OS: Windows_NT x64 10.0.17763
my os is win7,0.4.0 can not loadTexture in my pc.
Like when just using #iChannel0 "t.png"
or if there's a spelling mistake.
Texture access just returns zero values.
When running Show GLSL Preview
from the command palette I get the following error:
Unable to open 'GLSL Preview': Cannot read property 'document' of undefined.
include other file as common function
I have already saved a new workspace with the glsl file open and saved it, then reopened the workspace - still get this error followed by; 'Unable to open 'GLSL Preview": ENOENT: no such file or directory ...\undefined\other-shader.glsl
hi, i just came across your project - nice!
i'm currently working on something similar to help me with my lightmapping / path tracing research. i'd be interested in collaborating. here's the list of features beyond what ShaderToy supports that i'm currently supporting:
texture arrays
volume textures
multiple rendertargets
up to 32 texture inputs per pass
arbitrary texture resolutions
all GPU-supported texture formats
image load/store (and atomics)
arbitrary number of passes
slider widgets defined in metadata and rendered as an overlay
all declarations in metadata in the shader code .. e.g. to create a 1024x1024 buffer you just write "//$BUFFER:mybuffer,w=1024,h=1024" in the shader code, and then you can sample it with "texture(mybuffer,...)" etc.
send me an email if you are interested in sharing ideas or unifying our syntax!
[email protected]
Hi There
I'm using the extension to try shaders like on shadertoy. I think a play / stop button for the preview would be nice. Now it's always trying to complie, but I had moments when some thing heavy was beeing processed and I couldn't bearly move the cursor. So I had to type an error to stop the preview :)
Hi there :)
Well showing compile errors would be great. Or at least highlighting the line which has a problem.
This message from VS Code. My System is "Manjaro Linux", The mesa version is 3.0 Mesa 17.3.8
Does shader-toy only support one layer include file?
This is a very impressive plugin, and I had a lot of fun with it! However, if the preview has the full-screen feature, it can even be used as a screen saver.
As of the last few weeks , June 2019, I noticed none of my shaders work. They all complain that the variable "iGlobalTime" is not defined.
I am using the 64 bit version on Windows 10.
Any help would be most welcomed
Thanks,
sj
Hello,
I have encountered an issue with path resolution. The problem is as follows
I have my main.glsl fragment shader in the root folder and all my dependancies in deps folder
project/
├ deps/
| ├ dep1.glsl
| └ dep2.glsl
└ main.glsl
my main.glsl
has a line
#include "./deps/dep1.glsl"
and my dep1.glsl
has a line
#include "./dep2.glsl"
and I get an error that dep2.glsl cannot be found, but when I prepend "./deps" to the path so the line in dep1.glsl
looks like
#include "./deps/dep2.glsl"
everything works fine.
It's a minor issue but gets in the way of having some shared resources in multiple projects without copying them each time (as the paths will be different)
use glsl file to iChannel, not show every image
Is it hard to export uniforms(float,vec2,vec3) as 1d-slider or 2d-position-picker or 3d-color-picker for easy edit?
I use it to generate some noise texture,but they all save as 256x256,which is too small to use.
Is there a way to make iChannels use video files or webcam inputs as they do on the web based iChannel?
Simply if a shader is included in the shader that is rendered, changing the included file will not reload the preview.
The same might be true for buffer dependencies, though I had no chance to test that yet.
On my desktop this is not really a problem but on my laptop with an integrated GPU, the CPU usage goes up to 50%+ on all threads compared to ~15% on the regular Shadertoy website using the same very basic shader code.
I don't know if this is because of a limitation by VSCode or something?
Similar to Shadertoy.com, support audio channels as inputs into shaders.
Suggested by @edap
Just as shadertoy.com we should support keyboard input. Ideally we would have the same interface (e.g. a 256x3 texture specifying:
I personally miss a release (this frame), which we could support optionally by a setting.
Additionally I think we should inject code for querying the key-states for ease of use. Unless anyone has an idea why shadertoy.com does not allow that.
It would be great to have an option to set resolution/size for the preview window. It's a minor thing and I have a workaround by putting a small window underneath.
like this one:
https://www.shadertoy.com/view/4ttSWf
how to transplant the multipass shdertoy code to vsc using your plugin, can you make a demo, thanks!
https://www.shadertoy.com/view/ldyfDG
it reports:
“GLSL Preview”: Maximum call stack size exceeded。
Shadertoy.com use pre-defined uniform:
uniform vec3 iChannelResolution[4]
for texture image size ino. Using them in shader-toy seems not work.
Awesome extension, works great on Windows. Getting the following error trying to open one of the demo shaders on Linux.
[Embedded Page] Uncaught TypeError: Cannot read property 'getExtension' of null
Pause button and frame time show up, but no shader view.
This on Linux Deepin 15.8.
VSCode version info:
Version: 1.29.1
Commit: bc24f98b5f70467bc689abf41cc5550ca637088e
Date: 2018-11-15T19:07:43.495Z
Electron: 2.0.12
Chrome: 61.0.3163.100
Node.js: 8.9.3
V8: 6.1.534.41
Architecture: x64
This change breaks some shaders when copied from shadertoy.com, particularly everything that does a first-frame-setup will not work.
Adding support for the channel's filter & wrap modes would be fantastic 👍
I had update my Visual Code to 1.35.1, and update the Shader Toy plugin to 0.8.8,
and then I open the audio input setting, put the mp3 to the right place(if path is not correct, it will notice what went wrong),but when i preview with the shader, the audio input channel still not work, and has none error or notice. From the issue i know it added from 0.8.4, so if i want to experience, What shall I do?
Hello
My shader get not rendered. The Fps counter is running and no error gets displayed, but only the VS background color is rendered.
I'm developing a shader for a Phone background. This shader is programmed to run on the "shader editor" app: appstore. The shader runs without any problems on this app.(undefine "on_vs" for use on the app.)
My guess for the cause of this problem: I use arrays in my shader.
my shader:
#ifdef GL_FRAGMENT_PRECISION_HIGH
precision highp float;
#else
precision mediump float;
#endif
#define on_vs
#ifdef on_vs
vec2 resolution = iResolution.xy;
float time = iGlobalTime;
vec2 offset = iMouse.xy / iResolution.xy * vec2(-1.0, -1.0);
#else
uniform vec2 resolution;
uniform float time;
uniform vec2 offset;
#endif
void cswap(inout vec3[8] points, inout float[8] pdistance, int i){
if(pdistance[i]>pdistance[i+1]){
float tempf = pdistance[i];
pdistance[i] = pdistance[i+1];
pdistance[i+1] = tempf;
vec3 tempv3 = points[i];
points[i] = points[i+1];
points[i+1] = tempv3;
}
}
void sort(inout vec3[8] points, inout float[8] pdistance){
cswap(points,pdistance,0);
cswap(points,pdistance,2);
cswap(points,pdistance,4);
cswap(points,pdistance,6);
cswap(points,pdistance,1);
cswap(points,pdistance,3);
cswap(points,pdistance,5);
cswap(points,pdistance,2);
cswap(points,pdistance,4);
cswap(points,pdistance,3);
cswap(points,pdistance,2);
cswap(points,pdistance,4);
cswap(points,pdistance,1);
cswap(points,pdistance,3);
cswap(points,pdistance,5);
cswap(points,pdistance,0);
cswap(points,pdistance,2);
cswap(points,pdistance,4);
cswap(points,pdistance,6);
}
void FAST32_hash_3D( vec3 gridcell,
out vec4 lowz_hash_0,
out vec4 lowz_hash_1,
out vec4 lowz_hash_2,
out vec4 highz_hash_0,
out vec4 highz_hash_1,
out vec4 highz_hash_2 ) // generates 3 random numbers for each of the 8 cell corners
{
// gridcell is assumed to be an integer coordinate
// TODO: these constants need tweaked to find the best possible noise.
// probably requires some kind of brute force computational searching or something....
const vec2 OFFSET = vec2( 50.0, 161.0 );
const float DOMAIN = 69.0;
const vec3 SOMELARGEFLOATS = vec3( 635.298681, 682.357502, 668.926525 );
const vec3 ZINC = vec3( 48.500388, 65.294118, 63.934599 );
// truncate the domain
gridcell.xyz = gridcell.xyz - floor(gridcell.xyz * ( 1.0 / DOMAIN )) * DOMAIN;
vec3 gridcell_inc1 = step( gridcell, vec3( DOMAIN - 1.5, DOMAIN - 1.5, DOMAIN - 1.5 ) ) * ( gridcell + 1.0 );
// calculate the noise
vec4 P = vec4( gridcell.xy, gridcell_inc1.xy ) + OFFSET.xyxy;
P *= P;
P = P.xzxz * P.yyww;
vec3 lowz_mod = vec3( 1.0 / ( SOMELARGEFLOATS.xyz + gridcell.zzz * ZINC.xyz ) );
vec3 highz_mod = vec3( 1.0 / ( SOMELARGEFLOATS.xyz + gridcell_inc1.zzz * ZINC.xyz ) );
lowz_hash_0 = fract( P * lowz_mod.xxxx );
highz_hash_0 = fract( P * highz_mod.xxxx );
lowz_hash_1 = fract( P * lowz_mod.yyyy );
highz_hash_1 = fract( P * highz_mod.yyyy );
lowz_hash_2 = fract( P * lowz_mod.zzzz );
highz_hash_2 = fract( P * highz_mod.zzzz );
}
// convert a 0.0->1.0 sample to a -1.0->1.0 sample weighted towards the extremes
vec4 Cellular_weight_samples( vec4 samples )
{
samples = samples * 2.0 - 1.0;
//return (1.0 - samples * samples) * sign(samples); // square
return (samples * samples * samples) - sign(samples); // cubic (even more variance)
}
//
// Cellular Noise 3D
// Based off Stefan Gustavson's work at http://www.itn.liu.se/~stegu/GLSL-cellular
// http://briansharpe.files.wordpress.com/2011/12/cellularsample.jpg
//
// Speed up by using 2x2x2 search window instead of 3x3x3
// produces range of 0.0->1.0
//
float Cellular3D(vec3 P)
{
// establish our grid cell and unit position
vec3 Pi = floor(P);
vec3 Pf = P - Pi;
// calculate the hash.
// ( various hashing methods listed in order of speed )
vec4 hash_x0, hash_y0, hash_z0, hash_x1, hash_y1, hash_z1;
FAST32_hash_3D( Pi, hash_x0, hash_y0, hash_z0, hash_x1, hash_y1, hash_z1 );
// generate the 8 random points
// restrict the random point offset to eliminate artifacts
// we'll improve the variance of the noise by pushing the points to the extremes of the jitter window
const float JITTER_WINDOW = 0.23; // 0.166666666 will guarentee no artifacts. It is the intersection on x of graphs f(x)=( (0.5 + (0.5-x))^2 + 2*((0.5-x)^2) ) and f(x)=( 2 * (( 0.5 + x )^2) + x * x )
hash_x0 = Cellular_weight_samples( hash_x0 ) * JITTER_WINDOW + vec4(0.0, 1.0, 0.0, 1.0);
hash_y0 = Cellular_weight_samples( hash_y0 ) * JITTER_WINDOW + vec4(0.0, 0.0, 1.0, 1.0);
hash_x1 = Cellular_weight_samples( hash_x1 ) * JITTER_WINDOW + vec4(0.0, 1.0, 0.0, 1.0);
hash_y1 = Cellular_weight_samples( hash_y1 ) * JITTER_WINDOW + vec4(0.0, 0.0, 1.0, 1.0);
hash_z0 = Cellular_weight_samples( hash_z0 ) * JITTER_WINDOW + vec4(0.0, 0.0, 0.0, 0.0);
hash_z1 = Cellular_weight_samples( hash_z1 ) * JITTER_WINDOW + vec4(1.0, 1.0, 1.0, 1.0);
// return the closest squared distance
vec4 dx1 = Pf.xxxx - hash_x0;
vec4 dy1 = Pf.yyyy - hash_y0;
vec4 dz1 = Pf.zzzz - hash_z0;
vec4 dx2 = Pf.xxxx - hash_x1;
vec4 dy2 = Pf.yyyy - hash_y1;
vec4 dz2 = Pf.zzzz - hash_z1;
vec4 d1 = dx1 * dx1 + dy1 * dy1 + dz1 * dz1;
vec4 d2 = dx2 * dx2 + dy2 * dy2 + dz2 * dz2;
vec3 points[8];
points[0] = vec3(dx1.x,dy1.x,dz1.x);
points[1] = vec3(dx1.y,dy1.y,dz1.y);
points[2] = vec3(dx1.z,dy1.z,dz1.z);
points[3] = vec3(dx1.w,dy1.w,dz1.w);
points[4] = vec3(dx2.x,dy2.x,dz2.x);
points[5] = vec3(dx2.y,dy2.y,dz2.y);
points[6] = vec3(dx2.z,dy2.z,dz2.z);
points[7] = vec3(dx2.w,dy2.w,dz2.w);
float pdistance[8];
pdistance[0] = d1.x;
pdistance[1] = d1.y;
pdistance[2] = d1.z;
pdistance[3] = d1.w;
pdistance[4] = d2.x;
pdistance[5] = d2.y;
pdistance[6] = d2.z;
pdistance[7] = d2.w;
sort(points, pdistance);
vec3 minv = vec3(pdistance[0],pdistance[1],pdistance[2]);
float delta = (abs(minv.x - minv.y) + abs(minv.x - minv.z) + abs(minv.y - minv.z))/3.0;
float temp = ((minv.y / minv.x)/3.0) * -1.0 + 1.0;
float distance_to_middle = (minv.x + minv.y) / 2.0;
float c_to_mid = (distance_to_middle - minv.x);
c_to_mid /= distance_to_middle;
c_to_mid = c_to_mid * -1.0 + 1.0;
return smoothstep(0.93,1.0,c_to_mid);
return minv.x;
}
float CellFast(vec3 p, vec3 offset, float frequency, float amplitude)
{
float h = Cellular3D((p + offset) * frequency);
h *= amplitude;
return h;
}
vec2 rotate(vec2 pos, float angle){
float a = atan(pos.x/pos.y);
float l = sqrt(pos.x * pos.x + pos.y * pos.y);
a += angle;
pos.x = l*cos(a);
pos.y = l*sin(a);
return pos;
}
void main(void) {
float max_res = max(resolution.x,resolution.y);
vec2 uv = gl_FragCoord.xy /max_res;
vec2 soffset = offset * 0.7;
vec3 pos = vec3(uv + soffset,time/200.0);
pos.yz = rotate(pos.yz, 0.1);
float heigth = CellFast(pos, vec3(1.0,1.0,1.0), 8.0, 1.0);
gl_FragColor = vec4(heigth, heigth, heigth, 1.0);
}
https://www.shadertoy.com/view/Mtt3z4
I am trying to add this slider to make a noise maker(with the new save feature).but iMouse seems no work,the slider can not be moved.
I don't know if it is possible or not but it would be awesome to see shader compile time and shader 1 frame draw time.
I don't know if it is possible to make this awesome plugin compatible with (Desktop) OpenGL.
I am creating shaders for desktop GLSL and they don't seem to display without modifications.
Could mouse input in the preview be available?
I'm using the following boilerplate code to make shaders compatible with ShaderToy and standard compilers (that includes VSCode extensions like Shaderc GLSL Linter):
//#version 460
precision highp float;
#ifdef STDGLSL
layout(location = 0) in VertexData
{
vec4 v_position;
vec3 v_normal;
vec2 v_texcoord;
};
layout(location = 0) out vec4 fragColor;
layout(binding = 0) uniform ShadertoyBlock
{
vec3 iResolution;
float iGlobalTime;
float iTimeDelta;
int iFrame;
vec4 iMouse;
vec4 iDate;
float iSampleRate;
};
float iTime = iGlobalTime;
uniform sampler2D iChannel0;
uniform sampler2D iChannel1;
uniform sampler2D iChannel2;
uniform sampler2D iChannel3;
void mainImage(out vec4, in vec2);
void main(void) { mainImage(fragColor, v_texcoord * iResolution.xy); }
#else
#iChannel0 "file://./text.png"
#endif
This works quite nicely but there are 2 issues:
main()
to main(void)
, otherwise your regex would pick it up and not generate its own main. Should be documented or improved (better preprocessor handling).If it can export image as a image,it can be used as a procedural texture editor。
#pragma glslify: value_noise21 = require("..\Include\value_noise21.glsl") // not working...
#pragma glslify: simplex_noise21 = require("F:\git\shadertoy\Include\value_noise21.glsl") //works...
I think local glslify module is useful to develop daily, thus it'll be very convinent if shadertoy support it. thanks!
When running the preview command, the preview window opens, but no content is visible. The developer console shows the generated page, and the error: [Embedded Page] Uncaught ReferenceError: THREE is not defined
From my quick review of the generated code, it looks like the canvas and all relevant script tags are generated after the </body>
tag, which seems problematic.
The full generated code (edited for privacy):
<head>
<style>
html, body, #canvas { margin: 0; padding: 0; width: 100%; height: 100%; display: block; }
#error {font-family: Consolas; font-size: 1.2em; color:#ccc; background-color:black; font-weight: bold;}
</style>
</head>
<body>
<div id="error"></div>
<div id="container"></div>
</body>
<script src="/home/user/.vscode/extensions/stevensona.shader-toy-0.1.8/resources/jquery.min.js"></script>
<script src="/home/user/.vscode/extensions/stevensona.shader-toy-0.1.8/resources/three.min.js"></script>
<canvas id="canvas"></canvas>
<script id="vs" type="x-shader/x-vertex">
void main() {
gl_Position = vec4(position, 1.0);
}
</script>
<script id="fs" type="x-shader/x-fragment">
uniform vec3 iResolution;
uniform float iGlobalTime;
uniform float iTimeDelta;
uniform int iFrame;
uniform float iChannelTime[4];
uniform vec3 iChannelResolution[4];
uniform vec4 iMouse;
uniform sampler2D iChannel0;
uniform sampler2D iChannel1;
uniform sampler2D iChannel2;
uniform sampler2D iChannel3;
// uniform vec4 iDate;
// uniform float iSampleRate;
void main()
{
// -- snip --
}
</script>
<script type="text/javascript">
(function(){
console.error = function (message) {
if('7' in arguments) {
$("#error").html("<h3>Shader failed to compile</h3><ul>")
$("#error").append(arguments[7].replace(/ERROR: \d+:(\d+)/g, function(m, c) { return "<li>Line " + String(Number(c) - 27); }));
$("#error").append("</ul>");
}
};
})();
var canvas = document.getElementById('canvas');
var scene = new THREE.Scene();
var renderer = new THREE.WebGLRenderer({canvas: canvas, antialias: true});
var camera = new THREE.PerspectiveCamera(45, canvas.clientWidth / canvas.clientWidth, 1, 1000);
var clock = new THREE.Clock();
var resolution = new THREE.Vector3(canvas.clientWidth, canvas.clientHeight, 1.0);
var channelResolution = new THREE.Vector3(128.0, 128.0, 0.0);
var mouse = new THREE.Vector4(0, 0, 0, 0);
var shader = new THREE.ShaderMaterial({
vertexShader: document.getElementById('vs').textContent,
fragmentShader: document.getElementById('fs').textContent,
depthWrite: false,
depthTest: false,
uniforms: {
iResolution: { type: "v3", value: resolution },
iGlobalTime: { type: "f", value: 0.0 },
iTimeDelta: { type: "f", value: 0.0 },
iFrame: { type: "i", value: 0 },
iChannelTime: { type: "fv1", value: [0., 0., 0., 0.] },
iChannelResolution: { type: "v3v", value:
[channelResolution, channelResolution, channelResolution, channelResolution]
},
iMouse: { type: "v4", value: mouse },
}
});
if(false) {
Function.prototype;
Function.prototype;
Function.prototype;
Function.prototype;
}
var quad = new THREE.Mesh(
new THREE.PlaneGeometry(2, 2),
shader
);
scene.add(quad);
camera.position.z = 10;
render();
function render() {
requestAnimationFrame(render);
if (canvas.width !== canvas.clientWidth || canvas.height !== canvas.clientHeight) {
renderer.setSize(canvas.clientWidth, canvas.clientHeight, false);
camera.aspect = canvas.clientWidth / canvas.clientHeight;
camera.updateProjectionMatrix();
resolution = new THREE.Vector3(canvas.clientWidth, canvas.clientHeight, 1.0);
}
shader.uniforms['iResolution'].value = resolution;
shader.uniforms['iGlobalTime'].value = clock.getElapsedTime();
shader.uniforms['iTimeDelta'].value = clock.getDelta();
shader.uniforms['iFrame'].value = 0;
shader.uniforms['iMouse'].value = mouse;
renderer.render(scene, camera);
}
</script>
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.