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

Shader Wizard - CG Shader Generator NOW AVAILABLE

Discussion in 'Assets and Asset Store' started by imaginaryhuman, Oct 9, 2012.

  1. KRGraphics

    KRGraphics

    Joined:
    Jan 5, 2010
    Posts:
    4,436
    However, the shader is set to SM 3.0
     
  2. imaginaryhuman

    imaginaryhuman

    Joined:
    Mar 21, 2010
    Posts:
    5,834
    Nepture_Imagine... honestly I think the shader you're using/wanting to make is `over the head` of the scope of what ShaderWizard currently can do. I recommend trying Strumpy Shader Editor (it's free), because that more readily will let you build the complexity of shader you're needing with the advanced stuff like the fresnel and gloss maps and lighting etc. You've hilited for me an area where ShaderWizard can expand, but at the moment I don't think it's the tool for your job.
     
  3. KRGraphics

    KRGraphics

    Joined:
    Jan 5, 2010
    Posts:
    4,436
    Not a problem at all, just giving you some inspiration and ideas :)
     
  4. imaginaryhuman

    imaginaryhuman

    Joined:
    Mar 21, 2010
    Posts:
    5,834
    Yep thanks for that, you gave me some ideas for the next version.
     
  5. imaginaryhuman

    imaginaryhuman

    Joined:
    Mar 21, 2010
    Posts:
    5,834
    Hey folks. Just wanted to mention that over 20 customers have now purchased ShaderWizard on the asset store. A big thank you to everyone for your support and interest! Sometimes it's important to know that other people have put their trust in a product, just as user reviews can speak volumes. Thank you to the few who have submitted reviews also - I could use some more if anyone has time ;)

    I also wanted to hilight one of the benefits of ShaderWizard which is for the development of efficient mobile games. Anyone developing for iOs/Android etc knows you need your shaders to be ultra optimized and using the fastest/most compact data formats possible. ShaderWizard has its sights firmly set in this regard by using the smallest possible data formats and carefully optimized shader code. While many Unity shaders often include extra parameters, inputs, data precision and operations that you just don't need, ShaderWizard specifically only adds the bare minimum of what is necessary to get the job done.

    For example with the standard single-texture shader, you can easily output `pure texture` with no lighting or vertex colors slowing things down, and when you want to add a blend mode that's exactly all that will be added, nothing more. Then when you want to throw in some vertex colors, it's easy. ShaderWizard even ignores the ability to apply tiling/offset to texture inputs to save a few extra cycles in the vertex shader (optional of course).

    When you look at the multitexturing shaders you'll also find lots of optimization, intelligent re-use of variables and carefully hand-tuned code that runs like a charm. You can even load up a full set of 8 textures using all of iOs's texture units in a single shader, combining them with alphablending or alphatesting or any of many photoshop-like blends, all before anything is ever output to the screen, saving up to almost 50% of texture write-time, especially when you're overlaying multiple textures with transparency. This can save on overdraw and speed things up in scenarios where you can make use of it. With standard shaders you'd have to render each texture separately, incurring additional write operations, not to mention the overheads of dealing with alpha test/blend on mobile devices. ... so why not do it all in a single shader, then write and blend just once!

    ShaderWizard is building momentum, with more cool shaders under development that will put smiles on many faces, especially more high-efficiency shaders for mobile games. And still only $20 at the asset store :)

    http://u3d.as/content/ocean-wave-software/shader-wizard-cg-shader-generator/3qr
     
    Last edited: Dec 1, 2012
  6. EskemaGames

    EskemaGames

    Joined:
    Jun 23, 2010
    Posts:
    318
    I bought it and it works really well, I have one question though. I'm trying to create a lightmap shader, as I'm not using beast and the lightmaps comes from 3d studio, so I cannot use any of the lightmaps shaders that comes with unity, I'm fighting to get a shader that gets the 2 textures, the normal base texture and the shadows texture with alpha channel, mapped as usual on the second UV channel.
    Suggestions?
     
  7. imaginaryhuman

    imaginaryhuman

    Joined:
    Mar 21, 2010
    Posts:
    5,834
    Hi, and thanks. ShaderWizard by default only uses a single set of texture coords but you can modify the sourcecode to use a second set of UV coords. Actually this could be something I could add to the next version fairly easily.

    How to implement a second set of texture coordinates to a ShaderWizard shader:

    First of all switch on `verbose` comments. This will add-in a few extra lines of commented-out code which may be used as part of support for a second set of UV coords.

    Select the MultiTexture shader function and set it to 2 texture layers.

    For the second texture layer, set the layer merge function to whatever you like. I'm thinking either you will want to Multiply it (which will multiply RGB but not A), or AlphaBlend it (layer 1 is alphablended on top of layer 0), or you might also try AlphaBlendAdd, or something else, depending on the effect you want.

    Select your two textures - I'd put your shadow texture in layer 1 and your normal texture in layer 0. Note that the shader in layer 1 will be blended `on top of` the result from layer 0. If the texture on layer 1 has an Alpha channel and you use a merge which uses the alpha, such as AlphaBlend or AlphaBlendAdd, its Alpha will be used to determine how much it blends with layer 0. Note also that the Alpha from layer 0 will separately propagate all the way through the shader to the final blending stage, where it is then optionally used to blend with the backbuffer. So you could in fact give your base texture an alpha channel which determines how the final combined pixels will blend with the screen - to do that you'd simply choose a `blend mode` such as AlphaBlend, in addition to your merge mode.

    Decide if you want to pass in texture tiling/offset values in the Adjust menu. If you don't need to scroll the textures or scale them, I'd leave it out as it makes the vertex shader a little faster.

    Set the `Blend` mode you want to use to combine the shader output with the back buffer... either `solid` to just replace the pixels, or for example `AlphaBlend` to blend with the pixels. Then generate the shader + material.

    Now we need to go into the source code. There are three sections with some code commented out which we need to enable.

    The first section is this one, which defines the data structure passed from Unity to the shader:
    Code (csharp):
    1.  
    2.             //Data structure communication from Unity to the vertex shader
    3.             //Defines what inputs the vertex shader accepts
    4.             struct AppData {
    5.                 float4 vertex : POSITION;                   //Receive vertex position
    6.                 half2 texcoord : TEXCOORD0;                 //Receive texture coordinates
    7.                             //half2 texcoord1 : TEXCOORD1;              //Receive texture coordinates
    8.                             //fixed4 color : COLOR;                     //Receive vertex colors
    9.             };
    10.  
    Notice there is a line "//half2 texcoord1 : TEXCOORD1;" - simply uncomment this line by removing the // from the start. This tells the shader that it can receive UV2 coordinates as input to the shader.

    Then look at the second section - this defines the data structure passed between the vertex shader and the fragment shader:
    Code (csharp):
    1.  
    2.             //Data structure for communication from vertex shader to fragment shader
    3.             //Defines what inputs the fragment shader accepts
    4.             struct VertexToFragment {
    5.                 float4 pos : POSITION;                      //Send fragment position to fragment shader
    6.                 half2 uv : TEXCOORD0;                       //Send interpolated texture coordinate to fragment shader
    7.                             //half2 uv2 : TEXCOORD1;                    //Send interpolated texture coordinate to fragment shader
    8.                             //fixed4 color : COLOR;                     //Send interpolated gouraud-shaded vertex color to fragment shader
    9.             };
    10.  
    Notice the line "//half2 uv2 : TEXCOORD1;" - uncomment this line also by removing the // from the start. This tells the shader that it can pass on the UV2 coordinates it received from unity to the fragment shader.

    Then look at the third section:
    Code (csharp):
    1.  
    2.             //Vertex shader
    3.             VertexToFragment vert(AppData v) {
    4.                 VertexToFragment o;                         //Create a data structure to pass to fragment shader
    5.                 o.pos = mul(UNITY_MATRIX_MVP,v.vertex);     //Include influence of Modelview + Projection matrices
    6.                 o.uv = TRANSFORM_TEX(v.texcoord,_Texture0);//Send texture coords from unit 0 to fragment shader
    7.                             //o.uv2 = v.texcoord1.xy;                   //Send texture coords from unit 1 to fragment shader
    8.                             //o.color = v.color;                        //Send interpolated vertex color to fragment shader
    9.                             //o.color = _Color;                         //Send solid color to fragment shader
    10.                 return o;                                   //Transmit data to the fragment shader
    11.             }
    12.  
    This is the vertex shader. Uncomment the line "//o.uv2 = v.texcoord1.xy;" by removing the // from the start. Now, the way this line is set up, it ignores the tiling and offset for the texture. All it's doing is `passing on` the texture coordinates unmodified. So long as you don't want to offset or scale the texture that will use the UV2 coords, you can leave it as is. If you switched on tiling/offset in the Adjust menu and you want the texture associated with UV2 to be scrollable/scalable, then you need to CHANGE this line to:
    Code (csharp):
    1.  
    2. o.uv2 = TRANSFORM_TEX(v.texcoord2,_Texture1);
    3.  
    This tells the shader to use the tile/offset values to adjust the texture coordinates for the UV2 channel. Note then that whatever texture you set up as texture layer 1 will be affected by this. At this stage the vertex shader is passing on the UV2 coordinates to the fragment shader.

    Then let's look at the fragment shader:
    Code (csharp):
    1.  
    2.             //Fragment shader
    3.             fixed4 frag(VertexToFragment i) : COLOR {
    4.                 //Multitexturing Shader - Start with Layer 0
    5.                 fixed4 Result = tex2D(_Texture0, i.uv);     //Start with Texture Layer 0 as-is
    6.                 fixed4 Pixel;                               //Temporary pixel from texture layer
    7.                 //Alpha Blend Layer 1
    8.                 Pixel=tex2D(_Texture1, i.uv2);              //Read pixel from Layer 1
    9.                 fixed Alpha=Pixel.a;                        //Get the alpha value of the pixel
    10.                 fixed IAlpha=1.0-Alpha;                     //Calculate the inverse of the alpha value
    11.                 Result=fixed4(Result.r*IAlpha, Result.g*IAlpha, Result.b*IAlpha, Result.a) + fixed4(Pixel.r*Alpha, Pixel.g*Alpha, Pixel.b*Alpha,0); //Alphablend this texture with the previous result
    12.                 return Result;                              //Return the final result
    13.             }
    14.  
    This is the fragment shader I generated with ShaderWizard where texture 0 is your base texture, texture 1 is your shadow texture, and they're being combined with n AlphaBlend operation. The merge you use may be different. Either way, somewhere in the code you will see the line: "Pixel=tex2D(_Texture1, i.uv);" - this is reading a pixel from the texture on layer 1. However, notice the variable is using i.uv, which means `input from vertex shader - refer to the `uv` variable` which is the first set of UV coords. What we have to do here is append the number 2 on the end like:
    Code (csharp):
    1.  
    2. Pixel=tex2D(_Texture1, i.uv2);
    3.  
    This tells the shader to use the second set of texture coordinates when reading the texels from texture layer 1. Without this, despite everything we set up and passed through the pipeline before, it would have used the first set of uv coords to read the texture. So once this is changed, the second set of coords are used.

    Note that if you make a MultiTexture shader with more than 2 layers, it's going to have multiple instances of the `Pixel=` line in the fragment shader, so in that case you'll want to set i.uv or i.uv2 depending on which `layer` is meant to use which set of UV's. In the commented shader output it will give comments in the fragment shader to tell you where the processing of each layer begins.

    Note also that the tiling and offset parameters which we've possibly set up to affect UV2, are being pulled in from a specific texture in the Unity editor. So for example if we set up Texture layer 1 as your shadow layer and we adjust the offset/scale for that texture, those controls will affect ANY texture using the UV2 texture coords.

    The final shader should look something like this:
    Code (csharp):
    1.  
    2.  
    3. Shader "ShaderWizard/MultiTexture/ShaderWizard-MultiTexture-000-AlphaBlend-Solid-Tile&Offset" {
    4.  
    5.     //"MultiTexture" shader with "Solid" blending
    6.     //MultiTexturing with 2 texture layers:
    7.         //Layer 1, Merged by Alpha Blend
    8.     //Z-Writing is Off and Z-Testing is Off
    9.     //Color masking is RGBA and Culling is Off
    10.     //Texture coords can be adjusted with Tiling and Offset in material
    11.  
    12.     //Set up the shader to receive external inputs from Unity
    13.     Properties {
    14.         _Texture0 ("Texture 0", 2D) = "" {}     //Receive input from a Texture on Texture Unit 0
    15.         _Texture1 ("Texture 1", 2D) = "" {}     //Receive input from a Texture on Texture Unit 1
    16.     }
    17.  
    18.     //Define a shader
    19.     SubShader {
    20.  
    21.         //Define what queue/order to render this shader in
    22.         Tags {"Queue" = "Geometry" "RenderType" = "Opaque"}     //Background | Geometry | AlphaTest | Transparent | Overlay - Render this shader as part of the geometry queue because it does not use blending
    23.  
    24.         //Define a pass
    25.         Pass {
    26.  
    27.             //Set up blending and other operations
    28.             Cull Off            // Back | Front | Off - Do not cull any triangle faces
    29.             ZTest Off           //Less | Greater | LEqual | GEqual | Equal | NotEqual | Always - Z-Buffer/Depth testing is off
    30.             ZWrite Off          //On | Off - Z coordinates from pixel positions will not be written to the Z/Depth buffer
    31.             AlphaTest Off //0.0 //Less | Greater | LEqual | GEqual | Equal | NotEqual | Always   (also 0.0 (float value) | [_AlphaTestThreshold]) - All pixels will continue through the graphics pipeline because alpha testing is Off
    32.             Lighting Off            //On | Off - Lighting will not be calculated or applied
    33.             ColorMask RGBA      //RGBA | RGB | A | 0 | any combination of R, G, B, A - Color channels allowed to be modified in the backbuffer are: RGBA
    34.             //BlendOp   //Add       // Min | Max | Sub | RevSub - BlendOp is not being used and will default to an Add operation when combining the source and destination parts of the blend mode
    35.             Blend Off           //SrcFactor DstFactor (also:, SrcFactorA DstFactorA) = One | Zero | SrcColor | SrcAlpha | DstColor | DstAlpha | OneMinusSrcColor | OneMinusSrcAlpha | OneMinusDstColor | OneMinusDstAlpha - Blending between shader output and the backbuffer will use blend mode 'Solid'
    36.                                 //Blend SrcAlpha OneMinusSrcAlpha     = Alpha blending
    37.                                 //Blend One One                       = Additive
    38.                                 //Blend OneMinusDstColor One          = Soft Additive
    39.                                 //Blend DstColor Zero                 = Multiplicative
    40.                                 //Blend DstColor SrcColor             = 2x Multiplicative
    41.  
    42.             CGPROGRAM                       //Start a program in the CG language
    43.             #pragma target 2.0              //Run this shader on at least Shader Model 2.0 hardware (e.g. Direct3D 9)
    44.             #pragma fragment frag           //The fragment shader is named 'frag'
    45.             #pragma vertex vert             //The vertex shader is named 'vert'
    46.             #include "UnityCG.cginc"        //Include Unity's predefined inputs and macros
    47.  
    48.             //Unity variables to be made accessible to Vertex and/or Fragment shader
    49.             uniform sampler2D _Texture0;                    //Define _Texture0 from Texture Unit 0 to be sampled in 2D
    50.             uniform float4 _Texture0_ST;                    //Use the Float _Texture0_ST to pass the Offset and Tiling for the texture(s)
    51.             uniform sampler2D _Texture1;                    //Define _Texture1 from Texture Unit 1 to be sampled in 2D
    52.             uniform float4 _Texture1_ST;                    //Use the Float _Texture1_ST to pass the Offset and Tiling for the texture(s)
    53.  
    54.             //Data structure communication from Unity to the vertex shader
    55.             //Defines what inputs the vertex shader accepts
    56.             struct AppData {
    57.                 float4 vertex : POSITION;                   //Receive vertex position
    58.                 half2 texcoord : TEXCOORD0;                 //Receive texture coordinates
    59.                 half2 texcoord1 : TEXCOORD1;                //Receive texture coordinates
    60.                             //fixed4 color : COLOR;                     //Receive vertex colors
    61.             };
    62.  
    63.             //Data structure for communication from vertex shader to fragment shader
    64.             //Defines what inputs the fragment shader accepts
    65.             struct VertexToFragment {
    66.                 float4 pos : POSITION;                      //Send fragment position to fragment shader
    67.                 half2 uv : TEXCOORD0;                       //Send interpolated texture coordinate to fragment shader
    68.                 half2 uv2 : TEXCOORD1;                      //Send interpolated texture coordinate to fragment shader
    69.                             //fixed4 color : COLOR;                     //Send interpolated gouraud-shaded vertex color to fragment shader
    70.             };
    71.  
    72.             //Vertex shader
    73.             VertexToFragment vert(AppData v) {
    74.                 VertexToFragment o;                         //Create a data structure to pass to fragment shader
    75.                 o.pos = mul(UNITY_MATRIX_MVP,v.vertex);     //Include influence of Modelview + Projection matrices
    76.                 o.uv = TRANSFORM_TEX(v.texcoord,_Texture0);//Send texture coords from unit 0 to fragment shader
    77.                 o.uv2 = TRANSFORM_TEX(v.texcoord1,_Texture1);           //Send texture coords from unit 1 to fragment shader
    78.                             //o.color = v.color;                        //Send interpolated vertex color to fragment shader
    79.                             //o.color = _Color;                         //Send solid color to fragment shader
    80.                 return o;                                   //Transmit data to the fragment shader
    81.             }
    82.  
    83.             //Fragment shader
    84.             fixed4 frag(VertexToFragment i) : COLOR {
    85.                 //Multitexturing Shader - Start with Layer 0
    86.                 fixed4 Result = tex2D(_Texture0, i.uv);     //Start with Texture Layer 0 as-is
    87.                 fixed4 Pixel;                               //Temporary pixel from texture layer
    88.                 //Alpha Blend Layer 1
    89.                 Pixel=tex2D(_Texture1, i.uv2);              //Read pixel from Layer 1
    90.                 fixed Alpha=Pixel.a;                        //Get the alpha value of the pixel
    91.                 fixed IAlpha=1.0-Alpha;                     //Calculate the inverse of the alpha value
    92.                 Result=fixed4(Result.r*IAlpha, Result.g*IAlpha, Result.b*IAlpha, Result.a) + fixed4(Pixel.r*Alpha, Pixel.g*Alpha, Pixel.b*Alpha,0); //Alphablend this texture with the previous result
    93.                 return Result;                              //Return the final result
    94.             }
    95.  
    96.             ENDCG                           //End of CG program
    97.  
    98.         }
    99.     }
    100. }
    101.  
    102. //This shader was generated by ShaderWizard and is Copyright (c) 2012 Paul West/Ocean Wave Software
    103.  
    The shader code there is valid, no errors, but I haven't tested it to see what it does... you need to set up a second set of UV coords in your MESH data to see it in action. I hope this answers your question :)

    A couple of final points - I will try to implement this automatically in the next version of ShaderWizard - it will probably be something like having a simple dropdown menu next to each texture layer allowing you to choose what UV channel it will work with. This will remove the need to do any of the above code-fiddling!

    Also, anyone writing efficient/mobile shaders should consider optimizing the data types in some areas of the ShaderWizard shaders for possibly even greater performance (it's already fast, but maybe can be a smidge faster) - I could add this as an option also in the next version). Note that in the VertexToFragment data structure, the UV coordinates for example are in `half` format - this is a pretty fast limited-range format with values up to like 60,000 or something, possibly using 2 bytes instead of 4. I THINK you can change this to `fixed` format by simply changing the word `half` to `fixed` in front of the UV lines. `Fixed` is an even smaller format, possibly stored in only 1 or 2 bytes, with a range of 0..1 or 0..2 .... so if in your mesh you are never referencing texture coordinates higher than 1, it should be safe to change to this fixed format for a little boost. On the same note if you need really big texture coordinates you'll need to change this AND the lines in the `AppData` structure to `float` instead of `half` for greater precision, which will slow it down some.

    The fragment shaders are quite highly optimized using `fixed` where possible for color data since it stays in the range of 0..1... so there isn't much to optimize here, but experts might be able to squeeze a slight bit of juice from a few tweaks ;)

    Sorry that you'll have to resort to changing the sourcecode to implement what you want to do - something that ShaderWizard aims to completely alleviate. I'll aim to make this happen in the next version :D
     
    Last edited: Dec 1, 2012
  8. EskemaGames

    EskemaGames

    Joined:
    Jun 23, 2010
    Posts:
    318
    Thanks, the shader doesn't work but it's a start. I did some basic modifications and got this, but the colors doesn't match the original texture, with this code

    Code (csharp):
    1.  
    2. fixed4 Result = tex2D(_Texture0, i.uv);
    3. Result *= Result * tex2D(_Texture1, i.uv2);
    4.  
    I have the lightmap perfectly integrated, but the whole texture looks darker regarding the original colors, your configuration shows everything transparent and doesn't work ;)

    This is yours


    This is mine


    And this is expected result
     
  9. imaginaryhuman

    imaginaryhuman

    Joined:
    Mar 21, 2010
    Posts:
    5,834
    Hmm. So the second set of UV's works okay, but just the way the textures are combined does not?

    The formula you showed up there - is that the shader you described as `yours`, as shown in your second image?

    If so ... it looks like you're:

    a) multiplying the first texture by the second texture, and then
    b) multiplying THAT result by the first texture

    So it's doing a multiply operation, which typically darkens an image, and then you're multiplying that result again which will darken it even further.

    Don't you just want:
    Code (csharp):
    1.  
    2. Result *= tex2D(_Texture1, i.uv2);
    3.  
    ??
     
  10. EskemaGames

    EskemaGames

    Joined:
    Jun 23, 2010
    Posts:
    318
    My shader it's just yours but doing the multiplication instead of your code to get the inverse alpha, and yes, I've tried to just multiply the base texture by the second texture as you described with no luck, I'm still getting dark colours. As an example, imagine a scale from 1 to 10, 10 should be the perfect value, and I'm getting a slightly dark tone like an 8.
     
  11. imaginaryhuman

    imaginaryhuman

    Joined:
    Mar 21, 2010
    Posts:
    5,834
    In the application you originally generated your models etc in, where you saw the third image results, do you know what formula it uses to combine the lightmap with the base texture? Because all you're doing is a normal multiply. It almost seems like there is something else going on here like gamma correction or some kind of bias or scaling of lightmap values, or multiplied additionally by 1.2 or something.
     
  12. EskemaGames

    EskemaGames

    Joined:
    Jun 23, 2010
    Posts:
    318
    Apparently the difference was the monitor itself, the artist seems to have a much brighter and colourful monitor configuration than my iMac, finally I solved this adding a bit of white color to increase the bright a bit.

    Thanks :)

    Code (csharp):
    1.  
    2. Result *= tex2D(_Texture1, i.uv2) + fixed4(0.1,0.1,0.1,0);
    3.  
     
  13. imaginaryhuman

    imaginaryhuman

    Joined:
    Mar 21, 2010
    Posts:
    5,834
    lol, that's funny. Don't you just love cross browser/cross platform/cross computer differences :D

    Glad you figured it out.
     
  14. sashahush

    sashahush

    Joined:
    Sep 5, 2012
    Posts:
    75
    Hello, i was looking at this tool and i was wondering is it possible to use this to lets say to make a snow shader?
    To make it 3d models look like they are covered with snow texture on their flatter surfaces. thanks!
     
  15. imaginaryhuman

    imaginaryhuman

    Joined:
    Mar 21, 2010
    Posts:
    5,834
    Hi. The way I think snow shaders work, they have to take into account the `normal` of the surface and do a cross-fade/alphablend between two textures based on whether the angle falls within a given range. ShaderWizard currently doesn't feed any `normals` into the shader - it could generate the basic shader template for you containing some alphablend code but you'd have to edit the sourcecode to implement the normals and snow effect yourself.
     
  16. imaginaryhuman

    imaginaryhuman

    Joined:
    Mar 21, 2010
    Posts:
    5,834
    On second thoughts I guess if you draw your textures wisely you wouldn't have to worry about the parts that don't receive snow (ie sides of objects) because you could just put the snow parts in the part of the texture that covers the top of the object. But then I think what you need is a `dissolve` shader to gradually increase the amount of snow pixels that show. I'm pretty sure there are snow shaders scattered around the forums, but I am thinking about adding dissolve capabilities in the next version.
     
  17. imaginaryhuman

    imaginaryhuman

    Joined:
    Mar 21, 2010
    Posts:
    5,834
    Any further feature requests, let them be known for the next version.

    Also thanks to the 20+ people who bought Shader Wizard already, which will help support a fun christmas for my family this year ;) And merry christmas to you!
     
  18. Finjitzu

    Finjitzu

    Joined:
    Sep 8, 2011
    Posts:
    160
    I agree dissolve would be great. Also a video explaining some stuff. I'm basically afraid of shaders. So a video showing the production of some cool shaders and what some of the basic-advanced switches do would be great for me.

    So does this mean the materials I make can't receive or cast shadows, use light probes, or add a normal texture or specular texture?
     
  19. imaginaryhuman

    imaginaryhuman

    Joined:
    Mar 21, 2010
    Posts:
    5,834
    The thing with ShaderWizard is that it is easy to use and you don't even need to know about how shaders work particularly, you don't need to know how to program them or make them do what you want. All the tool is is a bunch of dropdown menus and a few text boxes, easy to operate. You just choose what you want or don't want and hit generate. You're choosing between preset functions based on whether you want vertex colors, texturing, etc, or whether you want multitexturing. Then if you choose multitexture you just select your textures and choose what photoshop blends you want between each layer. Maybe set up a final blend mode and hit generate. It's pretty easy. The functionality is all documented. Here is the documentation: View attachment $Readme.txt I suggest you use something other than Notepad.exe to view otherwise the lines will flow into each other.

    Because it's so straightforward I don't think a video will help, all it will show is someone choosing options from dropdown menus, setting textures and clicking a button.

    To answer your other question you are correct, you cannot use shadows, light probes, any other kind of lighting, normal mapping or specular highlights. Those things are already supported well in the standard Unity shaders and when you get down to it the cases where you want to use those features you aren't going to likely have much room for customization. ShaderWizard is better suited for 2D or mobile and simpler stuff.
     
    Last edited: Feb 5, 2013
  20. johnny12345

    johnny12345

    Joined:
    Oct 8, 2012
    Posts:
    45
    Would this be able to create a diffuse overlay,so 2 textures 2 bump maps then be able to blend the both and tile one of the texture and bump maps
    Ill just explain a little more,I have my main texture with a bump map,I then want to overlay another texture with bump map and be able to adjust the overlay strength on the shader plus tile that overlayed texture and bump map

    Thanks
     
    Last edited: Mar 28, 2013
  21. imaginaryhuman

    imaginaryhuman

    Joined:
    Mar 21, 2010
    Posts:
    5,834
    No.

    ShaderWizard can't currently do any kind of bumpmapping. You could use it to create a shader which has almost everything you need such as the textures you want for input and ways to combine them, but you'd have to dip into cg code to modify it to do the bumpmapping part.
     
  22. u0204909

    u0204909

    Joined:
    Jun 25, 2012
    Posts:
    21
    Hi I cant generate shaders that work. When I inspect the generated shaders, they all have these similar error messages. I am using a Macbook Pro and the latest version of Unity

    Shader has errors or is not supported by your graphics card
    GLSL vertext shader: 330: ERROR: 'constructor': can't convert at line 38
    GLSL vertext shader: 333: ERROR: 'constructor': can't convert at line 38
    Shader program had errors at line 39
     
    Last edited: Apr 3, 2013
  23. imaginaryhuman

    imaginaryhuman

    Joined:
    Mar 21, 2010
    Posts:
    5,834
    Hi.

    Can you post the full shader sourcecode?

    I can say this.. ShaderWizard only generates ShaderLab sourcecode including cg code... Unity is responsible for converting this to work on various platforms by compiling it into GLSL, DirectX, OpenGL etc...to work on various platforms. If the shader sourcecode was fundamentally flawed I think it would fail to compile the shaders for any platform. Have you tried setting the `shader model` dropdown to Shader Model 3.0? ... if the shader is quite long it may be creating a scenario where ShaderModel 2 doesn't support enough instructions or whatever features. I'd need to see your shader sourcecode to look at it further. Otherwise it could be possible that your gfx card actually does not support some feature, maybe needing a driver update or something.
     
  24. u0204909

    u0204909

    Joined:
    Jun 25, 2012
    Posts:
    21
    I private messaged you the source code.. Not sure if you want it to be posted publicly...
     
  25. imaginaryhuman

    imaginaryhuman

    Joined:
    Mar 21, 2010
    Posts:
    5,834
    I saw it. ... the code looks fine to me. It's quite simple.

    Have you tried selecting shader model 3 to see if the error goes away? Maybe the opengl driver for your mac needs updating or doesn't support the features or something... because I know this works fine on pretty much everyone else's systems.
     
  26. u0204909

    u0204909

    Joined:
    Jun 25, 2012
    Posts:
    21
    Hi, I tried it on my PC as well and I cannot create shaders that work too.. I dont think it's a driver problem because the demo shaders that you provided are fine so i believe it's more of a compilation issue? I can also generate the shader using the default settings when I first import Shader Wizard on both my pc and mac, but I cannot generate working shaders using some other settings on both my pc and mac..

    Using shader model 3 doesnt change things as well..

    I also tried to re-create the multi texture shaders in your demo because I know those are working.. The generated ones work.. So I tried generating all types. Color, VertexColor and MultiTextures work but not Texture, Texture + Color, Texture + VertexColor..

    Do you want me to send the shaders you? Give me your email? The email here only provides a form.
     
    Last edited: Apr 4, 2013
  27. imaginaryhuman

    imaginaryhuman

    Joined:
    Mar 21, 2010
    Posts:
    5,834
    Hmm. Can you perhaps post a screen grab of the shaderwizard interface showing what settings you have it on when you get the error?
     
  28. u0204909

    u0204909

    Joined:
    Jun 25, 2012
    Posts:
    21
    $Screen Shot 2013-04-04 at 10.35.42 AM.png

    $Screen Shot 2013-04-04 at 10.35.58 AM.png
     
    Last edited: Apr 4, 2013
  29. u0204909

    u0204909

    Joined:
    Jun 25, 2012
    Posts:
    21
    Hi, just wanted to check if you have found out the cause of the above problem..
     
  30. imaginaryhuman

    imaginaryhuman

    Joined:
    Mar 21, 2010
    Posts:
    5,834
    Hi. Well I set up Shader Wizard with the exact same settings as you and build the shaders and have absolutely no errors, which is what I expected. The code generated is 100% correct and compilable.

    There has to be something about your computer or your copy of Unity that is creating this error. I tried it in Unity 3.5 and Unity 4.0 and both were fine. I don't know if perhaps your project folder has some corruption in the files or metadata or something. Maybe try reimporting the package or import it to a completely new project? Or maybe you need to upgrade Unity to a newer version if there's a bug influencing this from Unity. Otherwise it may be something relating to your graphics driver. That's about the best I can tell you... it doesn't appear to really be anything to do with Shader Wizard being the issue, it generates perfect code and then it's something between Unity and your computer that's failing to compile the GLSL shader properly.
     
  31. u0204909

    u0204909

    Joined:
    Jun 25, 2012
    Posts:
    21
    I am using the latest version of Unity, 4.1.2f1 and i tried creating new projects and importing Shader Wizard on both my PC and Macbook Pro and I get the same results.

    So,
    1) It cant be due to a corruption in my project folder since I tested it in a new project
    2) I already upgraded to the latest version of unity. You said you are using 4.0 but I assume you meant that you were using 4.1.2f1 as well? If not, maybe you need to upgrade as well?
    3) I really dont think it is the graphics driver because I tested on 2 different computers with the same results and if it was, my multitexture shaders shouldnt be compiling properly as well but they do compile fine! Why would my driver support a more complicated shader and not the simpler one?

    Btw, how do you get the multi texture demo shaders to work? They are compiled fine but they change my textures to pink and and I dont get an option to import the textures in the material.
     
    Last edited: Apr 20, 2013
  32. imaginaryhuman

    imaginaryhuman

    Joined:
    Mar 21, 2010
    Posts:
    5,834
    I'm sorry but it still has to be your system. The sourcecode is perfectly fine and compiles perfectly fine without any errors on my computer, and nobody else has this problem either.
     
  33. imaginaryhuman

    imaginaryhuman

    Joined:
    Mar 21, 2010
    Posts:
    5,834
    Just a quick gratuitous bump to say Shader Wizard 2 is still available on the asset store - only $20. If you're used to photoshop blend modes, or want to set up a quick multi-texturing shader, Shader Wizard can help. Works great to set up new shaders as a kind of template that you can modify, if you're more of a shader expert. Also good for mobile games, getting that speed up on simpler shaders.
     
  34. toto2003

    toto2003

    Joined:
    Sep 22, 2010
    Posts:
    528
    hello
    i m very interested at your tool, i m looking to animate a texture A by offseting or using animation and got a texture b as overlay, did your tool allow that?
    if yes you got a photoshop guy loving you! :)
     
  35. toto2003

    toto2003

    Joined:
    Sep 22, 2010
    Posts:
    528
    ok, i just purchase your asset, i manage to create a new shader, wasn t that hard :D , and let the option on allow tiling and offset, my issue is i can offset and tile texture 0, but not texture 1 wich is the one i want to offset theough an animation like a parallax, also texture 0 offset the whole shader not only the diffuse texture...
    is there any work around that?

    thanks
     
  36. imaginaryhuman

    imaginaryhuman

    Joined:
    Mar 21, 2010
    Posts:
    5,834
    Hi there,

    Yes, thanks for purchasing, you put a smile on my face :)

    The way Shader Wizard is set up, it uses only one set of texture coordinates. The way this works is, when you ask Unity to adjust the tiling/scaling of the texture, you're really instructing the hardware to manipulate the texture coordinates using an internal Texture Matrix. To get that to happen, in the vertex shader we have to tell it which texture coordinates to apply the adjustment to, so we tell it to adjust the first set of UV's. Those adjusted texture coordinates then pass through to the fragment shader which then reads texels from your texture layers based on the adjusted coordinates. But because the system is only working from the first set of UV's, it uses the same adjusted coordinates for all texture layers. Shader Wizard isn't sophisticated enough yet to let you specify which texture layer goes with which set of texture coordinates. So as you adjust the coords you'll find out, as you have, that it applies to all texture layers the same.

    So to do what you're wanting to do, you will need to modify the shader that you generated a bit to allow a) input of a second set of UV's, b) adjustment of the vertex shader to also multiply the second set of UV's by the second texture adjustment, and then c) in the fragment shader use the second set of UV coords to read the second texture layer. I haven't done this before myself but it is doable, but you would need to know how to modify ShaderLab programs, or find someone who can do this for you. Unfortunately ShaderWizard doesn't have built-in support for the second set of UV's. If you post the shader that you generated here, I can possibly try and modify it for you. Otherwise if you'd prefer a refund you can always ask Unity for one.

    I suppose an alternative, if you don't have two sets of UV's on your model, would be to just send a second copy of the UV coords from the vertex shader to the fragment shader without multiplying it by the offset/scaling, and then use that for the second texture layer in the fragment shader.

    Sorry it sounds a bit technical and complicated, you probably were hoping to just use the Shader Wizard interface to do this easily.
     
    Last edited: May 27, 2013
  37. toto2003

    toto2003

    Joined:
    Sep 22, 2010
    Posts:
    528
    hello, wow, thanks for the technical answer, unfortunately i m a noob and writing shaders is out of my competences, i love your tool for his simplicity and for someone like me who know photoshop it s just perfect, i dont understand what you re saying :) but i find a twist way to achieve the result i was looking for just by duplicate a plane with only one texture, offset them so they act like a layer, one is a diffuse only and the other is set on multiply, so i can play with the offset on the plane who got the multiply shader :)

    just to make sure i m doing thing correctly is this correct to control the uv that way?

    myRenderer.material.SetTextureOffset ("_MainTex", offset);



    thanks a lot for your support
     
  38. imaginaryhuman

    imaginaryhuman

    Joined:
    Mar 21, 2010
    Posts:
    5,834
    Ah, that's a nifty solution, yes separating out the geometry as two planes will work. I don't know the exact syntax of setting the texture offset but it looks right... if it works you probably nailed it. :)
     
  39. imaginaryhuman

    imaginaryhuman

    Joined:
    Mar 21, 2010
    Posts:
    5,834
    Hey, if you get a chance, please feel free to add a review on the asset store. It's hard to get people to review when I don't know who they are.
     
  40. Amfu

    Amfu

    Joined:
    Apr 9, 2013
    Posts:
    180
    Does it includes Triplanar mapping?
     
  41. imaginaryhuman

    imaginaryhuman

    Joined:
    Mar 21, 2010
    Posts:
    5,834
    No. That's pretty advanced. ShaderWizard is currently mostly for artists who need an easy way to create somewhat customized shaders without having to write code. That means that in order to be useful it has to allow there to be flexibility in what the shader does, which means it doesn't necessarily focus on very specific one-use-only shaders like triplanar mapping. Rather it focusses on letting you combine texture layers in various ways, or generating some clean and efficient simple mobile shaders. I recognize this tool could use some expansion in terms of what kinds of shaders it can create, including support for lighting etc, but right now it can't do the triplanar.
     
  42. toto2003

    toto2003

    Joined:
    Sep 22, 2010
    Posts:
    528
    just did :)
    unfortunately i didnt manage to animate the uv, i was using this as it work on any diffuse shader, but didn t work on wizard shader...
    using UnityEngine;
    using System.Collections;

    public class ScrollUV : MonoBehaviour {
    public Vector2 direction = new Vector2(1,0);
    public float speed = 1;

    void Update () {
    renderer.material.mainTextureOffset += direction * speed * Time.deltaTime;
    }
    }

    any help would be appreciated.
     
  43. imaginaryhuman

    imaginaryhuman

    Joined:
    Mar 21, 2010
    Posts:
    5,834
    I'm looking at the docs: http://docs.unity3d.com/Documentation/ScriptReference/Material.SetTextureOffset.html

    Their example is:

    // Scroll main texture based on time
    var scrollSpeed : float = 0.5;
    function Update () {
    var offset : float = Time.time * scrollSpeed;
    renderer.material.SetTextureOffset ("_MainTex", Vector2(offset,0));
    }

    Note that _MainTex is the name of the texture `variable` within the shader code. ShaderWizard generates these variables with the simple names _Texture0 or _Texture1 or _Texture2 etc. So maybe refer to it by name by putting the name in a string like this?

    renderer.material.SetTextureOffset ("_Texture0", renderer.material.GetTextureOffset("_Texture0") + (direction * speed * Time.deltaTime));

    I think you're doing basically the right thing but `mainTextureOffset` refers to the texture which is named "_MainTex", which doesn't exist in the ShaderWizard shader. This is mentioned here: http://docs.unity3d.com/Documentation/ScriptReference/Material-mainTextureOffset.html - so either rename "_Texture0" in the shader sourcecode to "_MainTex" or use GetTextureOffset and SetTextureOffset using instead "_Texture0" as the name. <- note you may need to use an underscore before Texture0, the forum is showing it as a space for some reason.
     
    Last edited: May 28, 2013
  44. toto2003

    toto2003

    Joined:
    Sep 22, 2010
    Posts:
    528
    awesome,it just work, thanks a million.
     
  45. imaginaryhuman

    imaginaryhuman

    Joined:
    Mar 21, 2010
    Posts:
    5,834
    Sure, glad to hear it! Actually in a future version I might revert to using _MainTex for the first texture, or as an option. It was an oversight on my part early on.
     
  46. imaginaryhuman

    imaginaryhuman

    Joined:
    Mar 21, 2010
    Posts:
    5,834
    I identified a small issue in recent version of Unity where GLSL shader errors were coming up and stopping the shader compilation, thus rendering them useless with a `pink` output. I tracked this down and fixed it/made a workaround. I've resubmitted ShaderWizard 2.1 to the asset store, it should be available in the next few days.
     
  47. blackant

    blackant

    Joined:
    Jun 18, 2009
    Posts:
    529
    look very interresting, will buy it and send you feedbacks.
     
  48. imaginaryhuman

    imaginaryhuman

    Joined:
    Mar 21, 2010
    Posts:
    5,834
    Sounds good, thanks!
     
  49. blackant

    blackant

    Joined:
    Jun 18, 2009
    Posts:
    529
    really nice and simple to use !
    i love it, it will allow to not loose time to search the right shader on asset store.
    gain time, gain money !

    thanks for your plugin
     
  50. imaginaryhuman

    imaginaryhuman

    Joined:
    Mar 21, 2010
    Posts:
    5,834
    Cool, you're welcome, thanks for your support!