Add uv offsets to autogenerated 2D uv coordinates.
The original render_gl3.c code does the following: ``` mjr_setf4(plane, 0.5*scl[0], 0, 0, -0.5); glTexGenfv(GL_S, GL_OBJECT_PLANE, plane); mjr_setf4(plane, 0, -0.5*scl[1], 0, -0.5); glTexGenfv(GL_T, GL_OBJECT_PLANE, plane); ``` The 4th component of the GL_OBJECT_PLANE function effectively describes a UV-offset for the generates uvs. In our filament implementation, we had overlooked this 4th component. PiperOrigin-RevId: 863181644 Change-Id: I60688117ea2019257da683cdda0c7d389dd5af1e
This commit is contained in:
committed by
Copybara-Service
parent
f022faadf7
commit
e35c981f48
@@ -23,6 +23,7 @@ material {
|
||||
{ type : float, name : GlossinessFactor },
|
||||
{ type : float, name : EmissiveFactor },
|
||||
{ type : float3, name : UvScale },
|
||||
{ type : float3, name : UvOffset },
|
||||
{ type : sampler2d, name : BaseColor }
|
||||
],
|
||||
variables : [
|
||||
@@ -38,7 +39,7 @@ vertex {
|
||||
|
||||
fragment {
|
||||
void material(inout MaterialInputs material) {
|
||||
vec2 uv = variable_vertex_pos.xy * materialParams.UvScale.xy;
|
||||
vec2 uv = variable_vertex_pos.xy * materialParams.UvScale.xy + materialParams.UvOffset.xy;
|
||||
|
||||
prepareMaterial(material);
|
||||
material.baseColor = materialParams.BaseColorFactor;
|
||||
|
||||
@@ -24,6 +24,7 @@ material {
|
||||
{ type : float, name : GlossinessFactor },
|
||||
{ type : float, name : EmissiveFactor },
|
||||
{ type : float3, name : UvScale },
|
||||
{ type : float3, name : UvOffset },
|
||||
{ type : sampler2d, name : BaseColor }
|
||||
],
|
||||
variables : [
|
||||
@@ -39,7 +40,7 @@ vertex {
|
||||
|
||||
fragment {
|
||||
void material(inout MaterialInputs material) {
|
||||
vec2 uv = variable_vertex_pos.xy * materialParams.UvScale.xy;
|
||||
vec2 uv = variable_vertex_pos.xy * materialParams.UvScale.xy + materialParams.UvOffset.xy;
|
||||
|
||||
prepareMaterial(material);
|
||||
material.baseColor = materialParams.BaseColorFactor;
|
||||
|
||||
@@ -484,8 +484,15 @@ void Drawable::UpdateMaterial(const mjvGeom& geom, bool use_segid_color) {
|
||||
params.uv_scale.y = 2.0f * plane_scale / tile_size_y;
|
||||
}
|
||||
|
||||
// We want to do the equivalent of:
|
||||
// mjr_setf4(splane, 0.5 * scl.x, 0, 0, -0.5);
|
||||
// mjr_setf4(tplane, 0, -0.5 * scl.y, 0, -0.5);
|
||||
// glTexGenfv(GL_S, GL_OBJECT_PLANE, splane);
|
||||
// glTexGenfv(GL_T, GL_OBJECT_PLANE, tplane);
|
||||
params.uv_scale.x = 0.5f * params.uv_scale.x;
|
||||
params.uv_scale.y = 0.5f * params.uv_scale.y;
|
||||
params.uv_scale.y = -0.5f * params.uv_scale.y;
|
||||
params.uv_offset.x = -0.5f;
|
||||
params.uv_offset.y = -0.5f;
|
||||
} else {
|
||||
// For cube maps, if `tex_uniform` is true, then scale the texture so that
|
||||
// it covers a 1x1 area of world space rather than the area of the object.
|
||||
|
||||
@@ -110,6 +110,9 @@ void Material::UpdateMaterialInstances() {
|
||||
if (material->hasParameter("UvScale")) {
|
||||
instance->setParameter("UvScale", params_.uv_scale);
|
||||
}
|
||||
if (material->hasParameter("UvOffset")) {
|
||||
instance->setParameter("UvOffset", params_.uv_offset);
|
||||
}
|
||||
|
||||
if (instances_[DrawMode::kSegmentation]) {
|
||||
instances_[DrawMode::kSegmentation]->setParameter(
|
||||
|
||||
@@ -54,6 +54,7 @@ class Material {
|
||||
filament::math::float4 segmentation_color = {1, 1, 1, 1};
|
||||
filament::math::float2 tex_repeat = {1, 1};
|
||||
filament::math::float3 uv_scale = {1, 1, 1};
|
||||
filament::math::float3 uv_offset = {0, 0, 0};
|
||||
float specular = -1.0f;
|
||||
float glossiness = -1.0f;
|
||||
float metallic = -1.0f;
|
||||
|
||||
Reference in New Issue
Block a user