Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Every single shader broken in unity 2018.4.20.f1 #40

Open
soupbb opened this issue Jul 30, 2021 · 1 comment
Open

Every single shader broken in unity 2018.4.20.f1 #40

soupbb opened this issue Jul 30, 2021 · 1 comment

Comments

@soupbb
Copy link

soupbb commented Jul 30, 2021

Shader "ShaderMan/MyShader"
{
Properties{
_MainTex("MainTex",2D) = "white"{} 

}
SubShader
{
Tags { "RenderType" = "Transparent" "Queue" = "Transparent" }
Pass
{
ZWrite Off
Blend SrcAlpha OneMinusSrcAlpha
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
		


float4 vec4(float x,float y,float z,float w){return float4(x,y,z,w);}
float4 vec4(float x){return float4(x,x,x,x);}
float4 vec4(float2 x,float2 y){return float4(float2(x.x,x.y),float2(y.x,y.y));}
float4 vec4(float3 x,float y){return float4(float3(x.x,x.y,x.z),y);}


float3 vec3(float x,float y,float z){return float3(x,y,z);}
float3 vec3(float x){return float3(x,x,x);}
float3 vec3(float2 x,float y){return float3(float2(x.x,x.y),y);}

float2 vec2(float x,float y){return float2(x,y);}
float2 vec2(float x){return float2(x,x);}

float vec(float x){return float(x);}



struct VertexInput {
float4 vertex : POSITION;
float2 uv:TEXCOORD0;
float4 tangent : TANGENT;
float3 normal : NORMAL;
//VertexInput
};
struct VertexOutput {
float4 pos : SV_POSITION;
float2 uv:TEXCOORD0;
//VertexOutput
};
sampler2D _MainTex; 


VertexOutput vert (VertexInput v)
{
VertexOutput o;
o.pos = UnityObjectToClipPos (v.vertex);
o.uv = v.uv;
//VertexFactory
return o;
}

// Created by inigo quilez - iq/2013

// Turbulence and Day/Night cycle added by Michael Olson - OMGparticles/2015
// License Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License.

// Volumetric clouds. It performs level of detail (LOD) for faster rendering and antialiasing

float fTurbulence = 0.35;
float fSunSpeed = 0.35;

float3 vNightColor = vec3(.15, 0.3, 0.6);
float3 vHorizonColor = vec3(0.6, 0.3, 0.4);
float3 vDayColor = vec3(0.7,0.8,1);

float3 vSunColor = vec3(1.0,0.8,0.6);
float3 vSunRimColor = vec3(1.0,0.66,0.33);

float3 v3sunDir;
void updateSun() {
float fSpeed = fSunSpeed * _Time.y;
v3sunDir = normalize( vec3(cos(fSpeed),sin(fSpeed),0.0) );
}

float noise( in float3 x )
{
float3 p = floor(x);
float3 f = frac(x);
f = fff*(3.0-2.0*f);
float2 uv = (p.xy+vec2(37.0,17.0)p.z) + f.xy;
float4 rg = tex2D( _MainTex, (uv+ 0.5)/256.0, -100.0 );
return (-1.0+2.0
lerp( rg.g, rg.r, f.z ));
}

float map5( in float3 p )
{
float3 q = p - vec3(0.0,0.1,1.0)_Time.y;
float f;
f = 0.50000
noise( q ); q = q2.02 + _Time.y * fTurbulence * 1.0;
f += 0.25000
noise( q ); q = q2.03 + _Time.y * fTurbulence * 2.0;
f += 0.12500
noise( q ); q = q2.01 + _Time.y * fTurbulence * 4.0;
f += 0.06250
noise( q ); q = q2.02 + _Time.y * fTurbulence * 8.0;
f += 0.03125
noise( q );
return clamp( 1.5 - p.y - 2.0 + 1.75*f, 0.0, 1.0 );
}

float map4( in float3 p )
{
float3 q = p - vec3(0.0,0.1,1.0)_Time.y;
float f;
f = 0.50000
noise( q ); q = q2.02 + _Time.y * fTurbulence * 1.0;
f += 0.25000
noise( q ); q = q2.03 + _Time.y * fTurbulence * 2.0;
f += 0.12500
noise( q ); q = q2.01 + _Time.y * fTurbulence * 4.0;
f += 0.06250
noise( q );
return clamp( 1.5 - p.y - 2.0 + 1.75f, 0.0, 1.0 );
}
float map3( in float3 p )
{
float3 q = p - vec3(0.0,0.1,1.0)
_Time.y;
float f;
f = 0.50000noise( q ); q = q2.02 + _Time.y * fTurbulence * 1.0;
f += 0.25000noise( q ); q = q2.03 + _Time.y * fTurbulence * 2.0;
f += 0.12500noise( q );
return clamp( 1.5 - p.y - 2.0 + 1.75
f, 0.0, 1.0 );
}
float map2( in float3 p )
{
float3 q = p - vec3(0.0,0.1,1.0)_Time.y;
float f;
f = 0.50000
noise( q ); q = q2.02 + _Time.y * fTurbulence * 1.0;
f += 0.25000
noise( q );
return clamp( 1.5 - p.y - 2.0 + 1.75*f, 0.0, 1.0 );
}

float4 integrate( in float4 sum, in float dif, in float den, in float3 bgcol, in float t )
{
// lighting
float3 lin = vec3(0.9,0.95,1.0) + 0.5vec3(0.7, 0.5, 0.3)dif * smoothstep(-0.3, 0.3, v3sunDir.y);
float4 col = vec4( lerp( 1.15
vec3(1.0,0.95,0.8), vec3(0.65), den ), den );
col.xyz = lin;
//col.xyz = lerp( col.xyz, bgcol, 1.0-exp(-0.003
t
t) );
// front to back blending
col.a *= 0.4;
col.rgb = col.a;
return sum + col
(1.0-sum.a);
}

#define MARCH(STEPS,MAPLOD) [unroll(100)]
for(int i=0; i<STEPS; i++) { float3 pos = ro + trd; if( pos.y<-3.0 || pos.y>2.0 || sum.a > 0.99 ) break; float den = MAPLOD( pos ); if( den>0.01 ) { float dif = clamp((den - MAPLOD(pos+0.3v3sunDir))/0.6, 0.0, 1.0 ); sum = integrate( sum, dif, den, bgcol, t ); } t += max(0.01float(i),0.02t); }

float4 raymarch( in float3 ro, in float3 rd, in float3 bgcol )
{
float4 sum = vec4(0.0);

float t = 0.0;

MARCH(20,map5);
MARCH(30,map4);
MARCH(40,map3);
MARCH(50,map2);

return clamp( sum, 0.0, 1.0 );

}

float3x3 setCamera( in float3 ro, in float3 ta, float cr )
{
float3 cw = normalize(ta-ro);
float3 cp = vec3(sin(cr), cos(cr),0.0);
float3 cu = normalize( cross(cw,cp) );
float3 cv = normalize( cross(cu,cw) );
return float3x3( cu, cv, cw );
}

float4 render( in float3 ro, in float3 rd )
{
float sun = clamp( dot(v3sunDir,rd), 0.0, 1.0 );

float fSunHeight = v3sunDir.y;

// below this height will be full night color
float fNightHeight = -0.8;
// above this height will be full day color
float fDayHeight   = 0.3;

float fHorizonLength = fDayHeight - fNightHeight;
float fInverseHL = 1.0 / fHorizonLength;
float fHalfHorizonLength = fHorizonLength / 2.0;
float fInverseHHL = 1.0 / fHalfHorizonLength;
float fMidPoint = fNightHeight + fHalfHorizonLength;

float fNightContrib = clamp((fSunHeight - fMidPoint) * (-fInverseHHL), 0.0, 1.0);
float fHorizonContrib = -clamp(abs((fSunHeight - fMidPoint) * (-fInverseHHL)), 0.0, 1.0) + 1.0;
float fDayContrib = clamp((fSunHeight - fMidPoint) * ( fInverseHHL), 0.0, 1.0);

// sky color
float3 vSkyColor = vec3(0.0);
vSkyColor += lerp(vec3(0.0),   vNightColor, fNightContrib);   // Night
vSkyColor += lerp(vec3(0.0), vHorizonColor, fHorizonContrib); // Horizon
vSkyColor += lerp(vec3(0.0),     vDayColor, fDayContrib);     // Day

float3 col = vSkyColor;

// atmosphere brighter near horizon
col -= clamp(rd.y, 0.0, 0.5);

// draw sun
col += 0.4 * vSunRimColor * pow( sun,    4.0 );
col += 1.0 * vSunColor    * pow( sun, 2000.0 );

// stars
float fStarSpeed = -fSunSpeed * 0.5;

float fStarContrib = clamp((fSunHeight - fDayHeight) * (-fInverseHL), 0.0, 1.0);

float3 vStarDir = rd * float3x3( vec3(cos(fStarSpeed), -sin(fStarSpeed), 0.0),
                           vec3(sin(fStarSpeed),  cos(fStarSpeed), 0.0),
                           vec3(0.0,             0.0,            1.0));
                          
col += pow((tex2D(_MainTex, vStarDir.xy).r + tex2D(_MainTex, vStarDir.zy).r) * 0.5, 42.0) * fStarContrib * 40.0;

// raymarch clouds
float4 res = raymarch( ro, rd, col );

// partially tint clouds to match sky color
res *= vec4(pow(vSkyColor, vec3(0.25)), 1.0);
    
col = col*(1.0-res.w) + res.xyz;

return vec4( col, 1.0 );

}

fixed4 frag(VertexOutput vertex_output) : SV_Target
{

float2 p = (-1 + 2.0*vertex_output.uv)/ 1;

float2 m = _iMouse.xy/1;

updateSun();

// camera
float3 ro = 4.0*normalize(vec3(sin(6.28*m.x + 1.5), 0.4 * m.y, cos(6.28*m.x + 1.5)));
float3 ta = vec3(0.0, -1.0, 0.0);
float3x3 ca = setCamera( ro, ta, 0.0 );
// ray
float3 rd = ca * normalize( vec3(p.xy,1.5));

return render( ro, rd );

}

void mainVR( out float4 fragColor, in float2 vertex_output.uv, in float3 fragRayOri, in float3 fragRayDir )
{
return render( fragRayOri, fragRayDir );

}
ENDCG
}

}
}

@soupbb
Copy link
Author

soupbb commented Jul 30, 2021

'vNightColor': initial value must be a literal expression
Compiling Vertex program

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant