Browse Source

Got textures working

* Update readme with instructions for creating a textured mesh
* Darkened background color
pitch-detection
Macoy Madson 2 years ago
parent
commit
9697e487b4
  1. 32
      ReadMe.org
  2. 2
      src/OgreInitialize.cake
  3. 31
      test/data/Materials/Monkey_Fur.material
  4. 49
      test/src/OgreHlms.cpp

32
ReadMe.org

@ -40,6 +40,38 @@ You are now ready to export. Open your model or create one, then do ~File -> Exp
- Don't *export materials*. These are v1 materials as far as I know, which don't work with Ogre 2
- Don't *export scene*. I don't use these files
- Ensure *mesh export version* is set to ~v2~
** Materials and Textures
The ~blender2ogre~ plugin doesn't do much to help with Ogre v2 materials.
For a textured mesh:
- UV unwrap mesh
- Create new image for texturing
- Add a new material and set the diffuse input to your new image. Name the material what you'd like it to be called in the game as well
- Paint the texture as desired
- In the Image Editor window, do ~Image -> Save As~ and save the image to a lossless format (I used PNG)
- Run the following to convert the image to ~.dds~ (which will be a larger file, but will load /drastically/ faster):
#+BEGIN_SRC sh
convert assets/MyTexture.png data/Materials/Textures/MyTexture.dds
#+END_SRC
- Export the mesh. Because export materials doesn't do us any good yet, we only export the mesh to get the updated UV coordinates and material (name only)
- Create a ~.material~ text file like below:
#+BEGIN_SRC C
hlms MyMaterial pbs
{
roughness 0.4
fresnel 1.33
diffuse_map MyTexture.dds
// normal_map Rocks_Normal.tga
// roughness_map Rocks_Spec.tga
// specular_map Rocks_Diffuse.tga
}
#+END_SRC
- Finally, add the material to the ~Ogre::Item~:
#+BEGIN_SRC C++
item->setDatablock("MyMaterial");
#+END_SRC
This is only necessary if the mesh didn't already have the Material name set.
** Converting ~.mesh.xml~ to ~.mesh~
You shouldn't need to do this step if you set ~OGRETOOLS_XML_CONVERTER~, but in case blender2ogre didn't recognize it, here's how I worked around it:

2
src/OgreInitialize.cake

@ -210,7 +210,7 @@
(var workspaceName (const (in Ogre String)) "Main Workspace")
;; const IdString definitionNameId = workspaceName;
;; TODO: This needs initializer parameters
(var-construct backgroundColour (const (in Ogre ColourValue)) 0.2f 0.2f 0.2f)
(var-construct backgroundColour (const (in Ogre ColourValue)) 0.0302f 0.03f 0.03f)
(on-call-ptr compositorManager createBasicWorkspaceDef
workspaceName backgroundColour (call (in Ogre IdString)))
(on-call-ptr compositorManager addWorkspace

31
test/data/Materials/Monkey_Fur.material

@ -1,24 +1,11 @@
// Monkey_Fur generated by blender2ogre 2020-10-15 18:57:37.105310
material Monkey_Fur {
receive_shadows on
technique {
pass {
diffuse 0.208633 0.074452 0.015482 1.0
specular 0.488345 0.482978 0.480619 1.0 64.0
alpha_to_coverage off
colour_write on
depth_check on
depth_func less_equal
illumination_stage
light_clip_planes off
light_scissor off
normalise_normals off
polygon_mode solid
scene_blend_op add
shading gouraud
transparent_sorting on
hlms MonkeyFur pbs
{
roughness 0.4
fresnel 1.33
}
}
}
diffuse_map MonkeyTexture.dds
// normal_map Rocks_Normal.tga
// roughness_map Rocks_Spec.tga
// specular_map Rocks_Diffuse.tga
}

49
test/src/OgreHlms.cpp

@ -25,7 +25,7 @@ void ogreCreatePbsSpheres(Ogre::Root* root, Ogre::SceneManager* sceneManager)
const int numX = 8;
const int numZ = 8;
const float armsLength = 1.0f;
const float armsLength = 1.f;
const float startX = (numX - 1) / 2.0f;
const float startZ = (numZ - 1) / 2.0f;
@ -33,9 +33,10 @@ void ogreCreatePbsSpheres(Ogre::Root* root, Ogre::SceneManager* sceneManager)
Ogre::SceneNode* rootSceneNode = sceneManager->getRootSceneNode();
const Ogre::String meshNameV2 = "Sphere.mesh";
// const Ogre::String meshNameV2 = "Suzanne.mesh";
{
Ogre::MeshPtr v2Mesh = Ogre::MeshManager::getSingleton().load(
"Sphere.mesh", Ogre::ResourceGroupManager::AUTODETECT_RESOURCE_GROUP_NAME);
meshNameV2, Ogre::ResourceGroupManager::AUTODETECT_RESOURCE_GROUP_NAME);
}
for (int x = 0; x < numX; ++x)
@ -47,13 +48,27 @@ void ogreCreatePbsSpheres(Ogre::Root* root, Ogre::SceneManager* sceneManager)
hlmsPbs->createDatablock(datablockName, datablockName, Ogre::HlmsMacroblock(),
Ogre::HlmsBlendblock(), Ogre::HlmsParamVec()));
Ogre::TextureGpu* texture = textureMgr->createOrRetrieveTexture(
"SaintPetersBasilica.dds", Ogre::GpuPageOutStrategy::Discard,
Ogre::TextureFlags::PrefersLoadingFromFileAsSRGB, Ogre::TextureTypes::TypeCube,
Ogre::ResourceGroupManager::AUTODETECT_RESOURCE_GROUP_NAME,
Ogre::TextureFilter::TypeGenerateDefaultMipmaps);
// Reflection texture
{
Ogre::TextureGpu* texture = textureMgr->createOrRetrieveTexture(
"SaintPetersBasilica.dds", Ogre::GpuPageOutStrategy::Discard,
Ogre::TextureFlags::PrefersLoadingFromFileAsSRGB, Ogre::TextureTypes::TypeCube,
Ogre::ResourceGroupManager::AUTODETECT_RESOURCE_GROUP_NAME,
Ogre::TextureFilter::TypeGenerateDefaultMipmaps);
datablock->setTexture(Ogre::PBSM_REFLECTION, texture);
}
// Diffuse texture
{
Ogre::TextureGpu* texture = textureMgr->createOrRetrieveTexture(
"MonkeyTexture.dds", Ogre::GpuPageOutStrategy::Discard,
Ogre::TextureFlags::PrefersLoadingFromFileAsSRGB, Ogre::TextureTypes::Type2D,
Ogre::ResourceGroupManager::AUTODETECT_RESOURCE_GROUP_NAME,
Ogre::TextureFilter::TypeGenerateDefaultMipmaps);
datablock->setTexture(Ogre::PBSM_DIFFUSE, texture);
}
datablock->setTexture(Ogre::PBSM_REFLECTION, texture);
datablock->setDiffuse(Ogre::Vector3(0.0f, 1.0f, 0.0f));
datablock->setRoughness(std::max(0.02f, x / std::max(1.0f, (float)(numX - 1))));
@ -66,13 +81,17 @@ void ogreCreatePbsSpheres(Ogre::Root* root, Ogre::SceneManager* sceneManager)
Ogre::SCENE_DYNAMIC);
}
// // TODO this is a hack that relies on ogre-load-mesh being called some time before this
// // This is because "sphere.mesh" is an old-style mesh which I need a converter for or something
// Ogre::Item* item = sceneManager->createItem(
// "Suzanne.mesh Imported", Ogre::ResourceGroupManager::AUTODETECT_RESOURCE_GROUP_NAME,
// Ogre::SCENE_DYNAMIC);
item->setDatablock(datablock);
// // TODO this is a hack that relies on ogre-load-mesh being called some time before
// this
// // This is because "sphere.mesh" is an old-style mesh which I need a converter for or
// something Ogre::Item* item = sceneManager->createItem(
// "Suzanne.mesh Imported",
// Ogre::ResourceGroupManager::AUTODETECT_RESOURCE_GROUP_NAME, Ogre::SCENE_DYNAMIC);
// if (z % 2 == 0)
item->setDatablock(datablock);
// else
// item->setDatablock("MonkeyFur");
item->setVisibilityFlags(0x000000002);
Ogre::SceneNode* sceneNode = ((Ogre::SceneNode*)rootSceneNode->createChild());

Loading…
Cancel
Save