自定义 PBR(MetallicBased) 材质

说明:

    带有法线贴图,带有metallic based PBR map。基于物理渲染,可完善的使用mixedlighting。
包含三张贴图

Albedo:

  • RGBA

Materialmap:

  • R=预留
  • G=roughness
  • B=预留
  • A=metallic

NormalMap:

  • RGB=NormalMap

代码块:

物理材质:

Shader "WH40K/Static/Static_Metal_200" {Properties {_Color ("Color", Color) = (1,1,1,1)_MainTex ("Albedo (RGB)", 2D) = "white" {}_Glossiness ("Smoothness", Range(0,1)) = 0.7_MaterialMap ("Material", 2D) = "white" {}_BumpMap ("NormalMap", 2D) ="bump"{}}SubShader {Tags { "RenderType"="Opaque" }LOD 200CGPROGRAM// Physically based Standard lighting model, and enable shadows on all light types#pragma surface surf Standard fullforwardshadows// Use shader model 3.0 target, to get nicer looking lighting#pragma target 3.0sampler2D _MainTex;sampler2D _MaterialMap;sampler2D _BumpMap;struct Input {float2 uv_MainTex;float2 uv_MaterialMap;float2 uv_BumpMap;};half _Glossiness;half _Metallic;fixed4 _Color;// Add instancing support for this shader. You need to check 'Enable Instancing' on materials that use the shader.// See https://docs.unity3d.com/Manual/GPUInstancing.html for more information about instancing.// #pragma instancing_options assumeuniformscalingUNITY_INSTANCING_CBUFFER_START(Props)// put more per-instance properties hereUNITY_INSTANCING_CBUFFER_ENDvoid surf (Input IN, inout SurfaceOutputStandard o) {// Albedo comes from a texture tinted by colorfixed4 c = tex2D (_MainTex, IN.uv_MainTex) * _Color;fixed4 m = tex2D (_MaterialMap, IN.uv_MaterialMap);o.Albedo = c.rgb;o.Smoothness = (1-m.g)*_Glossiness;o.Metallic = m.a;o.Alpha = c.a;o.Normal = UnpackNormal (tex2D (_BumpMap, IN.uv_BumpMap));}ENDCG}FallBack "Diffuse"
}

非物理材质

Shader "WH40K/Static/Static_Metal_100" {Properties {_Color ("Color", Color) = (1,1,1,1)_MainTex ("Albedo (RGB)", 2D) = "white" {}_Glossiness ("Smoothness", Range(0,1)) = 0.7_MaterialMap ("Material", 2D) = "white" {}_BumpMap ("NormalMap", 2D) ="bump"{}}SubShader {Tags { "RenderType"="Opaque" }LOD 100CGPROGRAM#pragma surface surf WH40KBlinnPhong exclude_path:prepass  noforwardadd halfasview interpolateview//定义变量sampler2D _MainTex;sampler2D _MaterialMap;sampler2D _BumpMap;fixed _Glossiness;fixed _Gloss;half _Specular;fixed4 _Color;//定义光照模型inline fixed4 WH40KBlinnPhongLight (SurfaceOutput s, half3 viewDir, UnityLight light){half3 h = normalize (light.dir + viewDir);fixed diff = max (0, dot (s.Normal, light.dir));float nh = max (0, dot (s.Normal, h));float spec = pow (nh, s.Specular*128.0) * s.Gloss;fixed4 c;//加0.1来对冲没有环境光的色差c.rgb = s.Albedo * light.color * diff + light.color  * spec+0.1;c.a = s.Alpha;return c;}inline fixed4 LightingWH40KBlinnPhong (SurfaceOutput s, half3 viewDir, UnityGI gi){fixed4 c;c = WH40KBlinnPhongLight (s, viewDir, gi.light);#if defined(DIRLIGHTMAP_SEPARATE)#ifdef LIGHTMAP_ONc += WH40KBlinnPhongLight (s, viewDir, gi.light2);#endif#ifdef DYNAMICLIGHTMAP_ONc += WH40KBlinnPhongLight (s, viewDir, gi.light3);#endif#endif#ifdef UNITY_LIGHT_FUNCTION_APPLY_INDIRECTc.rgb += s.Albedo * gi.indirect.diffuse;#endifreturn c;}inline void LightingWH40KBlinnPhong_GI (SurfaceOutput s,UnityGIInput data,inout UnityGI gi){gi = UnityGlobalIllumination (data, 1.0, s.Normal);}inline fixed4 LightingWH40KBlinnPhong_PrePass (SurfaceOutput s, half4 light){fixed spec = light.a * s.Gloss;fixed4 c;c.rgb = (s.Albedo * light.rgb + light.rgb * _SpecColor.rgb * spec);c.a = s.Alpha;return c;}// Use shader model 3.0 target, to get nicer looking lighting//#pragma target 3.0//定义 Input 结构体struct Input {float2 uv_MainTex;float2 uv_BumpMap;};// Add instancing support for this shader. You need to check 'Enable Instancing' on materials that use the shader.// See https://docs.unity3d.com/Manual/GPUInstancing.html for more information about instancing.// #pragma instancing_options assumeuniformscalingUNITY_INSTANCING_CBUFFER_START(Props)// put more per-instance properties hereUNITY_INSTANCING_CBUFFER_ENDvoid surf (Input IN, inout SurfaceOutput o) {fixed4 c = tex2D (_MainTex, IN.uv_MainTex) * _Color;fixed4 m = tex2D (_MaterialMap, IN.uv_MainTex);o.Albedo = tex2D (_MainTex, IN.uv_MainTex).rgb;o.Specular = m.g;o.Gloss = (1-m.g)*_Glossiness;o.Alpha = c.a;o.Normal = UnpackNormal (tex2D (_BumpMap, IN.uv_BumpMap));}ENDCG}FallBack "Diffuse"
}

Unity Custom PBR材质相关推荐

  1. unity build-in管线中的PBR材质Shader分析研究

    PBR分析 前言 我理解的PBR PBR组成部分 直接光漫反射 直接光镜面反射(高光) 间接光漫反射 间接光镜面反射 最终加和 结果 前言 近来,用到了几次Surface Shader,对于其封装好的 ...

  2. unity再战PBR材质流程与材质制作实践

    版权声明:本文为博主原创文章,未经博主允许不得转载. 这篇在上一篇的基础上增加了对PBR的认识,主要包括了金属度和粗糙度(光滑度)的测试 unity里PBR流程,PBR材质属性具体分析 传统模型到PB ...

  3. SubstanceDesigner制作PBR材质制作并且同步到Unity小尝试

    SubstanceDesigner制作PBR材质制作并且同步到Unity小尝试 1.下载安装SubstanceDesigner,网址:https://zixue.3d66.com/softhtml/d ...

  4. Unity灯光、烘焙小结(五)Unity官方场景(PBR材质)制作经验总结

    ********************Unity官方PBR场景总结******************* 1.所有可见物体不设置碰撞,单独按照可见物体(高精度模型)创建一个低精度的物体进行碰撞,如下 ...

  5. Unity URP管线的PBR材质及Tessallation Shader(Height Map高度贴图)

    在使用URP管线的过程中发现默认的URP管线的shader是没有提供height map参数设置的,经过查找才知道URP管线中height map相关的功能需要自己写shader开启Tessallat ...

  6. 将angular转化为手机app_手机照片快速转化为PBR材质流程

    佬们好啊,继续带来一篇技术性推文,主要讲解如何将手机照片快速转化为PBR材质流程. 注:本文来自后台投稿 作者:unity蔡徐坤 今天尝试的一些材料非常有趣.用手机拍摄的照片使用Unity ArtEn ...

  7. PBR材质:基本原理和简单制作

    概要:介绍PBR材质的基本原理以及制作一个简单的PBR材质 参考资料:BASIC THEORY OF PHYSICALLY-BASED RENDERING 如有问题,多多指正. 侵删. 1.PBR是什 ...

  8. unity地面添加材质球_unity自带材质球

    Unity5中重点推出了一套基于物理的着色(Physically Based Shading,PBS)的多功能Shader,叫做标准着色器(Standard Shader).这套Shader的设计初衷 ...

  9. sp烘焙流程_小手雷-PBR材质流程(一)——(基本材质)

    小手雷-PBR材质流程(一) Substance Painter生存手册经过了12个章节的讲解后,已经完结了(。・ω・。) 相信大家经过了生存手册这一基础教程过后,对Substance Painter ...

最新文章

  1. linux 新建用户和权限分配
  2. 解决在C#(.net)按字节数截取字符串最后出现乱码的问题
  3. python fromfile_python之numpy文件操作
  4. AgileConfig轻量级配置中心1.3.0发布,支持多用户权限控制
  5. linux 下 安装 phpstorm
  6. 2021年数据科学家面试:4个基本SQL窗口函数介绍以及示例
  7. 联发科(MediaTek)Pentonic 电视芯片将率先支持杜比视界 IQ 精准细节功能
  8. ubuntu下的jdk环境变量配置(解决sun jdk和open jdk的问题)
  9. 2021年危险化学品经营单位安全管理人员考试报名及危险化学品经营单位安全管理人员作业考试题库
  10. 嗅探工具 --- wireshark、tcpdump、dsniff、ettercap、bettercap、netsniff-ng
  11. 计算机房图怎么画,机房CAD图纸的画法教程
  12. python人脸识别门禁系统毕设_基于人脸识别的门禁系统设计与实现
  13. c++跟踪调试怎么用 dev_DEVC++调试方法
  14. 《嵌入式应用开发》实验一、开发环境搭建与布局
  15. R语言 高版本 安装DMwR2 用knn插补缺失值
  16. 分享:SET“红绳”悬吊运动训练的基本概念
  17. 考研真有那么难吗?过来人分享一下
  18. [转帖]Windows7/2008中批量删除隧道适配器的方法
  19. 用 Python 分析了 6000 款 App,看看哪些神器你还没用过?
  20. 求一个有一千个元素的整数数组的最大子数组的和

热门文章

  1. 网络语言上多个C是什么意思,今年流行的网络用语,个个都很有意思,你知道几个呢?...
  2. 深圳mba学费一览表
  3. Node.js学习笔记——模块加载机制及npm指令详解
  4. PAT乙级练习题1030 完美数列
  5. HR面/综合面系列:公司相关
  6. 秋招Java开发工程师笔试_美团Java工程师面试题(2018秋招)
  7. BZOJ2144: 跳跳棋
  8. 什么是用户代理样式表
  9. JS:原生JS实现message消息提示框
  10. STM32F103移植FreeRTOS必须搞明白的系列知识---1(Cortex-CM3中断优先级)