浏览代码

Fix color picker in game

/main
sebastienlagarde 7 年前
当前提交
114acd41
共有 2 个文件被更改,包括 65 次插入53 次删除
  1. 93
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Debug/DebugColorPicker.shader
  2. 25
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Debug/DebugDisplay.hlsl

93
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Debug/DebugColorPicker.shader


return output;
}
float4 DisplayPixelInformationAtMousePosition(Varyings input, float4 result, float4 mouseResult)
float4 DisplayPixelInformationAtMousePosition(Varyings input, float4 result, float4 mouseResult, float4 mousePixelCoord)
if (_MousePixelCoord.z >= 0.0 && _MousePixelCoord.z <= 1.0 && _MousePixelCoord.w >= 0 && _MousePixelCoord.w <= 1.0)
bool flipY = _RequireToFlipInputTexture > 0.0;
if (mousePixelCoord.z >= 0.0 && mousePixelCoord.z <= 1.0 && mousePixelCoord.w >= 0 && mousePixelCoord.w <= 1.0)
{
// As when we read with the color picker we don't go through the final blit (that current hardcode a conversion to sRGB)
// and as our material debug take it into account, we need to a transform here.

// Display message offset:
int displayTextOffsetX = 1.5 * DEBUG_FONT_TEXT_WIDTH;
#if UNITY_UV_STARTS_AT_TOP
int displayTextOffsetY = -DEBUG_FONT_TEXT_HEIGHT;
#else
int displayTextOffsetY = DEBUG_FONT_TEXT_HEIGHT;
#endif
int displayTextOffsetY;
if (flipY)
{
displayTextOffsetY = DEBUG_FONT_TEXT_HEIGHT;
}
else
{
displayTextOffsetY = -DEBUG_FONT_TEXT_HEIGHT;
}
uint2 displayUnormCoord = uint2(_MousePixelCoord.x + displayTextOffsetX, _MousePixelCoord.y + displayTextOffsetY);
uint2 displayUnormCoord = uint2(mousePixelCoord.x + displayTextOffsetX, mousePixelCoord.y + displayTextOffsetY);
uint2 unormCoord = input.positionCS.xy;
if (_ColorPickerMode == COLORPICKERDEBUGMODE_BYTE || _ColorPickerMode == COLORPICKERDEBUGMODE_BYTE4)

DrawCharacter('R', _ColorPickerFontColor, unormCoord, displayUnormCoord, result.rgb);
DrawCharacter(':', _ColorPickerFontColor, unormCoord, displayUnormCoord, result.rgb);
DrawInteger(mouseValue.x, _ColorPickerFontColor, unormCoord, displayUnormCoord, result.rgb);
DrawCharacter('R', _ColorPickerFontColor, unormCoord, displayUnormCoord, flipY, result.rgb);
DrawCharacter(':', _ColorPickerFontColor, unormCoord, displayUnormCoord, flipY, result.rgb);
DrawInteger(mouseValue.x, _ColorPickerFontColor, unormCoord, displayUnormCoord, flipY, result.rgb);
displayUnormCoord.x = _MousePixelCoord.x + displayTextOffsetX;
displayUnormCoord.x = mousePixelCoord.x + displayTextOffsetX;
DrawCharacter('G', _ColorPickerFontColor, unormCoord, displayUnormCoord, result.rgb);
DrawCharacter(':', _ColorPickerFontColor, unormCoord, displayUnormCoord, result.rgb);
DrawInteger(mouseValue.y, _ColorPickerFontColor, unormCoord, displayUnormCoord, result.rgb);
displayUnormCoord.x = _MousePixelCoord.x + displayTextOffsetX;
DrawCharacter('G', _ColorPickerFontColor, unormCoord, displayUnormCoord, flipY, result.rgb);
DrawCharacter(':', _ColorPickerFontColor, unormCoord, displayUnormCoord, flipY, result.rgb);
DrawInteger(mouseValue.y, _ColorPickerFontColor, unormCoord, displayUnormCoord, flipY, result.rgb);
displayUnormCoord.x = mousePixelCoord.x + displayTextOffsetX;
DrawCharacter('B', _ColorPickerFontColor, unormCoord, displayUnormCoord, result.rgb);
DrawCharacter(':', _ColorPickerFontColor, unormCoord, displayUnormCoord, result.rgb);
DrawInteger(mouseValue.z, _ColorPickerFontColor, unormCoord, displayUnormCoord, result.rgb);
displayUnormCoord.x = _MousePixelCoord.x + displayTextOffsetX;
DrawCharacter('B', _ColorPickerFontColor, unormCoord, displayUnormCoord, flipY, result.rgb);
DrawCharacter(':', _ColorPickerFontColor, unormCoord, displayUnormCoord, flipY, result.rgb);
DrawInteger(mouseValue.z, _ColorPickerFontColor, unormCoord, displayUnormCoord, flipY, result.rgb);
displayUnormCoord.x = mousePixelCoord.x + displayTextOffsetX;
DrawCharacter('A', _ColorPickerFontColor, unormCoord, displayUnormCoord, result.rgb);
DrawCharacter(':', _ColorPickerFontColor, unormCoord, displayUnormCoord, result.rgb);
DrawInteger(mouseValue.w, _ColorPickerFontColor, unormCoord, displayUnormCoord, result.rgb);
DrawCharacter('A', _ColorPickerFontColor, unormCoord, displayUnormCoord, flipY, result.rgb);
DrawCharacter(':', _ColorPickerFontColor, unormCoord, displayUnormCoord, flipY, result.rgb);
DrawInteger(mouseValue.w, _ColorPickerFontColor, unormCoord, displayUnormCoord, flipY, result.rgb);
DrawCharacter('X', _ColorPickerFontColor, unormCoord, displayUnormCoord, result.rgb);
DrawCharacter(':', _ColorPickerFontColor, unormCoord, displayUnormCoord, result.rgb);
DrawFloat(mouseResult.x, _ColorPickerFontColor, unormCoord, displayUnormCoord, result.rgb);
DrawCharacter('X', _ColorPickerFontColor, unormCoord, displayUnormCoord, flipY, result.rgb);
DrawCharacter(':', _ColorPickerFontColor, unormCoord, displayUnormCoord, flipY, result.rgb);
DrawFloat(mouseResult.x, _ColorPickerFontColor, unormCoord, displayUnormCoord, flipY, result.rgb);
displayUnormCoord.x = _MousePixelCoord.x + displayTextOffsetX;
displayUnormCoord.x = mousePixelCoord.x + displayTextOffsetX;
DrawCharacter('Y', _ColorPickerFontColor, unormCoord, displayUnormCoord, result.rgb);
DrawCharacter(':', _ColorPickerFontColor, unormCoord, displayUnormCoord, result.rgb);
DrawFloat(mouseResult.y, _ColorPickerFontColor, unormCoord, displayUnormCoord, result.rgb);
displayUnormCoord.x = _MousePixelCoord.x + displayTextOffsetX;
DrawCharacter('Y', _ColorPickerFontColor, unormCoord, displayUnormCoord, flipY, result.rgb);
DrawCharacter(':', _ColorPickerFontColor, unormCoord, displayUnormCoord, flipY, result.rgb);
DrawFloat(mouseResult.y, _ColorPickerFontColor, unormCoord, displayUnormCoord, flipY, result.rgb);
displayUnormCoord.x = mousePixelCoord.x + displayTextOffsetX;
DrawCharacter('Z', _ColorPickerFontColor, unormCoord, displayUnormCoord, result.rgb);
DrawCharacter(':', _ColorPickerFontColor, unormCoord, displayUnormCoord, result.rgb);
DrawFloat(mouseResult.z, _ColorPickerFontColor, unormCoord, displayUnormCoord, result.rgb);
displayUnormCoord.x = _MousePixelCoord.x + displayTextOffsetX;
DrawCharacter('Z', _ColorPickerFontColor, unormCoord, displayUnormCoord, flipY, result.rgb);
DrawCharacter(':', _ColorPickerFontColor, unormCoord, displayUnormCoord, flipY, result.rgb);
DrawFloat(mouseResult.z, _ColorPickerFontColor, unormCoord, displayUnormCoord, flipY, result.rgb);
displayUnormCoord.x = mousePixelCoord.x + displayTextOffsetX;
DrawCharacter('W', _ColorPickerFontColor, unormCoord, displayUnormCoord, result.rgb);
DrawCharacter(':', _ColorPickerFontColor, unormCoord, displayUnormCoord, result.rgb);
DrawFloat(mouseResult.w, _ColorPickerFontColor, unormCoord, displayUnormCoord, result.rgb);
DrawCharacter('W', _ColorPickerFontColor, unormCoord, displayUnormCoord, flipY, result.rgb);
DrawCharacter(':', _ColorPickerFontColor, unormCoord, displayUnormCoord, flipY, result.rgb);
DrawFloat(mouseResult.w, _ColorPickerFontColor, unormCoord, displayUnormCoord, flipY, result.rgb);
}
}
}

float4 result = SAMPLE_TEXTURE2D(_DebugColorPickerTexture, sampler_DebugColorPickerTexture, input.texcoord);
//result.rgb = GetColorCodeFunction(result.x, _ColorPickerParam);
float4 mouseResult = SAMPLE_TEXTURE2D(_DebugColorPickerTexture, sampler_DebugColorPickerTexture, _MousePixelCoord.zw);
float4 mousePixelCoord = _MousePixelCoord;
if (_RequireToFlipInputTexture > 0.0)
{
mousePixelCoord.y = _ScreenParams.y - mousePixelCoord.y;
// Note: We must not flip the mousePixelCoord.w coordinate
}
float4 mouseResult = SAMPLE_TEXTURE2D(_DebugColorPickerTexture, sampler_DebugColorPickerTexture, mousePixelCoord.zw);
float4 finalResult = DisplayPixelInformationAtMousePosition(input, result, mouseResult);
float4 finalResult = DisplayPixelInformationAtMousePosition(input, result, mouseResult, mousePixelCoord);
return finalResult;
}

25
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Debug/DebugDisplay.hlsl


// color is current screen color
// color of the font to use
// direction is 1 or -1 and indicate fixedUnormCoord block shift
void DrawCharacter(uint asciiValue, float3 fontColor, uint2 currentUnormCoord, inout uint2 fixedUnormCoord, inout float3 color, int direction)
void DrawCharacter(uint asciiValue, float3 fontColor, uint2 currentUnormCoord, inout uint2 fixedUnormCoord, bool flipY, inout float3 color, int direction)
#if UNITY_UV_STARTS_AT_TOP
localCharCoord.y = DEBUG_FONT_TEXT_HEIGHT - localCharCoord.y;
#endif
if (!flipY)
localCharCoord.y = DEBUG_FONT_TEXT_HEIGHT - localCharCoord.y;
asciiValue -= DEBUG_FONT_TEXT_ASCII_START; // Our font start at ASCII table 32;
uint2 asciiCoord = uint2(asciiValue % DEBUG_FONT_TEXT_COUNT_X, asciiValue / DEBUG_FONT_TEXT_COUNT_X);

}
// Shortcut to not have to file direction
void DrawCharacter(uint asciiValue, float3 fontColor, uint2 currentUnormCoord, inout uint2 fixedUnormCoord, inout float3 color)
void DrawCharacter(uint asciiValue, float3 fontColor, uint2 currentUnormCoord, inout uint2 fixedUnormCoord, bool flipY, inout float3 color)
DrawCharacter(asciiValue, fontColor, currentUnormCoord, fixedUnormCoord, color, 1);
DrawCharacter(asciiValue, fontColor, currentUnormCoord, fixedUnormCoord, flipY, color, 1);
void DrawInteger(int intValue, float3 fontColor, uint2 currentUnormCoord, inout uint2 fixedUnormCoord, inout float3 color)
void DrawInteger(int intValue, float3 fontColor, uint2 currentUnormCoord, inout uint2 fixedUnormCoord, bool flipY, inout float3 color)
{
const uint maxStringSize = 16;

for (uint i = 0; i < maxStringSize; ++i)
{
// Numeric value incurrent font start on the second row at 0
DrawCharacter((absIntValue % 10) + '0', fontColor, currentUnormCoord, fixedUnormCoord, color, -1);
DrawCharacter((absIntValue % 10) + '0', fontColor, currentUnormCoord, fixedUnormCoord, flipY, color, -1);
if (absIntValue < 10)
break;
absIntValue /= 10;

if (intValue < 0)
{
DrawCharacter('-', fontColor, currentUnormCoord, fixedUnormCoord, color, -1);
DrawCharacter('-', fontColor, currentUnormCoord, fixedUnormCoord, flipY, color, -1);
}
// 5. Reset cursor at end location

void DrawFloat(float floatValue, float3 fontColor, uint2 currentUnormCoord, inout uint2 fixedUnormCoord, inout float3 color)
void DrawFloat(float floatValue, float3 fontColor, uint2 currentUnormCoord, inout uint2 fixedUnormCoord, bool flipY, inout float3 color)
DrawInteger(intValue, fontColor, currentUnormCoord, fixedUnormCoord, color);
DrawCharacter('.', fontColor, currentUnormCoord, fixedUnormCoord, color);
DrawInteger(intValue, fontColor, currentUnormCoord, fixedUnormCoord, flipY, color);
DrawCharacter('.', fontColor, currentUnormCoord, fixedUnormCoord, flipY, color);
DrawInteger(fracValue, fontColor, currentUnormCoord, fixedUnormCoord, color);
DrawInteger(fracValue, fontColor, currentUnormCoord, fixedUnormCoord, flipY, color);
}
#endif
正在加载...
取消
保存