1
0
Fork 0

WS30: Use perlin texture to reduce tiling

Use a perlin noise texture to rotate some of the landclass
textures to reduce tiling.

Also add a quality=1 technique which uses it.
This commit is contained in:
Stuart Buchanan 2021-01-26 20:17:17 +00:00
parent b3abc93e96
commit 580c375d4b
4 changed files with 230 additions and 2 deletions

View file

@ -19,6 +19,15 @@
<shininess>1.2</shininess>
</material>
<texture n="6">
<image>Textures/perlin.png</image>
<type>2d</type>
<filter>nearest</filter>
<wrap-s>repeat</wrap-s>
<wrap-t>repeat</wrap-t>
<internal-format>normalized</internal-format>
</texture>
<texture n="10">
<image>Textures/Terrain/snow3.png</image>
<type>2d</type>
@ -182,7 +191,7 @@
<technique n="5">
<predicate>
<and>
<property>/sim/rendering/shaders/quality-level</property>
<property>/sim/rendering/shaders/skydome</property>
<or>
<less-equal>
<value type="float">2.0</value>
@ -269,6 +278,15 @@
<internal-format><use>texture[4]/internal-format</use></internal-format>
</texture-unit>
<texture-unit>
<unit>6</unit>
<image><use>texture[6]/image</use></image>
<filter><use>texture[6]/filter</use></filter>
<wrap-s><use>texture[6]/wrap-s</use></wrap-s>
<wrap-t><use>texture[6]/wrap-t</use></wrap-t>
<internal-format><use>texture[6]/internal-format</use></internal-format>
</texture-unit>
<program>
<vertex-shader>Shaders/ws30-ALS.vert</vertex-shader>
<vertex-shader>Shaders/shadows-include.vert</vertex-shader>
@ -414,6 +432,12 @@
<type>sampler-1d</type>
<value type="int">4</value>
</uniform>
<uniform>
<name>perlin</name>
<type>sampler-2d</type>
<value type="int">6</value>
</uniform>
<uniform>
<name>colorMode</name>
<type>int</type>
@ -444,6 +468,145 @@
</pass>
</technique>
<!-- Non-ALS technique with texture rotation -->
<technique n="11">
<predicate>
<and>
<property>/sim/rendering/shaders/quality-level</property>
<or>
<less-equal>
<value type="float">2.0</value>
<glversion/>
</less-equal>
<and>
<extension-supported>GL_ARB_shader_objects</extension-supported>
<extension-supported>GL_ARB_shading_language_100</extension-supported>
<extension-supported>GL_ARB_vertex_shader</extension-supported>
<extension-supported>GL_ARB_fragment_shader</extension-supported>
</and>
</or>
</and>
</predicate>
<pass>
<lighting>true</lighting>
<material>
<ambient><use>material/ambient</use></ambient>
<diffuse><use>material/diffuse</use></diffuse>
<specular><use>material/specular</use></specular>
<emissive><use>material/emissive</use></emissive>
<shininess><use>material/shininess</use></shininess>
<color-mode>ambient-and-diffuse</color-mode>
</material>
<blend><use>transparent</use></blend>
<alpha-test><use>transparent</use></alpha-test>
<shade-model>smooth</shade-model>
<cull-face>back</cull-face>
<render-bin>
<bin-number><use>render-bin/bin-number</use></bin-number>
<bin-name><use>render-bin/bin-name</use></bin-name>
</render-bin>
<texture-unit>
<unit>0</unit>
<image><use>texture[0]/image</use></image>
<filter>nearest</filter>
<mag-filter>nearest</mag-filter>
<wrap-s><use>texture[0]/wrap-s</use></wrap-s>
<wrap-t><use>texture[0]/wrap-t</use></wrap-t>
<internal-format><use>texture[0]/internal-format</use></internal-format>
<mipmap-control>
<r>max</r>
<g>max</g>
<b>max</b>
</mipmap-control>
</texture-unit>
<texture-unit>
<unit>1</unit>
<image><use>texture[1]/image</use></image>
<filter>nearest-mipmap-nearest</filter>
<mag-filter>nearest-mipmap-nearest</mag-filter>
<wrap-s><use>texture[0]/wrap-s</use></wrap-s>
<wrap-t><use>texture[0]/wrap-t</use></wrap-t>
<internal-format><use>texture[0]/internal-format</use></internal-format>
</texture-unit>
<texture-unit>
<unit>2</unit>
<image><use>texture[2]/image</use></image>
<filter><use>texture[2]/filter</use></filter>
<wrap-s><use>texture[2]/wrap-s</use></wrap-s>
<wrap-t><use>texture[2]/wrap-t</use></wrap-t>
<internal-format><use>texture[2]/internal-format</use></internal-format>
</texture-unit>
<texture-unit>
<unit>3</unit>
<image><use>texture[3]/image</use></image>
<filter><use>texture[3]/filter</use></filter>
<wrap-s><use>texture[3]/wrap-s</use></wrap-s>
<wrap-t><use>texture[3]/wrap-t</use></wrap-t>
<internal-format><use>texture[3]/internal-format</use></internal-format>
</texture-unit>
<texture-unit>
<unit>4</unit>
<image><use>texture[4]/image</use></image>
<filter><use>texture[4]/filter</use></filter>
<wrap-s><use>texture[4]/wrap-s</use></wrap-s>
<wrap-t><use>texture[4]/wrap-t</use></wrap-t>
<internal-format><use>texture[4]/internal-format</use></internal-format>
</texture-unit>
<texture-unit>
<unit>6</unit>
<image><use>texture[6]/image</use></image>
<filter><use>texture[6]/filter</use></filter>
<wrap-s><use>texture[6]/wrap-s</use></wrap-s>
<wrap-t><use>texture[6]/wrap-t</use></wrap-t>
<internal-format><use>texture[6]/internal-format</use></internal-format>
</texture-unit>
<program>
<vertex-shader>Shaders/ws30.vert</vertex-shader>
<fragment-shader n="0">Shaders/include_fog.frag</fragment-shader>
<fragment-shader n="1">Shaders/ws30-q1.frag</fragment-shader>
</program>
<uniform>
<name>landclass</name>
<type>sampler-2d</type>
<value type="int">0</value>
</uniform>
<uniform>
<name>atlas</name>
<type>sampler-2d</type>
<value type="int">1</value>
</uniform>
<uniform>
<name>dimensionsArray</name>
<type>sampler-1d</type>
<value type="int">2</value>
</uniform>
<uniform>
<name>diffuseArray</name>
<type>sampler-1d</type>
<value type="int">3</value>
</uniform>
<uniform>
<name>specularArray</name>
<type>sampler-1d</type>
<value type="int">4</value>
</uniform>
<uniform>
<name>perlin</name>
<type>sampler-2d</type>
<value type="int">6</value>
</uniform>
</pass>
</technique>
<!-- Minimal technique -->
<technique n="12">
<pass>
@ -548,7 +711,6 @@
<type>sampler-1d</type>
<value type="int">4</value>
</uniform>
</pass>
</technique>

65
Shaders/ws30-q1.frag Normal file
View file

@ -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;
}

View file

@ -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;

BIN
Textures/perlin.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB