google/filament

Clip space transform cannot affect the Z component

wddl opened this issue · 1 comments

wddl commented

Describe the bug
I have set the material.clipSpaceTransform, but it does not change the value of the z-component. The code is as follows 。The output of the vertex shader in RenderDoc is as follows: According to the clipSpaceTransform in the following code, the z-value should be 0.
image
`
filament::math::float3 QUAD_VERTICES_TEST[4] = {
{-2, -2 , 0.3},
{2 , -2 , 0.3},
{2 , 2 , 0.3},
{-2 , 2 , 0.3}
};
uint16_t QUAD_INDICES[6] = { 0, 1, 2 ,0 , 2 , 3 };

void GussianSplat::setupTest(filament::Engine* pEngein, filament::Scene* pScene, filament::View* pView)
{
filament::math::mat4f clipTran;
clipTran[0] = { 0.25 , 0 , 0 , 0 };
clipTran[1] = { 0 , 0.25 , 0 , 0 };
clipTran[2] = { 0 , 0 , 0 ,0 };
clipTran[3] = { 0 , 0 , 0 ,1 };

Skybox* pSkybox = Skybox::Builder().color({ 0.0, 0.0, 0.0, 0.0 }).build(*pEngein);
pScene->setSkybox(pSkybox);
pView->setPostProcessingEnabled(false);

MaterialBuilder::init();
MaterialBuilder builder;
builder.depthCulling(false);
builder.blending(MaterialBuilder::BlendingMode::TRANSPARENT);
builder.shading(MaterialBuilder::Shading::UNLIT);
builder.instanced(true);
builder.vertexDomain(MaterialBuilder::VertexDomain::DEVICE);
builder.parameter("clipTran", MaterialBuilder::UniformType::MAT4);

std::string vertexShader = R"SHADER(
	void materialVertex(inout MaterialVertexInputs material) {
	
	material.clipSpaceTransform = materialParams.clipTran;
	
}

)SHADER";

std::string fragmentShader = R"SHADER(
void material(inout MaterialInputs material) {			
	prepareMaterial(material);					
	material.baseColor = vec4(1.0 , 0.0 , 0.0 , 1.0);			
}

)SHADER";

builder.materialVertex(vertexShader.c_str());
builder.material(fragmentShader.c_str());
Package const pkg = builder.build(pEngein->getJobSystem());
filament::Material* pMat = Material::Builder().package(pkg.getData(), pkg.getSize()).build(*pEngein);
pMat->getDefaultInstance()->setParameter("clipTran", clipTran);

VertexBuffer* pVb = VertexBuffer::Builder()
	.vertexCount(4)
	.bufferCount(1)
	.attribute(VertexAttribute::POSITION, 0, VertexBuffer::AttributeType::FLOAT3, 0, 12)
	.build(*pEngein);
pVb->setBufferAt(*pEngein, 0,
	VertexBuffer::BufferDescriptor(QUAD_VERTICES_TEST, 48, nullptr));
IndexBuffer* pIb = IndexBuffer::Builder()
	.indexCount(6)
	.bufferType(IndexBuffer::IndexType::USHORT)
	.build(*pEngein);
pIb->setBuffer(*pEngein,
	IndexBuffer::BufferDescriptor(QUAD_INDICES, 12, nullptr));
Entity entity = EntityManager::get().create();
RenderableManager::Builder(1)
	.material(0, pMat->getDefaultInstance())
	.geometry(0, RenderableManager::PrimitiveType::TRIANGLES, pVb, pIb, 0, 6)
	.instances(1)
	.culling(false)
	.receiveShadows(false)
	.castShadows(false)
	.build(*pEngein, entity);
pScene->addEntity(entity);

}`
May I ask what the reason is for this?

To Reproduce
Steps to reproduce the behavior:

  1. run above code
  2. view the vertex shader output in the ‘renderdoc’ tool

Expected behavior
The transform Can change the z value

Screenshots

Logs

Desktop (please complete the following information):

  • OS: [windows 11]
  • GPU: []
  • Backend: [OpenGL]

Smartphone (please complete the following information):

  • Device: []
  • OS: [Android]

Additional context

wddl commented

@romainguy
Thank you to reply!
But i need to set gl_Position, if in device domain cannot change z value, how can the gl_position be modified?