UnityShader Demo01:冰块材质

作者: 时过敬迁 | 来源:发表于2017-08-21 12:27 被阅读0次

简单版本效果如下

这里写图片描述

原理
使用法线贴图扭曲透明颜色贴图的uv值
Shader 代码1

Shader"PengLu/normal/iceTrans" {
Properties {
    _Color ("Main Color", Color) = (1,1,1,1)
    _MainTex ("BaseTex ", 2D) = "white" {}
    _BumpMap ("Normalmap", 2D) = "bump" {}
    _BumpAmt ("Distortion", range (0,2)) = 0.1

}

SubShader {
    Tags { "Queue"="Transparent""RenderType"="Opaque" }
    ZWrite off



CGPROGRAM
#pragma surface surfLambert nolightmap nodirlightmap alpha:blend

 sampler2D _BumpMap;
 sampler2D _MainTex;
 float4 _Color;
 float _BumpAmt;

struct Input {
    float2 uv_MainTex;
    float2 uv_BumpMap;
};


void surf (Input IN,inout SurfaceOutput o) {
    fixed3 nor = UnpackNormal (tex2D(_BumpMap, IN.uv_BumpMap));
    fixed4 trans =tex2D(_MainTex,IN.uv_MainTex+nor.xy*_BumpAmt)*_Color;

    o.Albedo = trans.rgb;
    o.Alpha =trans.a;
    o.Emission = trans; 
}
ENDCG
}

FallBack"Transparent/VertexLit"
}

surface版本 shader代码:

Shader "PengLu/Custom/iceRefrationSurf" {
Properties {
    _Color ("Main Color", Color) = (1,1,1,1)
    _MainTex ("BaseTex", 2D) = "white" {}
    _BumpMap ("Normalmap", 2D) = "bump" {}
    _BumpAmt ("Distortion", range (0,1)) = 0.12
}

SubShader {
    Tags { "Queue"="Transparent" "RenderType"="Opaque" }
     ZWrite off
     Lighting off

    GrabPass {                          
            Name "BASE"
            Tags { "LightMode" = "Always" }
        }

CGPROGRAM
#pragma surface surf Lambert nolightmap nodirlightmap
#pragma target 3.0
#pragma debug

float4 _Color;
sampler2D _MainTex;
sampler2D _BumpMap;
sampler2D _GrabTexture;
float _BumpAmt;



struct Input {
    float2 uv_MainTex;
    float2 uv_BumpMap;
    float4 screenPos;
};


void surf (Input IN, inout SurfaceOutput o) {
    fixed3 nor = UnpackNormal (tex2D(_BumpMap, IN.uv_BumpMap));
    fixed4 col = tex2D(_MainTex,IN.uv_MainTex);
    float4 screenUV2 = IN.screenPos;
    screenUV2.xy = screenUV2.xy / screenUV2.w;
    screenUV2.xy += nor.xy * _BumpAmt;

    fixed4 trans = tex2D(_GrabTexture,screenUV2.xy)*_Color;
    trans*=col; 
    o.Albedo = trans.rgb;
    o.Emission = trans.rgb;
;   
}                                                                                                                                                                                                                                                                                                   
ENDCG
}

FallBack "Transparent/VertexLit"
}
surface版本效果

surface版本目前还有问题,在编辑视图里面结果是对的,但是再camera显示不正确。暂时能力不够没找到方法修改

相关文章

  • UnityShader Demo01:冰块材质

    简单版本效果如下 原理使用法线贴图扭曲透明颜色贴图的uv值Shader 代码1 surface版本 shader代...

  • 3.《unityshader中级篇》使用属性

    如何使用属性?? 我们都清楚shader和材质之间的关系非同一般,我们需要一个调节unityshader中参数的方...

  • UnityShader:入门篇

    今天我们来具体了解UnityShader及ShaderLab。 ShaderLab 学习UnityShader首先...

  • 媒体查询

    demo01 demo02 demo03

  • demo01

    图像处理基本操作 1. 读取图像 opencv提供了imread函数来读取图像,该函数有两个参数,filepath...

  • java,javac,javap命令的作用

    jdk里面自带有一些工具,比如java demo01:是用来运行一个类,javac demo01:是用来编译一个类...

  • 5.Unityshader的类型

    在unityshader中我们可以用三种形式来编写unityshader 1. 表面着色器 需要的代码量少,渲染代...

  • UnityShader学习笔记—UnityShader结构

  • 冰块

    今天上学的路上时候到处都是冰块,我慢悠悠的走进班级,开始晨诵,晨诵完第一节课是语文课。下课的时候我跟付雨涵他们玩。...

  • 冰块

    案上的冰块,半尺厚 冰块里的文字,冬眠的青蛙 没有阳光网站,收购 他们不喜欢听,禾苗间蛙唱 他们的树上,焦燥蝉声,...

网友评论

    本文标题:UnityShader Demo01:冰块材质

    本文链接:https://www.haomeiwen.com/subject/rtucdxtx.html