Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lookup table to increase styling performance #4662

Closed
SunBlack opened this issue Nov 17, 2016 · 3 comments
Closed

Lookup table to increase styling performance #4662

SunBlack opened this issue Nov 17, 2016 · 3 comments

Comments

@SunBlack
Copy link

If you want to match a id from batch table to a fixed color you have to write something like this:

tileset.style = new Cesium3DTileStyle({
	"color" : {
		"conditions" : [
			["(${MYPROPERTY} === 0)", "rgb(196, 196, 196)"],
			["(${MYPROPERTY} === 1)", "rgb(64, 64, 64)"],
			["(${MYPROPERTY} === 2)", "rgb(128, 128, 0)"],
			["(${MYPROPERTY} === 3)", "rgb(128, 0, 0)"],
			["true", "rgb(255, 255, 255)"],
		]
	}
});

The result of this condition is currently

vec4 getColorFromStyle() 
{ 
    if ((czm_tiles3d_style_MYPROPERTY == 0.0)) 
    { 
        return vec4(0.7686274509803922, 0.7686274509803922, 0.7686274509803922, 1.0); 
    } 
    else if ((czm_tiles3d_style_MYPROPERTY == 1.0)) 
    { 
        return vec4(0.25098039215686274, 0.25098039215686274, 0.25098039215686274, 1.0); 
    } 
    else if ((czm_tiles3d_style_MYPROPERTY == 2.0)) 
    { 
        return vec4(0.5019607843137255, 0.5019607843137255, 0.0, 1.0); 
    } 
    else if ((czm_tiles3d_style_MYPROPERTY == 3.0)) 
    { 
        return vec4(0.5019607843137255, 0.0, 0.0, 1.0); 
    } 
    else if (true) 
    { 
        return vec4(1.0, 1.0, 1.0, 1.0); 
    } 
    return vec4(1.0); 
}

I don't believe this has still a good performance in case you have thousands of ids, so it would be nice if cesium does support lookup tables or has a way to integrate something like this without need to touch core of Cesium.

So maybe a syntax like this would be nice:

tileset.style = new Cesium3DTileStyle({
	"color" : {
		"lookup" : [{
			"name" : "COLOR_MAPPING1",
			"expression" : "MYPROPERTY",
			"values": [
				["0", "rgb(196, 196, 196)"],
				["1", "rgb(64, 64, 64)"],
				["2", "rgb(128, 128, 0)"],
				["3", "rgb(128, 0, 0)"],
				["default", "rgb(255, 255, 255)"],
			]
		},
		{
			"name" : "COLOR_MAPPING2",
			"expression" : "MYPROPERTY",
			"values": [
				["0", "rgb(196, 196, 0)"],
				["1", "rgb(64, 0, 64)"],
				["2", "rgb(128, 128, 32)"],
				["3", "rgb(128, 0, 32)"],
				["default", "rgb(255, 255, 255)"],
			]
		}],
		"color" : {
			"conditions" : [
				["(${MYCONDITION} === 0)", "lookup(COLOR_MAPPING1, ${MYCONDITION})"],
				["(${MYCONDITION} === 1)", "lookup(COLOR_MAPPING2, ${MYCONDITION})"]
				["true", "rgb(255, 255, 255)"],
			]
		}
	}
});

The lookup table can be implement with a 1D-texture (maybe we can extend the lookuptable to a 2D-texture, too). Another way is maybe to use a switch-statement, which are supported by glsl, too. We should do a performance comparison to check which way is best to handle large condition tables.

@lilleyse
Copy link
Contributor

If you want to match a id from batch table to a fixed color you have to write something like this

It could be that the shader backend is not suitable for this use case. Have you checked out the PointCloudBatched tileset? When points are grouped together with BATCH_ID the point cloud uses the JavaScript styling engine instead. This makes it possible to get features (in this case groups of points) and style them with the Cesium API via Cesium3DTileFeature.

However this also means that all points batched together share the same metadata. This could be a problem depending on your use case.

Basically the main reservation I have about the look up table approach is the complexity it adds to the spec. Switch-case is definitely better for some cases, but I would still be worried about storing all those values in the shader text itself rather than the texture approach you suggested.

@pjcozzi
Copy link
Contributor

pjcozzi commented Nov 18, 2016

@SunBlack you may also want to consider just storing unique per-point colors instead of mapping the id to color at runtime.

Also, when you have suggestions for changing the spec, please submit an issue to the https://github.com/AnalyticalGraphicsInc/3d-tiles repo so we can keep an archive of spec decisions in that repo. Thanks!

@pjcozzi
Copy link
Contributor

pjcozzi commented Dec 20, 2016

@SunBlack please see my above comment:

@SunBlack you may also want to consider just storing unique per-point colors instead of mapping the id to color at runtime.

And open a new issue in https://github.com/AnalyticalGraphicsInc/3d-tiles if there is a spec update you want to discuss.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants