小编Pio*_*iec的帖子

将8位颜色转换为RGB值

我正在使用"反射阴影贴图"在我的游戏引擎中实现全局照明.RSM具有颜色纹理.为了节省内存.我将24位值打包成8位值.好.我知道怎么收拾它.但是我该如何打开包装呢?我有意创建一个带有8位调色板的一维纹理,有255种不同的颜色.我的8位颜色将是该纹理中的像素索引.我不知道如何生成这种纹理.有没有数学方法将8位值转换为rgb?

@edit颜色采用以下格式:
RRR GGG BB

@ edit2:我正在打包我的颜色:

int packed = (red / 32 << 5) + (green / 32 << 2) + (blue / 64);
//the int is actually a byte, c# compiler is bitching if it's byte.
Run Code Online (Sandbox Code Playgroud)

@ edit3:
好吧,我觉得我找到了一种方法.告诉我,如果这是错的.

@ edit4这是错的......

int r = (packed >> 5) * 32;    
int g = ((packed >> 2) << 3) * 32;    
int b = (packed << 6) * 64;
Run Code Online (Sandbox Code Playgroud)

rgb bit-manipulation colors 8-bit

6
推荐指数
2
解决办法
8251
查看次数

寻找在 C# 中对数组求和的更快方法

在我目前正在开发的应用程序中,我必须有效地对相当大的向量数组求和。这是我的代码:

public List<double[, ,]> normalMaps;

public double[, ,] Mix(double[] weights, double gain)
{
    int w, h;
    w = normalMaps[0].GetLength(0);
    h = normalMaps[0].GetLength(1);

    double[, ,] ret = new double[w, h, 3];
    int normcount = normalMaps.Count;

    //for (int y = 0; y < h; y++)
    Parallel.For(0, h, y =>            
    {
        for (int x = 0; x < w; x++)
        {
            for (int z = 0; z < normcount; z++) 
            {
                ret[x, y, 0] += normalMaps[z][x, y, 0] * weights[z];
                ret[x, y, 1] …
Run Code Online (Sandbox Code Playgroud)

c#

2
推荐指数
1
解决办法
2700
查看次数

标签 统计

8-bit ×1

bit-manipulation ×1

c# ×1

colors ×1

rgb ×1