Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No content in preview window #9

Closed
ircubic opened this issue Feb 13, 2017 · 2 comments
Closed

No content in preview window #9

ircubic opened this issue Feb 13, 2017 · 2 comments

Comments

@ircubic
Copy link

ircubic commented Feb 13, 2017

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>
@stevensona
Copy link
Owner

Thanks for the detailed report. Which platform is this on?

@stevensona
Copy link
Owner

@ircubic please update the extension and let me know if the issue is resolved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants