Results 1 to 8 of 8

Thread: Alpha Blend, multiple alpha masks and textures?

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    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.

  2. #2
    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,

  3. #3
    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

  4. #4
    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;

  5. #5
    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
  •