Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

HPS

This is a very simple HPS sample to create a shell using Physically Based Rendering (or PBR).

More details are available about PBR and related properties under the Materials documentation.

Instructions

  1. Add the following code to a CHPSView User Code method in the MFC Sandbox application:

    Code Block
    void CHPSView::OnUserCode3()
    {
    	PortfolioKey portfolio = Database::CreatePortfolio();
    	SegmentKey my_seg = GetCanvas().GetFrontView().GetAttachedModel().GetSegmentKey();
    	my_seg.GetPortfolioControl().Push(portfolio);
    	{
    		auto load_png = [&](const char * file_name, const char * image_name) -> bool {
    			HPS::Image::ImportOptionsKit iok;
    			iok.SetFormat(HPS::Image::Format::Png);
    			ImageKit image_kit = Image::File::Import(file_name, iok);
    			ImageDefinition image_def = portfolio.DefineImage(image_name, image_kit);
    			TextureDefinition txr_def = portfolio.DefineTexture(image_name, image_def);
    			return true;
    		};
    
    		load_png("ship.png", "ship");
    
    		load_png("IMAGE_PBR_PATH/chipped-paint-metal/chipped-paint-metal-albedo.png", "chipped-paint-metal-albedo");
    		load_png("IMAGE_PBR_PATH/chipped-paint-metal/chipped-paint-ao.png", "chipped-paint-metal-ao");
    		load_png("IMAGE_PBR_PATH/chipped-paint-metal/chipped-paint-metal-metal.png", "chipped-paint-metal-metalness");
    		load_png("IMAGE_PBR_PATH/chipped-paint-metal/chipped-paint-metal-rough2.png", "chipped-paint-metal-roughness");
    		load_png("IMAGE_PBR_PATH/chipped-paint-metal/chipped-paint-metal-normal-dx.png", "chipped-paint-metal-normal");
    
    		GlyphKit glyphKit = GlyphKit();
    		glyphKit.SetRadius(0);
    		glyphKit.SetOffset(GlyphPoint(0, 0));
    
    		ImageGlyphElement imageGlyphElement;
    		imageGlyphElement.SetSource("ship");
    
    		GlyphElementArray glyphElements;
    		glyphElements.push_back(imageGlyphElement);
    		glyphKit.SetElements(glyphElements);
    
    		portfolio.DefineGlyph("shipGlyph", glyphKit);
    	}
    	SegmentKey shellSegment = my_seg.Subsegment();
    	shellSegment.GetVisibilityControl().SetEverything(false);
    
    	// Insert a small test shell with parameterization
    	ShellKey shellKey;
    	{
    		float const quad_points[] =
    		{
    			-0.75f, 0.75f, 0.0f,
    			0.75f, 0.75f, 0.0f,
    			0.75f, -0.75f, 0.0f,
    			-0.75f, -0.75f, 0.0f
    		};
    
    		int const quad_flist[] =
    		{
    			4, 0, 1, 2, 3
    		};
    
    		float const quad_uvs[] =
    		{
    			0.0f, 1.0f,
    			1.0f, 1.0f,
    			1.0f, 0.0f,
    			0.0f, 0.0f,
    		};
    
    		shellKey = shellSegment.InsertShell(4, (Point const *)&quad_points[0], 5, quad_flist);
    		shellKey.SetVertexParametersByRange(0, 8, quad_uvs, 2);
    	}
    
    	my_seg.GetVisibilityControl().SetEverything(false).SetFaces(true).SetLights(true);
    	my_seg.ReferenceGeometry(shellKey);
    
    	PBRMaterialKit pbr;
    	pbr.SetBaseColorMap("chipped-paint-metal-albedo");
    	pbr.SetNormalMap("chipped-paint-metal-normal");
    	pbr.SetMetalnessMap("chipped-paint-metal-metalness", HPS::Material::Texture::ChannelMapping::Red);
    	pbr.SetRoughnessMap("chipped-paint-metal-roughness", HPS::Material::Texture::ChannelMapping::Red);
    	pbr.SetOcclusionMap("chipped-paint-metal-ao", HPS::Material::Texture::ChannelMapping::Red);
    
    	my_seg.SetPBRMaterial(pbr);
    
    	my_seg.InsertDistantLight(Vector(0.4174f, 0.2564f, -0.8951f));
    }
  2. Download the Chipped Paint Metal PBR Material images archive from FreePBR.com called chipped-paint-metal-ue and install it on your system.

  3. Replace “IMAGE_PBR_PATH” in the code with the actual path to the unzipped Chipped Paint Metal files.

This should result in a scene similar to:

...

3DF

This is a very simple 3DF sample function to create a shell using Physically Based Rendering (or PBR).

More details are available about PBR and related properties under the Materials documentation.

Instructions

  1. Add the following test function to a HOOPS 3DF application:

    Code Block
    languagecpp
    int TestPBR ()
    {
    	if (!IsShaderDriver()) // make sure driver is ogl or dx11
    		return TEST_UNSUPPORTED;
    
        HC_Open_Segment ("a");
    		HC_Open_Segment("image"); {
    			HC_Set_Visibility("images=off");
    			auto load_png = [](const char * file_name, const char * image_name) -> bool {
    				FILE *file = fopen(file_name), "rb");
    				if (!file)
    					return false;
    				fseek(file, 0, SEEK_END);
    				int length = ftell(file);
    				fseek(file, 0, SEEK_SET);
    				unsigned char * buffer = new unsigned char[length];
    				fread(buffer, sizeof(unsigned char), length, file);
    				fclose(file);
    				HC_Insert_Compressed_Image(0, 0, 0, H_FORMAT_TEXT("png, name = %s", image_name), -1, -1, length, buffer);
    				delete[] buffer;
    				return true;
    			};
    
    			if (!load_png("IMAGE_PBR_PATH/sandstonecliff-albedo.png", "sandstonecliff-albedo"))
    				return TEST_IMAGE_MISSING;
    			if (!load_png("IMAGE_PBR_PATH/sandstonecliff-ao.png", "sandstonecliff-ao"))
    				return TEST_IMAGE_MISSING;
    			if (!load_png("IMAGE_PBR_PATH/sandstonecliff-metalness.png", "sandstonecliff-metalness"))
    				return TEST_IMAGE_MISSING;
    			if (!load_png("IMAGE_PBR_PATH/sandstonecliff-roughness.png", "sandstonecliff-roughness"))
    				return TEST_IMAGE_MISSING;
    			if (!load_png("IMAGE_PBR_PATH/sandstonecliff-normal-ue.png", "sandstonecliff-normal"))
    				return TEST_IMAGE_MISSING;
    		} HC_Close_Segment();
    
    		HC_Set_PBR_Material("sandstonecliff-albedo", "sandstonecliff-normal", nullptr,
    							"sandstonecliff-metalness", 0,
    							"sandstonecliff-roughness", 0,
    							"sandstonecliff-ao", 0,
    							nullptr,
    							1.0, 1.0, 1.0, 1.0, 1.0,
    							nullptr);
    		HC_Insert_Distant_Light(1, 1, -1);
    
    		HC_Open_Segment("shell"); {
    			float const quad_points[] = {
    				-0.75f, 0.75f, 0.0f,
    				0.75f, 0.75f, 0.0f,
    				0.75f, -0.75f, 0.0f,
    				-0.75f, -0.75f, 0.0f
    			};
    			int const quad_flist[] = {4, 0, 1, 2, 3};
    			float const quad_uvs[] = {
    				0.0f, 1.0f,
    				1.0f, 1.0f,
    				1.0f, 0.0f,
    				0.0f, 0.0f,
    			};
    
    			HC_Set_Visibility("no edges, no markers");
    			HC_KEY	shell_key = HC_Insert_Shell(4, quad_points, 5, quad_flist);
    			HC_MSet_Vertex_Parameters(shell_key, 0, 4, 2, quad_uvs);
    		} HC_Close_Segment();
    	
        HC_Close_Segment();
    
        return TEST_COMPLETE;
    }

  2. Download the Sand Stone Cliff images archive from FreePBR.com called sandstonecliff-ue and install it on your system.

  3. Replace “IMAGE_PBR_PATH” in the code with the actual path to the unzipped Sand Stone Cliff files.

...

Filter by label (Content by label)
showLabelsfalse
max5
spacescom.atlassian.confluence.content.render.xhtml.model.resource.identifiers.SpaceResourceIdentifier@2318a5
sortmodified
showSpacefalse
sortreversemodifiedtrue
typepagereversetrue
cqllabel = "PBR" and type = "page" and space = "KBHV"
labelskb-how-to-article
Page Properties
hiddentrue

Related issues

Jira Legacy
serverId43f371d0-7091-3b3c-9683-94c0b791358d
keySDHV-10062