Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

[SOLVED]How Blend textures using the alpha channel of a third texture?

Discussion in 'Shaders' started by IsGreen, Jun 29, 2014.

  1. IsGreen

    IsGreen

    Joined:
    Jan 17, 2014
    Posts:
    206
    Programming shaders is one of the things I dislike about the game programming, but seeing that have released versions of two visual editors shaders I have decided to create a first shader type "Blend Textures', using a third type AlphaMask texture.

    I do not know what types of parameters or operations are necessary to get the alpha channel of a texture, to merge two others.



    As shown in the image had thought of using vector type XYZ to get the texture color 'Blend' and other vector W to get the alpha channel of the texture 'AlphaMask'.

    I have not found an operation called 'Blend' to merge the textures, so I used the 'Add' operation, is that correct? Or should perform another process?

    Besides, I get a compile error that says 'vert' is not fully initialized.

    See if anyone can lend a hand.
     
  2. shaderbytes

    shaderbytes

    Joined:
    Nov 11, 2010
    Posts:
    900
    you can blend two colors using a normalized value with the "lerp" instruction :

    lerp(color1,color2,alpha)
     
  3. IsGreen

    IsGreen

    Joined:
    Jan 17, 2014
    Posts:
    206
    You're right. Thanks for advice.






    At first used 'TexWithXform', instead of Texture.

    If I use 'TextWithXform' appear compilation erros: vert output parameter 'o' not completely initialized.

    _____________________________________________________________________________

    Another question, also, the tiling changes, no effect.

    How change tiling texture aspect?
     
  4. shaderbytes

    shaderbytes

    Joined:
    Nov 11, 2010
    Posts:
    900
    I dont know anything about the extension you are using but my guess would be to look for some sort of UV node to use with your mask?
     
  5. IsGreen

    IsGreen

    Joined:
    Jan 17, 2014
    Posts:
    206
    I desist. I think is graphic card problem: NVIDIA GeForce 9500 GS.(Don't support DirectX 11).

    I probe with Strumpy Shader Editor, that have a object called Sample2D, and appear the same compiling shader error: 'vert' output parameter 'o' not completely initialized.

    I don't know if Sample2D Strumpy Shader Editor object, is same that 'TextWithXform' ShaderFusion Editor object.

    I suppose, because appear the same error type.


     
  6. kebrus

    kebrus

    Joined:
    Oct 10, 2011
    Posts:
    415
    Post the code of the working version and me or someone else will edit it for the tilling effect.
     
  7. IsGreen

    IsGreen

    Joined:
    Jan 17, 2014
    Posts:
    206
    It is not necessary, and neither do any good.

    I wanted to make a similar Terrain shader for meshes, with various color and bump textures, which used UV mapping coordinates of a mesh, applying mask textures.
     
  8. kebrus

    kebrus

    Joined:
    Oct 10, 2011
    Posts:
    415
    You should definitely try shader forge if you don't know how to write them manually, you can keep using the other node editors to do what you want, if in the end the only problem left is the tilling me or someone can easily fix it

    cheers
     
  9. IsGreen

    IsGreen

    Joined:
    Jan 17, 2014
    Posts:
    206
    Not a computer programming problem.

    The hard work is done by visual editors.

    The problem is that I have problems on my computer.
     
  10. LasseWestmark

    LasseWestmark

    Joined:
    Mar 18, 2014
    Posts:
    12
    This line needs to be added to the beginning of your vertex program.

    UNITY_INITIALIZE_OUTPUT(Input,o);

    Earlier we could use partially initialized outputs but this is now a no go.

    Full explanation here:

    http://docs.unity3d.com/Manual/SL-PlatformDifferences.html
     
  11. IsGreen

    IsGreen

    Joined:
    Jan 17, 2014
    Posts:
    206
    You're right. Thanks for advice.

    I finished BlendTex Shader. I have created 3 type:

    -Diffuse: No Bumped. Only color maps.
    -BumpMain: Only MainTexture is bumped.
    -Bumped: All textures are bumped.

    To blend textures, the shader use de alpha channel of mask textures(AlphaMask). Unity can convert black/white images to AlphaMask.

    This video show the shader ThreeBlendTexBumpMain(1 main texture, 3 blend textures, 1 bump texture) in a cave mesh:




    This image show the same shader in a wall mesh:




    Download link.
     
    Last edited: Jul 5, 2014