fragment-shader

GLSL ES fragment shader produces very different results on different devices

不羁岁月 提交于 2020-01-14 18:44:31
问题 I am developing a game for Android using OpenGL ES 2.0 and have a problem with a fragment shader for drawing stars in the background. I've got the following code: precision mediump float; varying vec2 transformed_position; float rand(vec2 co) { return fract(sin(dot(co.xy ,vec2(12.9898,78.233))) * 43758.5453); } void main(void) { float distance = 10.0; float quantization_strength = 4.0; vec3 background_color = vec3(0.09, 0.0, 0.288); vec2 zero = vec2(0.0, 0.0); vec2 distance_vec = vec2

Can't draw triangle using Opengl

前提是你 提交于 2020-01-11 14:21:10
问题 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,

Three.js Transparency Errors With Multiple Particle Systems Sorting

北慕城南 提交于 2020-01-06 06:59:09
问题 I have two THREE.ParticleSystem systems with particles that have textures with alpha transparency, one is using AdditiveBlending (fire texture), the other uses NormalBlending (smoke texture) and they use simple custom vertex and fragment shaders. Each ParticleSystem has "sortParticles = true" and independently they work perfectly, however when both types of particles overlap the first particle system (fire texture) has a similar transparency depth error that is normally associated with

Draw a line segment in a fragment shader

牧云@^-^@ 提交于 2020-01-05 07:47:12
问题 I'm struggling to understand the following code, the idea is to draw a simple segment in a fragment shader. I tried to decompose it but I still don't get the ??? line. It would be awesome to have a nice explanation. I couldn't find anything on SO or Google. float lineSegment(vec2 p, vec2 a, vec2 b) { float thickness = 1.0/100.0; vec2 pa = p - a; vec2 ba = b - a; float h = clamp( dot(pa,ba)/dot(ba,ba), 0.0, 1.0 ); // ???????? float idk = length(pa - ba*h); return smoothstep(0.0, thickness, idk

Chroma key Fragment Shader fails to find the color

↘锁芯ラ 提交于 2020-01-04 11:42:55
问题 I'm trying to write a fragment-shader that functions as a chroma-key filter for a specific color (for example make all pixels with a specific green transparent). The shader I'm writing is for use in WebGL trough PIXI.js. JSFiddle: https://jsfiddle.net/IbeVanmeenen/hexec6eg/14/ So far, I wrote this code for the shader, based on the shader I've found here. varying vec2 vTextureCoord; uniform float thresholdSensitivity; uniform float smoothing; uniform vec3 colorToReplace; uniform sampler2D

Chroma key Fragment Shader fails to find the color

ぃ、小莉子 提交于 2020-01-04 11:42:26
问题 I'm trying to write a fragment-shader that functions as a chroma-key filter for a specific color (for example make all pixels with a specific green transparent). The shader I'm writing is for use in WebGL trough PIXI.js. JSFiddle: https://jsfiddle.net/IbeVanmeenen/hexec6eg/14/ So far, I wrote this code for the shader, based on the shader I've found here. varying vec2 vTextureCoord; uniform float thresholdSensitivity; uniform float smoothing; uniform vec3 colorToReplace; uniform sampler2D

Colour bit-wise shift in OpenGL shader GLSL

廉价感情. 提交于 2020-01-04 05:14:08
问题 I am passing vec4 to the shaders with xyz and a colour value and I tried to bit-wise shift the colour component to their own r g and b floats but having issues: Vertex shader: #version 150 in vec4 position; out vec2 Texcoord; uniform mat4 model; uniform mat4 view; uniform mat4 proj; void main() { Texcoord = vec2(position.w, position.w); gl_Position = proj * view * model * vec4(position.xyz, 1.0); } Fragment shader: #version 150 in vec2 Texcoord; out vec4 outColor; uniform sampler2D tex; void

Blurring the depth buffer in OpenGL - how to access mipmap levels in a fragment shader?

别说谁变了你拦得住时间么 提交于 2020-01-03 19:10:10
问题 I'm trying to blur a depth texture by blurring & blending mipmap levels in a fragment shader. I have two frambuffer objects: 1) A color frambuffer with a depth renderobject attached. 2) A z framebuffer with a depth texture attached. Once I render the scene to the color framebuffer object, I then blit to the depth buffer object, and can successfully render that (output is a GL_LUMINANCE depth texture). I can successfully access any given mipmap level by selecting it prior to drawing the depth

Can one fragment access all texture pixel values in WebGL GLSL? (Not just it's own TexCoord)

心已入冬 提交于 2020-01-03 00:56:33
问题 Let's pretend I'm making a compute shader using WebGL and GLSL. In this shader, each fragment (or pixel) would like to look at every pixel on a texture, then decide on it's own color. Normally a fragment samples it's provided texture coordinate (UV value) from a few textures, but I want to sample effectively all UV values from a single texture for a single fragment. Is this possible? 回答1: EDIT: I was able to sample from each pixel in a 128x128 texture, but moving to 256x256 causes Chrome to

How to use texture2d_array array in metal?

拈花ヽ惹草 提交于 2020-01-02 11:03:10
问题 I have been trying to use texture2d_array for my application of live filters in metal. But I'm not getting the proper result. Im creating the texture array like this, Code: Class MetalTextureArray . class MetalTextureArray { private(set) var arrayTexture: MTLTexture private var width: Int private var height: Int init(_ width: Int, _ height: Int, _ arrayLength: Int, _ device: MTLDevice) { self.width = width self.height = height let textureDescriptor = MTLTextureDescriptor() textureDescriptor