Questions tagged [fragment-shader]

A GPU program used in rendering. It is executed for each sample taken from a rasterized primitive. The output of this process is a number of values and a floating-point depth.

Resources

1506 questions
9
votes
1 answer

How to write pass-through vertex and fragment shaders for a framebuffer with attached texture?

I'm attempting to use shaders to modify a texture that is bound to a framebuffer, but I'm confused as to how the shaders get the "original" input values. I'm doing the following: GLuint textureId = 0; glGenTextures(1,…
Mark Ingram
  • 71,849
  • 51
  • 176
  • 230
9
votes
2 answers

Android OpenGL ES 2.0: Is "switch-case" syntax possible in GLSL fragment shader on Samsung Galaxy S2?

Does anybody know how to do switch case syntax in the fragment shader on the Samsung Galaxy S2? I get the compilation error: Expected literal or '(', got 'switch'. My syntax is as follows: switch(i){ case 0: x = alphas[0]; break; case 1:…
Navigateur
  • 1,852
  • 3
  • 23
  • 39
8
votes
2 answers

2 Textures, 1 Shader - OpenGL ES 2.0

ES 2.0 newbie here. I'm currently trying to make some 3D interlaced images from stereo images with ES 2.0 and the PowerVR SDK. I can output one image texture fine, but when I try to output the second one, I seem to be overwriting the first. So, my…
8
votes
1 answer

Passing a float or color into a Metal fragment shader from Swift

I'm trying to write a fragment shader in Metal but can't get my head around how to pass in single values (e.g. float, float4 or half4). My shaders are as follows: #include using namespace metal; typedef struct { float4…
Doug
  • 2,972
  • 3
  • 22
  • 28
8
votes
3 answers

ThreeJS [r85]: Custom Shader with Shadowmap

I've created a custom shader to be able to use a BlendMap with 4 different textures but I'm unable to get the shadows/lightning effects to work with it. What am I missing here? Or is there some other way I can achieve same functionality? Mesh…
8
votes
1 answer

Pixelated lighting shader

I've written a GLSL shader for use in Unity3D with my pixelated iOS app. It has two ONE problems: 1) The effect doesn't always stay with the moon, and 2) the lighting doesn't look pixelated. I'll explain a little. The shader is meant to cause a…
Catlard
  • 853
  • 6
  • 13
  • 30
8
votes
1 answer

What is this technique, if not bilinear filtering?

I'm trying to replicate the automatic bilinear filtering algorithm of Unity3D using the next code: fixed4 GetBilinearFilteredColor(float2 texcoord) { fixed4 s1 = SampleSpriteTexture(texcoord + float2(0.0, _MainTex_TexelSize.y)); fixed4 s2 =…
A.Quiroga
  • 5,704
  • 6
  • 37
  • 58
8
votes
3 answers

Compute bounding quad of a sphere with vertex shader

I'm trying to implement an algorithm from a graphics paper and part of the algorithm is rendering spheres of known radius to a buffer. They say that they render the spheres by computing the location and size in a vertex shader and then doing…
Ben Jones
  • 919
  • 1
  • 8
  • 22
8
votes
1 answer

Accessing same-named uniform in vertex and fragment shaders fails

I'm still very inexperienced with shaders but I'm climbing the learning curve well. Something I've stumbled upon this morning is an effort to use a same-named uniform in both fragment and vertex shaders. The uniform can be defined in both shaders,…
Tom Pace
  • 2,347
  • 1
  • 24
  • 32
8
votes
1 answer

Passing several textures to shader in LibGDX

I need to pass 2(or more) textures to one shader. Also I have to bind textures in render method, because I use FrameBuffer and try to bind textures on fly. So, my code is below: @Override public void show () { fbo = new…
Nolesh
  • 6,848
  • 12
  • 75
  • 112
8
votes
1 answer

GLSL shader not unrolling loop when needed

My 9600GT hates me. Fragment shader: #version 130 uint aa[33] = uint[33]( 0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0, 0,0,0 ); void main() { int i=0; int a=26; for (i=0; i
user2464424
  • 1,536
  • 1
  • 14
  • 28
8
votes
1 answer

Can someone please explain this Fragment Shader? It is a Chroma Key Filter (Green screen effect)

I'm trying to understand how this chroma key filter works. Chroma Key, if you don't know, is a green screen effect. Would someone be able to explain how some of these functions work and what they are doing exactly? float maskY = 0.2989 *…
kilakev
  • 123
  • 1
  • 5
8
votes
1 answer

what's the counterpart for gl_TexCoord in OpenGL ES 2.0

I have a OpenGL shader which uses gl_TexCoord like the following does. But in OpenGL ES, gl_TexCoord is not supported. I wonder what can I do to refactor the code to get it work on OpenGL ES. void main() { //scene depth calculation float…
tom
  • 14,273
  • 19
  • 65
  • 124
7
votes
1 answer

Really simple custom shader in Three.js - how to make it work?

I'm trying to make the simplest custom shader for Three.js that I can, but I haven't figured out how to make it work. The object the I'm using the shader for doesn't appear at all. In my page html I have: