New tree rendering algorithm
Draw trees in two passes, opaque and transparent. This allows us to have some transparency, which is better looking, and dispense with sorting. Author: Tim Moore <timoore@redhat.com>
This commit is contained in:
parent
3f1e9b8733
commit
ffa9cae11c
2 changed files with 52 additions and 10 deletions
|
@ -1,6 +1,16 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<!-- Effects files for trees, which are placed by a shader. -->
|
<!-- Effects files for trees, which are placed by a shader. -->
|
||||||
|
|
||||||
|
<!-- Trees are drawn in two passes. The first draws the opaque parts
|
||||||
|
with z writes enabled. The second draws the the transparent bits
|
||||||
|
with z testing enabled and z writes disabled. The transparent
|
||||||
|
tree silhouettes will blend correctly against the opaque
|
||||||
|
geometry. They may cause artifacts when blending against other
|
||||||
|
edges, but the overall "forest" is supposed to be nice and
|
||||||
|
fuzzy. There might also be artifacts when blending over other
|
||||||
|
transparent objects, but that's mostly unavoidable.
|
||||||
|
|
||||||
|
Note: no sorting needed! -->
|
||||||
<PropertyList>
|
<PropertyList>
|
||||||
<name>Effects/tree</name>
|
<name>Effects/tree</name>
|
||||||
<parameters>
|
<parameters>
|
||||||
|
@ -17,20 +27,16 @@
|
||||||
</less-equal>
|
</less-equal>
|
||||||
</and>
|
</and>
|
||||||
</predicate>
|
</predicate>
|
||||||
<pass>
|
<pass n="0">
|
||||||
<lighting>true</lighting>
|
<lighting>true</lighting>
|
||||||
<material>
|
<material>
|
||||||
<ambient type="vec4d">1.0 1.0 1.0 1.0</ambient>
|
<ambient type="vec4d">1.0 1.0 1.0 1.0</ambient>
|
||||||
<diffuse type="vec4d">1.0 1.0 1.0 1.0</diffuse>
|
<diffuse type="vec4d">1.0 1.0 1.0 1.0</diffuse>
|
||||||
<color-mode>off</color-mode>
|
<color-mode>off</color-mode>
|
||||||
</material>
|
</material>
|
||||||
<render-bin>
|
|
||||||
<bin-number>2</bin-number> <!-- RANDOM_OBJECTS_BIN -->
|
|
||||||
<bin-name>DepthSortedBin</bin-name>
|
|
||||||
</render-bin>
|
|
||||||
<alpha-test>
|
<alpha-test>
|
||||||
<comparison>gequal</comparison>
|
<comparison>gequal</comparison>
|
||||||
<reference type="float">0.33</reference>
|
<reference type="float">1.0</reference>
|
||||||
</alpha-test>
|
</alpha-test>
|
||||||
<texture-unit>
|
<texture-unit>
|
||||||
<unit>0</unit>
|
<unit>0</unit>
|
||||||
|
@ -48,9 +54,46 @@
|
||||||
<type>sampler-2d</type>
|
<type>sampler-2d</type>
|
||||||
<value type="int">0</value>
|
<value type="int">0</value>
|
||||||
</uniform>
|
</uniform>
|
||||||
<!-- The vertex shader isn't doing two-sided lighting yet, but
|
</pass>
|
||||||
should be soon. -->
|
<pass n="1">
|
||||||
<vertex-program-two-side type="bool">true</vertex-program-two-side>
|
<lighting>true</lighting>
|
||||||
|
<material>
|
||||||
|
<ambient type="vec4d">1.0 1.0 1.0 1.0</ambient>
|
||||||
|
<diffuse type="vec4d">1.0 1.0 1.0 1.0</diffuse>
|
||||||
|
<color-mode>off</color-mode>
|
||||||
|
</material>
|
||||||
|
<render-bin>
|
||||||
|
<bin-number>2</bin-number> <!-- RANDOM_OBJECTS_BIN -->
|
||||||
|
<bin-name>RenderBin</bin-name>
|
||||||
|
</render-bin>
|
||||||
|
<alpha-test>
|
||||||
|
<comparison>less</comparison>
|
||||||
|
<!-- <reference type="float">0.33</reference> -->
|
||||||
|
<reference type="float">1.0</reference>
|
||||||
|
</alpha-test>
|
||||||
|
<blend>
|
||||||
|
<source>src-alpha</source>
|
||||||
|
<destination>one-minus-src-alpha</destination>
|
||||||
|
</blend>
|
||||||
|
<depth>
|
||||||
|
<write-mask>false</write-mask>
|
||||||
|
</depth>
|
||||||
|
<texture-unit>
|
||||||
|
<unit>0</unit>
|
||||||
|
<type>2d</type>
|
||||||
|
<image><use>texture[0]/image</use></image>
|
||||||
|
<wrap-s>clamp</wrap-s>
|
||||||
|
<wrap-t>clamp</wrap-t>
|
||||||
|
</texture-unit>
|
||||||
|
<program>
|
||||||
|
<vertex-shader>Shaders/tree.vert</vertex-shader>
|
||||||
|
<fragment-shader>Shaders/tree.frag</fragment-shader>
|
||||||
|
</program>
|
||||||
|
<uniform>
|
||||||
|
<name>baseTexture</name>
|
||||||
|
<type>sampler-2d</type>
|
||||||
|
<value type="int">0</value>
|
||||||
|
</uniform>
|
||||||
</pass>
|
</pass>
|
||||||
</technique>
|
</technique>
|
||||||
</PropertyList>
|
</PropertyList>
|
||||||
|
|
|
@ -29,7 +29,6 @@ void main(void)
|
||||||
vec3 diffuse = gl_FrontMaterial.diffuse.rgb * max(0.1, n);
|
vec3 diffuse = gl_FrontMaterial.diffuse.rgb * max(0.1, n);
|
||||||
vec4 ambientColor = gl_FrontLightModelProduct.sceneColor + gl_LightSource[0].ambient * gl_FrontMaterial.ambient;
|
vec4 ambientColor = gl_FrontLightModelProduct.sceneColor + gl_LightSource[0].ambient * gl_FrontMaterial.ambient;
|
||||||
gl_FrontColor = ambientColor + gl_LightSource[0].diffuse * vec4(diffuse, 1.0);
|
gl_FrontColor = ambientColor + gl_LightSource[0].diffuse * vec4(diffuse, 1.0);
|
||||||
gl_BackColor = gl_FrontColor;
|
|
||||||
|
|
||||||
float fogCoord = abs(ecPosition.z);
|
float fogCoord = abs(ecPosition.z);
|
||||||
fogFactor = exp( -gl_Fog.density * gl_Fog.density * fogCoord * fogCoord);
|
fogFactor = exp( -gl_Fog.density * gl_Fog.density * fogCoord * fogCoord);
|
||||||
|
|
Loading…
Reference in a new issue