I am currently trying to port this method to OpenGL. The Shader is working fine so far, but I have a problem with combining the different render passes.
Using the inbuild Materialtypes I can accomplish Multipasseffects easily:
Code: Select all
// First Pass
Node->setMaterialType(video::EMT_SOLID);
Node->setMaterialTexture(0,driver->getTexture("Data/textures/tileable_concrete_wall.jpg"));
Node->render();
//Second Pass
Node->setMaterialType(video::EMT_TRANSPARENT_ALPHA_CHANNEL);
Node->setMaterialTexture(0,driver->getTexture("Data/textures/BigSpark.png"));
Node->setMaterialTexture(1,driver->getTexture("Data/textures/metal_diamond.jpg"));
Node->render();
However, when using my Shader strange things happen. When using a CubeSceneNode it looks "quite" right:
(Sand, Gras and Stone = 1. Pass | Earth and Snow = 2. Pass) Two Problems occur: The second pass has a black outline and sometimes when the camera gets closer to the cube the first pass is not rendered anymore, just the second.
When I use a mesh (e.g. a terrain) only the second pass is rendered, I never see the first pass:
Shader code:
Vertex
Code: Select all
void main()
{
gl_TexCoord[0] = gl_MultiTexCoord0;
gl_Position = ftransform();
}
Code: Select all
uniform sampler2D SplatMap;
uniform sampler2D ColRed;
uniform sampler2D ColGreen;
uniform sampler2D ColBlue;
void main(){
vec4 SplatCol=texture2D(SplatMap,gl_TexCoord[0].xy);
vec4 RedCol=texture2D(ColRed,gl_TexCoord[0].xy*10);
vec4 GreenCol=texture2D(ColGreen,gl_TexCoord[0].xy*10);
vec4 BlueCol=texture2D(ColBlue,gl_TexCoord[0].xy*10);
gl_FragColor=(vec4(SplatCol.r*RedCol+SplatCol.g*GreenCol+SplatCol.b*BlueCol))*vec4(1,1,1,SplatCol.a);
}
Code: Select all
//Set up Cube or Mesh
Node = mgr->addCubeSceneNode();//mgr->addMeshSceneNode(mgr->getMesh("Data/terrain.b3d"));
Node->setMaterialFlag(video::EMF_LIGHTING,false);
Node->setMaterialFlag(video::EMF_NORMALIZE_NORMALS,true);
Node->setScale(core::vector3df(5,5,5));
video::IGPUProgrammingServices* gpu = mgr->getVideoDriver()->getGPUProgrammingServices();
if (gpu)
{
ITerrainSplattingShader *callback = new ITerrainSplattingShader();
ShaderMaterial1 = gpu->addHighLevelShaderMaterialFromFiles(
"Data/shader/terrainsplatting.vert", "vertMain", video::EVST_VS_1_1,
"Data/shader/terrainsplatting.frag", "pixelMain", video::EPST_PS_1_1,
callback, video::EMT_TRANSPARENT_ALPHA_CHANNEL);
callback->drop();
Node->setMaterialType((video::E_MATERIAL_TYPE)ShaderMaterial1);
}
Code: Select all
// First Pass
Node->setMaterialTexture(0,driver->getTexture("Data/textures/splat_1.tga"));
Node->setMaterialTexture(1,driver->getTexture("Data/textures/Felsen.jpg"));
Node->setMaterialTexture(2,driver->getTexture("Data/textures/Gras.jpg"));
Node->setMaterialTexture(3,driver->getTexture("Data/textures/Sand.jpg"));
Node->render();
// Second Pass
Node->setMaterialTexture(0,driver->getTexture("Data/textures/splat_2.tga"));
Node->setMaterialTexture(1,driver->getTexture("Data/textures/Schnee.jpg"));
Node->setMaterialTexture(2,driver->getTexture("Data/textures/Steppe.jpg"));
Node->render();
Code: Select all
DWORD alpha, srcblend, destblend;
device->GetRenderState(D3DRS_ALPHABLENDENABLE, &alpha);
device->GetRenderState(D3DRS_SRCBLEND, &srcblend);
device->GetRenderState(D3DRS_DESTBLEND, &destblend);
device->SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE);
device->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA);
device->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA);
Can anyone make sense out of this?
edit: Final Code here http://irrlicht.sourceforge.net/forum/v ... =9&t=38676
greetings