Specular.png ? Specular.png 逐定点光照 1.声明三个属性,_Specular控制高光反射材质,_Diffuse漫反射材质,_Gloss控制高光区域大小 Properties { _ Diffuse("Diffuse",Color) = (1,1,1,1) _Specular("Specular",Color) = (1,1,1,1) _Gloss(" .rgb*_Specular.rgb*pow(saturate(dot(worldNormal,halfDir)), _Gloss); 更改高光部分的代码 ? Specular_Blinn-Phong.png 对比Phong模型,高光部分更加明显
_Color("Color Tint",Color) = (1,1,1,1) _RampTex("Ramp Tex",2D) = "white"{} _Specular ("Specular",Color) = (1,1,1,1) _Gloss("Gloss",Range(8.0,256)) = 20 } SubShader{ fixed4 _Color; sampler2D _RampTex; float4 _RampTex_ST; fixed4 _Specular = _LightColor0.rgb * _Specular.rgb * pow(max(0, dot(worldNormal, halfDir)), _Gloss); return fixed4(specular + diffuse + ambient, 1.0); } ENDCG
BumpMap("Normal Map",2D) = "bump"{} _BumpScale("Bump Scale",Float) = 1.0 _SpecularMask("Specular Mask",2D) = "white"{} _SpecularScale("Specular Scale",Float) = 1.0 _Specular("Specular BumpScale; sampler2D _SpecularMask; float _SpecularScale; fixed4 _Specular = _LightColor0.rgb * specularMask * _Specular.rgb * pow(max(0, dot(halfDir, tangentNormal)), _Gloss) ; return fixed4(ambient + diffuse + specular, 1.0); } ENDCG
_Color("Color Tint",Color) = (1,1,1,1) _MainTex("Main Tex",2D) = "white"{} _Specular ("Specular",Color) = (1,1,1,1) _Gloss("Gloss",Range(8.0,256)) = 20 } SubShader{ Color; sampler2D _MainTex; float4 _MainTex_ST; fixed4 _Specular return fixed4(ambient + diffuse + specular,1.0); } ENDCG } } Fallback "Specular" } 在顶点着色器中通过_MainTex_ST来对纹理坐标进行偏移.
("Specular",Color) = (1,1,1,1) _Gloss("Gloss",Range(8.0,256)) = 20 } SubShader { fixed4(ambient+diffuse+specular,1.0); } ENDCG } } FallBack "Specular" } Gloss=8,specular=(168,83,47) 纹理属性: Textur Type:贴图类型(诸如纹理,法线贴图等),书中有Texture属性,但在新版本编译器中应该是以 ("Specular",Color) = (1,1,1,1) _Gloss("Gloss",Range(2.0,256)) = 20 } SubShader { specular = _LightColor0.rgb * _Specular.rgb * pow(max(0,dot(tangentNormal,halfDir)),_Gloss) – specularMask
_BumpMap("NormalMap",2D) = "bump"{} _BumpScale("Bump Scale" , Float) = 1.0 _Specular ("Specular",Color) = (1,1,1,1) _Gloss("Gloss",Range(8.0,256)) = 20 } SubShader{ BumpMap; float4 _BumpMap_ST; float _BumpScale; fixed4 _Specular = _LightColor0.rgb * _Specular.rgb * pow(temp, _Gloss); return fixed4(ambient + diffuse + specular, 1.0); } ENDCG } } }
2.1 片元着色器中修改光照参数 struct Light { vec3 position; vec3 ambient; vec3 diffuse; vec3 specular = light.specular * spec * texture(material.specular, TexCoords).rgb; // attenuation *= attenuation; vec3 result = ambient + diffuse + specular; FragColor = light.specular * spec * texture(material.specular, TexCoords).rgb; // spotlight (soft edges *= attenuation; vec3 result = ambient + diffuse + specular; FragColor = vec4(result, 1.0
2) Phong 三项:环境光 + 漫反射 + 镜面反射Phong 模型把最终颜色/亮度写成: I = I_ambient + I_diffuse + I_specular(1) 环境光 Ambient (图中箭头与法线夹角)夹角余弦:NdotL = max(dot(N, L), 0)I_diffuse = Kd * Il * NdotLKd:材质漫反射系数/底色Il:光源颜色/强度(3) 镜面反射 Specular (Phong 高光),取决于观察方向与反射方向的接近程度RdotV = max(dot(R, V), 0)I_specular = Ks * Il * (RdotV ^ shininess)Ks:材质镜面系数 = 0.3 * spec * uLightColor; vec3 color = (ambient + diffuse + specular) * uObjectColor; FragColor = 0.3 * spec * uLightColor; vec3 color = (ambient + diffuse + specular) * uObjectColor; FragColor
Relected Color---untilities---studio clear coat工作量光漆 index 1.5 scale 1.3 笔尖 离心率 Eccentricity 0.5 Specular Vcord 2.弄一个挡光板,surface 面片--- 面片加lambert材质球,Incanderscence白色 灯光: Color:灯光的颜色 Intensity: 强度(控制亮暗) Emit Specular Shading: Eccentricity 离心率0.4 Specular Roll of高光反射偏移 Reflectcivity反射 Special Effects Glow Intensity Sample Info加入other facingRatio--vCord 陶瓷 phong材质 Color 浅色(柔和) Cosine Power 余弦力 40 Reflectivity 0.2 Specular Color 高光白 木纹家具: Specular Shading Eccentricity 高光 0.3 Specular Roll off 反射,滑移 Specular Cloud
镜面光贴图和其他的纹理类似,比如上一篇的漫反射贴图 着色器中定义高光采样器 struct Material { sampler2D diffuse; sampler2D specular float shininess; }; c++代码中,设置高光采样器映射到第1个纹理单元,激活并绑定第一个纹理单元到纹理 lightingShader.setInt("material.specular 片元着色器 #version 330 core out vec4 FragColor; struct Material { sampler2D diffuse; sampler2D specular = light.specular * spec * texture(material.specular, TexCoords).rgb; vec3 result = ambient + diffuse + specular; FragColor = vec4(result, 1.0); } 2.
冯氏光照模型(Phong Lighting Model)便是其中常用的一个光照模型,它由三种元素光组成,分别是环境光(Ambient Lighting)、散射光(Diffuse Lighting)及镜面光(Specular vec3 specular = specularStrength * spec * lightColor; //镜面光最终强度 vec3 result = specular * objectColor lightColor; uniform vec3 viewPos; out vec2 v_texCoord; out vec3 ambient; out vec3 diffuse; out vec3 specular float diff = max(dot(unitNormal, lightDir), 0.0); diffuse = diffuseStrength * diff * lightColor; // Specular version 300 es precision mediump float; in vec2 v_texCoord; in vec3 ambient; in vec3 diffuse; in vec3 specular
: #include <GL/glut.h> #include <stdlib.h> // 初始化材质、光源、光照模型、深度缓存 void myInit(void) { GLfloat mat_specular ; glClearColor (0.0, 0.0, 0.0, 0.0); glShadeModel (GL_SMOOTH); glMaterialfv(GL_FRONT, GL_SPECULAR , mat_specular); glMaterialfv(GL_FRONT, GL_SHININESS, mat_shininess); glLightfv(GL_LIGHT0, GL_POSITION, light_position); glLightfv(GL_LIGHT0, GL_DIFFUSE, white_light); glLightfv(GL_LIGHT0, GL_SPECULAR
("Specular Color", Color) = (1, 1, 1, 1) _Gloss ("Gloss", Range(8.0, 256)) = 20 } SubShader { (atten, i, worldPos); return fixed4(ambient + (diffuse + specular) * atten, 1.0); } ENDCG = _LightColor0.rgb * _Specular.rgb * pow(max(0, dot(bump, halfDir)), _Gloss); //使用内置宏进行光照衰减和阴影的计算 UNITY_LIGHT_ATTENUATION(atten, i, worldPos); return fixed4((diffuse + specular) * atten, 1.0 ); } ENDCG } } FallBack "Specular" }
specular VS diffuse VS ambient 那么,我们在定义一种材质时,该如何定义它的光学特性呢? OpenGL ES为我们提供的思路是:将材料对光的反应分为三部分。 specular 光线直接照射到物体反射到观察者眼中,这束光被称作镜面反射光。我们称之为specular。 通常我们像这样定义它: float[] specular = {1.0f, 1.0f, 1.0f, 1.0f}; float[] materialSpec = {1.0f, 0.5f, 0.0f, 1.0f float[] ambient = {0.9f, 0.9f, 0.9f, 1.0f}; float[] diffuse = {0.5f, 0.5f, 0.5f, 1.0f}; float[] specular , STLUtils.floatToBuffer(specular)); gl.glLightfv(GL10.GL_LIGHT0, GL10.GL_POSITION, STLUtils.floatToBuffer
Specular Lighting = Cs * sum[Ls * (N • H)P * Atten * Spot] The following table identifies the variables Parameter Default value Type Description Cs (0,0,0,0) D3DCOLORVALUE Specular color. sum N/A N/A Summation of each light's specular component. P 0.0 FLOAT Specular reflection power. Range is 0 to +infinity Ls (0,0,0,0) D3DCOLORVALUE Light specular color.
全文主要内容脉络如下: 迪士尼与基于物理的渲染的发展 迪士尼采用的BRDF可视化方案与工具 迪士尼对测量材质数据库的观察结论 Diffuse项的观察结论 Specular D 项的观察结论 Specular ) 核心BRDF模型 漫反射项(Diffuse):Disney Diffuse 法线分布项(Specular D):GTR 菲涅尔项(Specular F):Schlick Fresnel 几何项(Specular 按照不同项的分类,可以总结为如下6个部分: Diffuse项的观察结论 Specular D 项的观察结论 Specular F 项的观察结论 Specular G 项的观察结论 布料(Fabric)材质的观察结论 clearcoat(清漆强度):有特殊用途的第二个镜面波瓣(specular lobe)。 G):Smith-GGX 几何项(Specular G)方面,对于主镜面波瓣(primary specular lobe),Disney参考了 Walter的近似方法,使用Smith GGX导出的G项
of Outline",Range(0,1))=0.5 10 _OutlineColor("Outline Color",Color)=(0,0,0,1) 11 _Specular ("Specular",Color)=(1,1,1,1) 12 _SpecularScale("Specular Scale",Range(0,0.1))=0.01 13 } Color; 89 sampler2D _MainTex; 90 sampler2D _Ramp; 91 fixed4 _Specular fixed w=fwidth(spec)*3.0; 151 152 //计算高光,在[-w,w]范围内平滑插值 153 fixed3 specular return fixed4(ambient+diffuse+specular,1.0); 156 } 157 ENDCG 158
Initialize material property, light source, lighting model, and depth buffer. void init(void) { GLfloat mat_specular , 1.0 }; // glClearColor (0.0, 0.0, 0.0, 0.0); glShadeModel (GL_SMOOTH); glMaterialfv(GL_FRONT, GL_SPECULAR , mat_specular); glMaterialfv(GL_FRONT, GL_SHININESS, mat_shininess); glLightfv(GL_LIGHT0, GL_POSITION , light_position); glLightfv(GL_LIGHT0, GL_DIFFUSE, white_light); glLightfv(GL_LIGHT0, GL_SPECULAR, white_light
particles[N][3]; float rtri = 0; // 初始化材质属性、光源、光照模型、深度缓冲区 void init(void) { //材质反光性设置 GLfloat mat_specular ; //背景色 glShadeModel(GL_SMOOTH); //多变性填充模式 //材质属性 glMaterialfv(GL_FRONT, GL_SPECULAR , mat_specular); glMaterialfv(GL_FRONT, GL_SHININESS, mat_shininess); //灯光设置 glLightfv(GL_LIGHT0 light_position); glLightfv(GL_LIGHT0, GL_DIFFUSE, white_light); //散射光属性 glLightfv(GL_LIGHT0, GL_SPECULAR
颜色,_Gloss粗糙度,_LightColor0系统参数光照颜色 fixed3 specular = _LightColor0.rgb * _Specular.rgb * pow(saturate(dot (reflectDir, viewDir)), _Gloss); o.color = ambient + diffuse + specular; 5.逐像素高光 将逐顶点高光代码发放在片元着色器中执行 = _LightColor0.rgb * _Specular.rgb * pow(max(0, dot(worldNormal, halfDir)), _Gloss); fixed3 color = ambient + diffuse + specular; ---- 三、纹理贴图 1.单张纹理 使用纹理取样替代纯色,在片元着色器中对纹理贴图取样,修改像素颜色; _MainTexture_ST return fixed4((diffuse+specular)*atten,1.0); } 2.阴影处理 Untiy中MeshRender组件上有两个选项: CastShadows——是否投射阴影