• 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
Tthe13th

Vertex world position

5 posts in this topic

Hi all,
I am working on a submarine game. I have a caustic effect and i want the effect to fade with increasing depth. I don't know much about hlsl programming only some basics that allows me to draw basic scene with some effects.
I was thinking about using vertex * worldmatrix y value to get the height but it doesn't work how i want.
[CODE]
void VertScene( float4 iPos : POSITION,
float3 iNormal : NORMAL,
float2 iTex : TEXCOORD0,
out float4 wPos : POSITION1,

out float4 oPos : POSITION,
out float2 oTex : TEXCOORD0,
out float oCamDist : TEXCOORD4,

out float4 vPos : TEXCOORD1,
out float3 vNormal : TEXCOORD2,
out float4 vPosLight : TEXCOORD3,
out float2 caustCoord : TEXCOORD5)
{
wPos = mul( iPos, g_mWorld );
vPos = mul( wPos, g_mView );
oPos = mul( vPos, g_mProj );
oTex = iTex;
oCamDist=oPos.z;
vNormal = mul(iNormal, (float3x3)mul(g_mWorld, g_mView));
vPosLight = mul( vPos, g_mViewToLightProj );
float2x2 rotation = {COS_0_15F, -SIN_0_15F, SIN_0_15F, COS_0_15F};
caustCoord=mul(wPos.xz, rotation);
}

/////// Pixel shader
float2 movement = caustCoord.xy;
movement.x = movement.x + cos(g_fTime * 0.2f*20) * 0.3f;
movement.y = movement.y + sin(g_fTime * 0.3f*20) * 0.2f;
float4 cautictex = tex2D(CausticTextureSampler, movement.xy * 0.07f);
float dcaust=0.2*(1.0-saturate((400.5-wPos.y)/20.0));

float4 ps_LightAmbient = dcaust * cautictex+
0.2 * g_LightAmbient +
0.6 * g_LightAmbient * saturate( dot( -normalize( float3( vPos - g_sun_poz ) ), normalize( vNormal ) ) );
[/CODE]

saturate((400.5-wPos.y)/20.0) doesn't seem to work, (400.5 is the water surface position, 20.0 is the max depth at witch caustic effect should be visible), when i use constant 0 - 0.2 it works well.
What am i doing wrong?
0

Share this post


Link to post
Share on other sites
Assuming that the water level is at y = 400.5 (where the water starts) you can define the max depth the caustics can reach (e.g. y = 380.5). Then you can calculate a linearly fade the effect like this:

[CODE]
m = 1 / (waterLevel - maDepth);

b = -maxDepth/m;

float dcaust = saturate ( (wPos.y*m) + b);
[/CODE]

[CODE]float dcaust = saturate( (0.05*wPos.y) - 19.025 );[/CODE]

or instead of linear attenuation try this:

[CODE]
float dcaust = saturate( (0.05*wPos.y) - 19.025 )
dcaust *= dcaust;
[/CODE]


Anyway, are you sure wPos.y contains the correct value? Why do you say your function doesn't work? Some screenshots might help. Edited by TiagoCosta
0

Share this post


Link to post
Share on other sites
[url="http://img.pictureup.cz/01062012/8b5e4d5c6f75ceaafc1f1664d8ab0e340aee4376.png"]http://img.pictureup...e340aee4376.png[/url] dcaust==0
[url="http://img.pictureup.cz/01062012/222433699c3d38c1f963c2c2ff19bda31ccdce40.png"]http://img.pictureup...da31ccdce40.png[/url] dcaust==0.05
[url="http://img.pictureup.cz/01062012/c0eb6a6c2ef8584ec5dc78bbd72ddfbf4aaec9e7.png"]http://img.pictureup...fbf4aaec9e7.png[/url] dcaust==0.2

About wPos, i am not sure if there is the correct y value, like i said i know only basics about HLSL, that's why i posted vertex shader code wPos = mul(iPos, g_mWorld);
0

Share this post


Link to post
Share on other sites
Well wPos.y is not what i needed.
I will ask this way: How do i get y value of a vertex in pixel shader?
0

Share this post


Link to post
Share on other sites
I'm not 100% familiar with SM 3.0 semantics, but instead of:
[CODE]out float4 wPos : POSITION1[/CODE]

try:
[CODE]out float4 wPos : TEXCOORD1[/CODE]

Dont forget to also change it in the pixel shader input

Because if you use POSITION[n] semantic as output of the vertex shader w-divide will be performed before rasterization. Edited by TiagoCosta
0

Share this post


Link to post
Share on other sites
Changing POSITION1 to TEXCOORD1 worked thanks a lot[img]http://public.gamedev.net//public/style_emoticons/default/smile.png[/img]
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