show some love to hyper
This commit is contained in:
1 parent
6da13bac1c
commit
15c8fce77c
52 files changed
+4091
-2008
No files matched your search
@@ -11,6 +11,7 @@ public class ThemeShaderBinder : MonoBehaviour
|
||||
private Texture2D _texture;
|
||||
private Color[] _colorCache;
|
||||
private int textureSize = 128;
|
||||
private Gradient _theme;
|
||||
|
||||
private void Start() {
|
||||
if (preferences == null) {
|
||||
@@ -24,20 +25,38 @@ public class ThemeShaderBinder : MonoBehaviour
|
||||
UpdateBinding();
|
||||
}
|
||||
|
||||
private void InitialiseTexture() {
|
||||
Debug.Log("Reinitialising spectrum texture...");
|
||||
_texture = new Texture2D(textureSize, 1);
|
||||
_colorCache = new Color[textureSize];
|
||||
_texture.name = $"ThemeTexture{textureSize}";
|
||||
public Color DecomposeHdrColor(Color linearColorHdr) {
|
||||
var maxColorComponent = linearColorHdr.maxColorComponent;
|
||||
float scaleFactor = 191f / maxColorComponent;
|
||||
float exposure = Mathf.Log(255f / scaleFactor) / Mathf.Log(2f);
|
||||
float factor = 1f / exposure;
|
||||
|
||||
if (exposure <= 1f) {
|
||||
return linearColorHdr;
|
||||
}
|
||||
|
||||
float r = linearColorHdr.r * factor;
|
||||
float g = linearColorHdr.g * factor;
|
||||
float b = linearColorHdr.b * factor;
|
||||
|
||||
return new Color(r, g, b, linearColorHdr.a);
|
||||
}
|
||||
|
||||
private void UpdateTexture() {
|
||||
// init
|
||||
if (_texture == null) InitialiseTexture();
|
||||
if (_theme == preferences.Theme()) return;
|
||||
|
||||
Debug.Log("Reinitialising Theme texture...");
|
||||
_texture = new Texture2D(textureSize, 1);
|
||||
_theme = preferences.Theme();
|
||||
_colorCache = new Color[textureSize];
|
||||
_texture.name = $"ThemeTexture{textureSize}";
|
||||
_texture.wrapMode = TextureWrapMode.Clamp;
|
||||
|
||||
Gradient theme = preferences.Theme();
|
||||
for (int i = 0; i < textureSize; i++) {
|
||||
_colorCache[i] = theme.Evaluate((float)i / (float)textureSize);
|
||||
// Color decomposed = DecomposeHdrColor(_theme.Evaluate((float)i / (float)textureSize));
|
||||
if (_theme == null) return;
|
||||
Color color = _theme.Evaluate((float)i / (float)textureSize);
|
||||
_colorCache[i] = color;
|
||||
}
|
||||
|
||||
_texture.SetPixels(_colorCache);
|
||||
|
||||
Reference in new issue
Block a user