Category : fragment-shader

I’m trying to calculate the reflection/refraction but with I perform a gl_FragColor = mix(objectColor, environmentColor, 1.0f); I start getting uniform errors that it can’t find my uniform for lightPosition. This doesn’t make sense as I’m using that uniform for calculating the diffuse lighting and when I remove the mix function to just gl_FragColor = objectColor; ..

Read more

I’m trying to do screen space reflections using ray marching, and I’m getting weird reflection. Would you tell me how to debug it, or reviewing it ? Would be grateful if you can spot any problem too. float4 position_from_texture(float2 uv) { return (position_tex.Sample(position_sampler, uv).xyzw); } float3 BinarySearch(inout float3 dir, inout float3 hitCoord, inout float dDepth) ..

Read more

unsigned int histogram[256]={0}; for(int i=0;i<width*height;i++) //to iterate over pixels ++histogram[image[i]]; const float cutoffpercentage = 0.05; //To cut off lower and upper values unsigned char lowerbound,upperbound; unsigned int histAccu =0; //pixel entries < 5% =lower bound const unsigned int lowerpercentile = cutoffpercentage * width*height; const unsigned int upperpercentile = (1-cutoffpercentage)*width*height; for(int h =0;h <256;h++){ histAccu += ..

Read more

I have created a texture with this call: glTexImage2D(GL_TEXTURE_2D, 0,GL_RGBA8, w, h, 0,GL_RGBA, GL_UNSIGNED_BYTE, 0); I render to the texture with a dark grey color: glColor3ub(42, 42, 42); glBegin()… Now I render this texture to the backbuffer using a custom shader. In the fragment I access the texture like this: #version 130 #extension GL_EXT_gpu_shader4 : ..

Read more

I’m writing OpenGL code for a project, using Visual Studio and C++. I have created a shader that contains a Uniform Block correctly linked and initialized in the source code. This is the source code part: unsigned int sunLightUBO; glGenBuffers(1, &sunLightUBO); glBindBuffer(GL_UNIFORM_BUFFER, sunLightUBO); glBufferData(GL_UNIFORM_BUFFER, 48, NULL, GL_STATIC_DRAW); glBufferSubData(GL_UNIFORM_BUFFER, 0, 12, &sunDirection); glBufferSubData(GL_UNIFORM_BUFFER, 12, 12, &sunAmbient); ..

Read more