Beispiel #1
0
        public override int?Fragment(FragmentShaderState state)
        {
            var color = _innerShader.Fragment(state);

            if (color == null)
            {
                return(null);
            }

            var intensity = state.Varying.PopFloat();

            if (intensity < 0)
            {
                return(BlackColor);
            }

            if (intensity > 1)
            {
                intensity = 1;
            }

            var intColor = new IntColor {
                Color = color.Value
            };

            intColor.Red   = (byte)(intColor.Red * intensity);
            intColor.Green = (byte)(intColor.Green * intensity);
            intColor.Blue  = (byte)(intColor.Blue * intensity);

            return(intColor.Color);;
        }
Beispiel #2
0
        public static Color AlphaBlend(Color foreground, Color background)
        {
            var frontInt = new IntColor(foreground);
            var backInt  = new IntColor(background);

            var alpha = frontInt.A;

            if (alpha == 0x00)
            {
                return(background);
            }

            var invAlpha  = 0xff - alpha;
            var backAlpha = backInt.A;

            if (backAlpha == 0xff)
            { // Opaque background case
                return(Color.FromRgba(
                           (alpha * frontInt.R + invAlpha * backInt.R) / 0xff,
                           (alpha * frontInt.G + invAlpha * backInt.G) / 0xff,
                           (alpha * frontInt.B + invAlpha * backInt.B) / 0xff,
                           0xff));
            }
            else
            { // General case
                backAlpha = backAlpha * invAlpha / 0xff;
                var outAlpha = alpha + backAlpha;
                return(Color.FromRgba(
                           (frontInt.R * alpha + backInt.R * backAlpha) / outAlpha,
                           (frontInt.G * alpha + backInt.G * backAlpha) / outAlpha,
                           (frontInt.B * alpha + backInt.B * backAlpha) / outAlpha,
                           outAlpha));
            }
        }
        private void fillOutLowerMips(VTexPage vTextPage, IntColor color, Func <IntColor, IntColor, bool> writePixel)
        {
            //Fill in lower (more textels) mip levels
            uint     x         = vTextPage.x;
            uint     y         = vTextPage.y;
            uint     w         = 1;
            uint     h         = 1;
            IntColor readPixel = new IntColor();

            for (int i = vTextPage.mip - 1; i >= 0; --i)
            {
                //This is probably really slow
                x = x << 1;
                y = y << 1;
                w = w << 1;
                h = h << 1;
                var mipLevelBitmap = fiBitmap[i];
                for (uint xi = 0; xi < w; ++xi)
                {
                    for (uint yi = 0; yi < h; ++yi)
                    {
                        readPixel.ARGB = mipLevelBitmap.getColorAtARGB(x + xi, y + yi, 0);
                        if (writePixel.Invoke(color, readPixel))
                        {
                            mipLevelBitmap.setColorAtARGB(color.ARGB, x + xi, y + yi, 0);
                        }
                    }
                }
            }
        }
Beispiel #4
0
        public override int?Fragment(FragmentShaderState state)
        {
            var z     = (byte)state.Varying.PopFloat();
            var color = new IntColor {
                Red = z, Green = z, Blue = z
            };

            return(color.Color);
        }
        internal void addPhysicalPage(PTexPage pTexPage)
        {
#if !DEBUG_MIP_LEVELS
            //Store 1x1 as mip 0, 2x2 as 1 4x4 as 2 etc, this way we can directly shift the decimal place
            //Then we will take fract from that
            //Store the page address as bytes
            var      vTextPage = pTexPage.VirtualTexturePage;
            IntColor color     = new IntColor();
            color.A = 255;
            //Reverse the mip level (0 becomes highest level (least texels) and highesetMip becomes the lowest level (most texels, full size)
            color.B = (byte)(highestMip - vTextPage.mip - 1); //Typecast bad, try changing the type in the struct to byte
            color.R = (byte)pTexPage.pageX;
            color.G = (byte)pTexPage.pageY;

            fiBitmap[vTextPage.mip].setColorAtARGB(color.ARGB, vTextPage.x, vTextPage.y, 0);
            fillOutLowerMips(vTextPage, color, (c1, c2) => c1.B - c2.B >= 0);
#endif
        }
        internal void removePhysicalPage(PTexPage pTexPage)
        {
#if !DEBUG_MIP_LEVELS
            var vTextPage = pTexPage.VirtualTexturePage;
            //Replace color with the one on the higher mip level
            IntColor color;
            if (vTextPage.mip + 1 < highestMip)
            {
                color = new IntColor(fiBitmap[vTextPage.mip + 1].getColorAtARGB((uint)vTextPage.x >> 1, (uint)vTextPage.y >> 1, 0));
            }
            else
            {
                color   = new IntColor();
                color.B = (byte)(highestMip - vTextPage.mip - 1);
            }
            byte replacementMipLevel = (byte)(highestMip - vTextPage.mip - 1);
            fiBitmap[vTextPage.mip].setColorAtARGB(color.ARGB, vTextPage.x, vTextPage.y, 0);
            fillOutLowerMips(vTextPage, color, (c1, c2) => c2.B == replacementMipLevel);
#endif
        }
Beispiel #7
0
        public override int?Fragment(FragmentShaderState state)
        {
            var color = _innerShader.Fragment(state);

            if (color == null)
            {
                return(null);
            }

            var intensity = state.Intensity;

            var intColor = new IntColor {
                Color = color.Value
            };

            intColor.Red   = (byte)(intColor.Red * intensity);
            intColor.Green = (byte)(intColor.Green * intensity);
            intColor.Blue  = (byte)(intColor.Blue * intensity);

            return(intColor.Color);
        }
Beispiel #8
0
        public override int?Fragment(FragmentShaderState state)
        {
            var color = _innerShader.Fragment(state);

            if (color == null)
            {
                return(null);
            }

            var normal = state.Varying.PopVector3();

            normal = Vector3.Normalize(normal);

            var intensity = Vector3.Dot(normal, _light);

            if (intensity < 0)
            {
                return(BlackColor);
            }

            if (intensity >= 1)
            {
                intensity = 1;
            }

            //const float intensityStepsCount = 5;
            //intensity = (float)Math.Floor(intensity * intensityStepsCount) / intensityStepsCount;

            var intColor = new IntColor {
                Color = color.Value
            };

            intColor.Red   = (byte)(intColor.Red * intensity);
            intColor.Green = (byte)(intColor.Green * intensity);
            intColor.Blue  = (byte)(intColor.Blue * intensity);

            return(intColor.Color);
        }
 public UInt32 ConvertCpuTexColorToHitProxyId(IntColor PixelColor)
 {
     return((UInt32)PixelColor.R << 24 | (UInt32)PixelColor.G << 16 | (UInt32)PixelColor.B << 8 | (UInt32)PixelColor.A << 0);
 }
Beispiel #10
0
 public IntEndPntPair(IntColor a, IntColor b)
 {
     A = a;
     B = b;
 }
 public IntEndPntPair(IntColor a, IntColor b)
 {
     this.A = a;
     this.B = b;
 }