Skip to content

Methods to get the SDF value #10

@liangjunchen88

Description

@liangjunchen88

Hey I am a new learner. Appreciate your excellent work for the package.

I am wondering how we can get the SDF value by sampling the sdf texture?
To be more specific, now we have SDFTexture.sdf(RenderTexture) and SDFTexture. worldToSDFTexCoords(Matrix4*4),
Below is what I thought:

          // Transform the vertex using the provided matrix
           var transformedVertex = m_worldToSDFTexCoords * new Vector4(vertex.x, vertex.y, vertex.z, 1.0f);
           var textureCoords = new Vector3(transformedVertex.x, transformedVertex.y, transformedVertex.z);
           // Ensure the texture coordinates are within the texture bounds
           textureCoords.x = Mathf.Clamp01(textureCoords.x);
           textureCoords.y = Mathf.Clamp01(textureCoords.y);
           textureCoords.z = Mathf.Clamp01(textureCoords.z);

           // How to read the SDF value from the texture at the specified texture coordinates? Like below?
           var sdfValue = m_sdf.GetPixel(textureCoords.x, textureCoords.y, textureCoords.z);

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions