Results 1 to 8 of 8

Thread: Alpha Blend, multiple alpha masks and textures?

  1. #1
    PGDCE Developer
    Join Date
    Jun 2010
    Location
    California, USA
    Posts
    25

    Question Alpha Blend, multiple alpha masks and textures?

    Okay, I am developing a level editor for my current game project, and while most of the level are small and I will be able to just create a static mesh for the ground and I could always use a single texture file from photoshop

    However, I would like to explore what is called Texture Splatting by many people. But I believe the technical term is Alpha-Blending. I am more or less wanting to know if this already exists in GLScene? if so I do not want to reinvent the wheel, but if not I will have to figure out a way to manage multiple materials and blend them together.

    As far as I can tell I can use a GLMultiMaterialShader to preform a pre render alpha blend of 2 materials, then use the result as a material to blend with the objects main material.

    So, any ideas?

  2. #2
    PGDCE Developer
    Join Date
    Jun 2010
    Location
    California, USA
    Posts
    25

    So far my results

    Alright I got something working kind of.

    However not the exact result I am looking for





    Where I actually want the mask to be applied to the tiles of the other textures.
    I am having trouble thinking of how to explain this.

    Code:
    with GLMaterialLibrary1 do
      begin
        with AddTextureMaterial('grass_alpha', 'grass_alpha.jpg') do
        begin
          Material.Texture.TextureMode := tmModulate;
          Material.BlendingMode := bmAdditive;
          Texture2Name := 'grass_texture';
        end;
    
        with AddTextureMaterial('grass_texture', 'grass_texture.jpg') do
        begin
          //Material.Texture.MappingMode := tmmCubeMapReflection;
        end;
    
      end;
    
      with GLMaterialLibrary2 do
      begin
        // Pass : 1
        with AddTextureMaterial('Pass1', 'dirt_texture.jpg') do
        begin
          //Material.Texture.TextureMode := tm;
          //Material.BlendingMode := bmAdditive;
          //Texture2Name := 'TestGrass';
        end;
    
        // Pass : 2
        with TGLLibMaterial.Create(GLMaterialLibrary2.Materials) do
        begin
          Name := 'TestGrass';
          Material.MaterialLibrary := GLMaterialLibrary1;
          Material.LibMaterialName := 'grass_alpha';
          //material.Texture.TextureMode := tmBlend;
          //Material.BlendingMode := bmAdditive;
        end;
      end;
    and then the I have a material in the GLMaterialLibrary1 that has a shader that blends all of the materials in GLMaterialLibrary2 to create its texture.

    Any suggestions?

  3. #3
    PGDCE Developer
    Join Date
    Jun 2010
    Location
    California, USA
    Posts
    25
    Alright I have a new idea however, I am not sure how this could be implemented in GLScene.

    To start off here is a better definition of what I am looking for: To be able to blend tiled (repeated X and Y) textures over a mesh (a terrain).
    The effect would give the ability to "Paint" a texture in my level editor.

    Now the Idea I have to make this look how I want it:
    Somehow to apply the texture over the whole surface and then apply the blend_mask on each tiled texture over the surface.

    So for each material (texture) i have in the MaterialLibrary I will need to have Non tiled Blend Mask.
    Then somehow apply the mask over the tiled texture that it is linked to. Then to do this for all of the textures in Library.

    I have a feeling I might be going about this all wrong, because its starting to make my head hurt thinking about it.

  4. #4
    PGDCE Developer
    Join Date
    Jun 2010
    Location
    California, USA
    Posts
    25

    Got it working :)

    Alright I finally got it figured out

    GLScene actually has the ability to do what I am looking for with just configuring of the Material Library.

    I am going to assume that since there is no replies on my posts other than myself, either this whole thing was a dumb question, no one uses glscene, or nobody does this with glscene if it is used

    Alright First a picture of what the end result will look like:


    So I am still using the previously posted image resources for the brown and green and the same blending mask. [DISCLAIMER] "I assume this is how this works in GLScene however I have not looked into the code to verify that this is how it is actually coded"

    Explanation:
    I have Two material libraries setup
    GLMatLib1 and GLMatLib2

    GLMatLib1 contains all of the AlphaBlendMaps and the Textures, It also includes a special Material that does not have a texture, but points to a Material Combine Shader.

    GLMatLib2 contains references to all of the Blended Texture and Alpha Maps along with a base non blended texture (in my case the Dirt Texture 'Brown')

    The special Shader Material in GLMatLib1 is set as the material for the mesh that I have for the terrain. The shader is called in place of a static texture file, and it Gets all of the Materials in GLMatLib2 and depending on their settings on each material, it will blend them into a single material to be used on the mesh.

    So I had the concept correct from the beginning, however You may scale, stretch a texture in the MaterialLibrary. So to get the effect i am looking for the Scale (size) of the alpha mask should be made the size of the whole mesh. This will then cause the Textures to be tiled to the mesh and the Alpha Mask to be the stretched once over the mesh. Causing the effect I am looking for.

    Code to add the materials:
    Code:
    with GLMaterialLibrary1 do
      begin
        with AddTextureMaterial('grass_alpha', 'grass_alpha.jpg') do
        begin
          //Material.Texture.TextureWrap := twNone;
          //showmessage(IntToStr(Material.Texture.TexWidth));
    
          Material.Texture.TextureWrap := twNone;
    
          Material.Texture.TextureMode := tmModulate;
          Material.BlendingMode := bmAdditive;
          TextureScale.X := 0.1;
          TextureScale.Y := 0.1;
    
          Texture2Name := 'grass_texture';
        end;
    
        with AddTextureMaterial('grass_texture', 'grass_texture.jpg') do
        begin
          //Material.Texture.MappingMode := tmmCubeMapReflection;
        end;
    
      end;
    
      with GLMaterialLibrary2 do
      begin
        // Pass : 1
        AddTextureMaterial('Pass1', 'dirt_texture.jpg');
        
        // Pass : 2
        with TGLLibMaterial.Create(GLMaterialLibrary2.Materials) do
        begin
          Name := 'TestGrass';
          Material.MaterialLibrary := GLMaterialLibrary1;
          Material.LibMaterialName := 'grass_alpha';
        end;
      end;
    Thanks, for reading this and sticking to it, even though I got no replies
    It's alright though, I don't think many people use GLScene.

    P.S. I will post an article on my site with a demo file when I get it all situated and cleaned up. Then I will link to it here so you can test it out.

  5. #5
    PGDCE Developer
    Join Date
    Jun 2010
    Location
    California, USA
    Posts
    25

    Not so done after all.

    Well after finishing that last reply, I realized that I wasn't actually finished with my code. I continued to add a third pass for a Dark Grass texture and it all went crazy. almost like there was a bloom effect of the textures. So, I started doing some research into the MultiMaterialShader and it isn't exactly what I thought it would be. And it would require a lot more to start combining multiple layers more than just the 2.

    So I am currently working on a hybrid version of the GLTexCombineShader of my own to allow for, Material1, Material2, BlendMask images and it will give you the combination of those two. I then plan to use this mixer again with every output per layer of mask and texture I have to add. I am hoping that this will result in the effect I am looking for.

    Any suggestions or directions for help are welcome.

    Thanks,

  6. #6
    PGDCE Developer
    Join Date
    Jun 2010
    Location
    California, USA
    Posts
    25
    So it seems that if I scale the grass_alpha texture that the texture2 that is applied gets the same scale.

    What I am looking for is to tile grass_texture and then stretch the grass_alpha mask and the tile dirt_texture. ten blend that together to get the above image results. Above looks to be the way I want it however it is not actually working the way I want it to. I would like to hear from somebody, if you have no clue what I am asking for just tell me. Or even if you know but have no clue how to do it, some possible suggestions, or even a library that has this capability in it that I could look at.

    this is all I have been working on for 3 days now, and I still don't even have one reply

  7. #7
    You wrote a post on the GLScene forum, so maybe yarunderoaker will help you.
    For me it is too complicated and I think it is better not to use GLScene for this - just write a tool to create any texture you want and then insert it to GLMaterialLibrary.

    Another solution is to write your own shader material and use transparency of mask file (.png) for the final color:
    gl_FragColor = TextureColor;
    gl_FragColor.a = MaskTextureColor.a;

  8. #8
    PGDCE Developer
    Join Date
    Jun 2010
    Location
    California, USA
    Posts
    25
    Well I think I have found the solution however I do not think that I will be able to implement it using GLScene. So, I guess I am going to be working on my own Material and Texturing code The key part I need is multiple texture maps for a single mesh that overlap

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •