Мастер
Регистрация: 13.06.2011
Сообщений: 1,103
Написано 481 полезных сообщений (для 1,836 пользователей)
|
Ответ: Кватернион. Как определить угол вращения.
еще одно солнце
Shader "Custom/Sun3" {
Properties {
}
SubShader {
Tags { "Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent" }
//Cull Off Lighting Off ZWrite Off Ztest Always Fog { Mode Off }
Blend One One
Pass {
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#pragma fragmentoption ARB_precision_hint_fastest
#pragma target 3.0
#include "UnityCG.cginc"
fixed4 _TintColor;
struct appdata_t {
half4 vertex : POSITION;
fixed4 color : COLOR;
half2 texcoord : TEXCOORD0;
};
struct v2f {
half4 vertex : POSITION;
fixed4 color : COLOR;
half2 texcoord : TEXCOORD0;
};
v2f vert (appdata_t v)
{
v2f o;
o.vertex = mul(UNITY_MATRIX_MVP, v.vertex);
o.color = v.color;
o.texcoord =v.texcoord;
return o;
}
half3 mod(half3 uv, half res){
return uv - res * floor(uv/res);
}
half snoise(half3 uv, half res){
const half3 s = half3(1e0, 1e2, 1e4);
uv *= res;
half3 uv0 = floor(mod(uv, res))*s;
half3 uv1 = floor(mod(uv+half3(1.), res))*s;
half3 f = frac(uv); f = f*f*(3.0-2.0*f);
half4 v = half4(uv0.x+uv0.y+uv0.z, uv1.x+uv0.y+uv0.z, uv0.x+uv1.y+uv0.z, uv1.x+uv1.y+uv0.z);
half4 r = frac(sin(v*1e-3)*1e5);
half r0 = lerp(lerp(r.x, r.y, f.x), lerp(r.z, r.w, f.x), f.y);
r = frac(sin((v + uv1.z - uv0.z)*1e-3)*1e5);
half r1 = lerp(lerp(r.x, r.y, f.x), lerp(r.z, r.w, f.x), f.y);
return lerp(r0, r1, f.z)*2.-1.;
}
fixed4 frag (v2f i) : COLOR
{
half radius = 0.24 ;
half invRadius = 1.0/radius;
half3 orange = half3( 0.8, 0.55, 0.2 );
half time = _Time.x;
half2 p = -0.5 + i.texcoord;
half fade = pow( length( 2.0 * p ), 0.5 );
half fVal1 = 1.0 - fade;
half fVal2 = 1.0 - fade;
half angle = atan2( p.x, p.y )/6.2832;
half dist = length(p);
half3 coord = half3( angle, dist, time * 0.1 );
half newTime1 = abs( snoise( coord + half3( 0.0, -time * ( 0.35 ), time * 0.015 ), 15.0 ) );
half newTime2 = abs( snoise( coord + half3( 0.0, -time * ( 0.15 ), time * 0.015 ), 45.0 ) );
half3 xCoord = half3( 0.0, -time, time * 0.2 ) + coord;
fVal1 += 0.125 * snoise( xCoord, ( 40 * newTime1 ) );
fVal2 += 0.125 * snoise( xCoord, ( 100 * (newTime1 +1.35) ) );
fVal1 += 0.05 * snoise( xCoord, ( 90 * newTime1 ) );
fVal2 += 0.05 * snoise( xCoord, ( 225 * (newTime1 +1.35) ) );
half corona = pow( fVal1 * max( 1.1 - fade, 0.0 ), 2.0 );
corona += pow( fVal2 * max( 1.1 - fade, 0.0 ), 2.0 );
corona *= 30*(2.0 - newTime1);
half sunColor = (0.6 + 0.4*snoise(4*half3(i.texcoord + half2(time*0.5,0),time*0.5),16));
half4 c = half4( sunColor, pow(max(sunColor,0.),2.), pow(max(sunColor,0.),3.), 1.0);
c.rgb *=orange;
if( dist < radius ){
corona *= pow( dist * invRadius, 24.0 );
float p = 5*(radius-dist)*invRadius;
c.rgb = lerp(0,c.rgb,p);
float starGlow = min( max( 1.0 - dist, 0.0 ), 1.0 );
c.rgb += starGlow * orange;
}else{c=0;}
if( dist > 1.3 * radius){
half d = 1.45 * radius - dist;
d *=invRadius*7.5;
corona = lerp(0,corona,d);
}
c.rgb = c.rgb + corona * orange;
return c;
}
ENDCG
}
}
}
кто нить наподобие этого в cg перевести пробовал?
https://www.shadertoy.com/view/4slGD4
|