fragment-shader

Efficient Bicubic filtering code in GLSL?

柔情痞子 提交于 2019-12-02 14:45:28
I'm wondering if anyone has complete, working, and efficient code to do bicubic texture filtering in glsl. There is this: http://www.codeproject.com/Articles/236394/Bi-Cubic-and-Bi-Linear-Interpolation-with-GLSL or https://github.com/visionworkbench/visionworkbench/blob/master/src/vw/GPU/Shaders/Interp/interpolation-bicubic.glsl but both do 16 texture reads where only 4 are necessary: https://groups.google.com/forum/#!topic/comp.graphics.api.opengl/kqrujgJfTxo However the method above uses a missing "cubic()" function that I don't know what it is supposed to do, and also takes an unexplained

WebGL Drawing Multiple Shapes of Different Colour

旧时模样 提交于 2019-12-02 12:40:51
I am currently in the process of learning both WebGL and Javascript. An assignment is requiring me to create multiple shapes using WebGL and for them to all be different colours, however, I am unable to figure out how to set it so that each shape has it's own colour. // HelloTriangle.js (c) 2012 matsuda // Vertex shader program var VSHADER_SOURCE = 'attribute vec4 a_Position;\n' + 'void main() {\n' + ' gl_Position = a_Position;\n' + '}\n'; // Fragment shader program var FSHADER_SOURCE = 'precision mediump float;\n' + 'uniform vec4 u_FragColor;\n' + 'void main() {\n' + ' gl_FragColor = u

Fragment shader inexplicable bahaviour

假如想象 提交于 2019-12-02 11:50:55
I have written a C++ program where I draw a teapot and apply lighting. It is itself simple, but I also use shaders. Simple I'm new with GLSL I just tried a simple fragment shader, but the screen output is inexplicable. In this file I initialize glew in the init method, where I also compile the vertex and fragment shader. They're in the "vertex_shader" and "fragment_shader" files. The thing you may not recognize is what's Light and Material. They're just some structs containing all info about the lights. I've tested these struct so I'm sure the work as expected. When I declare material

Can't draw triangle using Opengl

跟風遠走 提交于 2019-12-02 10:15:04
in this code i want to draw a simple triangle on a blue background using openGL however when i compile and run the code only a window with the blue background appears (without the white triangle that is supposed to be drawn), iam using Xcode my code #include <iostream> #include <string> #include <GLUT/glut.h> #include <OpenGL/gl3.h> #include <fstream> using namespace std; // VAO & VBO objects GLuint VBO; GLuint VAO; void display(); // vertex Data (position) float vertex[] = {-1.0, 0.0 , 1.0, 0.0, 1.0 , 0.0, 0.0, 0.0 , 0.0 }; GLuint Program; GLuint Vshader; GLuint Fshader; // main program int

How to implemen shadertoy code into three.js - clarifying the details

别等时光非礼了梦想. 提交于 2019-12-02 07:29:12
问题 So here is a previous question: How to implement a ShaderToy shader in three.js Tried to implement the steps from the link above into this code unsucessfully: three.js/blob/master/examples/webgl_shader.html So I replaced the original vertex shader and the origianl fragment shader so I got this code: <script id="vertexShader" type="x-shader/x-vertex"> varying vec2 vUv; void main() { vUv = uv; vec4 mvPosition = modelViewMatrix * vec4(position, 1.0 ); gl_Position = projectionMatrix * mvPosition;

OpenGL GLSL Binding Sampler for Fragment Shader

不想你离开。 提交于 2019-12-02 06:34:10
I am hoping to implement a shader on a 2D OpenGL application. My plan is to render a scene to a framebuffer object, and then render that framebuffer object to the screen using a shader. Here is the scene, which I have drawn to a framebuffer object, and then to the screen from there. Using the arrow keys makes the moon move around (I am quite proud of it!) However, when I try to render the framebuffer object to the screen using my shader program, I get this: It is very sad. This fragment shader is one which I got from a tutorial , and I'm sure the problem has to be with the Uniform Variables.

How to implemen shadertoy code into three.js - clarifying the details

微笑、不失礼 提交于 2019-12-02 05:25:19
So here is a previous question: How to implement a ShaderToy shader in three.js Tried to implement the steps from the link above into this code unsucessfully: three.js/blob/master/examples/webgl_shader.html So I replaced the original vertex shader and the origianl fragment shader so I got this code: <script id="vertexShader" type="x-shader/x-vertex"> varying vec2 vUv; void main() { vUv = uv; vec4 mvPosition = modelViewMatrix * vec4(position, 1.0 ); gl_Position = projectionMatrix * mvPosition; } </script> <script id="fragmentShader" type="x-shader/x-fragment"> uniform float iGlobalTime; uniform

How to pass-through fixed-function material and lighting to fragment shader?

旧城冷巷雨未停 提交于 2019-12-02 01:19:43
问题 I am adding a vertex and fragment shader to my OpenGL 2.1/GLSL 1.2 application. Vertex shader: #version 120 void main(void) { gl_Position = ftransform(); gl_FrontColor = gl_Color; } Fragment shader: #version 120 void main(void) { if (/* test some condition */) { discard; } else { gl_FragColor = gl_Color; } } The problem is that if the condition fails, gl_FragColor just gets set to whatever the last call to gl.glColor3f() was in my fixed-function method. Instead, I want to pass through the

Access to 3D array in fragment shader

自古美人都是妖i 提交于 2019-12-01 23:46:38
问题 I'm trying to provide access to a 3-dimensional array of scalar data to a fragment shader, from a Python program using PyOpenGL. In the fragment shader, I declare the a 3d sampler uniform uniform sampler3D vol; and in the Python program I have the following code to set up a scalar 3d texture vol = numpy.random.rand(3, 3, 3).astype(np.float32) texture = glGenTextures(1) glUniform1i(glGetUniformLocation(program, "vol"), 0) glActiveTexture(GL_TEXTURE0 + 0) glBindTexture(GL_TEXTURE_3D, texture)

OpenGL Implementing MultiPass

故事扮演 提交于 2019-12-01 22:52:12
I am having trouble porting some code I have successfully implemented in Shadertoy to desktop OpenGL, the problem is that I need to create a FrameBufferObject FBO so that I can do offscreen computations that will be later passed on to the main glsl fragment shader, the thing is that this buffer needs to reference itself as a texture to get the previous values for it to be able to run a simulation. I have successfully created the FBO: // Framebuffer configuration. unsigned int frameBufferOne; glGenFramebuffers(1, &frameBufferOne); glBindFramebuffer(GL_FRAMEBUFFER, frameBufferOne); // Create a