雷达波Shader
Posted 酷熊
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了雷达波Shader相关的知识,希望对你有一定的参考价值。
OSG版本:
vert
#version 120 varying out vec3 v; void main() { gl_FrontColor = gl_Color; gl_Position = ftransform(); v = gl_Vertex.xyz; }
frag
#version 120 varying in vec3 v; uniform float osg_FrameTime; void main() { //gl_FragColor = vec4(1,0,0,1); gl_FragColor = gl_Color; // 条带间隔 //if (mod(floor((v.z-osg_FrameTime*100000)/ 100000),2)!=0) // discard; //gl_FragColor = vec4(1,0,0,0.5); float alpha = (cos((v.z-osg_FrameTime*50000) / 20000)+1-0.2)/2; gl_FragColor = vec4(gl_Color.xyz,alpha); }
Unity版本:
// Upgrade NOTE: replaced ‘_World2Object‘ with ‘unity_WorldToObject‘ // Upgrade NOTE: replaced ‘_World2Object‘ with ‘unity_WorldToObject‘ Shader "Custom/RadarWave" { Properties { _Color ("Color", Color) = (1,1,1,1) _MainTex ("Albedo (RGB)", 2D) = "white" {} _Glossiness("Smoothness", Range(0,1)) = 0.5 _Metallic("Metallic", Range(0,1)) = 0.0 _TransVal("Transparency Value", Range(0,1)) = 0.5 _StripWidth("Strip Width", Range(0.01,1)) = 0.1 _Speed("Speed", Range(0.1,10)) = 1 [Enum(x,1,y,2,z,3)]_Direction("Moving Direction", Int)=3 } SubShader { Tags { "RenderType"="Opaque" "Queue" = "Transparent" } LOD 200 //Cull Off//关闭背面裁剪 //Lighting Off//此设置在surface shader中不起作用,貌似是在Unlit Shader中使用的 //ZWrite On //ZTest On Blend SrcAlpha OneMinusSrcAlpha CGPROGRAM // Physically based Standard lighting model, and enable shadows on all light types //#pragma surface surf Standard fullforwardshadows alpha vertex:vert #pragma surface surf NoLightModel fullforwardshadows alpha vertex:vert // Use shader model 3.0 target, to get nicer looking lighting #pragma target 3.0 sampler2D _MainTex; struct Input { float2 uv_MainTex; float4 modelPos_; }; half _Glossiness; half _Metallic; half _TransVal; half _StripWidth; half _Speed; int _Direction; 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 assumeuniformscaling UNITY_INSTANCING_CBUFFER_START(Props) // put more per-instance properties here UNITY_INSTANCING_CBUFFER_END void surf(Input IN, inout SurfaceOutput o) { // Albedo comes from a texture tinted by color fixed4 c = tex2D(_MainTex, IN.uv_MainTex) * _Color; o.Albedo = c.rgb; //float4 tmp = mul(unity_WorldToObject, IN.modelPos_); //_Time float4 t是自该场景加载开始所经过的时间,4个分量分别是 (t/20, t, t*2, t*3) float modelPos = _Direction == 1 ? IN.modelPos_.x : _Direction == 2 ? IN.modelPos_.y : IN.modelPos_.z; /*if (fmod(floor((modelPos -_Time.y*_Speed)/ _StripWidth),3)!=0) { //clip(-1); discard; } //o.Alpha = c.a; o.Alpha = _TransVal;*/ o.Alpha = (cos((modelPos - _Time.y*_Speed) / _StripWidth) + 1) / 2; o.Alpha = clamp(o.Alpha, 0.1, 0.9); } void vert(inout appdata_full v, out Input o) { UNITY_INITIALIZE_OUTPUT(Input, o); o.modelPos_ = v.vertex; } //命名规则:Lighting接#pragma suface之后起的名字 //lightDir :点到光源的单位向量 viewDir:点到摄像机的单位向量 atten:衰减系数 float4 LightingNoLightModel(SurfaceOutput s, float3 lightDir, half3 viewDir, half atten) { float4 c; c.rgb = s.Albedo; c.a = s.Alpha; return c; } ENDCG } FallBack "Diffuse" }
以上是关于雷达波Shader的主要内容,如果未能解决你的问题,请参考以下文章
Cg入门15:Vertex Shader - 几何变换 —波
雷达通信基于matlab无人机FMCW毫米波高度计雷达仿真含Matlab源码 1261期