Billboard sprites


#1

Billboard sprites are flat planes with a texture applied to them that always rotate automatically to face the player’s camera. They are used often in videogames to create cheap foliage. Creating a large open field full of thousands of flowers without killing people’s computers is easy to pull off with billboard sprites. They are also used sometimes to create fake godrays (crepuscular rays).

You can technically create sprites already in HiFi through particles, but for the use cases that I require, I need billboard sprites that do not move nor disappear.

So it would be nice if a new Sprite Entity was added as an option. Or an alternative option would be to integrate this functionality into the Model Entity. Add a tickable “Sprite” checkbox that will make the model always face the visitor’s camera. This behavior would of course have to be client-sided. Come to think of it, this functionality would also be useful for web and text entities.


#2

Hi PetVal, text entities have a checkbox to always face them.


#3

I admit I haven’t messed with those much yet, good to know!

Now I just need that same functionality to be added to Model Entities too., :wink:


#4

Hi there.

Sprite Entity will not be added. You should use texture channels and a shader upon a cube. See also @Jherico example of the same on the “Dreaming” Domain.

Here is the FS file in it’s entirety

float aspect(vec2 v) {
    return v.x / v.y;
}

vec3 indexedTexture(float i) {
    vec2 uv = _position.xy;
    uv += 0.5;
    uv.y = 1.0 - uv.y;
    
    float targetAspect = iWorldScale.x / iWorldScale.y;
    float sourceAspect = 1.0;
    if (i > 3.0) {
        sourceAspect = aspect(iChannelResolution[0].xy);
    } else if (i > 2.0) {
        sourceAspect = aspect(iChannelResolution[1].xy);
    } else if (i > 1.0) {
        sourceAspect = aspect(iChannelResolution[2].xy);
    } else {
        sourceAspect = aspect(iChannelResolution[3].xy);
    }
    float aspectCorrection = sourceAspect / targetAspect;
    if (aspectCorrection > 1.0) {
        float offset = aspectCorrection - 1.0;
        float halfOffset = offset / 2.0;
        uv.y -= halfOffset;
        uv.y *= aspectCorrection;
    } else {
        float offset = 1.0 - aspectCorrection;
        float halfOffset = offset / 2.0;
        uv.x -= halfOffset;
        uv.x /= aspectCorrection;
    }
    
    if (any(lessThan(uv, vec2(0.0)))) {
        return vec3(0.0);
    }

    if (any(greaterThan(uv, vec2(1.0)))) {
        return vec3(0.0);
    }

    

    vec4 color;
    if (i > 3.0) {
        color = texture(iChannel0, uv);
    } else if (i > 2.0) {
        color = texture(iChannel1, uv);
    } else if (i > 1.0) {
        color = texture(iChannel2, uv);
    } else {
        color = texture(iChannel3, uv);
    }
    return color.rgb * max(0.5, sourceAspect) * max(0.9, fract(iWorldPosition.x));
}

float getProceduralColors(inout vec3 diffuse, inout vec3 specular, inout float shininess) {
    if (_position.z > -0.49) {
        discard;
    }

    float t = mod(iGlobalTime / 5.0, 4.0);
    float f = fract(t);
    vec3 color = indexedTexture(t);
    if (f > 0.9) {
        t = mod(t + 1.0, 4.0);
        vec3 color2 = indexedTexture(t);
        color = mix(color, color2, smoothstep(0.9, 1.0, f));
    }
    specular = color;
    return 1.0;
}

#5

Also curious if billboard sprites are a good solution in VR world where you see depth. I think the effect is disapointing in VR


#6


Thanks, I will check this out, though I was under the impression that shaders that use textures were not supported in HiFI. At least that was what I read in my searches here on the forum. I guess that info was outdated?


From a distance, sprites are fine even in VR. It’s when you walk up close that the illusion is broken, but that can be resolved by using real meshes near the player, and sprite versions of those meshes in the inaccessible distance.


#7

Sell also the"image3d" overlay type.