True Image Effects for Unity Free

Discussion in 'Assets and Asset Store' started by aubergine, Nov 14, 2011.

  1. aubergine

    aubergine

    Member

    Joined:
    Sep 12, 2009
    Messages:
    1,995
    NOT AVAILABLE ANYMORE.
    Last edited: Jun 26, 2014
  2. Mauri

    Mauri

    Member

    Joined:
    Dec 9, 2010
    Messages:
    478
    First though was: Cool, sounds really great. And it's for Unity Free :eek:
    I opened it and saw: A Demo Scene, 3 Folders called _Media, _Scrips and _Shaders, one .cs-File named ImageFx.cs and a readme.txt.

    In the _Media folder are:
    - a forest_sky.mat
    - 6 jpgs named forest_sky_XX.jpg (XY = back, bottom, front, etc).

    In the _Scripts folder is:
    a .cs-File called ImageFxBase.cs.

    In the _Shaders folder are:
    - two Shaders named BloomSimple.shader and EdgeDetect.shader.

    The readme.txt says the following:
    I really wish there would be more image effects in the package here. The thread-title says "True Image Effects for Unity Free". Thats right, but there are only two inside the project. And not everybody have the knowlenghe to build their own shaders...


    Edit:
    Oh and a friendly tip: Next time please bring many informations as possible into your postings, when you release something. Like you've do here: http://forum.unity3d.com/threads/94120-Aubergines-PostPRocess-Effects-Released-in-Assetstore .. Because not everyone has the time or desire to download things blind.. ^^
    Last edited: Nov 16, 2011
  3. aubergine

    aubergine

    Member

    Joined:
    Sep 12, 2009
    Messages:
    1,995
    I released it for free for a reason. i also have a paid package in the assetstore as your link shows and if i include those shaders in this free package, then i think i wont be able to sell the other one.

    But, you are right. I will show here some new shaders and teach how to add new ones on your own if i find some time.
    Last edited: Nov 16, 2011
  4. Ippokratis

    Ippokratis

    Member

    Joined:
    Oct 13, 2008
    Messages:
    1,087
    Hi,
    Aubergine, thanks a lot for releasing the workflow you found for free. I really appreciate it and I find your shaders very educative. Have you considered writing some paid tutorials on how to make a shader ?

    Mauri :

    If you take the time to learn how to build a shader, even the simplest one, perhaps you will appreciate more Abergine's gesture ( giving these for free ). I also believe that this workflow is probably more valuable to people who want to learn how to make shaders, than to people who wish to use them.

    I believe that anyone who releases things for free cannot be expected to put extra time to advertise it properly. It is indeed a good practice though.
    Last edited: Jan 12, 2013
  5. aubergine

    aubergine

    Member

    Joined:
    Sep 12, 2009
    Messages:
    1,995
    Thanks for kind words Ippokratis. Unfortunately i am not the teacher type and i cant make any tutorials in commercial quality. And after all, there are so many quality tutorials for free all over the internet anyways.
  6. aubergine

    aubergine

    Member

    Joined:
    Sep 12, 2009
    Messages:
    1,995
    So, here is one simple tutorial about how to add a new shader to this pack.

    1. First things first, we make a clean new project in unity, and import everything in the package to this clean new project(for the sake of simplicity)

    2. As it is a zip file, imported assets will be messed up and needs your attention. As we are going to use the supplied demo scene for testing, we need to fix missing script in MainCamera, the skybox materials textures and the skybox material in the RenderSettings itself. (You know how to do those right?)

    3. as its all setup now, lets search the internet for a cool (but a simple one for the sake of this tutorial) shader. After alittle searching, we decide Nvidia Shader Library is the best place to find this kind of stuff.

    4.We scroll down the pages of shader library, what we are looking for is a (post effect (for now)) then we see the Post Negative in the middle of the page. It says Directx10 stuff, but we dont care, we are only interested in the math part of the fragment shader here.

    5. So we decide to convert this shader to unity and to this package, we download either of HLSL or CGFX file supplied (we can also look at the whitepaper to understand whats going on but who needs a document while theres the source code anyways)

    6. I downloaded the CGFX file, opened it with 7-zip (Which is also free by coincidence) and see theres a folder "CgFX", i clicked on it twice and see "post_negative.cgfx" file and "include" dir. Just looked at the include dir and saw a "Quad.cgh" file, and decided we dont need it(what quad file can do is already provided in unity and this pack) so we go back and open the "post_negative.cgfx" file.

    We see the below mambo jambo:

    Code (csharp):
    1. /*********************************************************************NVMH3****
    2. *******************************************************************************
    3. $Revision: #3 $
    4.  
    5. Copyright NVIDIA Corporation 2008
    6. TO THE MAXIMUM EXTENT PERMITTED BY APPLICABLE LAW, THIS SOFTWARE IS PROVIDED
    7. *AS IS* AND NVIDIA AND ITS SUPPLIERS DISCLAIM ALL WARRANTIES, EITHER EXPRESS
    8. OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF MERCHANTABILITY
    9. AND FITNESS FOR A PARTICULAR PURPOSE.  IN NO EVENT SHALL NVIDIA OR ITS SUPPLIERS
    10. BE LIABLE FOR ANY SPECIAL, INCIDENTAL, INDIRECT, OR CONSEQUENTIAL DAMAGES
    11. WHATSOEVER (INCLUDING, WITHOUT LIMITATION, DAMAGES FOR LOSS OF BUSINESS PROFITS,
    12. BUSINESS INTERRUPTION, LOSS OF BUSINESS INFORMATION, OR ANY OTHER PECUNIARY
    13. LOSS) ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF
    14. NVIDIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
    15.  
    16. % Create a negative image of the underlying scene.
    17. % Un-inverted alpha is preserved.
    18.  
    19. keywords: image_processing color_conversion
    20.  
    21.  
    22.  
    23. To learn more about shading, shaders, and to bounce ideas off other shader
    24.     authors and users, visit the NVIDIA Shader Library Forums at:
    25.  
    26.     http://developer.nvidia.com/forums/
    27.  
    28. *******************************************************************************
    29. ******************************************************************************/
    30.  
    31. /*****************************************************************/
    32. /*** HOST APPLICATION IDENTIFIERS ********************************/
    33. /*** Potentially predefined by varying host environments *********/
    34. /*****************************************************************/
    35.  
    36. // #define _XSI_        /* predefined when running in XSI */
    37.  
    38. #ifndef FXCOMPOSER_VERSION  /* for very old versions */
    39. #define FXCOMPOSER_VERSION 180
    40. #endif /* FXCOMPOSER_VERSION */
    41.  
    42. // #define FLIP_TEXTURE_Y   /* Different in OpenGL  DirectX */
    43.  
    44. /*****************************************************************/
    45. /*** EFFECT-SPECIFIC CODE BEGINS HERE ****************************/
    46. /*****************************************************************/
    47.  
    48. //
    49. // #define this macro to permit reading of COLLADA-FX
    50. //   shared-surface render targets
    51. //
    52. // #define SHARED_BG_IMAGE
    53.  
    54. #include "include/Quad.cgh"
    55.  
    56. float Script : STANDARDSGLOBAL <
    57.     string UIWidget = "none";
    58.     string ScriptClass = "scene";
    59.     string ScriptOrder = "postprocess";
    60.     string ScriptOutput = "color";
    61.     string Script = "Technique=Main;";
    62. > = 0.8;
    63.  
    64. // color and depth used for full-screen clears
    65.  
    66. float4 gClearColor <
    67.     string UIWidget = "Color";
    68.     string UIName = "Background";
    69. > = {0,0,0,0};
    70.  
    71. float gClearDepth <string UIWidget = "none";> = 1.0;
    72.  
    73. ///////////////////////////////////////////////////////////
    74. /////////////////////////////////////// Textures //////////
    75. ///////////////////////////////////////////////////////////
    76.  
    77. DECLARE_QUAD_TEX(gSceneTexture,gSceneSampler,"A8R8G8B8")
    78. DECLARE_QUAD_DEPTH_BUFFER(DepthBuffer,"D24S8")
    79.  
    80. //////////////////////////////////////////////////////
    81. /////////////////////////////////// pixel shader /////
    82. //////////////////////////////////////////////////////
    83.  
    84. QUAD_REAL4 negativePS(QuadVertexOutput IN,
    85.     uniform sampler2D SceneSampler) : COLOR
    86. {  
    87.     QUAD_REAL4 texCol = tex2D(SceneSampler, IN.UV);
    88.     return float4((float3(1,1,1)-texCol.xyz),texCol.w); // protect alpha
    89. }  
    90.  
    91. ///////////////////////////////////////
    92. /// TECHNIQUES ////////////////////////
    93. ///////////////////////////////////////
    94.  
    95. technique Main < string Script =
    96. #ifndef SHARED_BG_IMAGE
    97.     "RenderColorTarget0=gSceneTexture;"
    98.     "RenderDepthStencilTarget=DepthBuffer;"
    99.     "ClearSetColor=gClearColor;"
    100.     "ClearSetDepth=gClearDepth;"
    101.     "Clear=Color;"
    102.     "Clear=Depth;"
    103.     "ScriptExternal=Color;" // calls all "previous" techniques  materials
    104.     "Pass=PostP0;";
    105. #else /* defined(SHARED_BG_IMAGE)  - no nead to create one, COLLADA has done it for us  */
    106.     "ClearSetColor=gClearColor;"
    107.     "ClearSetDepth=gClearDepth;"
    108.     "Clear=Color;"
    109.     "Clear=Depth;"
    110.     "Pass=PostP0;";
    111. #endif /* SHARED_BG_IMAGE */
    112. > {
    113.     pass PostP0 < string Script =
    114.     "RenderColorTarget0=;"
    115.     "RenderDepthStencilTarget=;"
    116.     "Draw=Buffer;";
    117.     > {
    118.     VertexProgram = compile vp40 ScreenQuadVS2(QuadTexelOffsets);
    119.         DepthTestEnable = false;
    120.         DepthMask = false;
    121.         BlendEnable = false;
    122.         CullFaceEnable = false;
    123.         DepthFunc = LEqual;
    124.     FragmentProgram = compile fp40 negativePS(gSceneSampler);
    125.     }
    126. }
    127.  
    128. //////////////////////////////////////////////
    129. /////////////////////////////////////// eof //
    130. //////////////////////////////////////////////
    Too much junk.

    7. We just look over the file, see so many fancy stuff, but we are confident unity can do most of these by itself and remember we are here only to look at the Pixel Shader maths.

    Here it is (in the middle of the file):
    Code (csharp):
    1. //////////////////////////////////////////////////////
    2. /////////////////////////////////// pixel shader /////
    3. //////////////////////////////////////////////////////
    4.  
    5. QUAD_REAL4 negativePS(QuadVertexOutput IN,
    6.     uniform sampler2D SceneSampler) : COLOR
    7. {  
    8.     QUAD_REAL4 texCol = tex2D(SceneSampler, IN.UV);
    9.     return float4((float3(1,1,1)-texCol.xyz),texCol.w); // protect alpha
    10. }  
    Again to much mambo jambo.
    The main maths is:
    8. So, we look at the maths, its so simple, it takes the current pixel color from sampler (texCol) and calculates the inverse of the color, and returns this new color on the current pixel while protecting original alpha. "Meh!, so is this what shaders are all about??" we say. Then we answer back as "Yeah i guess so."

    9. After our schizofrenia fades away, we go back to our unity, there are 2 shaders already provided, "BloomSimple" and "EdgeDetect". (Now bloomsimple is a very simple thing that only does pixel fragment and edgedetect also provides a vertex fragment sample.)
    So, we remember post negative shader is only made of a pixel fragment, we decide our starting point should be "BloomSimple", so we duplicate it and name the new copy as "Negative" and obviously open it. We look at the very first line:
    Aaand, we need to give here a unique name, so we change "BloomSimple" to "Negative"

    10. We scroll down to pixelshader part of our duplicated shader and delete everything in there and start typing in the Nvidia shaders code there with care to do necessary conversions as follows:
    Our Changes:
    And here is our final shader:
    Code (csharp):
    1. Shader "Hidden/Aubergine/UnityFree/Negative" {
    2.     Properties {
    3.         _MainTex ("Base (RGB)", 2D) = "white" {}
    4.     }
    5.     SubShader {
    6.         Pass {
    7.             ZTest Always Cull Off ZWrite Off Lighting Off Fog { Mode off }
    8.             CGPROGRAM
    9.                 #pragma vertex vert
    10.                 #pragma fragment frag
    11.                 #include "UnityCG.cginc"
    12.                
    13.                 struct v2f {
    14.                     float4 pos : SV_POSITION;
    15.                     half2 uv : TEXCOORD0;
    16.                 };
    17.  
    18.                 uniform sampler2D _MainTex;
    19.  
    20.                 v2f vert(appdata_img v) {
    21.                     v2f o;
    22.                     o.pos = mul (UNITY_MATRIX_MVP, v.vertex);
    23.                     o.uv = MultiplyUV( UNITY_MATRIX_TEXTURE0, v.texcoord );
    24.                     return o;
    25.                 }
    26.  
    27.                 half4 frag (v2f i) : COLOR {
    28.                     half4 texCol = tex2D(_MainTex, i.uv);
    29.                     return half4((half3(1,1,1)-texCol.xyz),texCol.w); // protect alpha
    30.                 }
    31.             ENDCG
    32.         }
    33.     }
    34. }
    Thats all folks.
    Last edited: Nov 22, 2011
  7. Ippokratis

    Ippokratis

    Member

    Joined:
    Oct 13, 2008
    Messages:
    1,087
    Hi,
    Thanks a lot for the code and the explanations,
    -Ippokratis
  8. aubergine

    aubergine

    Member

    Joined:
    Sep 12, 2009
    Messages:
    1,995
    No problem, hope it helps to someone.
  9. Mauri

    Mauri

    Member

    Joined:
    Dec 9, 2010
    Messages:
    478
    @Ippokratis
    Don't get me wrong. Of course i appreciate it :)
  10. Namey5

    Namey5

    Member

    Joined:
    Jul 5, 2013
    Messages:
    1
    Uhh...The link you posted is just ads...ads everywhere. No download.
  11. aubergine

    aubergine

    Member

    Joined:
    Sep 12, 2009
    Messages:
    1,995
    You are aware the initial post is more than 3 years old.
    There are couple smiliar copy assets in the assetstore you can find.