Created
July 31, 2012 07:22
-
-
Save ikstewa/3214479 to your computer and use it in GitHub Desktop.
Simple perlin noise shader
This file contains hidden or 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
/** | |
* GLSL fragment shader for the noise clouds. | |
* | |
* @author Ian Stewart | |
* | |
*/ | |
varying float LightIntensity; | |
varying vec3 MCposition; | |
uniform sampler3D Noise; | |
uniform vec3 SkyColor; | |
uniform vec3 CloudColor; | |
uniform int TIME_FROM_INIT; | |
vec3 Offset = vec3(0.0,0.0,0.0); | |
void main() | |
{ | |
float offset = float(TIME_FROM_INIT) *0.00005; | |
Offset = vec3(-offset, offset, offset); | |
vec4 noisevec = texture3D(Noise, MCposition+Offset); | |
float intensity = (noisevec[0] + noisevec[1] + noisevec[2] | |
+ noisevec[3] + 0.03125) * 1.0; | |
vec3 color = mix(SkyColor, CloudColor, intensity) * LightIntensity; | |
color = clamp(color, 0.0, 1.0); | |
gl_FragData[0] = vec4(color, 1.0); | |
} |
This file contains hidden or 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
/** | |
* GLSL vertex shader for the noise clouds. | |
* | |
* @author Ian Stewart | |
* | |
*/ | |
varying float LightIntensity; | |
varying vec3 MCposition; | |
uniform vec3 LightPos; | |
uniform float Scale; | |
void main() | |
{ | |
gl_Position = ftransform(); | |
vec3 ECposition = vec3(gl_ModelViewMatrix * gl_Vertex); | |
MCposition = vec3(gl_Vertex) * Scale; | |
vec3 tnorm = -normalize(vec3(gl_NormalMatrix * gl_Normal)); | |
LightIntensity = dot(normalize(LightPos - ECposition), tnorm) * 1.5; | |
//LightIntensity = 1.5; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment