几个 shader

uniform sampler2D av_texture;
varying highp vec3 v_position;
varying highp vec2 v_texcoord;

void main(void){
    gl_FragColor = texture2D(av_texture, v_texcoord);
}

uniform sampler2D av_texture;
varying highp vec3 v_position;
varying highp vec2 v_texcoord;
varying highp vec2 v_blenduv;
uniform float uBlendAngle;
uniform float uPlaneWidth;
uniform float uPlaneHeight;
uniform mat4 uTransformMat;

highp float alphaNormalized(float x) {
    float lamda = 5.2;
    float gamma = 1.0;
    float a= 0.5;
    if(x <= 0.5) {
        x = a * pow(2.0 * x,lamda);
    } else {
        x = 1.0 - (1.0 - a) * pow(2.0 * (1.0 - x),lamda);
    }
    x = pow(x,gamma);
    return x;
}

void main(void){
    float pi = 3.1415926535898;
    float phi,angle,alpha1,alpha2;
    //在xz平面
    phi = pi * (v_position.z/ uPlaneHeight + 0.5);
    float z = cos(phi);
    float ringradius = sin(phi);
    float theta = pi * 2.0 * ((v_position.x / uPlaneWidth + 0.5));
    float x = ringradius * cos(theta);
    float y = ringradius * sin(theta);

    vec4 pos = uTransformMat * vec4(x,y,z,1.0);
    x = pos.x;
    y = pos.y;
    z = pos.z ;

    if(z > 0.0) {
        phi = atan(sqrt(y * y + z * z),x);
    } else {
        phi = atan(abs(y),x);
    }
    phi = phi/pi * 180.0;
    angle = (90.0 + uBlendAngle/2.0) - phi;
    alpha1 = angle/uBlendAngle;
    alpha1 = clamp(alpha1,0.0,1.0);
    alpha1 = alphaNormalized(alpha1);

    vec4 color1 = texture2D(av_texture,v_texcoord);
    vec4 color2 = texture2D(av_texture,v_blenduv);
    gl_FragColor = color2 * alpha1 + color1 * (1.0 - alpha1);
    gl_FragColor.a = 1.0;
}

uniform sampler2D av_texture;
varying highp vec3 v_position;
varying highp vec2 v_texcoord;
uniform mat4 uTransformMat;
uniform float uPlaneWidth;
uniform float uPlaneHeight;

void main(void){
    float pi = 3.141592653589793238462643383279502884;
    //在xz平面
    float phi = pi * (v_position.z/ uPlaneHeight + 0.5);
    float theta = pi * 2.0 * ((v_position.x / uPlaneWidth + 0.5));

    float z = cos(phi);
    float ringradius = sin(phi);
    float x = ringradius * cos(theta);
    float y = ringradius * sin(theta);

    vec4 pos = uTransformMat * vec4(x,y,z,1.0);

    //can not use -pos.z,bug.
    phi = atan(sqrt(pos.x * pos.x + pos.y * pos.y),pos.z);
    theta = atan(pos.y,pos.x);
    theta += 2.0 * pi;
    theta = mod(theta,2.0 * pi);

    float u = clamp(theta/(2.0 * pi),0.0,1.0);
    float v = clamp(1.0 - phi/pi,0.0,1.0);
    gl_FragColor = texture2D(av_texture, vec2(u,v));
}

uniform sampler2D av_texture;
varying highp vec3 v_position;
varying highp vec2 v_texcoord;
uniform float uClipAngle;
uniform float uPlaneWidth;
uniform float uPlaneHeight;
uniform mat4 uRotMat;
uniform float uFov;

void main(void){
    gl_FragColor = texture2D(av_texture, v_texcoord);
    float pi = 3.14159265358979323846;
    float xi = v_position.x/uPlaneWidth + 0.5;
    float yi = (v_position.z)/uPlaneHeight + 0.5;
    float phi = pi * yi;
    float z = cos(phi);
    float ringradius = sin(phi);
    float clipAngle = uFov/180.0*pi;
    float theta = (pi * 2.0 - clipAngle)/2.0 + clipAngle * xi;
    float x = ringradius * cos(theta);
    float y = ringradius * sin(theta);
    vec4 vec = uRotMat * vec4(x,y,z,1.0);
    phi = atan(sqrt(vec.x * vec.x + vec.y * vec.y),vec.z);
    phi = phi/pi * 180.0;
    float blendAngle = 5.0/180.0 * pi;
    //sbs no blend
    if(uClipAngle/180.0 * pi - blendAngle < pi) {
        blendAngle = 0.0;
    }
    if(phi > uClipAngle/2.0 - blendAngle) {
        gl_FragColor.a = (uClipAngle/2.0 - phi)/blendAngle;
    }
}

attribute highp vec3 av_vertex;
attribute highp vec2 av_texcoord;
attribute highp vec2 av_blenduv;
varying highp vec3 v_position;
varying highp vec2 v_texcoord;
varying highp vec2 v_blenduv;
uniform mediump mat4 modelviewprojectionMat;

void main(void){
    gl_Position = modelviewprojectionMat * vec4(av_vertex.xyz,1.0);
    v_position = av_vertex;
    v_texcoord = av_texcoord;
    v_blenduv = av_blenduv;
}

attribute highp vec3 av_vertex;
attribute highp vec2 av_texcoord;
varying highp vec3 v_position;
varying highp vec2 v_texcoord;
uniform mediump mat4 modelviewprojectionMat;

void main(void){
    gl_Position = modelviewprojectionMat * vec4(av_vertex.xyz,1.0);
    v_position = av_vertex;
    v_texcoord = av_texcoord;
}

attribute highp vec3 av_vertex;
attribute highp vec2 av_texcoord;
attribute highp vec2 av_blenduv;
varying highp vec3 v_position;
varying highp vec2 v_texcoord;
varying highp vec2 v_blenduv;
uniform mediump mat4 modelviewprojectionMat;
uniform float uPlaneWidth;
uniform float uPlaneHeight;
void main(void){
    gl_Position = modelviewprojectionMat * vec4(av_vertex.xyz,1.0);
    v_position = av_vertex;
    v_texcoord = av_texcoord;
    v_blenduv = av_blenduv;
}

uniform sampler2D av_texture;
varying highp vec3 v_position;
varying highp vec2 v_texcoord;
uniform mat4 uTransformMat;
uniform float uPanoHeight;
uniform float uChartletWidth;
uniform float uChartletHeight;
uniform float uChartletAngle;
void main(void){
    float pi = 3.1415926535898;
    //在xz平面
    float phi = pi * (v_position.z/ uPanoHeight + 0.5);
    float z = cos(phi);
    float ringradius = sin(phi);
    float theta = pi * 2.0 * ((v_position.x / (uPanoHeight * 2.0) + 0.5));
    float x = ringradius * cos(theta);
    float y = ringradius * sin(theta);

    vec4 pos = uTransformMat * vec4(x,y,z,1.0);
    //can not use -pos.z,bug.
    phi = atan(sqrt(pos.x * pos.x + pos.y * pos.y),pos.z);
    theta = atan(pos.y,pos.x);
    theta -= pi/2.0;
    while(theta < 0.0) {
        theta += pi * 2.0;
    }

    float chartletRadius = sqrt(uChartletWidth/2.0 * uChartletWidth/2.0 + uChartletHeight/2.0 * uChartletHeight/2.0);
    float angle = uChartletAngle/180.0 * pi;
    float r = (pi - phi)/angle * chartletRadius;
    float u = r * cos(theta) + uChartletWidth/2.0;
    float v = r * sin(theta) + uChartletHeight/2.0;
    u /= uChartletWidth;
    v /= uChartletHeight;

//    hflip
    u = 1.0 - u;

//    float u = v_texcoord.x;
//    float v = v_texcoord.y;
    if(u < 0.0 || v < 0.0
        || u > 1.0 || v > 1.0) {
        gl_FragColor = vec4(0.0,0.0,0.0,0.0);
    } else {
        gl_FragColor = texture2D(av_texture, vec2(u,v));
    }
}

uniform sampler2D av_texture;
varying highp vec3 v_position;
varying highp vec2 v_texcoord;
varying highp vec2 v_blenduv;
uniform float uBlendAngle;
uniform mat4 uTransformMat;

highp float alphaNormalized(float x) {
    float lamda = 5.2;

    float gamma = 1.0;
    float a= 0.5;
    if(x <= 0.5) {
        x = a * pow(2.0 * x,lamda);
    } else {
        x = 1.0 - (1.0 - a) * pow(2.0 * (1.0 - x),lamda);
    }
    x = pow(x,gamma);
    return x;
}

vec4 transformPosition() {
    //transform from vertex to pos corresponding to uv
    //cos(theta) = cos(2pi - theta)
    //sin(theta) = -sin(2pi - theta)
    //v(x,y,z) => uvpos(x,-z,-y)
    vec4 pos = uTransformMat * vec4(v_position.x,-v_position.z,-v_position.y,1.0);
    return pos;
}

void main(void)
{
    float pi = 3.1415926535898;
    float phi,angle,alpha1,alpha2;
    vec4 pos = transformPosition();
    if(pos.x > 0.0) {
        phi = atan(sqrt(pos.y * pos.y + pos.z * pos.z),pos.x);
    } else {
        phi = atan(abs(pos.y),pos.x);
    }
    phi = phi/pi * 180.0;
    angle = phi - (90.0 - uBlendAngle/2.0);
    alpha1 = angle/uBlendAngle;
    alpha1 = clamp(alpha1,0.0,1.0);
    alpha1 = alphaNormalized(alpha1);

    vec4 color1 = texture2D(av_texture,v_texcoord);
    vec4 color2 = texture2D(av_texture,v_blenduv);
    gl_FragColor = color1 * alpha1 + color2 * (1.0 - alpha1);
    gl_FragColor.a = 1.0;
}
{
	"version":	1,
	"info":	{
		"gps":	{
			"altitude":	0,
			"longitude":	0,
			"latitude":	0
		},
		"gyro":	{
			
"gy":	0.949728,
			
"az":	0.006412,
			
"gx":	-0.032753,
			
"ay":	0.003080,
			
"gz":	-0.311359,
			
"ax":	0.004583
		
},
		"offset":	"2_744.201_765.480_755.949
_0.000_0.000_90.000
_744.261_2275.801_753.489
_-0.510_-0.300_90.690_3040_1520_1026",
		
"serialNumber":	"",
		
"orientation":	{
			"x":	0.232000,
			"y":	0,
			"z":	0,
			"w":	0
		}
	}
}?  


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
### 回答1: 好的,下面是一个简单的火焰shader示例: 首先,在Unity中创建一个新的Shader文件。然后将以下代码复制并粘贴到Shader文件中: ``` Shader "Custom/Fire" { Properties { _MainTex ("Texture", 2D) = "white" {} _Speed ("Speed", Range(0.1, 10)) = 1 _Scale ("Scale", Range(0.1, 10)) = 1 _Intensity ("Intensity", Range(1, 10)) = 1 _Color ("Color", Color) = (1, 0.5, 0, 1) } SubShader { Tags { "Queue"="Transparent" "RenderType"="Opaque" } LOD 100 Pass { CGPROGRAM #pragma vertex vert #pragma fragment frag #include "UnityCG.cginc" struct appdata { float4 vertex : POSITION; float2 uv : TEXCOORD0; }; struct v2f { float2 uv : TEXCOORD0; float4 vertex : SV_POSITION; }; sampler2D _MainTex; float _Speed; float _Scale; float _Intensity; fixed4 _Color; v2f vert (appdata v) { v2f o; o.vertex = UnityObjectToClipPos(v.vertex); o.uv = v.uv; return o; } fixed4 frag (v2f i) : SV_Target { fixed4 col = tex2D(_MainTex, i.uv); float noise = _Intensity * (_Scale * sum(noise(3, 0.5, 0.1, i.uv * _Speed)) + 1); col.rgb += _Color.rgb * noise; return col; } ENDCG } } FallBack "Diffuse" } ``` 这个shader包含了以下几个属性: - `_MainTex`: 火焰的纹理图像。 - `_Speed`: 火焰动画的速度。 - `_Scale`: 火焰的大小。 - `_Intensity`: 火焰的强度。 - `_Color`: 火焰的颜色。 然后在一个材质上使用这个shader,将纹理图像设置为火焰图像,调整其他属性以获得所需的火焰效果。 希望这个示例对你有所帮助! ### 回答2: 火焰shader是一种用于在游戏或动画中渲染逼真火焰效果的技术。在Unity中编写火焰shader需要以下步骤: 1. 创建一个新的Shader。在Unity的项目资源管理器中,右键点击创建一个新的Shader,并为其命名。 2. 在shader中定义属性。使用Properties块来定义火焰所需的所有属性,如火焰贴图、颜色、尺寸等。 3. 编写顶点和片段着色器。在SubShader块中编写顶点和片段着色器。顶点着色器用于传递顶点位置和法线等信息,片段着色器用于计算每个像素的颜色。 4. 使用噪声函数生成动态效果。使用Simplex Noise和Perlin Noise等噪声算法,在片段着色器中生成火焰的动态效果。可以根据时间、位置等参数调整生成的噪声,实现动态火焰效果。 5. 计算火焰颜色。使用颜色插值来实现火焰颜色的变化。可以根据火焰高度、密度等属性,将火焰渐变为黄色、橙色、红色等。 6. 添加光照效果。可以根据火焰法线向量和光照信息,计算光照对火焰的影响,使火焰看起来更真实。 7. 调试和优化。在调试过程中,可以根据实际效果对火焰shader进行优化,比如减少计算量、调整颜色变化等。 8. 在游戏中应用。将编写好的火焰shader应用到游戏中的火焰模型上。可以通过将shader附加到渲染器组件或材质上来实现。 通过以上步骤,我们可以在Unity中编写一个基本的火焰shader,实现逼真的火焰效果。根据需要,还可以进一步调整参数和效果,以达到更加细致和生动的火焰效果。 ### 回答3: 在Unity中写一个火焰shader是一个很有趣的挑战。一个火焰shader需要模拟出火焰的效果,包括不断变化的颜色,流动的形状和闪烁的光亮。 首先,我们需要定义火焰所在的位置,可以使用一个二维纹理图像来表示。纹理图像中的每一个点代表火焰的某一个位置,其颜色值代表火焰的强度。 接下来,我们可以通过在shader中使用噪声函数来创建火焰的形状。噪声函数可以生成具有随机性的数值,用于模拟火焰的起伏形状。 然后,我们可以使用一些算法来模拟火焰的运动。一个常见的方法是使用流体动力学方程来模拟火焰的流动,通过在shader中使用这些算法,可以让火焰看起来具有流动感。 除了形状和运动,火焰的颜色也是非常重要的一部分。我们可以通过在shader中创建一个渐变效果,根据火焰的强度来决定火焰的颜色。从红色到橙色再到黄色,再到白色,可以使火焰看起来非常真实。 最后,我们可以通过在shader中使用一些技巧,模拟火焰的闪烁效果。通过颜色的变化和强度的调整,让火焰看起来具有动态和变化的光亮。 总结起来,编写一个火焰shader需要考虑到火焰的形状、颜色、流动和闪烁效果。通过使用噪声函数、渐变效果和流体动力学方程,我们可以在Unity中创建出逼真的火焰效果。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值