ospray icon indicating copy to clipboard operation
ospray copied to clipboard

subdv texturing issue

Open iqch opened this issue 4 years ago • 2 comments

Simple subdiv

_geometry = ospNewGeometry("subdivision");

	static float pos[] = { 
		-1.0,	-1.0,	0.0, 
		-1.0,	1.0,	0.0,
		1.0,	1.0,	0.0, 
		1.0,	-1.0,	0.0,
		-1.5,	0.0,	0.0
	};

	_positions = ospNewSharedData(pos, OSP_VEC3F, 5);
	ospCommit(_positions);

	ospSetObject(_geometry, "vertex.position", _positions);

	static unsigned int indices[] = { 0,1,2,3,0,1,4 };

	_indices = ospNewSharedData(indices, OSP_UINT, 7);
	ospCommit(_indices);

	ospSetObject(_geometry, "index", _indices);

	static float uv[] = {
		0.0,	0.0,
		0.0,	1.0,
		1.0,	1.0,
		1.0,	0.0,

		0.5,	0.5 };

	_texcoord = ospNewSharedData(uv, OSP_VEC2F, 5);
	ospCommit(_texcoord);

	ospSetObject(_geometry, "vertex.texcoord", _texcoord);

	unsigned int faces[] = { 4, 3 };
	_faces = ospNewSharedData(faces, OSP_UINT, 2);
	ospCommit(_faces);
	
	ospSetObject(_geometry, "face", _faces);

	ospSetFloat(_geometry, "level", 15.0f);

	ospSetInt(_geometry, "mode", OSP_SUBDIVISION_PIN_ALL);

	ospCommit(_geometry);

	_model = ospNewGeometricModel(_geometry);
	ospSetObject(_model, "material", renderParam->_material);
	ospCommit(_model);

	_group = ospNewGroup();

	OSPData geometricModels = ospNewSharedData1D(&_model, OSP_GEOMETRIC_MODEL, 1);
	ospCommit(geometricModels);
	ospSetObject(_group, "geometry", geometricModels);
	ospCommit(_group);

	_instance = ospNewInstance(_group);
	ospCommit(_instance);

	_instances = ospNewSharedData1D(&_instance, OSP_INSTANCE, 1);
	ospCommit(_instances);

	ospSetObject(_world, "instance", _instances);

Simple material _renderParam->_material = ospNewMaterial("pathtracer", "principled");

const char* file = "F:\\Clouds\\YandexDisk\\Projects\\OSPRayHd\\tests\\test2.jpg";
OSPTexture texture = HdOSPRayMaterial::LoadOIIOTexture2D(file,true);

ospSetObject(_renderParam->_material, "map_baseColor", texture);
ospCommit(_renderParam->_material);

Loading as from hdospray project

OSPTexture HdOSPRayMaterial::LoadOIIOTexture2D(const char * file, bool nearestFilter) { ImageInput* in = ImageInput::open(file); if (!in) { std::cerr << "#osp: failed to load texture '" << file << "'" << std::endl; return nullptr; }

const ImageSpec& spec = in->spec();
//osp::vec2i size;
ospcommon::math::vec2i size;
size.x = spec.width;
size.y = spec.height;
int channels = spec.nchannels;
const bool hdr = spec.format.size() > 1;
int depth = hdr ? 4 : 1;
const size_t stride = size.x * channels * depth;
unsigned char* data
       = (unsigned char*)malloc(sizeof(unsigned char) * size.y * stride);

in->read_image(hdr ? TypeDesc::FLOAT : TypeDesc::UINT8, data);
in->close();
ImageInput::destroy(in);

// flip image (because OSPRay's textures have the origin at the lower left
// corner)
for (int y = 0; y < size.y / 2; y++) 
{
    unsigned char* src = &data[y * stride];
    unsigned char* dest = &data[(size.y - 1 - y) * stride];
    for (size_t x = 0; x < stride; x++)
        std::swap(src[x], dest[x]);
}

OSPData ospData = ospNewSharedData2D(data, OSP_VEC3UC, size.x ,size.y); // I KNOW, BETTER TO RESOLVE DATATYPE
ospCommit(ospData);

OSPTexture ospTexture = ospNewTexture("texture2d");
OSPTextureFormat fmt = HdOSPRayMaterial::osprayTextureFormat(depth, channels);
ospSetInt(ospTexture, "format", (int)fmt);
ospSetInt(ospTexture, "flags",nearestFilter ? 
	OSP_TEXTURE_FILTER_NEAREST : OSP_TEXTURE_FILTER_BILINEAR);

ospSetObject(ospTexture, "data", ospData);

ospCommit(ospTexture);

return ospTexture;

};

poduces strange grayish borders on connection edges

2020-06-05_02-30-43 2020-06-05_02-32-41

framebuffer

    _frameBuffer = ospNewFrameBuffer(_width, _height, OSP_FB_RGBA32F,
           OSP_FB_COLOR | OSP_FB_VARIANCE | OSP_FB_ACCUM );

renderer

_renderer = ospNewRenderer("pathtracer");

ospSetInt(_renderer, "pixelSamples", 1);
ospCommit(_renderer);

rendering call ospRenderFrameBlocking(_frameBuffer, _renderer, _camera, _world);

iqch avatar Jun 04 '20 23:06 iqch

Looks like the gray from the right side bleeds in: textures in OSPRay are fetched with "REPEAT" border mode. A quick test to confirm this is to use OSP_TEXTURE_FILTER_NEAREST.

johguenther avatar Jun 05 '20 10:06 johguenther

Both produces same result, I tried. A bit later I will test it wit manually constructed map, to exclude oiio affection

пт, 5 июня 2020 г. в 13:44, Johannes Günther [email protected]:

Looks like the gray from the right side bleeds in: textures in OSPRay are fetched with "REPEAT" border mode. A quick test to confirm this is to use OSP_TEXTURE_FILTER_NEAREST.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/ospray/ospray/issues/426#issuecomment-639402852, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAQD2CNMABBVIQPIWLT27TTRVDEA3ANCNFSM4NTCDOKQ .

iqch avatar Jun 05 '20 11:06 iqch