Files
cup_edit/materials/unlit_fixed_size.mat

50 lines
1.7 KiB
Plaintext

material {
name : UnlitFixedSize,
parameters : [
{
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;
}
}