1
0
Fork 0

WS30: Shader change to use texture atlas

These changes use the generated Texture2DArray for
texture lookup, supporting arbritary sets of material
textures.
This commit is contained in:
Stuart Buchanan 2020-12-05 13:11:59 +00:00
parent d73b9d8128
commit 3e3593119c
3 changed files with 25 additions and 47 deletions

View file

@ -19,19 +19,6 @@
</emissive>
<shininess>1.2</shininess>
</material>
<texture n="1">
<image>Textures/Terrain/cropgrass1.png</image>
<type>2d</type>
<filter>linear-mipmap-linear</filter>
<!-- also repeat -->
<wrap-s>repeat</wrap-s>
<wrap-t>repeat</wrap-t>
<!--
<wrap-r>clamp-to-border</wrap-r>
-->
<!-- float, signed-integer, integer -->
<internal-format>normalized</internal-format>
</texture>
<texture n="2">
<image>Textures/Terrain/city1.png</image>
<type>2d</type>
@ -504,8 +491,8 @@
<image>
<use>texture[0]/image</use>
</image>
<filter>nearest-mipmap-nearest</filter>
<mag-filter>nearest-mipmap-nearest</mag-filter>
<filter>nearest</filter>
<mag-filter>nearest</mag-filter>
<wrap-s>
<use>texture[0]/wrap-s</use>
</wrap-s>
@ -527,17 +514,16 @@
<image>
<use>texture[1]/image</use>
</image>
<filter>
<use>texture[1]/filter</use>
</filter>
<filter>nearest-mipmap-nearest</filter>
<mag-filter>nearest-mipmap-nearest</mag-filter>
<wrap-s>
<use>texture[1]/wrap-s</use>
<use>texture[0]/wrap-s</use>
</wrap-s>
<wrap-t>
<use>texture[1]/wrap-t</use>
<use>texture[0]/wrap-t</use>
</wrap-t>
<internal-format>
<use>texture[1]/internal-format</use>
<use>texture[0]/internal-format</use>
</internal-format>
</texture-unit>
<texture-unit>
@ -767,7 +753,7 @@
<value type="int">0</value>
</uniform>
<uniform>
<name>grass</name>
<name>atlas</name>
<type>sampler-2d</type>
<value type="int">1</value>
</uniform>

View file

@ -1,11 +1,11 @@
<?xml version="1.0"?>
<PropertyList>
<map>
<description>111 - Continuous urban fabric</description>
<landclass>1</landclass>
<material-name>Urban</material-name>
</map>
<map>
<description>111 - Continuous urban fabric</description>
<landclass>1</landclass>
<material-name>Urban</material-name>
</map>
<map>
<description>112 - Discontinuous urban fabric</description>
@ -268,7 +268,7 @@
<map>
<description>999 - NODATA</description>
<landclass>48</landclass>
<material-name>Default</material-name>
<material-name>Ocean</material-name>
</map>
</PropertyList>

View file

@ -1,7 +1,8 @@
// WS30 FRAGMENT SHADER
// -*-C++-*-
#version 120
#version 130
#extension GL_EXT_texture_array : enable
// written by Thorsten Renk, Oct 2011, based on default.frag
// Ambient term comes in gl_Color.rgb.
@ -11,10 +12,10 @@ varying vec3 relPos;
uniform sampler2D landclass;
uniform sampler2D grass;
uniform sampler2D city;
uniform sampler2D forest;
uniform sampler2D water;
uniform sampler2DArray atlas;
//uniform sampler2D city;
//uniform sampler2D forest;
//uniform sampler2D water;
varying float yprime_alt;
@ -97,20 +98,11 @@ void main()
// is closer to what the OpenGL fixed function pipeline does.
color = clamp(color, 0.0, 1.0);
int lc = int(texture2D(landclass, gl_TexCoord[0].st).r * 256.0 + 0.5);
if ((lc == 1) || (lc == 2) || (lc == 4) || (lc == 5))
{
texel = texture2D(city, gl_TexCoord[0].st);
} else if ((lc > 21) && (lc < 25))
{
texel = texture2D(forest, gl_TexCoord[0].st);
} else if (lc > 38)
{
texel = texture2D(water, gl_TexCoord[0].st);
} else {
texel = texture2D(grass, gl_TexCoord[0].st);
}
int lc = int(texture2D(landclass, gl_TexCoord[0].st).b * 255.0 + 0.5);
//vec2 st = mod(gl_TexCoord[0].st, 0.125); // mod to 1/8 of the space
//st.s = st.s + 0.125 * mod(lc, 8);
//st.y = st.y + 0.125 * int(lc/8);
texel = texture(atlas, vec3(gl_TexCoord[0].st, lc));
//texel = texture2D(texture, gl_TexCoord[0].st);
fragColor = color * texel + specular;