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:
parent
d73b9d8128
commit
3e3593119c
3 changed files with 25 additions and 47 deletions
|
@ -19,19 +19,6 @@
|
||||||
</emissive>
|
</emissive>
|
||||||
<shininess>1.2</shininess>
|
<shininess>1.2</shininess>
|
||||||
</material>
|
</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">
|
<texture n="2">
|
||||||
<image>Textures/Terrain/city1.png</image>
|
<image>Textures/Terrain/city1.png</image>
|
||||||
<type>2d</type>
|
<type>2d</type>
|
||||||
|
@ -504,8 +491,8 @@
|
||||||
<image>
|
<image>
|
||||||
<use>texture[0]/image</use>
|
<use>texture[0]/image</use>
|
||||||
</image>
|
</image>
|
||||||
<filter>nearest-mipmap-nearest</filter>
|
<filter>nearest</filter>
|
||||||
<mag-filter>nearest-mipmap-nearest</mag-filter>
|
<mag-filter>nearest</mag-filter>
|
||||||
<wrap-s>
|
<wrap-s>
|
||||||
<use>texture[0]/wrap-s</use>
|
<use>texture[0]/wrap-s</use>
|
||||||
</wrap-s>
|
</wrap-s>
|
||||||
|
@ -527,17 +514,16 @@
|
||||||
<image>
|
<image>
|
||||||
<use>texture[1]/image</use>
|
<use>texture[1]/image</use>
|
||||||
</image>
|
</image>
|
||||||
<filter>
|
<filter>nearest-mipmap-nearest</filter>
|
||||||
<use>texture[1]/filter</use>
|
<mag-filter>nearest-mipmap-nearest</mag-filter>
|
||||||
</filter>
|
|
||||||
<wrap-s>
|
<wrap-s>
|
||||||
<use>texture[1]/wrap-s</use>
|
<use>texture[0]/wrap-s</use>
|
||||||
</wrap-s>
|
</wrap-s>
|
||||||
<wrap-t>
|
<wrap-t>
|
||||||
<use>texture[1]/wrap-t</use>
|
<use>texture[0]/wrap-t</use>
|
||||||
</wrap-t>
|
</wrap-t>
|
||||||
<internal-format>
|
<internal-format>
|
||||||
<use>texture[1]/internal-format</use>
|
<use>texture[0]/internal-format</use>
|
||||||
</internal-format>
|
</internal-format>
|
||||||
</texture-unit>
|
</texture-unit>
|
||||||
<texture-unit>
|
<texture-unit>
|
||||||
|
@ -767,7 +753,7 @@
|
||||||
<value type="int">0</value>
|
<value type="int">0</value>
|
||||||
</uniform>
|
</uniform>
|
||||||
<uniform>
|
<uniform>
|
||||||
<name>grass</name>
|
<name>atlas</name>
|
||||||
<type>sampler-2d</type>
|
<type>sampler-2d</type>
|
||||||
<value type="int">1</value>
|
<value type="int">1</value>
|
||||||
</uniform>
|
</uniform>
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
<?xml version="1.0"?>
|
<?xml version="1.0"?>
|
||||||
<PropertyList>
|
<PropertyList>
|
||||||
|
|
||||||
<map>
|
<map>
|
||||||
<description>111 - Continuous urban fabric</description>
|
<description>111 - Continuous urban fabric</description>
|
||||||
<landclass>1</landclass>
|
<landclass>1</landclass>
|
||||||
<material-name>Urban</material-name>
|
<material-name>Urban</material-name>
|
||||||
</map>
|
</map>
|
||||||
|
|
||||||
<map>
|
<map>
|
||||||
<description>112 - Discontinuous urban fabric</description>
|
<description>112 - Discontinuous urban fabric</description>
|
||||||
|
@ -268,7 +268,7 @@
|
||||||
<map>
|
<map>
|
||||||
<description>999 - NODATA</description>
|
<description>999 - NODATA</description>
|
||||||
<landclass>48</landclass>
|
<landclass>48</landclass>
|
||||||
<material-name>Default</material-name>
|
<material-name>Ocean</material-name>
|
||||||
</map>
|
</map>
|
||||||
|
|
||||||
</PropertyList>
|
</PropertyList>
|
||||||
|
|
|
@ -1,7 +1,8 @@
|
||||||
// WS30 FRAGMENT SHADER
|
// WS30 FRAGMENT SHADER
|
||||||
|
|
||||||
// -*-C++-*-
|
// -*-C++-*-
|
||||||
#version 120
|
#version 130
|
||||||
|
#extension GL_EXT_texture_array : enable
|
||||||
|
|
||||||
// written by Thorsten Renk, Oct 2011, based on default.frag
|
// written by Thorsten Renk, Oct 2011, based on default.frag
|
||||||
// Ambient term comes in gl_Color.rgb.
|
// Ambient term comes in gl_Color.rgb.
|
||||||
|
@ -11,10 +12,10 @@ varying vec3 relPos;
|
||||||
|
|
||||||
|
|
||||||
uniform sampler2D landclass;
|
uniform sampler2D landclass;
|
||||||
uniform sampler2D grass;
|
uniform sampler2DArray atlas;
|
||||||
uniform sampler2D city;
|
//uniform sampler2D city;
|
||||||
uniform sampler2D forest;
|
//uniform sampler2D forest;
|
||||||
uniform sampler2D water;
|
//uniform sampler2D water;
|
||||||
|
|
||||||
|
|
||||||
varying float yprime_alt;
|
varying float yprime_alt;
|
||||||
|
@ -97,20 +98,11 @@ void main()
|
||||||
// is closer to what the OpenGL fixed function pipeline does.
|
// is closer to what the OpenGL fixed function pipeline does.
|
||||||
color = clamp(color, 0.0, 1.0);
|
color = clamp(color, 0.0, 1.0);
|
||||||
|
|
||||||
int lc = int(texture2D(landclass, gl_TexCoord[0].st).r * 256.0 + 0.5);
|
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
|
||||||
if ((lc == 1) || (lc == 2) || (lc == 4) || (lc == 5))
|
//st.s = st.s + 0.125 * mod(lc, 8);
|
||||||
{
|
//st.y = st.y + 0.125 * int(lc/8);
|
||||||
texel = texture2D(city, gl_TexCoord[0].st);
|
texel = texture(atlas, vec3(gl_TexCoord[0].st, lc));
|
||||||
} 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);
|
|
||||||
}
|
|
||||||
|
|
||||||
//texel = texture2D(texture, gl_TexCoord[0].st);
|
//texel = texture2D(texture, gl_TexCoord[0].st);
|
||||||
fragColor = color * texel + specular;
|
fragColor = color * texel + specular;
|
||||||
|
|
Loading…
Add table
Reference in a new issue