I have setup a TEffectNode and initialized with all the field data that is used in CastleTerrain… The effect is added to the appearance node for my terrain mesh and setup texture layers paralleling the layers in CastleTerrain.
function TTerrainMesh.InitAppearance : TAppearanceNode;
var Effect : TEffectNode;
VertexPart, FragmentPart: TEffectPartNode;
i : integer;
begin
Result := inherited;
Effect := TEffectNode.Create;
Effect.Language := slGLSL;
Effect.UniformMissing := umIgnore;
Result.SetEffects([effect]);
Effect.AddCustomField( TSFVec4f.Create(Effect, true, 'uv_scale', Vector4( 1, 1, 1, 1)));
Effect.AddCustomField(TSFVec4f.Create(Effect, true, 'metallic', Vector4( 1, 1, 1, 1)));
Effect.AddCustomField(TSFVec4f.Create(Effect, true, 'roughness', Vector4( 1, 1, 1, 1)));
Effect.AddCustomField(TSFFloat.Create(Effect, true, 'height_1', 4));
Effect.AddCustomField(TSFFloat.Create(Effect, true, 'height_2', 8));
TTextureLayer.CreateForTerrain( self, 1, 'castle-data:/terrain/textures/island_sand2_d.jpg', effect );
TTextureLayer.CreateForTerrain( self, 2, 'castle-data:/terrain/textures/ground_mud2_d.jpg', effect );
TTextureLayer.CreateForTerrain( self, 3, 'castle-data:/terrain/textures/mntn_green_d.jpg', effect );
TTextureLayer.CreateForTerrain( self, 4, 'castle-data:/terrain/textures/moss_ground_d.jpg', effect );
Effect.AddCustomField(TSFFloat.Create(Effect, true, 'layers_influence', 1.0));
Effect.AddCustomField(TSFFloat.Create(Effect, true, 'steep_emphasize', 2.0));
{ initialize 2 EffectPart nodes (one for vertex shader, one for fragment shader) }
FragmentPart := TEffectPartNode.Create;
FragmentPart.ShaderType := stFragment;
FragmentPart.Contents := {$I terrain.fs.inc};
VertexPart := TEffectPartNode.Create;
VertexPart.ShaderType := stVertex;
VertexPart.Contents := {$I terrain.vs.inc};
Effect.SetParts([FragmentPart, VertexPart]);
// result.Texture := initTexture( 'castle-data:/grid2.png' );
end;
But the terrain ends up just being the untextured phong shaded white. I am not sure if the glsl is running correctly or getting an error. Is there a way to see?
Or perhaps I am missing a connection somewhere to make the effect apply?