崩坏三 - 武器 - 童谣 NPR渲染分析

崩坏三 - 武器 - 童谣 NPR渲染分析

  • 童谣 NPR渲染
    • 演示视频链接
    • 大致想法
    • Ramp
    • 高光效果
    • 边缘光效果
    • 镰刀刃部
    • 效果截图
    • 完整代码
    • 镰刀身体部分
    • 镰刀刃部分

童谣 NPR渲染

在这里插入图片描述

演示视频链接

https://www.bilibili.com/video/av68650714

大致想法

镰刀身体部分:
描边 + Ramp多阶色 + 高光 + 边缘光 + 菲涅尔反射 + HSV调节

镰刀刃部:
扰动 + Emission + 金属 + Gloss + 菲涅尔反射

Ramp

分阶色Shader代码

// multi stepsfloat diff = smoothstep(_RampThreshold - ndl, _RampThreshold + ndl, ndl);float interval = 1 / _ToonSteps;// float ramp = floor(diff * _ToonSteps) / _ToonSteps;float level = round(diff * _ToonSteps) / _ToonSteps;float ramp ;if (_RampSmooth == 1){ramp = interval * linearstep(level - _RampSmooth * interval * 0.5, level + _RampSmooth * interval * 0.5, diff) + level - interval;}else{ramp = interval * smoothstep(level - _RampSmooth * interval * 0.5, level + _RampSmooth * interval * 0.5, diff) + level - interval;}ramp = max(0, ramp);ramp *= atten;_SColor = lerp(_HColor, _SColor, _SColor.a);float3 rampColor = lerp(_SColor.rgb, _HColor.rgb, ramp);

高光效果

高光Shader代码

 // specularfloat spec = pow(ndh, s.Specular * 128.0) * s.Gloss;spec *= atten;spec = smoothstep(0.5 - _SpecSmooth * 0.5, 0.5 + _SpecSmooth * 0.5, spec);

边缘光效果

边缘光Shader代码

            float rim = (1.0 - ndv) * ndl;rim *= atten;rim = smoothstep(_RimThreshold - _RimSmooth * 0.5, _RimThreshold + _RimSmooth * 0.5, rim);fixed4 color;fixed3 diffuse = s.Albedo * rampColor *(ndv + 1.5);fixed3 specular = _SpecColor.rgb * spec;fixed3 rimColor = _RimColor.rgb * _RimColor.a * rim;

镰刀刃部

Shader代码

float4 frag(VertexOutput i) : COLOR {i.normalDir = normalize(i.normalDir);float3x3 tangentTransform = float3x3( i.tangentDir, i.bitangentDir, i.normalDir);float3 viewDirection = normalize(_WorldSpaceCameraPos.xyz - i.posWorld.xyz);float4 _Normal_var = tex2D(_Normal,TRANSFORM_TEX(i.uv0, _Normal));float3 normalLocal = _Normal_var.rgb;float3 normalDirection = normalize(mul( normalLocal, tangentTransform )); // Perturbed normalsfloat3 viewReflectDirection = reflect( -viewDirection, normalDirection );float3 lightDirection = normalize(_WorldSpaceLightPos0.xyz);float3 lightColor = _LightColor0.rgb;float3 halfDirection = normalize(viewDirection+lightDirection);
// Lighting:float attenuation = LIGHT_ATTENUATION(i);float3 attenColor = attenuation * _LightColor0.xyz;float Pi = 3.141592654;float InvPi = 0.31830988618;
/ Gloss:float gloss = _Gloss;float perceptualRoughness = 1.0 - _Gloss;float roughness = perceptualRoughness * perceptualRoughness;float specPow = exp2( gloss * 10.0 + 1.0 );
/// GI Data:UnityLight light;#ifdef LIGHTMAP_OFFlight.color = lightColor;light.dir = lightDirection;light.ndotl = LambertTerm (normalDirection, light.dir);#elselight.color = half3(0.f, 0.f, 0.f);light.ndotl = 0.0f;light.dir = half3(0.f, 0.f, 0.f);#endifUnityGIInput d;d.light = light;d.worldPos = i.posWorld.xyz;d.worldViewDir = viewDirection;d.atten = attenuation;#if defined(LIGHTMAP_ON) || defined(DYNAMICLIGHTMAP_ON)d.ambient = 0;d.lightmapUV = i.ambientOrLightmapUV;#elsed.ambient = i.ambientOrLightmapUV;#endif#if UNITY_SPECCUBE_BLENDING || UNITY_SPECCUBE_BOX_PROJECTIONd.boxMin[0] = unity_SpecCube0_BoxMin;d.boxMin[1] = unity_SpecCube1_BoxMin;#endif#if UNITY_SPECCUBE_BOX_PROJECTIONd.boxMax[0] = unity_SpecCube0_BoxMax;d.boxMax[1] = unity_SpecCube1_BoxMax;d.probePosition[0] = unity_SpecCube0_ProbePosition;d.probePosition[1] = unity_SpecCube1_ProbePosition;#endifd.probeHDR[0] = unity_SpecCube0_HDR;d.probeHDR[1] = unity_SpecCube1_HDR;Unity_GlossyEnvironmentData ugls_en_data;ugls_en_data.roughness = 1.0 - gloss;ugls_en_data.reflUVW = viewReflectDirection;UnityGI gi = UnityGlobalIllumination(d, 1, normalDirection, ugls_en_data );lightDirection = gi.light.dir;lightColor = gi.light.color;
// Specular:float NdotL = saturate(dot( normalDirection, lightDirection ));float LdotH = saturate(dot(lightDirection, halfDirection));float3 specularColor = _Metallic;float specularMonochrome;float4 node_3538 = _Time;float2 node_6877 = (i.uv0+(_Speed*node_3538.g)*float2(1,1));float4 _MeltTex_var = tex2D(_MeltTex,TRANSFORM_TEX(node_6877, _MeltTex));float2 node_8337 = lerp(i.uv0,(float3(i.uv0,0.0)*_MeltTex_var.rgb*2.0).rg,_Intensity);float4 node_4378 = tex2D(_MainTex,TRANSFORM_TEX(node_8337, _MainTex));float3 node_5719 = (_MianColor.rgb*node_4378.rgb);float3 diffuseColor = ((_FresnelColor.rgb*pow(1.0-max(0,dot(normalDirection, viewDirection)),_FresnelScale))+(node_5719+node_5719)); // Need this for specular when using metallicdiffuseColor = DiffuseAndSpecularFromMetallic( diffuseColor, specularColor, specularColor, specularMonochrome );specularMonochrome = 1.0-specularMonochrome;float NdotV = abs(dot( normalDirection, viewDirection ));float NdotH = saturate(dot( normalDirection, halfDirection ));float VdotH = saturate(dot( viewDirection, halfDirection ));float visTerm = SmithJointGGXVisibilityTerm( NdotL, NdotV, roughness );float normTerm = GGXTerm(NdotH, roughness);float specularPBL = (visTerm*normTerm) * UNITY_PI;#ifdef UNITY_COLORSPACE_GAMMAspecularPBL = sqrt(max(1e-4h, specularPBL));#endifspecularPBL = max(0, specularPBL * NdotL);#if defined(_SPECULARHIGHLIGHTS_OFF)specularPBL = 0.0;#endifhalf surfaceReduction;#ifdef UNITY_COLORSPACE_GAMMAsurfaceReduction = 1.0-0.28*roughness*perceptualRoughness;#elsesurfaceReduction = 1.0/(roughness*roughness + 1.0);#endifspecularPBL *= any(specularColor) ? 1.0 : 0.0;float3 directSpecular = attenColor*specularPBL*FresnelTerm(specularColor, LdotH);half grazingTerm = saturate( gloss + specularMonochrome );float3 indirectSpecular = (gi.indirect.specular);indirectSpecular *= FresnelLerp (specularColor, grazingTerm, NdotV);indirectSpecular *= surfaceReduction;float3 specular = (directSpecular + indirectSpecular);
/// Diffuse:NdotL = max(0.0,dot( normalDirection, lightDirection ));half fd90 = 0.5 + 2 * LdotH * LdotH * (1-gloss);float nlPow5 = Pow5(1-NdotL);float nvPow5 = Pow5(1-NdotV);float3 directDiffuse = ((1 +(fd90 - 1)*nlPow5) * (1 + (fd90 - 1)*nvPow5) * NdotL) * attenColor;float3 indirectDiffuse = float3(0,0,0);indirectDiffuse += gi.indirect.diffuse;float3 diffuse = (directDiffuse + indirectDiffuse) * diffuseColor;
// Emissive:float node_5997 = (node_4378.b*_Emission);float3 emissive = float3(node_5997,node_5997,node_5997);
/// Final Color:float3 finalColor = diffuse + specular + emissive;fixed4 finalRGBA = fixed4(finalColor,1);UNITY_APPLY_FOG(i.fogCoord, finalRGBA);return finalRGBA;}

效果截图

截图一
在这里插入图片描述
截图二
在这里插入图片描述

完整代码

镰刀身体部分

Shader "Toon"
{Properties{// Colors_Color ("Color", Color) = (1, 1, 1, 1)_HColor ("Highlight Color", Color) = (0.8, 0.8, 0.8, 1.0)_SColor ("Shadow Color", Color) = (0.2, 0.2, 0.2, 1.0)// texture_MainTex ("Main Texture", 2D) = "white" { }// ramp_ToonSteps ("Steps of Toon", range(1, 9)) = 2_RampThreshold ("Ramp Threshold", Range(0.1, 1)) = 0.5_RampSmooth ("Ramp Smooth", Range(0, 1)) = 0.1// specular_SpecColor ("Specular Color", Color) = (0.5, 0.5, 0.5, 1)_SpecSmooth ("Specular Smooth", Range(0, 1)) = 0.1_Shininess ("Shininess", Range(0.001, 10)) = 0.2// rim light[HDR]_RimColor ("Rim Color", Color) = (1,1,1,1)_RimThreshold ("Rim Threshold", Range(0, 1)) = 0.5_RimSmooth ("Rim Smooth", Range(0, 1)) = 0.289_Outline ("Outline", Range(0, 1)) = 0.002_OutColor ("Outline Color", Color) = (0, 0, 0, 1)_Factor("Factor",range(0,1)) = 0.5//rgb to hsv_HueOffset("Hue Offset", Range(0,1)) = 0_SaturationOffset("Hue Offset", Range(-1,1)) = 0.3_ValueOffset("Hue Offset", Range(-1,1)) = 0.15_BloomFactor("_BloomFactor", Range(0.0, 0.9)) = 0[HDR]_FresnealColor("FresnealColor",Color) = (1,0.4191,0.6715,1)_FresnealScale("FresnealScale",Range(0,10)) = 1.88 }SubShader{Tags { "RenderType" = "Opaque" }Pass {NAME "OUTLINE"Tags{ "LightMode" = "Always" }Cull FrontZWrite OnCGPROGRAM#pragma multi_compile_fog#pragma vertex vert#pragma fragment frag#include "UnityCG.cginc"float _Outline;fixed4 _OutColor;float _Factor;struct a2v {float4 vertex : POSITION;float3 normal : NORMAL;}; struct v2f {float4 pos : SV_POSITION;UNITY_FOG_COORDS(0)};v2f vert (a2v v) {v2f o;float3 dir = normalize(v.vertex.xyz);float3 dir2 = v.normal;float D = dot(dir,dir2);dir = dir * sign(D);dir = dir * _Factor + dir2 * (1 - _Factor);v.vertex.xyz += dir * _Outline;o.pos = UnityObjectToClipPos(v.vertex);UNITY_TRANSFER_FOG(o, o.pos);return o;}float4 frag(v2f i) : SV_Target { float4 c = _OutColor;UNITY_APPLY_FOG(i.fogCoord, c);return c;               }ENDCG}CGPROGRAM#pragma surface surf Toon addshadow fullforwardshadows exclude_path:deferred exclude_path:prepass#pragma surface surf Standard fullforwardshadows keepalpha#pragma target 3.0fixed4 _Color;fixed4 _HColor;fixed4 _SColor;sampler2D _MainTex;float _RampThreshold;float _RampSmooth;float _ToonSteps;float _SpecSmooth;fixed _Shininess;fixed4 _RimColor;fixed _RimThreshold;float _RimSmooth;float _HueOffset;float _SaturationOffset;float _ValueOffset;float _BloomFactor;fixed4 _FresnealColor;float _FresnealScale;struct Input{float2 uv_MainTex;float3 viewDir; };struct v2f  {  float4 pos : SV_POSITION;  float3 worldNormal : TEXCOORD0;  };  v2f vert(appdata_base v)  {  v2f o;  o.pos = UnityObjectToClipPos(v.vertex);   o.worldNormal = mul(v.normal, (float3x3)unity_WorldToObject);  return o;  }  float linearstep(float min, float max, float t){return saturate((t - min) / (max - min));}inline fixed4 LightingToon(SurfaceOutput s, half3 lightDir, half3 viewDir, half atten){half3 normalDir = normalize(s.Normal);half3 halfDir = normalize(lightDir + viewDir);float ndl = max(0, dot(normalDir, lightDir));float ndh = max(0, dot(normalDir, halfDir));float ndv = max(0, dot(normalDir, viewDir));fixed3 Fresneal = pow(1.0 - max(0,dot(normalDir, viewDir)),_FresnealScale)*_FresnealColor.rgb;fixed4 finalFresneal = fixed4(Fresneal,1);// multi stepsfloat diff = smoothstep(_RampThreshold - ndl, _RampThreshold + ndl, ndl);float interval = 1 / _ToonSteps;// float ramp = floor(diff * _ToonSteps) / _ToonSteps;float level = round(diff * _ToonSteps) / _ToonSteps;float ramp ;if (_RampSmooth == 1){ramp = interval * linearstep(level - _RampSmooth * interval * 0.5, level + _RampSmooth * interval * 0.5, diff) + level - interval;}else{ramp = interval * smoothstep(level - _RampSmooth * interval * 0.5, level + _RampSmooth * interval * 0.5, diff) + level - interval;}ramp = max(0, ramp);ramp *= atten;_SColor = lerp(_HColor, _SColor, _SColor.a);float3 rampColor = lerp(_SColor.rgb, _HColor.rgb, ramp);// specularfloat spec = pow(ndh, s.Specular * 128.0) * s.Gloss;spec *= atten;spec = smoothstep(0.5 - _SpecSmooth * 0.5, 0.5 + _SpecSmooth * 0.5, spec);// rimfloat rim = (1.0 - ndv) * ndl;rim *= atten;rim = smoothstep(_RimThreshold - _RimSmooth * 0.5, _RimThreshold + _RimSmooth * 0.5, rim);fixed4 color;fixed3 diffuse = s.Albedo * rampColor *(ndv + 1.5);fixed3 specular = _SpecColor.rgb * spec;fixed3 rimColor = _RimColor.rgb * _RimColor.a * rim;float3 rgb = diffuse.rgb;float4 k = float4(0.0, -1.0 / 3.0, 2.0 / 3.0, -1.0);float4 p = lerp(float4(rgb.bg, k.wz), float4(rgb.gb, k.xy), step(rgb.b, rgb.g));// 比较r和max(b,g)float4 q = lerp(float4(p.xyw, rgb.r), float4(rgb.r, p.yzx), step(p.x, rgb.r));float d = q.x - min(q.w, q.y);float e = 1.0e-10;float3 hsv = float3(abs(q.z + (q.w - q.y) / (6.0 * d + e)), d / (q.x + e), q.x);hsv.x = hsv.x + _HueOffset;hsv.y = hsv.y + _SaturationOffset;hsv.z = hsv.z + _ValueOffset;rgb = saturate(3.0*abs(1.0-2.0*frac(hsv.x+float3(0.0,-1.0/3.0,1.0/3.0)))-1); //明度和饱和度为1时的颜色rgb = (lerp(float3(1,1,1),rgb,hsv.y)*hsv.z); // hsvcolor.rgb = rgb + specular + rimColor;color.a = s.Alpha;fixed4 col;col.rgb = color.rgb;col.a = 1;return col + finalFresneal;}void surf(Input IN, inout SurfaceOutput o){fixed4 mainTex = tex2D(_MainTex, IN.uv_MainTex);o.Albedo = mainTex.rgb * _Color.rgb;o.Alpha = _BloomFactor;o.Specular = _Shininess;o.Gloss = mainTex.a;}ENDCG}FallBack "Diffuse"
}

镰刀刃部分

Shader "Shader Forge/WeaponShader" {Properties {_MainTex ("MainTex", 2D) = "white" {}_Emission ("Emission", Range(0, 1)) = 0.6_Metallic ("Metallic", Range(0, 1)) = 0.73_Gloss ("Gloss", Range(0, 1)) = 0.69_Normal ("Normal", 2D) = "black" {}_Speed ("Speed", Range(0, 5)) = 0.4_MeltTex ("MeltTex", 2D) = "black" {}_Intensity ("Intensity", Range(0, 1)) = 0.2436957[HDR]_MianColor ("MianColor", Color) = (0.2426471,0.8119676,1,1)_FresnelScale ("FresnelScale", Range(0.01, 10)) = 4.188035[HDR]_FresnelColor ("FresnelColor", Color) = (0.3676471,0.8430021,1,1)}SubShader {Tags {"RenderType"="Opaque"}Pass {Name "FORWARD"Tags {"LightMode"="ForwardBase"}CGPROGRAM#pragma vertex vert#pragma fragment frag#define UNITY_PASS_FORWARDBASE#define SHOULD_SAMPLE_SH ( defined (LIGHTMAP_OFF) && defined(DYNAMICLIGHTMAP_OFF) )#define _GLOSSYENV 1#include "UnityCG.cginc"#include "AutoLight.cginc"#include "Lighting.cginc"#include "UnityPBSLighting.cginc"#include "UnityStandardBRDF.cginc"#pragma multi_compile_fwdbase_fullshadows#pragma multi_compile LIGHTMAP_OFF LIGHTMAP_ON#pragma multi_compile DIRLIGHTMAP_OFF DIRLIGHTMAP_COMBINED DIRLIGHTMAP_SEPARATE#pragma multi_compile DYNAMICLIGHTMAP_OFF DYNAMICLIGHTMAP_ON#pragma multi_compile_fog#pragma only_renderers d3d9 d3d11 glcore gles #pragma target 3.0uniform sampler2D _MainTex; uniform float4 _MainTex_ST;uniform float _Emission;uniform float _Metallic;uniform float _Gloss;uniform sampler2D _Normal; uniform float4 _Normal_ST;uniform float _Speed;uniform sampler2D _MeltTex; uniform float4 _MeltTex_ST;uniform float _Intensity;uniform float4 _MianColor;uniform float _FresnelScale;uniform float4 _FresnelColor;struct VertexInput {float4 vertex : POSITION;float3 normal : NORMAL;float4 tangent : TANGENT;float2 texcoord0 : TEXCOORD0;float2 texcoord1 : TEXCOORD1;float2 texcoord2 : TEXCOORD2;};struct VertexOutput {float4 pos : SV_POSITION;float2 uv0 : TEXCOORD0;float2 uv1 : TEXCOORD1;float2 uv2 : TEXCOORD2;float4 posWorld : TEXCOORD3;float3 normalDir : TEXCOORD4;float3 tangentDir : TEXCOORD5;float3 bitangentDir : TEXCOORD6;LIGHTING_COORDS(7,8)UNITY_FOG_COORDS(9)#if defined(LIGHTMAP_ON) || defined(UNITY_SHOULD_SAMPLE_SH)float4 ambientOrLightmapUV : TEXCOORD10;#endif};VertexOutput vert (VertexInput v) {VertexOutput o = (VertexOutput)0;o.uv0 = v.texcoord0;o.uv1 = v.texcoord1;o.uv2 = v.texcoord2;#ifdef LIGHTMAP_ONo.ambientOrLightmapUV.xy = v.texcoord1.xy * unity_LightmapST.xy + unity_LightmapST.zw;o.ambientOrLightmapUV.zw = 0;#elif UNITY_SHOULD_SAMPLE_SH#endif#ifdef DYNAMICLIGHTMAP_ONo.ambientOrLightmapUV.zw = v.texcoord2.xy * unity_DynamicLightmapST.xy + unity_DynamicLightmapST.zw;#endifo.normalDir = UnityObjectToWorldNormal(v.normal);o.tangentDir = normalize( mul( unity_ObjectToWorld, float4( v.tangent.xyz, 0.0 ) ).xyz );o.bitangentDir = normalize(cross(o.normalDir, o.tangentDir) * v.tangent.w);o.posWorld = mul(unity_ObjectToWorld, v.vertex);float3 lightColor = _LightColor0.rgb;o.pos = UnityObjectToClipPos( v.vertex );UNITY_TRANSFER_FOG(o,o.pos);TRANSFER_VERTEX_TO_FRAGMENT(o)return o;}float4 frag(VertexOutput i) : COLOR {i.normalDir = normalize(i.normalDir);float3x3 tangentTransform = float3x3( i.tangentDir, i.bitangentDir, i.normalDir);float3 viewDirection = normalize(_WorldSpaceCameraPos.xyz - i.posWorld.xyz);float4 _Normal_var = tex2D(_Normal,TRANSFORM_TEX(i.uv0, _Normal));float3 normalLocal = _Normal_var.rgb;float3 normalDirection = normalize(mul( normalLocal, tangentTransform )); // Perturbed normalsfloat3 viewReflectDirection = reflect( -viewDirection, normalDirection );float3 lightDirection = normalize(_WorldSpaceLightPos0.xyz);float3 lightColor = _LightColor0.rgb;float3 halfDirection = normalize(viewDirection+lightDirection);
// Lighting:float attenuation = LIGHT_ATTENUATION(i);float3 attenColor = attenuation * _LightColor0.xyz;float Pi = 3.141592654;float InvPi = 0.31830988618;
/ Gloss:float gloss = _Gloss;float perceptualRoughness = 1.0 - _Gloss;float roughness = perceptualRoughness * perceptualRoughness;float specPow = exp2( gloss * 10.0 + 1.0 );
/// GI Data:UnityLight light;#ifdef LIGHTMAP_OFFlight.color = lightColor;light.dir = lightDirection;light.ndotl = LambertTerm (normalDirection, light.dir);#elselight.color = half3(0.f, 0.f, 0.f);light.ndotl = 0.0f;light.dir = half3(0.f, 0.f, 0.f);#endifUnityGIInput d;d.light = light;d.worldPos = i.posWorld.xyz;d.worldViewDir = viewDirection;d.atten = attenuation;#if defined(LIGHTMAP_ON) || defined(DYNAMICLIGHTMAP_ON)d.ambient = 0;d.lightmapUV = i.ambientOrLightmapUV;#elsed.ambient = i.ambientOrLightmapUV;#endif#if UNITY_SPECCUBE_BLENDING || UNITY_SPECCUBE_BOX_PROJECTIONd.boxMin[0] = unity_SpecCube0_BoxMin;d.boxMin[1] = unity_SpecCube1_BoxMin;#endif#if UNITY_SPECCUBE_BOX_PROJECTIONd.boxMax[0] = unity_SpecCube0_BoxMax;d.boxMax[1] = unity_SpecCube1_BoxMax;d.probePosition[0] = unity_SpecCube0_ProbePosition;d.probePosition[1] = unity_SpecCube1_ProbePosition;#endifd.probeHDR[0] = unity_SpecCube0_HDR;d.probeHDR[1] = unity_SpecCube1_HDR;Unity_GlossyEnvironmentData ugls_en_data;ugls_en_data.roughness = 1.0 - gloss;ugls_en_data.reflUVW = viewReflectDirection;UnityGI gi = UnityGlobalIllumination(d, 1, normalDirection, ugls_en_data );lightDirection = gi.light.dir;lightColor = gi.light.color;
// Specular:float NdotL = saturate(dot( normalDirection, lightDirection ));float LdotH = saturate(dot(lightDirection, halfDirection));float3 specularColor = _Metallic;float specularMonochrome;float4 node_3538 = _Time;float2 node_6877 = (i.uv0+(_Speed*node_3538.g)*float2(1,1));float4 _MeltTex_var = tex2D(_MeltTex,TRANSFORM_TEX(node_6877, _MeltTex));float2 node_8337 = lerp(i.uv0,(float3(i.uv0,0.0)*_MeltTex_var.rgb*2.0).rg,_Intensity);float4 node_4378 = tex2D(_MainTex,TRANSFORM_TEX(node_8337, _MainTex));float3 node_5719 = (_MianColor.rgb*node_4378.rgb);float3 diffuseColor = ((_FresnelColor.rgb*pow(1.0-max(0,dot(normalDirection, viewDirection)),_FresnelScale))+(node_5719+node_5719)); // Need this for specular when using metallicdiffuseColor = DiffuseAndSpecularFromMetallic( diffuseColor, specularColor, specularColor, specularMonochrome );specularMonochrome = 1.0-specularMonochrome;float NdotV = abs(dot( normalDirection, viewDirection ));float NdotH = saturate(dot( normalDirection, halfDirection ));float VdotH = saturate(dot( viewDirection, halfDirection ));float visTerm = SmithJointGGXVisibilityTerm( NdotL, NdotV, roughness );float normTerm = GGXTerm(NdotH, roughness);float specularPBL = (visTerm*normTerm) * UNITY_PI;#ifdef UNITY_COLORSPACE_GAMMAspecularPBL = sqrt(max(1e-4h, specularPBL));#endifspecularPBL = max(0, specularPBL * NdotL);#if defined(_SPECULARHIGHLIGHTS_OFF)specularPBL = 0.0;#endifhalf surfaceReduction;#ifdef UNITY_COLORSPACE_GAMMAsurfaceReduction = 1.0-0.28*roughness*perceptualRoughness;#elsesurfaceReduction = 1.0/(roughness*roughness + 1.0);#endifspecularPBL *= any(specularColor) ? 1.0 : 0.0;float3 directSpecular = attenColor*specularPBL*FresnelTerm(specularColor, LdotH);half grazingTerm = saturate( gloss + specularMonochrome );float3 indirectSpecular = (gi.indirect.specular);indirectSpecular *= FresnelLerp (specularColor, grazingTerm, NdotV);indirectSpecular *= surfaceReduction;float3 specular = (directSpecular + indirectSpecular);
/// Diffuse:NdotL = max(0.0,dot( normalDirection, lightDirection ));half fd90 = 0.5 + 2 * LdotH * LdotH * (1-gloss);float nlPow5 = Pow5(1-NdotL);float nvPow5 = Pow5(1-NdotV);float3 directDiffuse = ((1 +(fd90 - 1)*nlPow5) * (1 + (fd90 - 1)*nvPow5) * NdotL) * attenColor;float3 indirectDiffuse = float3(0,0,0);indirectDiffuse += gi.indirect.diffuse;float3 diffuse = (directDiffuse + indirectDiffuse) * diffuseColor;
// Emissive:float node_5997 = (node_4378.b*_Emission);float3 emissive = float3(node_5997,node_5997,node_5997);
/// Final Color:float3 finalColor = diffuse + specular + emissive;fixed4 finalRGBA = fixed4(finalColor,1);UNITY_APPLY_FOG(i.fogCoord, finalRGBA);return finalRGBA;}ENDCG}Pass {Name "FORWARD_DELTA"Tags {"LightMode"="ForwardAdd"}Blend One OneCGPROGRAM#pragma vertex vert#pragma fragment frag#define UNITY_PASS_FORWARDADD#define SHOULD_SAMPLE_SH ( defined (LIGHTMAP_OFF) && defined(DYNAMICLIGHTMAP_OFF) )#define _GLOSSYENV 1#include "UnityCG.cginc"#include "AutoLight.cginc"#include "Lighting.cginc"#include "UnityPBSLighting.cginc"#include "UnityStandardBRDF.cginc"#pragma multi_compile_fwdadd_fullshadows#pragma multi_compile LIGHTMAP_OFF LIGHTMAP_ON#pragma multi_compile DIRLIGHTMAP_OFF DIRLIGHTMAP_COMBINED DIRLIGHTMAP_SEPARATE#pragma multi_compile DYNAMICLIGHTMAP_OFF DYNAMICLIGHTMAP_ON#pragma multi_compile_fog#pragma only_renderers d3d9 d3d11 glcore gles #pragma target 3.0uniform sampler2D _MainTex; uniform float4 _MainTex_ST;uniform float _Emission;uniform float _Metallic;uniform float _Gloss;uniform sampler2D _Normal; uniform float4 _Normal_ST;uniform float _Speed;uniform sampler2D _MeltTex; uniform float4 _MeltTex_ST;uniform float _Intensity;uniform float4 _MianColor;uniform float _FresnelScale;uniform float4 _FresnelColor;struct VertexInput {float4 vertex : POSITION;float3 normal : NORMAL;float4 tangent : TANGENT;float2 texcoord0 : TEXCOORD0;float2 texcoord1 : TEXCOORD1;float2 texcoord2 : TEXCOORD2;};struct VertexOutput {float4 pos : SV_POSITION;float2 uv0 : TEXCOORD0;float2 uv1 : TEXCOORD1;float2 uv2 : TEXCOORD2;float4 posWorld : TEXCOORD3;float3 normalDir : TEXCOORD4;float3 tangentDir : TEXCOORD5;float3 bitangentDir : TEXCOORD6;LIGHTING_COORDS(7,8)UNITY_FOG_COORDS(9)};VertexOutput vert (VertexInput v) {VertexOutput o = (VertexOutput)0;o.uv0 = v.texcoord0;o.uv1 = v.texcoord1;o.uv2 = v.texcoord2;o.normalDir = UnityObjectToWorldNormal(v.normal);o.tangentDir = normalize( mul( unity_ObjectToWorld, float4( v.tangent.xyz, 0.0 ) ).xyz );o.bitangentDir = normalize(cross(o.normalDir, o.tangentDir) * v.tangent.w);o.posWorld = mul(unity_ObjectToWorld, v.vertex);float3 lightColor = _LightColor0.rgb;o.pos = UnityObjectToClipPos( v.vertex );UNITY_TRANSFER_FOG(o,o.pos);TRANSFER_VERTEX_TO_FRAGMENT(o)return o;}float4 frag(VertexOutput i) : COLOR {i.normalDir = normalize(i.normalDir);float3x3 tangentTransform = float3x3( i.tangentDir, i.bitangentDir, i.normalDir);float3 viewDirection = normalize(_WorldSpaceCameraPos.xyz - i.posWorld.xyz);float4 _Normal_var = tex2D(_Normal,TRANSFORM_TEX(i.uv0, _Normal));float3 normalLocal = _Normal_var.rgb;float3 normalDirection = normalize(mul( normalLocal, tangentTransform )); // Perturbed normalsfloat3 lightDirection = normalize(lerp(_WorldSpaceLightPos0.xyz, _WorldSpaceLightPos0.xyz - i.posWorld.xyz,_WorldSpaceLightPos0.w));float3 lightColor = _LightColor0.rgb;float3 halfDirection = normalize(viewDirection+lightDirection);
// Lighting:float attenuation = LIGHT_ATTENUATION(i);float3 attenColor = attenuation * _LightColor0.xyz;float Pi = 3.141592654;float InvPi = 0.31830988618;
/ Gloss:float gloss = _Gloss;float perceptualRoughness = 1.0 - _Gloss;float roughness = perceptualRoughness * perceptualRoughness;float specPow = exp2( gloss * 10.0 + 1.0 );
// Specular:float NdotL = saturate(dot( normalDirection, lightDirection ));float LdotH = saturate(dot(lightDirection, halfDirection));float3 specularColor = _Metallic;float specularMonochrome;float4 node_3538 = _Time;float2 node_6877 = (i.uv0+(_Speed*node_3538.g)*float2(1,1));float4 _MeltTex_var = tex2D(_MeltTex,TRANSFORM_TEX(node_6877, _MeltTex));float2 node_8337 = lerp(i.uv0,(float3(i.uv0,0.0)*_MeltTex_var.rgb*2.0).rg,_Intensity);float4 node_4378 = tex2D(_MainTex,TRANSFORM_TEX(node_8337, _MainTex));float3 node_5719 = (_MianColor.rgb*node_4378.rgb);float3 diffuseColor = ((_FresnelColor.rgb*pow(1.0-max(0,dot(normalDirection, viewDirection)),_FresnelScale))+(node_5719+node_5719)); // Need this for specular when using metallicdiffuseColor = DiffuseAndSpecularFromMetallic( diffuseColor, specularColor, specularColor, specularMonochrome );specularMonochrome = 1.0-specularMonochrome;float NdotV = abs(dot( normalDirection, viewDirection ));float NdotH = saturate(dot( normalDirection, halfDirection ));float VdotH = saturate(dot( viewDirection, halfDirection ));float visTerm = SmithJointGGXVisibilityTerm( NdotL, NdotV, roughness );float normTerm = GGXTerm(NdotH, roughness);float specularPBL = (visTerm*normTerm) * UNITY_PI;#ifdef UNITY_COLORSPACE_GAMMAspecularPBL = sqrt(max(1e-4h, specularPBL));#endifspecularPBL = max(0, specularPBL * NdotL);#if defined(_SPECULARHIGHLIGHTS_OFF)specularPBL = 0.0;#endifspecularPBL *= any(specularColor) ? 1.0 : 0.0;float3 directSpecular = attenColor*specularPBL*FresnelTerm(specularColor, LdotH);float3 specular = directSpecular;
/// Diffuse:NdotL = max(0.0,dot( normalDirection, lightDirection ));half fd90 = 0.5 + 2 * LdotH * LdotH * (1-gloss);float nlPow5 = Pow5(1-NdotL);float nvPow5 = Pow5(1-NdotV);float3 directDiffuse = ((1 +(fd90 - 1)*nlPow5) * (1 + (fd90 - 1)*nvPow5) * NdotL) * attenColor;float3 diffuse = directDiffuse * diffuseColor;
/// Final Color:float3 finalColor = diffuse + specular;fixed4 finalRGBA = fixed4(finalColor * 1,0);UNITY_APPLY_FOG(i.fogCoord, finalRGBA);return finalRGBA;}ENDCG}Pass {Name "Meta"Tags {"LightMode"="Meta"}Cull OffCGPROGRAM#pragma vertex vert#pragma fragment frag#define UNITY_PASS_META 1#define SHOULD_SAMPLE_SH ( defined (LIGHTMAP_OFF) && defined(DYNAMICLIGHTMAP_OFF) )#define _GLOSSYENV 1#include "UnityCG.cginc"#include "Lighting.cginc"#include "UnityPBSLighting.cginc"#include "UnityStandardBRDF.cginc"#include "UnityMetaPass.cginc"#pragma fragmentoption ARB_precision_hint_fastest#pragma multi_compile_shadowcaster#pragma multi_compile LIGHTMAP_OFF LIGHTMAP_ON#pragma multi_compile DIRLIGHTMAP_OFF DIRLIGHTMAP_COMBINED DIRLIGHTMAP_SEPARATE#pragma multi_compile DYNAMICLIGHTMAP_OFF DYNAMICLIGHTMAP_ON#pragma multi_compile_fog#pragma only_renderers d3d9 d3d11 glcore gles #pragma target 3.0uniform sampler2D _MainTex; uniform float4 _MainTex_ST;uniform float _Emission;uniform float _Metallic;uniform float _Gloss;uniform float _Speed;uniform sampler2D _MeltTex; uniform float4 _MeltTex_ST;uniform float _Intensity;uniform float4 _MianColor;uniform float _FresnelScale;uniform float4 _FresnelColor;struct VertexInput {float4 vertex : POSITION;float3 normal : NORMAL;float2 texcoord0 : TEXCOORD0;float2 texcoord1 : TEXCOORD1;float2 texcoord2 : TEXCOORD2;};struct VertexOutput {float4 pos : SV_POSITION;float2 uv0 : TEXCOORD0;float2 uv1 : TEXCOORD1;float2 uv2 : TEXCOORD2;float4 posWorld : TEXCOORD3;float3 normalDir : TEXCOORD4;};VertexOutput vert (VertexInput v) {VertexOutput o = (VertexOutput)0;o.uv0 = v.texcoord0;o.uv1 = v.texcoord1;o.uv2 = v.texcoord2;o.normalDir = UnityObjectToWorldNormal(v.normal);o.posWorld = mul(unity_ObjectToWorld, v.vertex);o.pos = UnityMetaVertexPosition(v.vertex, v.texcoord1.xy, v.texcoord2.xy, unity_LightmapST, unity_DynamicLightmapST );return o;}float4 frag(VertexOutput i) : SV_Target {i.normalDir = normalize(i.normalDir);float3 viewDirection = normalize(_WorldSpaceCameraPos.xyz - i.posWorld.xyz);float3 normalDirection = i.normalDir;UnityMetaInput o;UNITY_INITIALIZE_OUTPUT( UnityMetaInput, o );float4 node_3538 = _Time;float2 node_6877 = (i.uv0+(_Speed*node_3538.g)*float2(1,1));float4 _MeltTex_var = tex2D(_MeltTex,TRANSFORM_TEX(node_6877, _MeltTex));float2 node_8337 = lerp(i.uv0,(float3(i.uv0,0.0)*_MeltTex_var.rgb*2.0).rg,_Intensity);float4 node_4378 = tex2D(_MainTex,TRANSFORM_TEX(node_8337, _MainTex));float node_5997 = (node_4378.b*_Emission);o.Emission = float3(node_5997,node_5997,node_5997);float3 node_5719 = (_MianColor.rgb*node_4378.rgb);float3 diffColor = ((_FresnelColor.rgb*pow(1.0-max(0,dot(normalDirection, viewDirection)),_FresnelScale))+(node_5719+node_5719));float specularMonochrome;float3 specColor;diffColor = DiffuseAndSpecularFromMetallic( diffColor, _Metallic, specColor, specularMonochrome );float roughness = 1.0 - _Gloss;o.Albedo = diffColor + specColor * roughness * roughness * 0.5;return UnityMetaFragment( o );}ENDCG}}FallBack "Diffuse"CustomEditor "ShaderForgeMaterialInspector"
}

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.rhkb.cn/news/18553.html

如若内容造成侵权/违法违规/事实不符,请联系长河编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

python啤酒童谣新手求助

为什么循环语句无法生效

chatgpt赋能python:Python高端玩法

Python高端玩法 如果你已经掌握了Python的基础知识,那么它还有许多高端玩法等着你去探索。在这篇文章中,我们将介绍一些Python高端玩法,包括函数式编程、元编程、异步编程、科学计算和机器学习。 函数式编程 Python是一门支持函数式编程范…

用于 LLM 应用开发的 LangChain 中文版

用于 LLM 应用开发的 LangChain 中文版 1. 模型、提示词和输出解析器1-1. 获取您的 OpenAI API 密钥1-2. Chat API : OpenAI1-3. Chat API : LangChain1-3-1. 模型1-3-2. 提示词模板 1-4. 输出解析器1-4-1. 将 LLM 输出字符串解析为 Python 字典 2. 记忆2-1. 会话缓冲区内存(Co…

MiniGPT4,开源了。

大家好,我是 Jack。 一个月前,我发布过一篇文章,讲解了 GPT4 的发布会。 ChatGPT 的对话能力,想必大家也早已体验过了,无论是文本生成能力,还是写代码的能力,甚至是上下文的关联对话能力&#…

飞书API调用尝试,实现飞书文档对于咨询的收集和实时的更新

摘要:主要就是记录一下自己从零开始做自己需要使用的脚本的过程,其中使用到chatgpt工具,也需要有记录作用,可以记录自己每天的工作进程,CSDN的是基于Markdown的方式,所以这个可以恰好植入到我的学习笔记的网…

恐怖的挥霍速度,每年烧上百亿美元,元宇宙大梦“压垮”Meta,苹果出手能否改写颓局...

点击上方“Python与机器智能”,选择“星标”公众号 第一时间获取价值内容 大数据文摘授权转载自AI前线 作者:刘燕,核子可乐 元宇宙玩家,似乎很擅长“画大饼”。 身为社交媒体巨头的掌门人,扎克伯格已经在虚拟现实之梦上…

GPT-4,大增长时代的序幕

作者|成诚 虽然我们早在 2017 年就预测了超大模型的到来,因此才搞了分布式深度学习框架 OneFlow(github.com/Oneflow-Inc/oneflow/),且 2020 年的 GPT-3 也掀起了大模型热潮(OneFlow——让每一位算法工程师…

ChatGPT4功能大全,附上一些官网推荐的例子

例子 探索一些示例应用程序的可能性 所有类别 问答 根据现有知识回答问题。 语法修正 将句子改成标准英语。 给二年级学生总结 将困难的文本翻译成更简单的概念。 自然语言到 OpenAI API 创建代码以使用自然语言指令调用 OpenAI API。 命令文本 将文本转换为编程命令。 英语到其…

《花雕学AI》34:用13种Prompt玩转AI聊天机器人—揭秘ChatGPT模型

引言: 聊天机器人是一种能够通过自然语言进行交流的智能系统,它可以模仿人类的对话方式,提供各种信息、服务或娱乐。随着人工智能技术的发展,聊天机器人的应用越来越广泛,从电商、教育、医疗、旅游等领域,到…

数字人入门文章速览

语音驱动三维人脸方法 OPPO 数字人语音驱动面部技术实践 【万字长文】虚拟人漫谈 Blendshape学习笔记 人脸重建速览,从3DMM到表情驱动动画 功能强大的python包(四):OpenCV 从Blendshapes到Animoji 3D人脸重建算法汇总 一、3D人脸重…

戴上脑机接口头盔,他用大脑跟别人「说话」

梅宁航 发自 凹非寺 量子位 报道 | 公众号 QbitAI 高位截瘫,全身器官失能,大脑还正常,却已口不能言。 怎么办? 现在最新研究进展来了——利用脑机接口,让别人跟患者的大脑直接对话。 近期,俄勒冈健康与科学…

如何用subtitle edit 将英文字幕转换成中文字幕

如何下载Subtitle edit和英文字幕转成中文字幕 Subtitle Edit是一个免费、中文化、使用方便、功能强大的影片字幕制作、同步、翻译与修改软件。这个软件内建影片即时预览功能,可以汇入与辨识字幕,支持SubRib、MicroDVD、Advanced Sub Station Alpha、Su…

whisper实践--基于whisper+pyqt5开发的语音识别翻译生成字幕工具

大家新年快乐,事业生活蒸蒸日上,解封的第一个年,想必大家都回家过年,好好陪陪家人了吧,这篇文章也是我在老家码的,还记得上篇我带大家基本了解了whisper,相信大家对whisper是什么,怎…

如何自动翻译字幕文件(机翻)

所需软件: Vscode 所需插件: Subtitles Editor 操作流程: 众所周知 vscode拥有强大的插件库,强大到甚至可以在vscode中打小霸王 插件库中搜索 Subtitles Editor ​ ​ 点击安装 支持常见的字幕文件格式(.str .vtt .sbv .sub) ​ 提前复制原英文字幕&#xff0…

Tern – 字幕组机翻小助手:自动翻译英文字幕为中英双语字幕[Win/macOS]

简介: Tern 是一款字幕文件翻译工具,它能利用 9 大主流机器翻译服务商(Google、微软、亚马逊等)对 .ass、.srt、.vtt 字幕文件进行翻译,可以减轻字幕组同学的工作量,也为那些对翻译要求不高的同学提供了啃…

借用AI工具为视频添加中文字幕,消除语言障碍,母语环境最快速地学习

由于chatgpt的启动,感觉语言已经完全不会成为学习的障碍,突发奇想,在我们查看youtube视频的时候,有没有方便的工具能够将其字幕翻译为中文。这样能够极大提高在youtube学习的效率,于是顺手问了一下ChatGPT,…

20221115使用google文档翻译SRT格式的字幕

20221115使用google文档翻译SRT格式的字幕 2022/11/15 18:52 (一)将SRT格式的字幕用WPS转换为DOCX的文档。 (请上传 .docx、.pdf、.pptx 或 .xlsx 文件) https://www.google.com.hk/?gws_rdssl Google 拍照搜索 Google 提供&a…

中文字幕!吴恩达 ChatGPT 最新课程

吴恩达是人工智能和机器学习领域国际最权威学者之一,他之前就发布过机器学习、深度学习的视频教程。 在小破站搜索机器学习、深度学习关键词,就能看到大佬的身影,教程高赞、高收藏,广受好评。相信国内 AI 方向的学生 90% 都是听他…

Python分析一下双色球,中大奖指日可待

一、需求简介 之前偶然见到一位网友提出了关于双色球数据的分析需求,感觉颇有趣味,便着手操作了一番。如下为某双色球发布站的页面,可以看到每期会产生红/蓝两种颜色的数字,其中红球为 33 选 6,蓝球为 16 选 1&#x…

最新中国福彩分析大数据分析大师拥有双色球数据展示微信小程序源码支持双色球数据分析多个接口

demo软件园每日更新资源,请看到最后就能获取你想要的: 1.最新中国福彩分析大数据分析大师拥有双色球数据展示微信小程序源码支持双色球数据分析多个接口 福彩大数据分析小程序,数据来自于中国福利彩票 拥有双色球数据展示 双色球数据分析多个接口 数据有每日奖金和…