51 lines
1.8 KiB
Plaintext
51 lines
1.8 KiB
Plaintext
material {
|
|
name : Gizmo,
|
|
parameters : [
|
|
{
|
|
type : mat4,
|
|
name : transform,
|
|
precision : high
|
|
},
|
|
{
|
|
type : float4,
|
|
name : color,
|
|
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) {
|
|
|
|
// we want to ensure the gizmo has the same size (in screen-space), no matter the distance from the camera
|
|
// we do this by scaling 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 / 4.0f); // divide by 4 so that the size is equivalent to the camera being 4 world-space units away from the (unscaled) gizmo
|
|
|
|
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.color;
|
|
}
|
|
}
|
|
|