简体   繁体   中英

Unity shader - How to generate normal map based on texture map

I'm currently stuck in a shader that i'm writing. I'm trying to create a rain shader. I have set up 3 particle system which simulates rain, and a camera to look at this simulation. The camera view is what I use as texture. In my shader I am now trying to make a normal map from that texture map, but I don't know how to do it.

Shader "Unlit/Rain"
{
    Properties
    {
        _MainTex("Albedo (RGB)", 2D) = "white" {}
        _Color("Color", Color) = (1,1,1,1)
        _NormalIntensity("NormalIntensity",Float) = 1
      
    }
        SubShader
        {
            
            Tags { "RenderType" = "Opaque" }
            LOD 100

            Pass
            {
                CGPROGRAM
                #pragma vertex vert
                #pragma fragment frag

                #include "UnityCG.cginc"
                #include "Lighting.cginc"
                #include "AutoLight.cginc"

                struct VertexInput {
                    float4 vertex : POSITION;
                    float2 uv : TEXCOORD0;
                    float4 normal : NORMAL;
                    float3 tangent : TANGENT;

                };

                struct VertexOutput {
                    float2 uv : TEXCOORD0;
                    float4 vertex : SV_POSITION;
                    float2 uv1 : TEXCOORD1;
                    float4 normals : NORMAL;

                    float3 tangentSpaceLight: TANGENT;
                   
                };

                sampler2D _MainTex;
                float4 _MainTex_ST;
                half4 _Color;
                float _NormalIntensity;

                VertexOutput vert(VertexInput v) {

                    VertexOutput o;
                    o.normals = v.normal;
                    o.uv1 = v.uv;
                    o.vertex = UnityObjectToClipPos( v.vertex );
                   // o.uv = TRANSFORM_TEX( v.uv, _MainTex ); // used for texture

                    return o;
                }



                float4 frag(VertexOutput i) : COLOR{

                    float4 col2 = tex2D(_MainTex, i.uv1); 
                    return col2 * i.normals * 5;
                }
                ENDCG
            }
        }
}

This is what the camera sees. I set the TargetTexture for this camera to be a texture I created.

In my shader I then put that texture as an albedo property

So what I wanna do is now find the normal for that texture to create a bumpmap.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM