ASE 'Terrain'


(WadeV1589) #1

I’ve read about alphamod dot product and I don’t think I get it so I’ll just say what I’d like to do.

Basically I have a large map and so would like to do the terrain as an ase, in one part of the map the angle of the terrain changes by 90 degrees to form 4 cliff faces. How can I blend between 2 textures on someting like this? Basically all the top surface would be one texture and the 4 cliff faces would be another texture with a blend between the two.

The reason I need them to blend is one texture is repeated several times over a small area while the other is one big texture to cover the entire upper surface so I need to blend using shaders from one image (not repeated) to another image (repeated several times).


(ratty redemption) #2

I`d do it by making a thin strip of meta shaded terrain and covering the join between the floor and wall terrain, and having that terrain fade from the floor tex to the wall tex… or have the edges of the strip translucent so it partly shows the floor and wall terrain.


(ydnar) #3

Grab the development build of Q3Map2 and download this sample map.

It uses q3map_alphaMod dotProduct2 to achieve blending between snow on horizontal-ish faces and rock on vertical-ish faces, transitioning smoothly between them. Make sure you look carefully at the example shader and textures, including their alpha channels.

Screenshots:

y


(Hewster) #4

mmmm… thats a lot better than my attempt with the old q3map_alphaMod dotProduct

Downloading now :slight_smile:

Hewster


(Hewster) #5

err ydnar, do you mean this version of q3map2?

http://akiba.shaderlab.com/GtkRadiant/tools/quake3/q3map2/Release/q3map2.exe

I cannot seem to find a development release in at the link you supplied

Hewster


(ratty redemption) #6

very nice blending in those pics ydnar :slight_smile:

does this only work with the latest q3map2? …or could I use it with 2.5.10?


(Hewster) #7

I think you need the latest development release of q3map2 Ratty:
"Grab the development build of Q3Map2 and download this sample map. "

The link I posted is what I believe to be the link to the version of
q3map2 Ydnar was speaking of :slight_smile:

Hewster


(WadeV1589) #8

Cool stuff, gonna go try it out.


(rgoer) #9

I have a test map together at http://www4.ncsu.edu/~rlcordes/picoterraintest.pk3. (Quake 3)


(The5thHorsemen) #10

geeeezzzzzzzzzzz louizzzzzzzzzzeeeeeeeeeeeee

I have to check that out

more stuff for me to play catch up on…


(Gringo Starr) #11

Wow! Those do look quite cool. Maybe for my next map, when the average graphics card is a GeF3 :slight_smile:


(Davros) #12

rgoer can you post that pk3 again? :drink:


(seremtan) #13

What in the hell is going on here?

These weird gold planes were flashing all over the screen whenever I looked at the terrain. Sky looked fine, though there was this error message for each .tga:

WARNING: reused image texture/shaderlab_terrain/env/sky_rt.tga with mixed glWrap Clampmode parm.

Don’t think it’s a driver issue (got latest Detonator 5). Am running Q3A 1.27, but I’ve never had problems with any other map. No texture compression, no AA or aniso, nothing like that.


(rgoer) #14

Sorry for the hiccup, the pk3 is back up at the same URL as posted before.


(Davros) #15

cheers rgoer, any more info on the shader parms? does q3map2 just apply the texture to faces more than 45 degrees?


(rgoer) #16

Here’s what it’s doing:

Assuming you’ve not got anything else modifying the vertex alpha for your terrain (like, say, a colormap for your picoterrain), then the alpha for each of your terrain’s vertexes is straight white. All the way solid.

The q3map_alphaMod dotproduct2 ( x y z ) line of the shader tells q3map2 to look at every vertex to which this shader is applied, and modify that vertexes’ vertex alpha in a certain way. That way is sort of complicated, but not really. You define a vector in the ( x y z ) part of the shader–In my example terrain shader, the vector I defined was ( 0 0 0.85 )–and there is also a vector defining the normal direction of every vertex of your terrain. The normal vector just tells quake which way the vertex is oriented–and between the 3 vertexes needed to define a surface, the average of their vertex normals becomes the surface normal. The surface normal, just like the vertex normals do for vertexes, define how a surface is oriented. The pitch, yaw, and roll of a given triangle. The slope of a given part of your terrain. The surface normal is really what we’re interested in, but you have to work with the vertex normals in order to get at it.

Anyway, q3map2 does a dotproduct operation between the vector you define, say, ( 0 0 0.85 ), and the normal vector for whatever vertex it is working on right now. I’m not sure if the op goes shader dot vertex or vertex dot shader, but either way, this is what’s going on. It then squares the result (that’s the difference between q3map_alphaMod dotproduct and q3map_alphaMod dotproduct2) and multiplies the original vertex alpha value–in our terrain’s case, that was probably 100% white–by the final dotproduct2 value.

With my vector, which points straight up, what ends up happening is this: the vertex alpha for horizontally flat areas of the terrain ends up staying pretty white. The alpha ramps down as slope increases, all the way to the point that the vertex alpha for vertical (“cliff”) faces becomes straight black. A gentle hill sloped at about 45 degrees would have 50% grey vertex alpha.

This stuff is all dependant on how you set your vector up in your shader, though. If I had used ( 0.85 0 0 ) in my shader, the vertical faces oriented in the +X direction would be the ones that get to keep their 100% white vertex alpha, and the horizontally flat faces would be pushed to black.

Anyway, now that q3map2 has worked out the vertex alpha for your terrain, next comes the actual shader drawing.

Dirt.tga, which has no alpha channel and no blendFunc, gets drawn on every triangle of your terrain. It is everywhere.

Rock.tga, which has a bright alpha channel (~90% white), gets blended and masked off pretty normally. However, the alphaGen oneMinusVertex essentially inverts that bright alpha channel, and Rock.tga ends up only getting drawn on terrain vertexes that have very dark (as dark as or darker than Rock.tga’s alpha channel is bright) vertex alpha.

Grass.tga has a similarly bright alpha channel (~90% white), and it gets blended and masked off likewise. Its alphaGen line uses the straight vertex alpha (instead of the inverted “oneMinusVertex” version), so Grass.tga, with its almost-white alpha channel, gets drawn on all vertexes that have very bright (as bright or brighter than Grass.tga’s alpha channel is bright) alpha–the horizontally flat surfaces.

Finally, just throw a map $lightmap on there and make sure the three previous passes had rgbGen identity, and you’re good to go.

When ydnar gets back, maybe he’d correct any glaring errors I made. I’m pretty sure that this is pretty much what’s going on, though, and good luck to you in experimenting with this stuff!


(ratty redemption) #17

Dirt.tga, which has no alpha channel and no blendFunc, gets drawn on every triangle of your terrain. It is everywhere.

does this mean there is more overdraw then using alphamaps and conventional meta shaders?


(rgoer) #18

I’m not sure how conventional metashaders divide up what gets drawn and what doesn’t. There is going to be a 100% overdraw of your base texture using this method, though, that much is sure. The performance hit hasn’t been noticable in any of the tests I’ve done yet, nor in ydnar’s example map (which was absolutely fucking gargantuan).


(ydnar) #19

Use the latest PR.

y


(Davros) #20

does distancecull work with picoterrain? i cant seem to get it working :???: i have a terrain that extends about 12000 with a distancecull of about 8000, but all the terrain is drawn. is it a drawback of using modelled terrain? its not a big problem just it would be good to cut a few polys out. the blending is awesome however! good stuff ydnar :clap:

edit got it working now :bash: