opengl - How to evade color stripes -


here convertion 32bit float per channel "unsigned byte" per channel color normalization save pci-express bandwidth other things. there can stripes of color , unnatural.

how can avoid this? on edge of spheres.

float color channels: enter image description here

unsigned byte channels: enter image description here

here, yellow edge on blue sphere , blue edge on red 1 should not exist.

normalization used(from opencl kernel) :

// multiplying r doesnt picture color gets bright , reddish. float r=rsqrt(pixel0.x*pixel0.x+pixel0.y*pixel0.y+pixel0.z*pixel0.z+0.001f); unsigned char rgb0=(unsigned char)(pixel0.x*255.0); unsigned char rgb1=(unsigned char)(pixel0.y*255.0); unsigned char rgb2=(unsigned char)(pixel0.z*255.0); rgba_byte[i*4+0]=rgb0>255?255:rgb0; rgba_byte[i*4+1]=rgb1>255?255:rgb1; rgba_byte[i*4+2]=rgb2>255?255:rgb2; rgba_byte[i*4+3]=255; 

binding buffer:

 gl11.glenableclientstate(gl11.gl_color_array);  gl15.glbindbuffer(gl15.gl_array_buffer, id);  gl11.glcolorpointer(4, gl11.gl_unsigned_byte, 4, 0);   

using lwjgl(glfw context) in java environment.

as andon m. said, clamped before casting (i couldnt see when nneded sleep heavily) , solved.

color quality not great way using smaller color buffer helped performance.

enter image description here

your original data set contains floating-point values outside normalized [0.0, 1.0] range, after multiplying 255.0 , casting unsigned char produces overflow. false coloring experienced occurs in areas of scene exceptionally bright in 1 or more color components.

it seems knew expect overflow when wrote rgb0>255?255:rgb0, logic not work because when unsigned char overflows wraps around 0 instead of number larger 255.

   the minimal solution clamp floating-point colors range [0.0, 1.0]    before converting fixed-point 0.8 (8-bit unsigned normalized) color, avoid overflow.

however, if frequent problem, may better off implementing hdr ldr post-process. identify brightest pixel in region (or all) of scene , normalize of colors range. sort of implementing begin (with r = sqrt (...)), using magnitude of current pixel normalize color.


Comments

Popular posts from this blog

node.js - Mongoose: Cast to ObjectId failed for value on newly created object after setting the value -

gradle error "Cannot convert the provided notation to a File or URI" -

python - NameError: name 'subprocess' is not defined -