Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "headers/baseshadersheader.fxh"
- #define inoise noiseFast
- #define fBm fBmFast
- #define turbulence turbulenceFast
- #define ridgedMF ridgedMFFast
- int Enum_Circuit_None = 0;
- int Enum_Circuit_Circle = 1;
- int Enum_Circuit_Square = 2;
- int Enum_Circuit_Diamond = 3;
- int Enum_Perlin_fBm = 0;
- int Enum_Perlin_turbulence = 1;
- int Enum_Perlin_ridgedMf = 2;
- int Enum_Worley_Euclidian = 0;
- int Enum_Worley_Manhattan = 1;
- int Enum_Worley_Chebyshev = 2;
- void FuncConstantVector(float4 constant, out float4 result)
- {
- result = constant;
- }
- void FuncScale(float4 a, float factor, out float4 result)
- {
- result = a*factor;
- }
- void FuncCircuit(float4 position, float hOffset, float vOffset, float hThickness, float vThickness, int centerShape, float centerSize, float2 cellSize, float edgeProbability, float2 jitter, out float4 hLine, out float4 vLine, out float4 center)
- {
- float2 cellID = floor(position.xy / cellSize);
- float2 cellPos = frac(position.xy / cellSize);
- float randN = perm2d(cellID.xy*.432).r;
- float randW = perm2d(cellID.xy*.432).g;
- float randS = perm2d((cellID.xy + float2(0,1))*.432).r;
- float randE = perm2d((cellID.xy + float2(1,0))*.432).g;
- float hasN = (randN <= edgeProbability) ? 1 : 0;
- float hasW = (randW <= edgeProbability) ? 1 : 0;
- float hasS = (randS <= edgeProbability) ? 1 : 0;
- float hasE = (randE <= edgeProbability) ? 1 : 0;
- jitter = jitter * (float2(perm(cellID.x*.324), perm(cellID.y*.324))*2-1);
- hOffset += jitter.x;
- vOffset += jitter.y;
- float2 cellLine = cellPos - float2(hOffset, vOffset); // now, 0,0 should be center.
- float nMod = 1-saturate(cellLine.y / vThickness);
- float sMod = 1-saturate(-cellLine.y / vThickness);
- float wMod = 1-saturate(cellLine.x / hThickness);
- float eMod = 1-saturate(-cellLine.x / hThickness);
- nMod = smoothstep(0.1, 0.2, nMod);
- sMod = smoothstep(0.1, 0.2, sMod);
- eMod = smoothstep(0.1, 0.2, eMod);
- wMod = smoothstep(0.1, 0.2, wMod);
- float nLine = hasN * wMod * eMod * nMod;
- float sLine = hasS * wMod * eMod * sMod;
- float eLine = hasE * nMod * sMod * eMod;
- float wLine = hasW * nMod * sMod * wMod;
- hLine = max(eLine, wLine);
- vLine = max(nLine, sLine);
- float2 centerComp = abs(cellPos - float2(hOffset, vOffset));
- center = 1000;
- if(centerShape == Enum_Circuit_Circle)
- center = length(centerComp);
- if(centerShape == Enum_Circuit_Square)
- center = max(centerComp.x, centerComp.y);
- if(centerShape == Enum_Circuit_Diamond)
- center = centerComp.x + centerComp.y;
- center = smoothstep(centerSize*0.98, centerSize*1.02, center);
- center = saturate(1.0 - center);
- float hasAll = hasN + hasW + hasS + hasE;
- if(hasAll == 0 || hasAll == 2)
- center = 0;
- }
- void FuncPerlin(float4 position, int octaves, float lacunarity, float gain, float ridgeOffset, int noiseType, out float4 noise)
- {
- float freq = 1.0, amp = 0.5;
- float sum = 0;
- float prev = 1.0;
- if(octaves == 1)
- amp = 1;
- for(int i=0; i<octaves; i++)
- {
- float noiseVal = noisePerlin(position.xyz*freq);
- if(noiseType == Enum_Perlin_turbulence)
- noiseVal = abs(noiseVal);
- if(noiseType == Enum_Perlin_ridgedMf)
- {
- noiseVal = ridge(noiseVal, ridgeOffset);
- float prevPrev = prev;
- prev = noiseVal;
- noiseVal *= prevPrev;
- }
- sum += noiseVal * amp;
- freq *= lacunarity;
- amp *= gain;
- }
- noise = sum.xxxx;
- if(noiseType == Enum_Perlin_fBm)
- noise = noise * 0.5 + 0.5;
- }
- void FuncWorley(float4 position, float jitter, int distanceMetric, int pointsPerCell, out float4 f1, out float4 f2, out float4 f3, out float4 f4, out float4 nearest)
- {
- float3 p1, p2, p3, p4;
- float of1, of2, of3, of4;
- int distanceType = DISTANCE_EUCLIDIAN;
- if(distanceMetric == Enum_Worley_Manhattan)
- distanceType = DISTANCE_MANHATTAN;
- if(distanceMetric == Enum_Worley_Chebyshev)
- distanceType = DISTANCE_CHEBYSHEV;
- voronoi(position.xyz, of1, p1, of2, p2, of3, p3, of4, p4, jitter, distanceType, pointsPerCell);
- f1 = of1.xxxx;
- f2 = of2.xxxx;
- f3 = of3.xxxx;
- f4 = of4.xxxx;
- nearest = float4(p1.xyz,1);
- }
- void FuncLinearCombination(float4 a, float4 b, float4 c, float4 d, float factora, float factorb, float factorc, float factord, out float4 result)
- {
- result = a*factora + b*factorb + c*factorc + d*factord;
- }
- void FuncMultiply(float4 a, float4 b, out float4 result)
- {
- result = a*b;
- }
- void FuncSubtract(float4 a, float4 b, out float4 result)
- {
- result = a-b;
- }
- void FuncSaturate(float4 a, out float4 result)
- {
- result = saturate(a);
- }
- void FuncScaleRange(float4 a, float oldMin, float oldMax, float newMin, float newMax, out float4 result)
- {
- result = (a-oldMin)/(oldMax-oldMin); // rescale to 0..1
- result = result*(newMax-newMin) + newMin;
- }
- void FuncLerp(float4 a, float4 b, float4 t, out float4 result)
- {
- result = lerp(a, b, t.x);
- }
- void ProceduralTexture(float3 positionIn, float2 texCoordIn, out float4 colorOut, out float heightOut)
- {
- float4 position = float4(positionIn, 1);
- float4 texCoord = float4(texCoordIn, 0, 0);
- float4 generated_result_0 = float4(0,0,0,0);
- FuncConstantVector(float4(0.2, 0.7, 0.4, 1), generated_result_0);
- float4 generated_result_1 = float4(0,0,0,0);
- FuncConstantVector(float4(0.4, 0.5, 1, 0), generated_result_1);
- float4 generated_result_2 = float4(0,0,0,0);
- FuncScale(position, float(10), generated_result_2);
- float4 generated_hLine_0 = float4(0,0,0,0);
- float4 generated_vLine_0 = float4(0,0,0,0);
- float4 generated_center_0 = float4(0,0,0,0);
- FuncCircuit(position, float(0.5), float(0.5), float(0.04), float(0.04), int(Enum_Circuit_Diamond), float(0.15), float2(0.1, 0.1), float(0.2), float2(0.4, 0.4), generated_hLine_0, generated_vLine_0, generated_center_0);
- float4 generated_hLine_1 = float4(0,0,0,0);
- float4 generated_vLine_1 = float4(0,0,0,0);
- float4 generated_center_1 = float4(0,0,0,0);
- FuncCircuit(position, float(0.5), float(0.5), float(0.02), float(0.02), int(Enum_Circuit_Diamond), float(0.1), float2(0.2, 0.2), float(0.7), float2(-0.2, 0.3), generated_hLine_1, generated_vLine_1, generated_center_1);
- float4 generated_noise_0 = float4(0,0,0,0);
- FuncPerlin(generated_result_2, int(1), float(2), float(0.5), float(1), int(Enum_Perlin_ridgedMf), generated_noise_0);
- float4 generated_f1_0 = float4(0,0,0,0);
- float4 generated_f2_0 = float4(0,0,0,0);
- float4 generated_f3_0 = float4(0,0,0,0);
- float4 generated_f4_0 = float4(0,0,0,0);
- float4 generated_nearest_0 = float4(0,0,0,0);
- FuncWorley(generated_result_2, float(0.9), int(Enum_Worley_Euclidian), int(1), generated_f1_0, generated_f2_0, generated_f3_0, generated_f4_0, generated_nearest_0);
- float4 generated_result_3 = float4(0,0,0,0);
- FuncLinearCombination(generated_hLine_0, generated_vLine_0, generated_center_0, float4(0,0,0,0), float(1), float(1), float(1), float(1), generated_result_3);
- float4 generated_result_4 = float4(0,0,0,0);
- FuncLinearCombination(generated_hLine_1, generated_vLine_1, generated_center_1, float4(0,0,0,0), float(1), float(1), float(1), float(1), generated_result_4);
- float4 generated_result_5 = float4(0,0,0,0);
- FuncMultiply(generated_result_0, generated_noise_0, generated_result_5);
- float4 generated_result_6 = float4(0,0,0,0);
- FuncSubtract(generated_f2_0, generated_f1_0, generated_result_6);
- float4 generated_result_7 = float4(0,0,0,0);
- FuncSaturate(generated_result_3, generated_result_7);
- float4 generated_result_8 = float4(0,0,0,0);
- FuncSaturate(generated_result_4, generated_result_8);
- float4 generated_result_9 = float4(0,0,0,0);
- FuncScaleRange(generated_result_6, float(0), float(1), float(0.3), float(1), generated_result_9);
- float4 generated_result_10 = float4(0,0,0,0);
- FuncMultiply(generated_result_8, generated_result_5, generated_result_10);
- float4 generated_result_11 = float4(0,0,0,0);
- FuncMultiply(generated_result_9, generated_result_1, generated_result_11);
- float4 generated_result_12 = float4(0,0,0,0);
- FuncMultiply(generated_result_11, generated_result_7, generated_result_12);
- float4 generated_result_13 = float4(0,0,0,0);
- FuncLerp(generated_result_12, generated_result_10, generated_result_8, generated_result_13);
- float4 color = generated_result_13;
- float4 height = float4(0,0,0,0);
- colorOut = color.xyzw;
- heightOut = height.x;
- }
- #include "headers/baseshaders.fxh"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement