1
0
Fork 0

HDR: WS30 basic terrain shader

This commit is contained in:
Stuart Buchanan 2023-04-12 18:11:41 +01:00
parent 23b4e6e26f
commit ce24a3f05f
2 changed files with 169 additions and 0 deletions

View file

@ -1874,4 +1874,103 @@
</pass> </pass>
</technique> </technique>
<technique n="109">
<scheme>hdr-geometry</scheme>
<pass>
<!-- Reverse floating point depth buffer -->
<depth>
<function>gequal</function>
<near>1.0</near>
<far>0.0</far>
</depth>
<stencil>
<function>always</function>
<value>9</value>
<pass>replace</pass>
</stencil>
<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 0 direct from VPBBuilder.cxx -->
<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>
<cull-face>back</cull-face>
<program>
<vertex-shader>Shaders/HDR/terrain_default.vert</vertex-shader>
<fragment-shader>Shaders/HDR/ws30.frag</fragment-shader>
<fragment-shader>Shaders/HDR/gbuffer_pack.glsl</fragment-shader>
<fragment-shader>Shaders/HDR/normal_encoding.glsl</fragment-shader>
<fragment-shader>Shaders/HDR/color.glsl</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>perlin</name>
<type>sampler-2d</type>
<value type="int">6</value>
</uniform>
</pass>
</technique>
</PropertyList> </PropertyList>

70
Shaders/HDR/ws30.frag Normal file
View file

@ -0,0 +1,70 @@
#version 330 core
in vec3 vN;
in vec2 texcoord;
uniform sampler2D landclass;
uniform sampler2DArray atlas;
uniform sampler2D perlin;
// Passed from VPBTechnique, not the Effect
uniform float fg_tileWidth;
uniform float fg_tileHeight;
uniform bool fg_photoScenery;
uniform vec4 fg_dimensionsArray[128];
uniform vec4 fg_ambientArray[128];
uniform vec4 fg_diffuseArray[128];
uniform vec4 fg_specularArray[128];
uniform vec4 fg_textureLookup1[128];
uniform vec4 fg_textureLookup2[128];
uniform mat4 fg_zUpTransform;
uniform vec3 fg_modelOffset;
const float TERRAIN_METALLIC = 0.0;
const float TERRAIN_ROUGHNESS = 0.95;
// gbuffer_pack.glsl
void gbuffer_pack(vec3 normal, vec3 base_color, float metallic, float roughness,
float occlusion, vec3 emissive, uint mat_id);
// color.glsl
vec3 eotf_inverse_sRGB(vec3 srgb);
void main()
{
vec3 texel;
vec4 specular = vec4(0.1, 0.1, 0.1, 1.0);
if (fg_photoScenery) {
texel = texture(landclass, vec2(texcoord.s, 1.0 - texcoord.t)).rgb;
} else {
// The Landclass for this particular fragment. This can be used to
// index into the atlas textures.
int lc = int(texture2D(landclass, texcoord).g * 255.0 + 0.5);
uint tex1 = uint(fg_textureLookup1[lc].r * 255.0 + 0.5);
//color = ambientArray[lc] + diffuseArray[lc] * NdotL * gl_LightSource[0].diffuse;
specular = fg_specularArray[lc];
// Different textures have different have different dimensions.
vec2 atlas_dimensions = fg_dimensionsArray[lc].st;
vec2 atlas_scale = vec2(fg_tileWidth / atlas_dimensions.s, fg_tileHeight / atlas_dimensions.t );
vec2 st = atlas_scale * texcoord;
// Rotate texture using the perlin texture as a mask to reduce tiling
if (step(0.5, texture(perlin, atlas_scale * texcoord / 8.0).r) == 1.0) {
st = vec2(atlas_scale.s * texcoord.t, atlas_scale.t * texcoord);
}
if (step(0.5, texture(perlin, - atlas_scale * texcoord / 16.0).r) == 1.0) {
st = -st;
}
texel = texture(atlas, vec3(st, tex1)).rgb;
}
vec3 color = eotf_inverse_sRGB(texel);
gbuffer_pack(vN, color, TERRAIN_METALLIC, TERRAIN_ROUGHNESS, 1.0, vec3(0.0), 3u);
}