Shader “Esther/Fire” {
Properties {
_ColorTex (“ColorTexture and alpha”, 2D) = “white” {}
_NoiseTex (“NoiseTexture”, 2D) = “white” {}
_AlphaTex (“AlphaTexture”, 2D) = “white” {}
_WindPower (“WindPowerDirection”, Vector) = (1,1,1)
}
SubShader {
Tags { “QUeue”=“Transparent” }
zWrite off
Blend SrcAlpha OneMinusSrcAlpha
Pass {
CGPROGRAM
#pragma vertex vertexFunction
#pragma fragment pixelFunction
#pragma glsl
#pragma target 3.0
uniform sampler2D _ColorTex;
uniform sampler2D _NoiseTex;
uniform sampler2D _AlphaTex;
uniform fixed3 _WindPower ;
struct ApptoVert {
half4 uvCoord : TEXCOORD0;
half4 inPos : POSITION;
fixed4 vertColor : COLOR;
fixed3 inNormal : NORMAL;
};
struct VerttoPix {
half4 outPos : SV_POSITION;
half4 uvCoord : TEXCOORD0;
half2 transUV1 : TEXCOORD1;
half2 transUV2 : TEXCOORD2;
half2 transUV3 : TEXCOORD3;
half perturb : TEXCOORD4;
half displaceV : TEXCOORD5;
fixed3 viewDir : TEXCOORD6;
fixed3 normalDir : TEXCOORD7;
};
VerttoPix vertexFunction(ApptoVert i) {
VerttoPix o;
o.uvCoord = i.uvCoord;
//scroll and tile the uv's for the noise texture. later this will create a perlin noise like effect
half3 scrollSpeedsY = ((-0.81*_Time.y),(-0.96*_Time.y),(-3.66*_Time.y));
half scrollSpeedsX = (10*_Time.x);
half3 scales = (1,2,3);
o.transUV1 = (i.uvCoord.xy * scales.x);
o.transUV1.y = o.transUV1.y + (scrollSpeedsY.x ) + i.vertColor;
o.transUV1.x = o.transUV1.x + (scrollSpeedsX ) + i.vertColor;
o.transUV2 = (i.uvCoord.xy * scales.y);
o.transUV2.y = o.transUV2.y + (scrollSpeedsY.y ) + i.vertColor;
o.transUV2.x = o.transUV2.x + (-0.8*scrollSpeedsX ) + i.vertColor;
o.transUV3 = (i.uvCoord.xy * scales.z);
o.transUV3.y = o.transUV3.y + (scrollSpeedsY.z ) + i.vertColor;
o.transUV3.x = o.transUV3.x + (0.37*scrollSpeedsX ) + i.vertColor;
//perturb effect, will be used in fragment shader
//The distortion effects are multiplied with Ycoord to create a stronger effect at the top of the model.
//Values have been tested and implemented
o.perturb = ((i.uvCoord.y)*1.80)+0.6;
//displace verts in their normal direction sampling noise texture for values. this creates jitter effect
//the jitter has a slight delay for the different flame_models by adding their vertColor to the time
half disScrol = (_Time.y + (i.vertColor.x*0.15))*2;
half4 displaceValue = tex2Dlod(_NoiseTex.half4(disScrol,disScrol*0.17,0,0)); //scroll through texture. Y displacement *0.1 makes sure its not repeating
half displacement = (displaceValue.x-0.5) * 0.05; //-0.5 makes sure scale goes from -0.5 to 0.5 the *0.05 decides how much
i.inPos = (i.inPos + fixed4(i.inNormal,0) * displacement); // displaces the verts along their normal
i.inPos.y = i.inPos.y + (pow(i.uvCoord.y,0.5) * (displaceValue + (i.vertColor*1.5)))*0.2; //make the flame jitter extra in the Y-axis. the flame model
//make the torch wave in the windpowers direction
fixed bellyGradient = pow(i.uvCoord.y * (1-i.uvCoord.y), 2); //make the displacement only effect the middle of the model
i.inPos.xyz = i.inPos.xyz + bellyGradient * _WindPower * ((sin(_Time.z)+1)*0.5 + (sin(_Time.z*2.33)+1)*0.25); //Multiply the effect by two difference
//send displacement value to pixel shader, so color can be made birghter or less brighter depending on flicker.
o.displaceV = displaceValue.x;
half4 worldPos = mul(_Object2World, i.inPos);
//calculate view and normal direction to calculate edge detection later on
o.viewDir = normalize(_WorldSpaceCameraPos.xyz - worldPos.xyz);
o.normalDir = normalize(mul(_Object2World,float4(i.inNormal,0))xyz);
o.outPos = mul(UNITY_MATRIX_MVP,i.inPos);
return o;
}
fixed4 pixelFunction(VerttoPix v) : COLOR {
//sample the noise texture using the non-scaled, 2-scaled and 3-scaled uvs.
fixed4 noiseColor1 = tex2D(_NoiseTex,v.transUV1.xy);
fixed4 noiseColor2 = tex2D(_NoiseTex,v.transUV2.xy);
fixed4 noiseColor3 = tex2D(_NoiseTex,v.transUV3.xy);
//distort the noise textures. values were tested on good result and then implemented.
noiseColor1.y *=0.1;
noiseColor2.y *=-0.33;
noiseColor3.y *=0.68;
//add the different noise textures together
fixed4 finalNoise = noiseColor1 + noiseColor2 + noiseColor3;
//perturb the color texture by using the stacked noise textures and the perturb values
half2 noiseCoords;
noiseCoords.x = (finalNoise.x*v.perturb) + v.uvCoord.x;
noiseCoords.y = (finalNoise.y*v.perturb) + v.uvCoord.y;
//extract color through distorted uv coordinates
fixed4 baseColor = tex2D(_ColorTex,clamp(noiseCoords, 0.05,0.97));
//make the color of fire flicker between bright or not together with the scaling of the vertices
fixed4 texColor1 = baseColor + (fixed4(1,1,0.6,1)*((v.displaceV - 0.5)*0.5));
fixed Alpha2 = tex2D(_AlphaTex,v.uvCoord.xy).x;
fixed Alpha1 = tex2D(_AlphaTex,clamp(noiseCoords,0.005,0.95)); //the clamp reduces artifacts
//edge detection, fade edge
fixed edge = pow(saturate(dot(v.normalDir,v.viewDir)*2),3);
texColor1.a = Alpha1*Alpha2*edge;
return texColor1;
}
ENDCG
}
}
FallBack "Diffuse"
}
I’ve taken this code from here:
but the thing is that i am getting a shader error at line 13 and 14(specific error is: Shader error in ‘Esther/Fire’: GLSL vertex shader: 94: ERROR: ‘’ : methods are not supported at line 13 and Shader error in ‘Esther/Fire’: Shader program had errors at line 14)
which is this:
CGPROGRAM
#pragma vertex vertexFunction
I’ve tried a couple of things for around the last couple of hours, but nothing really seems to work. Can anyone help me out with this ? All i wanted is a shader when applied is giving the torch effect.
thanks in advance.