Git Product home page Git Product logo

Comments (6)

maluoi avatar maluoi commented on June 4, 2024

Thanks for writing this up! I'm curious how you're setting these, I tried to repro this, but when everything is sized right, it does seem to be behaving as expected!

I did have a moment where C# was coercing bytes and ushorts into ints, and tripping up my generic code. It did look a little similar to what you have here, is it possible you've got some of that going on?

My test was two textures of each format, red 4px grid, one at 32x32, and one at 42x32.
image

Code for this image is over here: https://github.com/StereoKit/StereoKit/blob/develop/Examples/StereoKitTest/Tests/TestTextures.cs

from stereokit.

mvvvv avatar mvvvv commented on June 4, 2024

I'm using the example given there : https://stereokit.net/Pages/StereoKit/Tex/SetColors.html but I changed the size from 128 to 138

    let width = 138;
    let height = 138;
    let mut raw_dots128 = Vec::new();
    let mut raw_dots_byte = Vec::new();
    let mut raw_dots_u16 = Vec::new();
    let mut raw_dots_u32 = Vec::new();
    for y in 0..height {
        for x in 0..width {
            if x % 128 == 0
                || (x + 1) % 128 == 0
                || (x - 1) % 128 == 0
                || y % 128 == 0
                || (y + 1) % 128 == 0
                || (y - 1) % 128 == 0
            {
                raw_dots.push(line_color);
                raw_dots128.push(line_color128);
                raw_dots_byte.push(220);
                raw_dots_u16.push(1220);
                raw_dots_u32.push(1220);
            } else if x % 64 == 0 || y % 64 == 0 {
                raw_dots.push(sub_line_color);
                raw_dots128.push(sub_line_color128);
                raw_dots_byte.push(0);
                raw_dots_u16.push(30000);
                raw_dots_u32.push(12200);
            } else {
                raw_dots.push(base_color);
                raw_dots128.push(base_color128);
                raw_dots_byte.push(50);
                raw_dots_u16.push(64000);
                raw_dots_u32.push(256 * 256 * 256 * 250);
            }
        }
    }

    let color_dots = raw_dots.as_slice();
    let color_dots128 = raw_dots128.as_slice();
    let color_dots_byte = raw_dots_byte.as_slice();
    let color_dots_u16 = raw_dots_u16.as_slice();
    let color_dots_u32 = raw_dots_u32.as_slice();

from stereokit.

mvvvv avatar mvvvv commented on June 4, 2024

it works when the size is 2^x but not with 42 or other values.
And with a size of 17 I also have the problem with R16. Very odd.

WidthXHeight 16x17 works well but 17x16 don't. The problem seems to be around the width value.

from stereokit.

maluoi avatar maluoi commented on June 4, 2024

Translating your code into C# and adding some random colors, I get this:
image

Only real change I made was that R32 needs to be a float, and not a u32. I tried with a couple of other weird sizes, but still couldn't get any of the weird stuff you're seeing!

Right now I'm guessing this is either some rust syntax thing, or a rust binding issue?

Here's my C# code, which I slotted into the TestTexture.cs file.

Color line_color128     = Color.HSV(0.6f, 0.05f, 1);
Color sub_line_color128 = Color.HSV(0.6f, 0.05f, 0.6f);
Color base_color128     = Color.HSV(0.6f, 0.1f, 0.25f);
Color32 line_color     = line_color128;
Color32 sub_line_color = sub_line_color128;
Color32 base_color     = base_color128;

int width  = 138;
int height = 138;
List<Color32>raw_dots      = new();
List<Color>  raw_dots128   = new();
List<byte>   raw_dots_byte = new();
List<ushort> raw_dots_u16  = new();
List<float>  raw_dots_f32  = new();
for (int y=0; y<height; y+=1) {
	for (int x=0; x<width; x+=1) {
		if (x % 128 == 0
			|| (x + 1) % 128 == 0
			|| (x - 1) % 128 == 0
			|| y % 128 == 0
			|| (y + 1) % 128 == 0
			|| (y - 1) % 128 == 0)
		{
			raw_dots     .Add(line_color);
			raw_dots128  .Add(line_color128);
			raw_dots_byte.Add(220);
			raw_dots_u16 .Add(1220);
			raw_dots_f32 .Add(.2f);
		}
		else if (x % 64 == 0 || y % 64 == 0) {
			raw_dots     .Add(sub_line_color);
			raw_dots128  .Add(sub_line_color128);
			raw_dots_byte.Add(0);
			raw_dots_u16 .Add(30000);
			raw_dots_f32 .Add(.2f);
		}
		else
		{
			raw_dots     .Add(base_color);
			raw_dots128  .Add(base_color128);
			raw_dots_byte.Add(50);
			raw_dots_u16 .Add(64000);
			raw_dots_f32 .Add(1);
		}
	}
}
Tex t = new Tex(TexType.Image, TexFormat.Rgba32);
t.SetColors(width, height, raw_dots.ToArray());
Material m = Material.Default.Copy();
m[MatParamName.DiffuseTex] = t;
testTextures.Add(new FormatTest { format = t.Format, mat = m, tex = t });

t = new Tex(TexType.Image, TexFormat.Rgba128);
t.SetColors(width, height, raw_dots128.ToArray());
m = Material.Default.Copy();
m[MatParamName.DiffuseTex] = t;
testTextures.Add(new FormatTest { format = t.Format, mat = m, tex = t });

t = new Tex(TexType.Image, TexFormat.R8);
t.SetColors(width, height, raw_dots_byte.ToArray());
m = Material.Default.Copy();
m[MatParamName.DiffuseTex] = t;
testTextures.Add(new FormatTest { format = t.Format, mat = m, tex = t });

t = new Tex(TexType.Image, TexFormat.R16);
t.SetColors(width, height, raw_dots_u16.ToArray());
m = Material.Default.Copy();
m[MatParamName.DiffuseTex] = t;
testTextures.Add(new FormatTest { format = t.Format, mat = m, tex = t });

t = new Tex(TexType.Image, TexFormat.R32);
t.SetColors(width, height, raw_dots_f32.ToArray());
m = Material.Default.Copy();
m[MatParamName.DiffuseTex] = t;
testTextures.Add(new FormatTest { format = t.Format, mat = m, tex = t });

from stereokit.

maluoi avatar maluoi commented on June 4, 2024

Yeah, actually, when you say this in rust

let mut raw_dots_byte = Vec::new();
let mut raw_dots_u16  = Vec::new();

Can you verify that it's ending up the correct type? I see no explicit mention of type anywhere in your code. From what I can read there, I'd expect it to be a 32 bit int.

from stereokit.

mvvvv avatar mvvvv commented on June 4, 2024

R16 is working well with the right type now, Thanks

Rust is managing inference so well that you don't have to import most of the type you're using. I'm using a middle function that decides of the value contained by the array then the value of the Vec.

I declared the type as you said but R8 is still having this strange behaviour, R16 only for 17x16 and R32 works well now.

from stereokit.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.