Pages: [1] 2
  Print  
Author Topic: Multitextured Terrain Example  (Read 5374 times)
Offline (Male) Goombert
Posted on: September 09, 2013, 01:25:02 PM

Contributor
Location: Cappuccino, CA
Joined: Jan 2013
Posts: 2988

View Profile


This is for a game I am making, enjoy!

Download: https://www.dropbox.com/s/1j2gkap2ygwyyfy/MultitexturedTerrain.egm
Size: 1.71mb's
« Last Edit: December 13, 2013, 08:15:46 AM by Robert B Colton » Logged
Welcome to ENIGMO, the game engine built by fucking aliens.

Offline (Unknown gender) TheExDeus
Reply #1 Posted on: July 04, 2014, 09:21:55 AM

Developer
Joined: Apr 2008
Posts: 1886

View Profile
Note: This is a reply to a message Robert sent me, but I post it here as it should be clarified for everyone.
Quote
I wanted to let you know that this terrain demo I made a while back works in OGL1 but still does not draw anything in OGL3 for some reason, it uses custom shaders because the terrain is multitextured. All it draws is the text.
The reason it doesn't render anything in GL3 is because GLSL is not compatible between GL1 and GL3. And it never will be. So if you make something that uses shaders, then you must choose - either use GL1 or GL3 graphics system, as it won't work for both. Another way to do it is to write two versions for each shader and load during runtime. The specific reason why this example doesn't render in GL3 is because the vertex shader looks like this:
Code: [Select]
varying float height;

void main() { 
    gl_TexCoord[0] = gl_MultiTexCoord0; 
    // Set the position of the current vertex 
    gl_Position = ftransform(); 
    height = gl_Vertex.z;
}
The deprecated stuff is this - "varying" no longer is used, "gl_TexCoord[0]" and "gl_MultiTexCoord0" is no longer defined, "ftransform();" and "gl_Vertex" is no longer used. So basically 90% of that shader is deprecated. The reason why we can't make it backwards compatible, is because built-in attributes like "gl_Vertex" require a special function (glVertexPointer) C++ side to work, while in GL3 position is just a general attribute. So we cannot use GL3 attribute function to set gl_Vertex. So the correct shader is something like this:
Code: [Select]
out float v_height;
in vec3 in_Position;
in vec2 in_TextureCoord;

out vec2 v_TextureCoord;

void main() {
    v_TextureCoord = in_TextureCoord; 
    // Set the position of the current vertex 
    gl_Position = modelViewProjectionMatrix * vec4(in_Position,1.0); 
    v_height = in_Position.z;
}
Attributes like "in_Position" and "in_TextureCoord", as well as matrices like "modelViewProjectionMatrix", are predefined by ENIGMA, so it is a lot easier to write shader code (+it's compatible with GM).

TL;DR - It's very unlikely that your GL1 shader code will be compatible with GL3. The only way to do it would be either "#define gl_vertex vec4(in_Position,1.0)" or try changing it with "glSetAttributePointer" - both of these methods should be impossible, as it's a built-in variable which is unchangeable. It might even be better to make a rudimentary shader convertor, as most of the conversion can be done via "Find and Replace".

Here is actually a water example I made using this example. The water has real-time reflections and is transformed in vertex shader to have waves (very basic though). I plan to add per-pixel lights (the moving ball), water refraction, sun and some other stuff. Maybe animated trees or other props.


The FPS is quite junk on my old ATI (yes, it's actually an ATI) laptop though, but that is to be expected. Especially when the water consists of 260k vertices which are transformed every frame. But on my Nvidia it runs with no problem.
Logged
Offline (Male) Goombert
Reply #2 Posted on: July 04, 2014, 03:03:44 PM

Contributor
Location: Cappuccino, CA
Joined: Jan 2013
Posts: 2988

View Profile
Haha, very nice Harri!

I wonder exactly how Studio handles backwards compatibility of shaders. I say we leave things the way we have them, it's expected for OGL1 and OGL3 shaders to match their relative specs.
Logged
Welcome to ENIGMO, the game engine built by fucking aliens.

Offline (Unknown gender) TheExDeus
Reply #3 Posted on: July 04, 2014, 03:32:33 PM

Developer
Joined: Apr 2008
Posts: 1886

View Profile
Quote
I wonder exactly how Studio handles backwards compatibility of shaders.
I don't think they have such a thing. They added shaders only in GM:S, when they added GLES. So all their shaders are just like ours in GL3. They never allowed GL1.1 shaders. So we do support all their shaders (when properly written) and I have tried some of them.

Added shading to terrain and per-pixel lights:
 
Logged
Offline (Male) Josh @ Dreamland
Reply #4 Posted on: July 04, 2014, 07:43:51 PM

Prince of all Goldfish
Developer
Location: Ohio, United States
Joined: Feb 2008
Posts: 2933

View Profile Email
That's actually looking beautiful, Harri. Sand's a little bright; maybe give it a little more saturation or less value, or perhaps a better transition to the grass is in order. Hard to say.
Logged
"That is the single most cryptic piece of code I have ever seen." -Master PobbleWobble
"I disapprove of what you say, but I will defend to the death your right to say it." -Evelyn Beatrice Hall, Friends of Voltaire
Offline (Male) time-killer-games
Reply #5 Posted on: July 05, 2014, 01:22:57 PM

Member
Location: Virginia Beach
Joined: Jan 2013
Posts: 1061

View Profile WWW Email
Now that's some sexy water reflections going on there. Does that same shader work in GM?. Is this just for terrain or do we support multiple image'd OBJ materials? In any case this looks pretty cool! Congrats! :D
Logged
Offline (Unknown gender) TheExDeus
Reply #6 Posted on: July 05, 2014, 04:44:38 PM

Developer
Joined: Apr 2008
Posts: 1886

View Profile
Yeah, I'm tweaking the whole thing. The texture was actually messed up, because I had repetition rate too big. So in that image texture size was like 2x2 pixels. That is why it's so grainy.

Here I added shoreline foam, refraction and absorption. Foam is the white thing around the island, refraction is when you look in the water and see trough it (hard to notice in this image) and absorption is when you see until a certain depth until you cannot see the land below. This case it's the blueish gradient with light blue on top and dark blue deeper below.

I will try to make a higher resolution screenshot. Right now everything runs in 800x600.

edit:
Quote
Does that same shader work in GM?
I haven't tested as I don't have GM:S, but in theory it should.
Quote
Is this just for terrain or do we support multiple image'd OBJ materials?
No, that would be something different. Here texture is applied automatically based on water level. So when you rise the water level, then border between land and water will always be sand. So it's based on .z coordinates and not based on a mask or something like that. But I am planning to replace it with a mask, so I could paint roads and so on. That would in theory work on any object, as you would just paint what texture is where and blend them automatically.
« Last Edit: July 05, 2014, 04:54:00 PM by TheExDeus » Logged
Offline (Male) Goombert
Reply #7 Posted on: July 05, 2014, 06:41:59 PM

Contributor
Location: Cappuccino, CA
Joined: Jan 2013
Posts: 2988

View Profile
God damn Harri, I actually started the original so that I could maybe do a SimCity clone, but you've far outdone me so far.

But anyway, that shit needs some mipmapping and anisotropic filtering, I am going to go cleanup that shit and get it working between OGL and Direct3D.
Logged
Welcome to ENIGMO, the game engine built by fucking aliens.

Offline (Unknown gender) TheExDeus
Reply #8 Posted on: July 05, 2014, 07:29:18 PM

Developer
Joined: Apr 2008
Posts: 1886

View Profile
Yeah, it really does need some filtering. The water is also to rough, but it's a start. I do have problems with rendering to surfaces though. I have some z-fighting or z-depth issues. Cannot figure it out.

Here is a larger image (right-click->View image):


Here you can see I don't have 60FPS even on a quite decent card. That's because none of that is optimized. I will add some stuff to ENIGMA to help with debugging.
« Last Edit: July 05, 2014, 07:35:13 PM by TheExDeus » Logged
Offline (Male) time-killer-games
Reply #9 Posted on: July 06, 2014, 08:46:37 AM

Member
Location: Virginia Beach
Joined: Jan 2013
Posts: 1061

View Profile WWW Email
Hairy, that is a true work of art. You should be proud. :) I'll test these shaders in GMS when I find the time.

PS add more scenery if you like, trees, rocks, etc just don't change anything with the shaders, textures, lighting, etc concerned with the water and terrain. It looks beautiful. :)
« Last Edit: July 06, 2014, 08:58:11 AM by time-killer-games » Logged
Offline (Unknown gender) TheExDeus
Reply #10 Posted on: July 06, 2014, 10:13:13 AM

Developer
Joined: Apr 2008
Posts: 1886

View Profile
Quote
I'll test these shaders in GMS when I find the time.
I haven't posted any shaders yet. They should in theory work, but what won't work is the example itself. I use EDL, so some conversion would have to be made. I also don't know how rendering 3D scene to surface works in GM now.

Fixed the z issue. Turns out I need to add depth buffer to FBO for depth buffer to work. :D I changed surface_create() a little to accommodate this as an option. Maybe I will add new options for data types and another option for number of texture targets. This would allow me to render to several textures at once via one shader.
Also made the foam a little less conspicuous.


edit: Why did Robert remove d3d_model_calculate_normals() function? In the commit it says that it didn't work, but didn't it? It's a very useful function. In the terrain demo I actually had to calculate normals in EDL, but I just noticed that I could of used the function that was previously in ENIGMA.
« Last Edit: July 06, 2014, 11:15:24 AM by TheExDeus » Logged
Offline (Male) time-killer-games
Reply #11 Posted on: July 06, 2014, 01:53:28 PM

Member
Location: Virginia Beach
Joined: Jan 2013
Posts: 1061

View Profile WWW Email
Really cool screens. Any chance you'd send me the shaders for GMS testing when you feel it's ready?I might need the textures/models too so I can reproduce a similar project completely in GML.
Logged
Offline (Unknown gender) TheExDeus
Reply #12 Posted on: July 06, 2014, 03:01:04 PM

Developer
Joined: Apr 2008
Posts: 1886

View Profile
I will just post the egm. Then you will be able to remove all the EDL sugar. Also, for now there are no models. All is in the project and the island is generated each time (that is why it's always different in those screens).
Logged
Offline (Male) Goombert
Reply #13 Posted on: July 06, 2014, 04:33:25 PM

Contributor
Location: Cappuccino, CA
Joined: Jan 2013
Posts: 2988

View Profile
Harri, people were complaining the normal calculation method was not working, I also had made changes to the way models were being built at that time I simply removed the function.

I suggest following whatever Unity3D offers in their model class.
http://docs.unity3d.com/ScriptReference/MeshUtility.html
http://docs.unity3d.com/ScriptReference/ModelImporter.html

I am also working on cleaning up our texture shit, some things were not done right in OGL, YYG has their functions mimicing Direct3D sampler states which are global, so I need to write a sampler cache for OGL. On top of that, I figured out how to do automatic mipmap generation for both systems.
https://github.com/enigma-dev/enigma-dev/pull/770
Logged
Welcome to ENIGMO, the game engine built by fucking aliens.

Offline (Unknown gender) egofree
Reply #14 Posted on: July 07, 2014, 03:44:02 AM
Contributor
Joined: Jun 2013
Posts: 604

View Profile Email
Looks nice Robert. I tested your example, and here is the result :

On DirectX 9, i've the following error message :

Quote
  Event[8]:   Parsing 1 sub-events:
Check `obj_terrain::draw...Syntax error in object `obj_terrain', Draw event:0:
Line 1, position 12 (absolute 11): Unknown function or script `shader_set'

With OpengGl3:



With, OpenGl1, it's ok, except a few glitches with the rivers :



It was tested on a laptop with Windows 8.1 64 bits and Intel HD Graphics 4000.
Logged
Pages: [1] 2
  Print