• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
Yours3!f

detail tessellation "jumping" surface

3 posts in this topic

Hi,

I'm trying to implement detail tessellation as in the DirectX SDK's DirectX 11 section: Detail tessellation.
My problem is that when I'm displacing the tessellated vertices in the tessellation evaluation shader, the resulting surface keeps "jumping" up and down.

Video:
http://youtu.be/K0LeOMi3tYg

here's the source code:
[CODE]
[vertex shader]

#version 410

uniform mat4 modelview;
uniform mat3 normal_mat;
uniform float tex_repeat;

in vec4 in_vertex;
in vec3 in_normal;
in vec3 in_tangent;
in vec2 in_texture;

out cross_shader_data
{
vec2 tex_coord;
vec4 vs_position;
vec3 normal;
vec3 tangent;
vec3 bitangent;
} o;

void main()
{
o.normal = normal_mat * in_normal; //transform normals, tangents, and bitangents into view space
o.tangent = normal_mat * in_tangent;
o.bitangent = cross(o.normal, o.tangent);

o.tex_coord = in_texture * tex_repeat;

o.vs_position = modelview * in_vertex; //transform vertices into view space
}

[tessellation control shader]

#version 410

layout(vertices = 3) out; //3 vertices define a patch (that is a triangle)

uniform vec4 tess_level; //=vec4(16)
uniform mat4 proj;
uniform vec2 screen_size; //screen width, height

in cross_shader_data
{
vec2 tex_coord;
vec4 vs_position;
vec3 normal;
vec3 tangent;
vec3 bitangent;
} i[];

out cross_shader_data
{
vec2 tex_coord;
vec4 vs_position;
vec3 normal;
vec3 tangent;
vec3 bitangent;
} o[];

vec2 get_screen_space_pos(vec4 pos)
{
vec4 ps_position = proj * pos; //transform view space position to projection space
vec2 ndc_pos = ps_position.xy / ps_position.w; //tranfrom into normalized device coordinates
return (ndc_pos + 1.0) * 0.5 * screen_size; //convert ndc coordinates to [0...1], and scale them to [0...screen size]
}

void main()
{
vec2 ss_position_0 = get_screen_space_pos(i[0].vs_position); //get screen space positions for the vertices
vec2 ss_position_1 = get_screen_space_pos(i[1].vs_position);
vec2 ss_position_2 = get_screen_space_pos(i[2].vs_position);

vec4 tess_factor = tess_level.xxxy; //get initial tessellation factor

//calculate tessellation factors, depending on screen space position
//(screen space LOD)
tess_factor.x = tess_level.w * distance(ss_position_2, ss_position_1);
tess_factor.y = tess_level.w * distance(ss_position_2, ss_position_0);
tess_factor.z = tess_level.w * distance(ss_position_0, ss_position_1);
tess_factor.w = 0.33 * (tess_factor.x + tess_factor.y + tess_factor.z);

gl_TessLevelOuter[0] = tess_factor.x;
gl_TessLevelOuter[1] = tess_factor.y;
gl_TessLevelOuter[2] = tess_factor.z;

gl_TessLevelOuter[0] = tess_factor.w;

//copy data
o[gl_InvocationID].tex_coord = i[gl_InvocationID].tex_coord;
o[gl_InvocationID].vs_position = i[gl_InvocationID].vs_position;
o[gl_InvocationID].normal = i[gl_InvocationID].normal;
o[gl_InvocationID].tangent = i[gl_InvocationID].tangent;
o[gl_InvocationID].bitangent = i[gl_InvocationID].bitangent;
}

[tessellation evaluation shader]

#version 410

//make triangles using fractional odd spacing, vertices are in counter clockwise order
layout(triangles, fractional_odd_spacing, ccw) in;

uniform sampler2D texture1; //XYZ normals, W height
uniform mat4 proj;
uniform float tess_height_scale; //=0.04

in cross_shader_data
{
vec2 tex_coord;
vec4 vs_position;
vec3 normal;
vec3 tangent;
vec3 bitangent;
} i[];

out cross_shader_data
{
vec2 tex_coord;
vec4 vs_position;
vec3 normal;
vec3 tangent;
vec3 bitangent;
} o;

void main()
{
//compute the new vertex parameters using barycentric coordinates
o.tex_coord = gl_TessCoord.x * i[0].tex_coord + gl_TessCoord.y * i[1].tex_coord + gl_TessCoord.z * i[2].tex_coord;
o.vs_position = gl_TessCoord.x * i[0].vs_position + gl_TessCoord.y * i[1].vs_position + gl_TessCoord.z * i[2].vs_position;
o.normal = gl_TessCoord.x * i[0].normal + gl_TessCoord.y * i[1].normal + gl_TessCoord.z * i[2].normal;
o.tangent = gl_TessCoord.x * i[0].tangent + gl_TessCoord.y * i[1].tangent + gl_TessCoord.z * i[2].tangent;
o.bitangent = gl_TessCoord.x * i[0].bitangent + gl_TessCoord.y * i[1].bitangent + gl_TessCoord.z * i[2].bitangent;

//calculate heightmap lod using viewspace position
float heightmap_miplevel = clamp( (length(o.vs_position) - 100.0 ) / 100.0, 0.0, 3.0);

//sample height
float height = textureLod( texture1, o.tex_coord, heightmap_miplevel ).w;

//displace vertex along normal
o.vs_position.xyz += normalize(o.normal) * ( tess_height_scale * (height - 1.0) );

gl_Position = proj * o.vs_position;
}

[pixel shader]

#version 410

uniform sampler2D texture0;
uniform sampler2D texture1;
uniform sampler2D texture2;
uniform float inv_neg_far;

in cross_shader_data
{
vec2 tex_coord;
vec4 vs_position;
vec3 normal;
vec3 tangent;
vec3 bitangent;
} i;

out vec4 albedo;
out vec4 normal;
out vec4 depth;
out vec4 extra;

void main()
{
//simple bumpmapping
mat3 ts_to_vs = mat3( normalize(i.tangent),
normalize(i.bitangent),
normalize(i.normal) );

albedo = vec4(texture(texture0, i.tex_coord).xyz, texture(texture2, i.tex_coord).x);
normal = vec4(ts_to_vs * (texture(texture1, i.tex_coord).xyz * 2.0 - 1.0) * 0.5 + 0.5, 1.0);
depth.x = i.vs_position.z * inv_neg_far;
extra = vec4(0.0);
}
[/CODE]

Best regards,
Yours3!f
0

Share this post


Link to post
Share on other sites
ok, so I replaced the tessellated mesh with a plane as it was in the sample, and I saw that the plane there was subdivided a little bit, it wasn't just 2 triangles. After that the flickering (jumping) is gone, but not all of the triangles get tessellated. See screenshot.
Any ideas what am I doing wrong?
0

Share this post


Link to post
Share on other sites
Hi!

Looks like here is some typo:
[CODE]gl_TessLevelOuter[0] = tess_factor.w;[/CODE]

I guess it should rather be
[CODE]gl_TessLevelInner[0] = tess_factor.w;[/CODE]
Does it?

Best regards
1

Share this post


Link to post
Share on other sites
[quote name='Tsus' timestamp='1337418755' post='4941383']
Hi!

Looks like here is some typo:
[CODE]gl_TessLevelOuter[0] = tess_factor.w;[/CODE]

I guess it should rather be
[CODE]gl_TessLevelInner[0] = tess_factor.w;[/CODE]
Does it?

Best regards
[/quote]
OMG lol this was the mistake [img]http://public.gamedev.net//public/style_emoticons/default/smile.png[/img] I cannot believe this... I've been struggling with this for like a week xD
BIG THANK YOU Tsus!!!
here's a pic about it:
0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0