Three.js/GLSL - Convert Pixel Coordinate to World Coordinate

前端 未结 1 1047
Happy的楠姐
Happy的楠姐 2021-01-19 22:01

I have a simple shader in my Three.js application that colors the screen red. However, I want to color all pixels to the right of a given world position to to a different co

相关标签:
1条回答
  • 2021-01-19 22:23

    Answer derived from WestLangley's Fiddle here: http://jsfiddle.net/ST4aM/2/.


    Vertex Shader

    <script type="x-shader/x-vertex" id="vertexshader">
        #ifdef GL_ES
        precision highp float;
        #endif
    
        varying float x;
        varying float y;
        void main()
        {
            gl_Position = projectionMatrix * modelViewMatrix * vec4(position,1.0);
            x = position.x;
            y = position.y;
        }
    </script>
    

    Fragment Shader

    <script type="x-shader/x-fragment" id="fragmentshader">
        #ifdef GL_ES
        precision highp float;
        #endif
    
        varying float x;
        varying float y;
    
        void main()
        {
            if(x > somePosition)
            {
                gl_FragColor = vec4(0.0, 1.0, 0.0, 1);
            }
    
            else
            {
                gl_FragColor = vec4(1.0, 0.0, 0.0, 1);
            }
        }
    </script>
    

    0 讨论(0)
提交回复
热议问题