forked from ronja-tutorials/ShaderTutorials
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
some files I used for texture generation
- Loading branch information
Ronja
committed
Nov 2, 2018
1 parent
497a409
commit aed162c
Showing
9 changed files
with
410 additions
and
0 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
#ifndef WHITE_NOISE | ||
#define WHITE_NOISE | ||
|
||
//to 1d functions | ||
|
||
|
||
float rand4dTo1d(float4 value, float4 dotDir = float4(12.9898, 78.233, 37.719, 17.4265)){ | ||
float4 smallValue = cos(value); | ||
float random = dot(smallValue, dotDir); | ||
random = frac(sin(random) * 143758.5453); | ||
return random; | ||
} | ||
|
||
//get a scalar random value from a 3d value | ||
float rand3dTo1d(float3 value, float3 dotDir = float3(12.9898, 78.233, 37.719)){ | ||
//make value smaller to avoid artefacts | ||
float3 smallValue = cos(value); | ||
//get scalar value from 3d vector | ||
float random = dot(smallValue, dotDir); | ||
//make value more random by making it bigger and then taking the factional part | ||
random = frac(sin(random) * 143758.5453); | ||
return random; | ||
} | ||
|
||
float rand2dTo1d(float2 value, float2 dotDir = float2(12.9898, 78.233)){ | ||
float2 smallValue = cos(value); | ||
float random = dot(smallValue, dotDir); | ||
random = frac(sin(random) * 143758.5453); | ||
return random; | ||
} | ||
|
||
float rand1dTo1d(float3 value, float mutator = 0.546){ | ||
float random = frac(sin(value + mutator) * 143758.5453); | ||
return random; | ||
} | ||
|
||
//to 2d functions | ||
|
||
float2 rand3dTo2d(float3 value){ | ||
return float2( | ||
rand3dTo1d(value, float3(12.989, 78.233, 37.719)), | ||
rand3dTo1d(value, float3(39.346, 11.135, 83.155)) | ||
); | ||
} | ||
|
||
float2 rand2dTo2d(float2 value){ | ||
return float2( | ||
rand2dTo1d(value, float2(12.989, 78.233)), | ||
rand2dTo1d(value, float2(39.346, 11.135)) | ||
); | ||
} | ||
|
||
float2 rand1dTo2d(float value){ | ||
return float2( | ||
rand2dTo1d(value, 3.9812), | ||
rand2dTo1d(value, 7.1536) | ||
); | ||
} | ||
|
||
//to 3d functions | ||
|
||
float3 rand3dTo3d(float3 value){ | ||
return float3( | ||
rand3dTo1d(value, float3(12.989, 78.233, 37.719)), | ||
rand3dTo1d(value, float3(39.346, 11.135, 83.155)), | ||
rand3dTo1d(value, float3(73.156, 52.235, 09.151)) | ||
); | ||
} | ||
|
||
float3 rand2dTo3d(float2 value){ | ||
return float3( | ||
rand2dTo1d(value, float2(12.989, 78.233)), | ||
rand2dTo1d(value, float2(39.346, 11.135)), | ||
rand2dTo1d(value, float2(73.156, 52.235)) | ||
); | ||
} | ||
|
||
float3 rand1dTo3d(float value){ | ||
return float3( | ||
rand1dTo1d(value, 3.9812), | ||
rand1dTo1d(value, 7.1536), | ||
rand1dTo1d(value, 5.7241) | ||
); | ||
} | ||
|
||
// to 4d // TEMP | ||
float4 rand4dTo4d(float4 value){ | ||
return float4( | ||
rand4dTo1d(value, float4(12.989, 78.233, 37.719, -12.15)), | ||
rand4dTo1d(value, float4(39.346, 11.135, 83.155, -11.44)), | ||
rand4dTo1d(value, float4(73.156, 52.235, 09.151, 62.463)), | ||
rand4dTo1d(value, float4(-12.15, 12.235, 41.151, -1.135)) | ||
); | ||
} | ||
|
||
#endif |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
%YAML 1.1 | ||
%TAG !u! tag:unity3d.com,2011: | ||
--- !u!21 &2100000 | ||
Material: | ||
serializedVersion: 6 | ||
m_ObjectHideFlags: 0 | ||
m_CorrespondingSourceObject: {fileID: 0} | ||
m_PrefabInternal: {fileID: 0} | ||
m_Name: Specs | ||
m_Shader: {fileID: 4800000, guid: 2e68161e77a226e45b87583fdfe5711e, type: 3} | ||
m_ShaderKeywords: | ||
m_LightmapFlags: 4 | ||
m_EnableInstancingVariants: 0 | ||
m_DoubleSidedGI: 0 | ||
m_CustomRenderQueue: -1 | ||
stringTagMap: {} | ||
disabledShaderPasses: [] | ||
m_SavedProperties: | ||
serializedVersion: 3 | ||
m_TexEnvs: | ||
- _BumpMap: | ||
m_Texture: {fileID: 0} | ||
m_Scale: {x: 1, y: 1} | ||
m_Offset: {x: 0, y: 0} | ||
- _DetailAlbedoMap: | ||
m_Texture: {fileID: 0} | ||
m_Scale: {x: 1, y: 1} | ||
m_Offset: {x: 0, y: 0} | ||
- _DetailMask: | ||
m_Texture: {fileID: 0} | ||
m_Scale: {x: 1, y: 1} | ||
m_Offset: {x: 0, y: 0} | ||
- _DetailNormalMap: | ||
m_Texture: {fileID: 0} | ||
m_Scale: {x: 1, y: 1} | ||
m_Offset: {x: 0, y: 0} | ||
- _EmissionMap: | ||
m_Texture: {fileID: 0} | ||
m_Scale: {x: 1, y: 1} | ||
m_Offset: {x: 0, y: 0} | ||
- _MainTex: | ||
m_Texture: {fileID: 0} | ||
m_Scale: {x: 1, y: 1} | ||
m_Offset: {x: 0, y: 0} | ||
- _MetallicGlossMap: | ||
m_Texture: {fileID: 0} | ||
m_Scale: {x: 1, y: 1} | ||
m_Offset: {x: 0, y: 0} | ||
- _OcclusionMap: | ||
m_Texture: {fileID: 0} | ||
m_Scale: {x: 1, y: 1} | ||
m_Offset: {x: 0, y: 0} | ||
- _ParallaxMap: | ||
m_Texture: {fileID: 0} | ||
m_Scale: {x: 1, y: 1} | ||
m_Offset: {x: 0, y: 0} | ||
m_Floats: | ||
- _BumpScale: 1 | ||
- _CellAmount: 32 | ||
- _Cutoff: 0.5 | ||
- _DetailNormalMapScale: 1 | ||
- _DstBlend: 0 | ||
- _GlossMapScale: 1 | ||
- _Glossiness: 0.5 | ||
- _GlossyReflections: 1 | ||
- _Metallic: 0 | ||
- _Mode: 0 | ||
- _OcclusionStrength: 1 | ||
- _Parallax: 0.02 | ||
- _Persistance: 0.4 | ||
- _Roughness: 3 | ||
- _SmoothnessTextureChannel: 0 | ||
- _SpecularHighlights: 1 | ||
- _SrcBlend: 1 | ||
- _Step: 0.784 | ||
- _UVSec: 0 | ||
- _ZWrite: 1 | ||
m_Colors: | ||
- _Color: {r: 1, g: 1, b: 1, a: 1} | ||
- _EmissionColor: {r: 0, g: 0, b: 0, a: 1} | ||
- _Period: {r: 4, g: 4, b: 0, a: 0} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
Shader "TextureForge/RiverSpecs" { | ||
Properties { | ||
_CellAmount ("Cell Amount", Range(1, 32)) = 2 | ||
_Step ("Cutoff", Range(0, 1)) = 0.4 | ||
} | ||
SubShader { | ||
Tags{ "RenderType"="Opaque" "Queue"="Geometry"} | ||
|
||
Pass{ | ||
CGPROGRAM | ||
|
||
//include useful shader functions | ||
#include "UnityCG.cginc" | ||
|
||
//define vertex and fragment shader | ||
#pragma vertex vert | ||
#pragma fragment frag | ||
|
||
#pragma target 3.0 | ||
|
||
#include "Random.cginc" | ||
|
||
float _CellAmount; | ||
float _Step; | ||
|
||
//the object data that's put into the vertex shader | ||
struct appdata{ | ||
float4 vertex : POSITION; | ||
float2 uv : TEXCOORD0; | ||
}; | ||
|
||
//the data that's used to generate fragments and can be read by the fragment shader | ||
struct v2f{ | ||
float4 position : SV_POSITION; | ||
float2 uv : TEXCOORD0; | ||
}; | ||
|
||
float easeIn(float interpolator){ | ||
return interpolator * interpolator; | ||
} | ||
|
||
float easeOut(float interpolator){ | ||
return 1 - easeIn(1 - interpolator); | ||
} | ||
|
||
float easeInOut(float interpolator){ | ||
float easeInValue = easeIn(interpolator); | ||
float easeOutValue = easeOut(interpolator); | ||
return lerp(easeInValue, easeOutValue, interpolator); | ||
} | ||
|
||
float2 modulo(float2 divident, float2 divisor){ | ||
float2 positiveDivident = divident % divisor + divisor; | ||
return positiveDivident % divisor; | ||
} | ||
|
||
float perlinNoise(float2 value, float2 period){ | ||
float2 cellsMimimum = floor(value); | ||
float2 cellsMaximum = ceil(value); | ||
|
||
cellsMimimum = modulo(cellsMimimum, period); | ||
cellsMaximum = modulo(cellsMaximum, period); | ||
|
||
//generate random directions | ||
float2 lowerLeftDirection = rand2dTo2d(float2(cellsMimimum.x, cellsMimimum.y)) * 2 - 1; | ||
float2 lowerRightDirection = rand2dTo2d(float2(cellsMaximum.x, cellsMimimum.y)) * 2 - 1; | ||
float2 upperLeftDirection = rand2dTo2d(float2(cellsMimimum.x, cellsMaximum.y)) * 2 - 1; | ||
float2 upperRightDirection = rand2dTo2d(float2(cellsMaximum.x, cellsMaximum.y)) * 2 - 1; | ||
|
||
float2 fraction = frac(value); | ||
|
||
//get values of cells based on fraction and cell directions | ||
float lowerLeftFunctionValue = dot(lowerLeftDirection, fraction - float2(0, 0)); | ||
float lowerRightFunctionValue = dot(lowerRightDirection, fraction - float2(1, 0)); | ||
float upperLeftFunctionValue = dot(upperLeftDirection, fraction - float2(0, 1)); | ||
float upperRightFunctionValue = dot(upperRightDirection, fraction - float2(1, 1)); | ||
|
||
float interpolatorX = easeInOut(fraction.x); | ||
float interpolatorY = easeInOut(fraction.y); | ||
|
||
//interpolate between values | ||
float lowerCells = lerp(lowerLeftFunctionValue, lowerRightFunctionValue, interpolatorX); | ||
float upperCells = lerp(upperLeftFunctionValue, upperRightFunctionValue, interpolatorX); | ||
|
||
float noise = lerp(lowerCells, upperCells, interpolatorY); | ||
return noise; | ||
} | ||
|
||
//the vertex shader | ||
v2f vert(appdata v){ | ||
v2f o; | ||
//convert the vertex positions from object space to clip space so they can be rendered | ||
o.position = UnityObjectToClipPos(v.vertex); | ||
o.uv = v.uv; | ||
return o; | ||
} | ||
|
||
float4 frag (v2f i) : SV_TARGET{ | ||
float2 value = i.uv * _CellAmount; | ||
//get noise and adjust it to be ~0-1 range | ||
float noise = perlinNoise(value, _CellAmount) + 0.5; | ||
float aa = fwidth(noise) * 0.5; | ||
noise = smoothstep(_Step - aa, _Step + aa, noise); | ||
//return noise; | ||
return float4(1,1,1,noise); | ||
} | ||
ENDCG | ||
} | ||
} | ||
FallBack "Standard" | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.