Hello,
Does the TerrainBlendEdit xml both hlsl glsl still work for Urho3D 1.40? I at the point where I am mixing the textures to get the cliff texture, etc? The old method isn’t working.
This was the old method.
/// Set component
terrainProcedural -> Initialize();
terrainProcedural -> SetDimensions(DEFAULTSIZE,DEFAULTSIZE);
terrainProcedural -> SetWorldType(terrainrule.worldtype, terrainrule.subworldtype, terrainrule.sealevel, terrainrule.creationtime);
terrainProcedural -> SetOctaves(override, octaves, persistence, octave1,octave2,octave3,octave4,octave5,octave6,octave7,octave8);
/// Generate Produracel map
terrain->GenerateProceduralHeightMap(terrainrule);
Image * producedHeightMapImage = new Image(context_);
producedHeightMapImage -> SetSize(DEFAULTSIZE+1,DEFAULTSIZE+1, 1, 4);
producedHeightMapImage -> SetData(terrain->GetData());
terrain->SetMaterial(cache->GetResource<Material>("Materials/TerrainEdit.xml"));
/// Get heightmap for texture blend
Image * terrainHeightMap= new Image(context_);
terrainHeightMap->SetSize(DEFAULTSIZE+1,DEFAULTSIZE+1,1,4);
terrainHeightMap ->SetData(terrain -> GetHeightMap () -> GetData());
terrainHeightMap -> FlipVertical();
/// Generte image
/// Define heightmap texture
int bw=DEFAULTSIZE+1,bh=DEFAULTSIZE+1;
Texture2D * blendtex=new Texture2D(context_);
blendtex -> SetNumLevels(1);
blendtex -> SetSize(0,0,0,TEXTURE_DYNAMIC);
terrain-> GetMaterial() -> SetTexture(TU_DIFFUSE ,blendtex);
/// Shared pointer for blend texture
SharedPtr<Image> blend;
SharedPtr<Image> blendMap;
blend = new Image(context_);
blend -> SetSize(bw,bh,1,4);
blend -> Clear(Color(1,0,0,0));
blendMap = new Image(context_);
blendMap -> SetSize(bw,bh,1,4);
blendMap -> Clear(Color(0,0,0,0));
float steep=0.0f;
float steepforlerp=0.0f;
/// create blend here
for(unsigned int x=0; x<bw; x++)
{
for(unsigned int y=0; y<bh; y++)
{
Color terrainHeightvalue=terrainHeightMap->GetPixel(x,y);
switch(terrainrule.worldtype)
{
case WORLD_DESERT:
{
Color currentcolor = blend -> GetPixel(x,y);
Color resultcolor=currentcolor.Lerp(Color(0.0f,1.0f,0.0f,0.0f), 1.0f);
blend-> SetPixel(x,y,resultcolor);
}
break;
default:
/// Compare to sealavel
if(terrainHeightvalue.r_<terrainrule.sealevel)
{
Color currentcolor = blend -> GetPixel(x,y);
// float mix=1.0f-((float)terrainHeightvalue.r_/terrainrule.sealevel);
float mix=(float)terrainHeightvalue.r_/terrainrule.sealevel;
float sterpforlerp=cutoff(mix,0.05f,0.040f,false);
Color resultcolor=currentcolor.Lerp(Color(0.0f,1.0f,0.0f,0.0f), sterpforlerp);
blend-> SetPixel(x,y,resultcolor);
}
break;
}
/// blend cliff
Vector2 nworld=Vector2(x/(float)bw, y/(float)bh);
Vector3 worldvalue=NormalizedToWorld( producedHeightMapImage,terrain,nworld);
Vector3 normalvalue=terrain->GetNormal(worldvalue);
steep=1.0f-normalvalue.y_;
steepforlerp=cutoff(steep,0.05f,0.040f,false);
Color currentcolor = blend -> GetPixel(x,y);
int mixfactor=rand()%99;
float mix=(float)(mixfactor+1)/100;
// Color resultcolor=currentcolor.Lerp(Color(0,0,mix,1.0f-mix), steepforlerp);
Color resultcolor=currentcolor.Lerp(Color(0,0,mix,1.0f-mix), steepforlerp);
blend-> SetPixel(x,y,resultcolor);
}
}
/// Rotate image and assign texture
blend -> FlipVertical ();
environmentbuild_ -> SetTextureMap(blend);
blendtex ->SetData(blend, true);
RigidBody* terrainbody = terrainNode->CreateComponent<RigidBody>();
CollisionShape* terrainshape = terrainNode->CreateComponent<CollisionShape>();
terrainbody->SetCollisionLayer(1);
terrainshape->SetTerrain();
Vector3 position(0.0f,0.0f);
position.y_ = terrain->GetHeight(position) + 1.0f;
/// Add node
manager_->AddGeneratedObject(terrainNode);
/// Position character
Node * characternode_ = Existence->scene_->CreateChild("Character");
characternode_->SetPosition(Vector3(0.0f, position.y_ , 0.0f));
/// Get the materials
Material * skyboxMaterial = skybox->GetMaterial();
/// Change environment
Existence->GenerateSceneUpdateEnvironment(terrainrule);
/// Set component
terrainProcedural -> Initialize();
terrainProcedural -> SetDimensions(DEFAULTSIZE,DEFAULTSIZE);
terrainProcedural -> SetWorldType(terrainrule.worldtype, terrainrule.subworldtype, terrainrule.sealevel, terrainrule.creationtime);
terrainProcedural -> SetOctaves(override, octaves, persistence, octave1,octave2,octave3,octave4,octave5,octave6,octave7,octave8);
/// Generate Produracel map
terrain->GenerateProceduralHeightMap(terrainrule);
Image * producedHeightMapImage = new Image(context_);
producedHeightMapImage -> SetSize(DEFAULTSIZE+1,DEFAULTSIZE+1, 1, 4);
producedHeightMapImage -> SetData(terrain->GetData());
terrain->SetMaterial(cache->GetResource<Material>("Materials/TerrainEdit.xml"));
/// Get heightmap for texture blend
Image * terrainHeightMap= new Image(context_);
terrainHeightMap->SetSize(DEFAULTSIZE+1,DEFAULTSIZE+1,1,4);
terrainHeightMap ->SetData(terrain -> GetHeightMap () -> GetData());
terrainHeightMap -> FlipVertical();
/// Generte image
/// Define heightmap texture
int bw=DEFAULTSIZE+1,bh=DEFAULTSIZE+1;
Texture2D * blendtex=new Texture2D(context_);
blendtex -> SetNumLevels(1);
blendtex -> SetSize(0,0,0,TEXTURE_DYNAMIC);
terrain-> GetMaterial() -> SetTexture(TU_DIFFUSE ,blendtex);
/// Shared pointer for blend texture
SharedPtr<Image> blend;
SharedPtr<Image> blendMap;
blend = new Image(context_);
blend -> SetSize(bw,bh,1,4);
blend -> Clear(Color(1,0,0,0));
blendMap = new Image(context_);
blendMap -> SetSize(bw,bh,1,4);
blendMap -> Clear(Color(0,0,0,0));
float steep=0.0f;
float steepforlerp=0.0f;
/// create blend here
for(unsigned int x=0; x<bw; x++)
{
for(unsigned int y=0; y<bh; y++)
{
Color terrainHeightvalue=terrainHeightMap->GetPixel(x,y);
switch(terrainrule.worldtype)
{
case WORLD_DESERT:
{
Color currentcolor = blend -> GetPixel(x,y);
Color resultcolor=currentcolor.Lerp(Color(0.0f,1.0f,0.0f,0.0f), 1.0f);
blend-> SetPixel(x,y,resultcolor);
}
break;
default:
/// Compare to sealavel
if(terrainHeightvalue.r_<terrainrule.sealevel)
{
Color currentcolor = blend -> GetPixel(x,y);
// float mix=1.0f-((float)terrainHeightvalue.r_/terrainrule.sealevel);
float mix=(float)terrainHeightvalue.r_/terrainrule.sealevel;
float sterpforlerp=cutoff(mix,0.05f,0.040f,false);
Color resultcolor=currentcolor.Lerp(Color(0.0f,1.0f,0.0f,0.0f), sterpforlerp);
blend-> SetPixel(x,y,resultcolor);
}
break;
}
/// blend cliff
Vector2 nworld=Vector2(x/(float)bw, y/(float)bh);
Vector3 worldvalue=NormalizedToWorld( producedHeightMapImage,terrain,nworld);
Vector3 normalvalue=terrain->GetNormal(worldvalue);
steep=1.0f-normalvalue.y_;
steepforlerp=cutoff(steep,0.05f,0.040f,false);
Color currentcolor = blend -> GetPixel(x,y);
int mixfactor=rand()%99;
float mix=(float)(mixfactor+1)/100;
// Color resultcolor=currentcolor.Lerp(Color(0,0,mix,1.0f-mix), steepforlerp);
Color resultcolor=currentcolor.Lerp(Color(0,0,mix,1.0f-mix), steepforlerp);
blend-> SetPixel(x,y,resultcolor);
}
}
/// Rotate image and assign texture
blend -> FlipVertical ();
environmentbuild_ -> SetTextureMap(blend);
blendtex ->SetData(blend, true);
RigidBody* terrainbody = terrainNode->CreateComponent<RigidBody>();
CollisionShape* terrainshape = terrainNode->CreateComponent<CollisionShape>();
terrainbody->SetCollisionLayer(1);
terrainshape->SetTerrain();
Vector3 position(0.0f,0.0f);
position.y_ = terrain->GetHeight(position) + 1.0f;
/// Add node
manager_->AddGeneratedObject(terrainNode);
/// Position character
Node * characternode_ = Existence->scene_->CreateChild("Character");
characternode_->SetPosition(Vector3(0.0f, position.y_ , 0.0f));
/// Get the materials
Material * skyboxMaterial = skybox->GetMaterial();
/// Change environment
Existence->GenerateSceneUpdateEnvironment(terrainrule);