HLSL تظليل بكسل - تغيير لون الصورة محددة هوى

StackOverflow https://stackoverflow.com/questions/1395073

  •  21-09-2019
  •  | 
  •  

سؤال

أود أن أكتب بيكسل شادر أن يأخذ صورة مدخلات و تحويل جميع الألوان من واحد هوى مجموعة (أيهامبورغ) إلى آخر هوى النطاق.

حافزي هو بسيط:أريد أن اللون مجموعة من مواد مختلفة بشكل مختلف, ولكن أنا لا أريد أن لون كامل الملمس فقط جزء مع هوى في نطاق معين.وبهذه الطريقة ، يمكن رسم صورة واحدة من سباقات السيارات ، ومن ثم تغيير لون فقط المشارب شعار على السيارة مع تظليل بكسل.

نظرت إلى HLSL الوثائق على الانترنت و لم أجد أي شيء للتعامل مع الأشكال.هل هناك مكتبة HLSL البرمجية المتاحة على الانترنت ؟

هنا بعض شبة الكود ما أحاول تحقيقه:

external float SrcMinHue,SrcMaxHue,TargetMin
void changeHues(image source)
{
   foreach x,y in image:
   {
      float sourceHue = getHue(source,x,y)
      if (SrcMinHue < sourceHue < SrcNaxHue):
          setHue(source,x,y,(TargetMin + (sourceHue - MinHue))
   }
}

أنا أعمل مع XNA Game Studio أن المعلومات المسائل إلى أي شخص.

هل كانت مفيدة؟

المحلول

ألق نظرة على "post RGB to HSV" عينة في صفحة مكتبة Nvidia Shader. قد يعطيك هذا الإلهام.

وإلا أعتقد أنه يمكنك "ببساطة" تحويل لون RGB إلى HSV في تظليل البكسل الخاص بك باستخدام الصيغة من ويكيبيديا ثم خذها من هناك.

نصائح أخرى

جعل المصفوفة التي تدور RGB اللون حول [1,1,1] محور (الإنارة محور)* من خلال زاوية من شأنه أن تدوير المصدر لون على لون الهدف.تعيين هذه المصفوفة كما بيكسل شادر المستمر.

في تظليل بكسل, تحويل بكسل لون من هذه المصفوفة.ثم lerp بين تناظري و تحويل الألوان وفقا الزاوية بين تناظري بكسل هوى مصدر اللون هوى.عند زاوية صغيرة ، استخدام تحويل اللون.عند زاوية كبيرة ، استخدام تناظري اللون.

لتحديد هوى بكسل طرح متوسط RGB* من بكسل.الزاوية بين متجه و [1,0,0] هو هوى.

*أنا على علم بأن الإنارة ليست بسيطة ، ولكن هذا هو جيدة بما فيه الكفاية من أجل تقريب هذه الحالة.

اللون/التشبع/السطوع/التباين HLSL Pixel Shader (Shazzam .FX)

/// <class>7Aliens HSBC Hue/Saturation/Brightness/Contrast</class>
/// <description>Blend modes Brightness/Contrast (Photoshop CS) with Hue and Saturation.</description>

sampler2D input : register(s0);

/// <summary>The brightness offset.</summary>
/// <minValue>-2</minValue>
/// <maxValue>2</maxValue>
/// <defaultValue>0</defaultValue>
float SliderBrightnes : register(C0);

/// <summary>The brightness offset.</summary> 
/// <minValue>-1</minValue>
/// <maxValue>1</maxValue>
/// <defaultValue>0</defaultValue>
float SliderContrast : register(C1);

/// <summary>The brightness offset.</summary>
/// <minValue>-1</minValue>
/// <maxValue>1</maxValue>
/// <defaultValue>0</defaultValue>
float sliderSaturation : register(C2);

/// <summary>The brightness offset.</summary>
/// <minValue>-180</minValue>
/// <maxValue>180</maxValue>
/// <defaultValue>0</defaultValue>
float sliderHue : register(C3);

float3x3 QuaternionToMatrix(float4 quat)
{
    float3 cross = quat.yzx * quat.zxy;
    float3 square= quat.xyz * quat.xyz;
    float3 wimag = quat.w * quat.xyz;

    square = square.xyz + square.yzx;

    float3 diag = 0.5 - square;
    float3 a = (cross + wimag);
    float3 b = (cross - wimag);

    return float3x3(
    2.0 * float3(diag.x, b.z, a.y),
    2.0 * float3(a.z, diag.y, b.x),
    2.0 * float3(b.y, a.x, diag.z));
}

const float3 lumCoeff = float3(0.2125, 0.7154, 0.0721);

float4 Desaturate(float3 color, float Desaturation)
{
    float3 grayXfer = float3(0.3, 0.59, 0.11);
    float grayf = dot(grayXfer, color);
    float3 gray = float3(grayf, grayf, grayf);
    return float4(lerp(color, gray, Desaturation), 1.0);
}

float4 main(float2 uv : TEXCOORD) : COLOR 
{ 
    float4  cInput; 
    cInput = tex2D( input , uv.xy);

    float4 inputColor;
    inputColor = cInput;
    float4 blendColor;
    blendColor = cInput;
    float4 resultColor;
    resultColor = cInput;

    float3 hsv; 
    float3 intensity;           
    float3 root3 = float3(0.57735, 0.57735, 0.57735);
    float half_angle = 0.5 * radians(sliderHue); // Hue is radians of 0 tp 360 degree
    float4 rot_quat = float4( (root3 * sin(half_angle)), cos(half_angle));
    float3x3 rot_Matrix = QuaternionToMatrix(rot_quat);     
    resultColor.rgb = mul(rot_Matrix, inputColor.rgb);

    resultColor = Desaturate(resultColor, -sliderSaturation);

    inputColor = resultColor;`enter code here`
    blendColor = resultColor;
    resultColor = resultColor;

    blendColor.rgb = clamp(blendColor.rgb / blendColor.a, 0, 1);
    if (resultColor.r > 0.5) resultColor.r = 1 - (1 - 2 * (resultColor.r - 0.5)) * (1 - blendColor.r); else resultColor.r = (2 * resultColor.r) * blendColor.r;
    if (resultColor.g > 0.5) resultColor.g = 1 - (1 - 2 * (resultColor.g - 0.5)) * (1 - blendColor.g); else resultColor.g = (2 * resultColor.g) * blendColor.g;
    if (resultColor.b > 0.5) resultColor.b = 1 - (1 - 2 * (resultColor.b - 0.5)) * (1 - blendColor.b); else resultColor.b = (2 * resultColor.b) * blendColor.b;

    float4 colorOverlay = resultColor;
    colorOverlay = colorOverlay * SliderContrast;
    resultColor.rgb = (1 - (colorOverlay.a)) * inputColor.rgb + colorOverlay.rgb;       

    inputColor = resultColor;
    blendColor = resultColor;

    float4 colorScreen = resultColor;
    colorScreen.rgb = (1.0f - (1.0f - inputColor.rgb) * (1.0f - blendColor.rgb));
    colorScreen = -(colorScreen * SliderBrightnes * -(1 - inputColor.r));
    resultColor.rgb = (1 - (colorScreen.a)) * inputColor.rgb + colorScreen.rgb;

    return resultColor; 
}
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top