2017-05-26 180 views
0

我不知道如何正確地說,在一般情況下,實質是,我發現了一個盛開的着色器:https://threejs.org/examples/webgl_postprocessing_unreal_bloom.htmlthree.js所着色顏色閾值

它工作正常,但有點不是有必要對我來說,它只分配明亮的區域和高光。

我需要突出顯示的不是亮度,我需要突出顯示顏色的強度。

例如:

http://dt-byte.ru/fe3ba464.png

在我強調了圈子裏應該有一個選擇的圖片,有想法如何做到這一點?提前

感謝)

回答

3

你可以使用一個RGBtoHSV功能檢查色調,飽和度,以及像素的值,則取的距離從實際的顏色來決定開花與否

this answer

vec3 rgb2hsv(vec3 c) 
{ 
    vec4 K = vec4(0.0, -1.0/3.0, 2.0/3.0, -1.0); 
    vec4 p = mix(vec4(c.bg, K.wz), vec4(c.gb, K.xy), step(c.b, c.g)); 
    vec4 q = mix(vec4(p.xyw, c.r), vec4(c.r, p.yzx), step(p.x, c.r)); 

    float d = q.x - min(q.w, q.y); 
    float e = 1.0e-10; 
    return vec3(abs(q.z + (q.w - q.y)/(6.0 * d + e)), d/(q.x + e), q.x); 
} 

因此

// PSEUDO CODE! 

uniform vec3 targetHSV; // supply hue, saturation, value in 0 to 1 range for each. 
          // Red = 0,1,1 

vec3 color = texture2D(renderTarget, uv).rgb; 
vec3 hsv = rgb2hsv(color); 
vec3 hueDist = abs(hsv.x - targetHSV.x); 

// hue wraps 
if (hueDist > 0.5) { 
    hueDist = 1. - hueDist; 
} 

// 2x for hue because it's at most .5 dist? 
float dist = length(vec3(hueDist * 2., hsv.yz - targetHSV.yz)); 

// now use dist < threshold or smoothstep or something to decide 
// whether value contributes to bloom 
+0

謝謝,但方法錯誤)參數(targetHSV)我不會指定,它將從像素中獲取。 而我得到:http://dt-byte.ru/ff02c45a.png – user2783211

+0

我只對這個調色板感興趣http://dt-byte.ru/f9750aa0.png,因爲沒有白色或灰色顏色) – user2783211

+0

再次感謝),我發現我錯了,現在一切正常。 – user2783211