#CameraServer

29 messages · Page 1 of 1 (latest)

umbral anchor
#

Is it possible to use the CameraServer class on platforms other than apple without the use of external programs yet? I asked this like 3 months ago and was wondering if anything has changed with it

#

(The main platform I care about here is linux but it working on windows is fine too)

golden ether
#

4.4 added camera support on Linux but I think Windows is still not supported

umbral anchor
#

well that means I can make a camera based game now

#

just cant do a windows release for a while

umbral anchor
#

uniform sampler2D camera_y;
uniform sampler2D camera_CbCr;

void fragment() {
    vec3 color;
    color.r = texture(camera_y, UV).r;
    color.gb = texture(camera_CbCr, UV).rg - vec2(0.5, 0.5);
    
    // YCbCr -> SRGB conversion
    // Using BT.709 which is the standard for HDTV
    color.rgb = mat3(
                        vec3(1.00000, 1.00000, 1.00000),
                        vec3(0.00000, -0.18732, 1.85560),
                        vec3(1.57481, -0.46813, 0.00000)) *
                color.rgb;
    
    COLOR = vec4(color, 1.0);
}```

```extends Sprite2D

@export var camera_name: String = ""
var camera: CameraFeed

# Called when the node enters the scene tree for the first time.
func _ready():
    print("cameras:")
    for feed in CameraServer.feeds():
        feed.set_format(0,{"output":"grayscale"})
        var name = feed.get_name()
        print(name)
        
        # if camera_name is left empty, use the first available camera
        if camera == null and (camera_name == "" or name == camera_name):
            camera = feed
    
    if camera == null:
        print("no matching camera")
        return
        
    print("using camera ", camera, " (", camera.get_name(), ")")
    
    camera.feed_is_active = true
    
    var cam_tex_y = material.get_shader_parameter("camera_y")
    var cam_tex_CbCr = material.get_shader_parameter("camera_CbCr")
    
    cam_tex_y.camera_feed_id = camera.get_id()
    cam_tex_CbCr.camera_feed_id = camera.get_id()
    
    material.set_shader_parameter("camera_y", cam_tex_y)
    material.set_shader_parameter("camera_CbCr", cam_tex_CbCr)```
#

theres basically all the code

golden ether
#

I don't know anything about camera color formats but it might just be the wrong one

#

I see yCbCr conversion in the shader which is one of the camera formats, but you need to check what your camera uses

umbral anchor
#

YCBCR seems to be what the camera is using (I changed the one line to feed.set_format(0,{"output":"copy"}))

#

unless I did the dictionary wrong?

golden ether
#

the docs are not crystal clear but that seems like a reasonable assumption

umbral anchor
#

would be nice if there was some example code

#

oh boy I sure do hope someone with very specific knowledge in this field shows up to help while I'm asleep

umbral anchor
#

Ok I'm conscious again

umbral anchor
#

ok since I'm already here might as well ask is there a way to get the color of a pixel on the camera?

golden ether
#

yeah you can call get_image() on the CameraTexture which will give you a copy of the texture's image data at that time, that can be accessed by scripts

#

that's an Image object which has all sorts of methods to access its data

#

you might have to replicate the color conversion done in the shader, if needed

umbral anchor
golden ether
#

pretty sure there's nothing built-in, no, but maybe someone made something like that as an extension?

umbral anchor
#

Yeah I was expecting that lol

#

I'll look around when I get home, hopefully there's a solution

#

I should just make evil dance dash (only works on the platforms dance dash doesn't work on [aka everything but windows lmao])

umbral anchor
#

managed to figure that out nvm