diff --git a/Effects/ws30.eff b/Effects/ws30.eff index 17e478ca8..69a5c5247 100644 --- a/Effects/ws30.eff +++ b/Effects/ws30.eff @@ -19,6 +19,15 @@ 1.2 + + Textures/perlin.png + 2d + nearest + repeat + repeat + normalized + + Textures/Terrain/snow3.png 2d @@ -182,7 +191,7 @@ - /sim/rendering/shaders/quality-level + /sim/rendering/shaders/skydome 2.0 @@ -269,6 +278,15 @@ texture[4]/internal-format + + 6 + texture[6]/image + texture[6]/filter + texture[6]/wrap-s + texture[6]/wrap-t + texture[6]/internal-format + + Shaders/ws30-ALS.vert Shaders/shadows-include.vert @@ -414,6 +432,12 @@ sampler-1d 4 + + perlin + sampler-2d + 6 + + colorMode int @@ -444,6 +468,145 @@ + + + + + /sim/rendering/shaders/quality-level + + + 2.0 + + + + GL_ARB_shader_objects + GL_ARB_shading_language_100 + GL_ARB_vertex_shader + GL_ARB_fragment_shader + + + + + + + true + + material/ambient + material/diffuse + material/specular + material/emissive + material/shininess + ambient-and-diffuse + + transparent + transparent + smooth + back + + render-bin/bin-number + render-bin/bin-name + + + + 0 + texture[0]/image + nearest + nearest + texture[0]/wrap-s + texture[0]/wrap-t + texture[0]/internal-format + + max + max + max + + + + + 1 + texture[1]/image + nearest-mipmap-nearest + nearest-mipmap-nearest + texture[0]/wrap-s + texture[0]/wrap-t + texture[0]/internal-format + + + + 2 + texture[2]/image + texture[2]/filter + texture[2]/wrap-s + texture[2]/wrap-t + texture[2]/internal-format + + + + 3 + texture[3]/image + texture[3]/filter + texture[3]/wrap-s + texture[3]/wrap-t + texture[3]/internal-format + + + + 4 + texture[4]/image + texture[4]/filter + texture[4]/wrap-s + texture[4]/wrap-t + texture[4]/internal-format + + + + 6 + texture[6]/image + texture[6]/filter + texture[6]/wrap-s + texture[6]/wrap-t + texture[6]/internal-format + + + + Shaders/ws30.vert + Shaders/include_fog.frag + Shaders/ws30-q1.frag + + + + landclass + sampler-2d + 0 + + + atlas + sampler-2d + 1 + + + dimensionsArray + sampler-1d + 2 + + + diffuseArray + sampler-1d + 3 + + + specularArray + sampler-1d + 4 + + + perlin + sampler-2d + 6 + + + + @@ -548,7 +711,6 @@ sampler-1d 4 - diff --git a/Shaders/ws30-q1.frag b/Shaders/ws30-q1.frag new file mode 100644 index 000000000..8263f0d69 --- /dev/null +++ b/Shaders/ws30-q1.frag @@ -0,0 +1,65 @@ +// WS30 FRAGMENT SHADER + +// -*-C++-*- +#version 130 +#extension GL_EXT_texture_array : enable + +varying vec3 normal; + +uniform sampler2D landclass; +uniform sampler2DArray atlas; +uniform sampler1D dimensionsArray; +uniform sampler1D diffuseArray; +uniform sampler1D specularArray; +uniform sampler2D perlin; + +// Passed from VPBTechnique, not the Effect +uniform float tile_width; +uniform float tile_height; + +// See include_fog.frag +uniform int fogType; +vec3 fog_Func(vec3 color, int type); + +void main() +{ + vec3 lightDir = gl_LightSource[0].position.xyz; + vec3 halfVector = gl_LightSource[0].halfVector.xyz; + vec4 texel; + vec4 fragColor; + + // The Landclass for this particular fragment. This can be used to + // index into the atlas textures. + int lc = int(texture2D(landclass, gl_TexCoord[0].st).g * 255.0 + 0.5); + + // If gl_Color.a == 0, this is a back-facing polygon and the + // normal should be reversed. + vec3 n = (2.0 * gl_Color.a - 1.0) * normal; + n = normalize(n); + float NdotL = dot(n, lightDir); + float NdotHV = max(dot(n, halfVector), 0.0); + + // Different textures have different have different dimensions. + // Dimensions array is scaled to fit in [0...1.0] in the texture1D, so has to be scaled back up here. + vec4 color = texture(diffuseArray, float(lc)/512.0) * NdotL; + vec4 specular = texture(specularArray, float(lc)/512.0); + vec2 atlas_dimensions = 10000.0 * texture(dimensionsArray, float(lc)/512.0).st; + vec2 atlas_scale = vec2(tile_width / atlas_dimensions.s, tile_height / atlas_dimensions.t ); + vec2 st = atlas_scale * gl_TexCoord[0].st; + + // Rotate texture using the perlin texture as a mask to reduce tiling + if (step(0.5, texture(perlin, atlas_scale * gl_TexCoord[0].st / 8.0).r) == 1.0) { + st = vec2(atlas_scale.s * gl_TexCoord[0].t, atlas_scale.t * gl_TexCoord[0].s); + } + + if (step(0.5, texture(perlin, - atlas_scale * gl_TexCoord[0].st / 16.0).r) == 1.0) { + st = -st; + } + + texel = texture(atlas, vec3(st, lc)); + + fragColor = texel + pow(NdotHV, gl_FrontMaterial.shininess) * gl_LightSource[0].specular * specular; + + fragColor.rgb = fog_Func(fragColor.rgb, fogType); + gl_FragColor = fragColor; +} diff --git a/Shaders/ws30.frag b/Shaders/ws30.frag index 64cd58c59..77b9238cc 100644 --- a/Shaders/ws30.frag +++ b/Shaders/ws30.frag @@ -44,6 +44,7 @@ void main() vec4 specular = texture(specularArray, float(lc)/512.0); vec2 atlas_dimensions = 10000.0 * texture(dimensionsArray, float(lc)/512.0).st; vec2 atlas_scale = vec2(tile_width / atlas_dimensions.s, tile_height / atlas_dimensions.t ); + texel = texture(atlas, vec3(atlas_scale * gl_TexCoord[0].st, lc)); fragColor = texel + pow(NdotHV, gl_FrontMaterial.shininess) * gl_LightSource[0].specular * specular; diff --git a/Textures/perlin.png b/Textures/perlin.png new file mode 100644 index 000000000..26c21e961 Binary files /dev/null and b/Textures/perlin.png differ