feat: Rename Gizmo material to UnlitFixedSize, and expose methods for using this material on other entities. Also exposes new methods for setting single float parameters.
This commit is contained in:
54
materials/unlit_fixed_size.mat
Normal file
54
materials/unlit_fixed_size.mat
Normal file
@@ -0,0 +1,54 @@
|
||||
material {
|
||||
name : UnlitFixedSize,
|
||||
parameters : [
|
||||
{
|
||||
type : mat4,
|
||||
name : transform,
|
||||
precision : high
|
||||
},
|
||||
{
|
||||
type : float4,
|
||||
name : baseColorFactor,
|
||||
precision : low
|
||||
},
|
||||
{
|
||||
type: float, // the number of world-space units between the camera and the (unscaled) gizmo
|
||||
name: scale,
|
||||
precision: low
|
||||
}
|
||||
],
|
||||
depthWrite : true,
|
||||
depthCulling : false,
|
||||
shadingModel : unlit,
|
||||
blending: transparent,
|
||||
variantFilter : [ skinning, shadowReceiver, vsm ],
|
||||
culling: none,
|
||||
instanced: false,
|
||||
vertexDomain: object
|
||||
}
|
||||
|
||||
vertex {
|
||||
void materialVertex(inout MaterialVertexInputs material) {
|
||||
// the object should have the same size (in screen-space), no matter the distance from the camera
|
||||
// scale the model-space vertex positions by the distance from the camera
|
||||
vec4 modelSpace = getPosition();
|
||||
vec4 worldSpace = getWorldFromModelMatrix() * modelSpace;
|
||||
vec4 viewSpace = getViewFromWorldMatrix() * worldSpace;
|
||||
float distanceFromCamera = length(viewSpace.xyz);
|
||||
modelSpace.xyz *= (distanceFromCamera / materialParams.scale);
|
||||
|
||||
worldSpace = getWorldFromModelMatrix() * modelSpace;
|
||||
material.worldPosition = worldSpace;
|
||||
//vec4 clipSpace = getClipFromWorldMatrix() * worldSpace;
|
||||
//clipSpace.z = 0.99f;
|
||||
//material.worldPosition = getWorldFromClipMatrix() * clipSpace;
|
||||
}
|
||||
}
|
||||
|
||||
fragment {
|
||||
void material(inout MaterialInputs material) {
|
||||
prepareMaterial(material);
|
||||
material.baseColor = materialParams.baseColorFactor;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user