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

melak47

Members
  • Content count

    8
  • Joined

  • Last visited

Community Reputation

112 Neutral

About melak47

  • Rank
    Newbie
  1. [quote name='swiftcoder' timestamp='1330920064' post='4919360'] You might want to think about working from the [url="http://sponeil.net/"]most current version of his shaders (poke around in 'downloads')[/url], rather than the dated, and somewhat badly-commented version in GPU Gems... [/quote] The thing is, I am! I have started the SkyFromSpace shader from scratch about 6 times now, once from the GPU Gems article, once from the current version, once from the article in nvidia FX Composer, trying to debug it, again from the current version in fx composer, once from someone else's source code on here, and once from Hyunkel's code here. I figured out why I didn't get the orange transition. Before I got the lightScale value right, the whole sphere was lit up so I multiplied the resulting diffuse by the lightAngle to make the far side of the planet dark. Now that the lightScale works correctly though, it was fading the diffuse out before the transition. Now that it's got the right value, the far side of the planet turns dark on it's own. I'm kind of clueless about the SkyFromSpace shader though...I guess I will take another stab at it sometime.
  2. [quote name='Hyunkel' timestamp='1330911352' post='4919321'] v3LightPos is actually the light direction, not the light position, even though the name suggests otherwise. It needs to be normalized. mScaleDepth, which I am assuming is fInvScaleDepth needs to be 1 / ScaleDepth. for "g" I would stick to -0.98f. It doesn't really influence anything too much besides the fake sun when rendering the sky from atmosphere though, which you aren't doing. Apart from that I can't find any problems. [/quote] Normalizing LighgtDir/Pos gives me more colored specks, they flicker extremely fast and are hard to capture: [img]http://dl.dropbox.com/u/21007284/specks.png[/img] In O'Neils C++ soruce code there are both rayleighScaleDepth and mieScaleDepth, though all the shaders only use the rayleigh one. InvScaleDepth is only used in this one line, so I opted for [CODE] float startDepth = exp(-1 / rScaleDepth); [/CODE] instead. Is the orange day/night transition in your renders a result of O'Neils shader, or something that you are doing? SkyFromSpace.fx: [CODE] cbuffer perObject { float4x4 Scale; float4x4 Rotation; float4x4 Position; float4 objColor; float4 objPos; int wire; int textured; }; cbuffer perFrame { float4x4 view; float4x4 projection; float4 CamPosW; float4 LightPosW; float4 WaveLength; float samples; float pRadius; float aRadius; float KrESun; float KmESun; float Kr4PI; float Km4PI; float g; float rScaleDepth; float mScaleDepth; }; struct appdata { float4 Pos : POSITION; float3 Normal : NORMAL; float3 UVW : TEXCOORD; }; struct v2p { float4 Pos : SV_POSITION; float4 Color0 : COLOR0; float4 Color1 : COLOR1; float3 Direction : TEXCOORD; }; float scale(float f) { float x = 1.0 - f; return rScaleDepth * exp(-0.00287 + x*(0.459 + x*(3.83 + x*(-6.80 + x*5.25)))); } // Calculates the Mie phase function float getMiePhase(float fCos, float fCos2, float g, float g2) { return 1.5 * ((1.0 - g2) / (2.0 + g2)) * (1.0 + fCos2) / pow(abs(1.0 + g2 - 2.0*g*fCos), 1.5); } // Calculates the Rayleigh phase function float getRayleighPhase(float fCos2) { //return 1.0; return 0.75 + 0.75*fCos2; } // Returns the near intersection point of a line and a sphere float getNearIntersection(float3 v3Pos, float3 v3Ray, float fDistance2, float fRadius2) { float B = 2.0 * dot(v3Pos, v3Ray); float C = fDistance2 - fRadius2; float fDet = max(0.0, B*B - 4.0 * C); return 0.5 * (-B - sqrt(fDet)); } v2p VS(appdata input) { //calculate prerequisites float4x4 WVP = transpose(mul(mul(mul(mul(projection, view), Position), Rotation), Scale)); float4x4 World = transpose(mul(mul(Position,Rotation),Scale)); float3 CamPos = CamPosW - objPos; float3 LightPos = LightPosW - objPos; LightPos /= length(LightPos); float3 InvWaveLength = 1.0 / pow(WaveLength.xyz, 4); float fscale = 1.0 / (aRadius - pRadius); float scaleOverScaleDepth = fscale / rScaleDepth; float altitude = length(CamPos); float3 pos = mul(input.Pos, World).xyz - objPos.xyz; float3 ray = pos - CamPos; pos /= length(pos); float far = length(ray); ray /= far; float near = getNearIntersection(CamPos, ray, altitude*altitude, aRadius*aRadius); //initial values float3 start = CamPos + ray * near; far -= near; float startAngle = dot(ray, start) / aRadius; float startDepth = exp(-1 / rScaleDepth); float startOffset = startDepth * scale(startAngle); float sampleLength = far / samples; float scaledLength = sampleLength * fscale; float3 sampleRay = ray * sampleLength; float3 samplePoint = start + sampleRay * 0.5; //loop through samples float3 frontColor = float3(0,0,0); for (int i=0; i<(int)samples; i++) { float height = length(samplePoint.xyz); float depth = exp(scaleOverScaleDepth * (pRadius - height)); float lightAngle = dot(LightPos, samplePoint) / height; float camAngle = dot(ray, samplePoint) / height; float scatter = (startOffset + depth * (scale(lightAngle) - scale(camAngle))); float3 attenuate = exp(-scatter * (InvWaveLength * Kr4PI + Km4PI)); frontColor += attenuate * (depth * scaledLength); samplePoint += sampleRay; } float3 c0 = frontColor * (InvWaveLength.xyz * KrESun); float3 c1 = frontColor * KmESun; float3 direction = CamPos - pos; float Cos = dot(LightPos, direction) / length(direction); v2p output; output.Pos = mul(input.Pos, WVP); output.Color0 = float4(c0, Cos); output.Color1 = float4(c1, 1); output.Direction = float4(direction, 1); return output; } float4 PS(v2p input) : SV_TARGET { float Cos = input.Color0.w; float3 color = getRayleighPhase(Cos*Cos) * input.Color0 + getMiePhase(Cos, Cos*Cos, g, g*g) * input.Color1; return float4(color, color.z); } [/CODE] And the GroundFromSpace.fx as well: [CODE] cbuffer perObject { float4x4 Scale; float4x4 Rotation; float4x4 Position; float4 objColor; float4 objPos; int wire; int textured; }; cbuffer perFrame { float4x4 view; float4x4 projection; float4 CamPosW; float4 LightPosW; float4 WaveLength; float samples; float pRadius; float aRadius; float KrESun; float KmESun; float Kr4PI; float Km4PI; float g; float rScaleDepth; float mScaleDepth; }; Texture2D objTexture; SamplerState texSampler; struct appdata { float4 Pos : POSITION; float3 Normal : NORMAL; float3 UVW : TEXCOORD; }; struct v2p { float4 Pos : SV_POSITION; float4 Color0 : COLOR0; float4 Color1 : COLOR1; float3 TexCoord : TEXCOORD; }; float scale(float fCos) { float x = 1.0 - fCos; return rScaleDepth * exp(-0.00287 + x*(0.459 + x*(3.83 + x*(-6.80 + x*5.25)))); } // Returns the near intersection point of a line and a sphere float getNearIntersection(float3 v3Pos, float3 v3Ray, float fDistance2, float fRadius2) { float B = 2.0 * dot(v3Pos, v3Ray); float C = fDistance2 - fRadius2; float fDet = max(0.0, B*B - 4.0 * C); return 0.5 * (-B - sqrt(fDet)); } v2p VS(appdata input) { //calculate prerequisites float4x4 WVP = transpose(mul(mul(mul(mul(projection, view), Position), Rotation), Scale)); float4x4 World = transpose(mul(mul(Position,Rotation),Scale)); float3 CamPos = CamPosW - objPos; float3 LightPos = LightPosW - objPos; float3 LightDir = LightPos / length(LightPos); float4 InvWaveLength = 1.0 / float4(pow(WaveLength.x, 4), pow(WaveLength.y, 4), pow(WaveLength.z, 4), 0); float fscale = 1.0 / (aRadius - pRadius); float scaleOverScaleDepth = fscale / rScaleDepth; float altitude = length(CamPos); float3 pos = mul(input.Pos, World).xyz - objPos.xyz; float3 ray = pos - CamPos; pos /= length(pos); float far = length(ray); ray /= far; float near = getNearIntersection(CamPos, ray, altitude*altitude, aRadius*aRadius); //initial values float3 start = CamPos + ray * near; far -= near; float depth = exp((pRadius - aRadius) / rScaleDepth); float camAngle = dot(-ray, pos); float lightAngle = dot(LightDir, pos); float camScale = scale(camAngle); float lightScale = scale(lightAngle); float camOffset = depth*camScale; float temp = lightScale + camScale; float sampleLength = far / samples; float scaledLength = sampleLength * fscale; float3 sampleRay = ray * sampleLength; float3 samplePoint = start + sampleRay * 0.5; //loop through samples float3 frontColor = float3(0,0,0); float3 attenuate; for (int i=0; i<(int)samples; i++) { float height = length(samplePoint.xyz); depth = exp(scaleOverScaleDepth * (pRadius - height)); float scatter = (depth*temp) - camOffset; attenuate = exp(-scatter * (InvWaveLength * Kr4PI + Km4PI)); frontColor += attenuate * (depth * scaledLength); samplePoint += sampleRay; } v2p output; output.Pos = mul(input.Pos, WVP); output.Color0 = float4(frontColor * (InvWaveLength.xyz * KrESun + KmESun), lightAngle); output.Color1 = float4(attenuate, 1); output.TexCoord = input.UVW; return output; } float4 PS(v2p input) : SV_TARGET { float4 planetColor; if (textured) planetColor = objTexture.Sample(texSampler, input.TexCoord.xyz); else planetColor = objColor; float lightAngle = input.Color0.w; float4 color = input.Color0 + (planetColor * input.Color1); color *= lightAngle; color.w = 1.0; return color; } [/CODE]
  3. I pass the object position to the shader and use vertex, camera and light position relative to that. These are my shader constants: [CODE] constBuffer.samples = 3; float Kr = 0.0025f; float Km = 0.0010f; float ESun = 20.0f; float pi = 3.14159265358979323846f; constBuffer.Kr4PI = Kr * 4 * pi; constBuffer.Km4PI = Km * 4 * pi; constBuffer.KrESun = Kr * ESun; constBuffer.KmESun = Km * ESun; constBuffer.pRadius = 1.0f; constBuffer.aRadius = 1.025f; constBuffer.rScaleDepth = 0.25f; constBuffer.mScaleDepth = 0.1f; constBuffer.CamPosW = XMFLOAT4(sin(t) * 5, 5, cos(t) * 5, 0.0f); constBuffer.LightPos = XMFLOAT4(1000, 1000, 1000, 0.0f); constBuffer.g = -0.99f; constBuffer.WaveLength = XMFLOAT4(0.65f, 0.57f, 0.475f, 0.0f); [/CODE] A few others I calculate in the shader: [CODE] float3 CamPos = CamPosW - objPos; float3 LightPos = LightPosW - objPos; float3 InvWaveLength = 1.0 / pow(WaveLength.xyz, 4); float fscale = 1.0 / (aRadius - pRadius); float scaleOverScaleDepth = fscale / rScaleDepth; float altitude = length(CamPos); float3 pos = mul(input.Pos, World).xyz - objPos.xyz; [/CODE]
  4. nvidia inspector will let you monitor GPU load, VRAM usage, clock speed and temperature. If what you are drawing so far is relatively simple, your app will push the GPU as fast as it can to draw more, and you will get thousands or even tenthousands of fps, with your GPU at 100% load. Presenting with vsync will make your Present call block until a vsync occurs (every 1/60th second, for example), so if you had 10.000 fps before, your GPU load might drop as low as 1% with vsync. It's as easy as calling Present(1, 0) instead of Present(0,0). [url="http://msdn.microsoft.com/en-us/library/windows/desktop/bb174576%28v=vs.85%29.aspx"]IDXGISwapChain::Present[/url] You could also wait for more vsyncs to save power if you like, for example when your app loses focus.
  5. The easiest thing would probably be to split it into two draw calls. set the primitive topology to pointlist before you draw your points, then to linelist before you draw your axes. your vertex buffer for the axes might look like this: [CODE] XMFLOAT3 vertices[] = { XMFLOAT3(0, 0, 0), XMFLOAT3(10, 0, 0), XMFLOAT3(0, 0, 0), XMFLOAT3(0, 10, 0), XMFLOAT3(0, 0, 0), XMFLOAT3(0, 0, 10), }; [/CODE]
  6. I tried to implement O'Neils shaders as well, but the most I ever got was a handful of brightly colored triangles somewhere. After I saw your post I figured I'd give the GroundFromSpace shader a try, and got it to work as well (for the most part. if the light is closer than 1 atmosphere radius, the lightScale value becomes an issue). Hoewver I do not get the orange-ish color around the night/day terminator. The SkyFromSpace shader however, I can't seem to get to work at all. How do you draw the atmosphere behind the planet? Disable depth buffer writes, draw the atmosphere, then render the planet? Doesn't the opaque planet skip any and all alpha blending with the transparent atmosphere if it is in front of it though? Even rewriting my SkyFromSpace shader after your code, all I get is this: (GroundFromSpace in the background): [img]http://dl.dropbox.com/u/21007284/triangle.png[/img] The underlying geometry is a geosphere, so that is likely just a single vertex's color lerping to the sourrounding 6 triangles.
  7. [quote name='mhagain' timestamp='1330683144' post='4918536'] Have a look at the documentation for SOSetTargets - this is controlled by the offset param. [/quote] Doh! This whole time I've been passing a nullpointer for the offset array, thinking that would be enough. Passing a pointer to an offset of 0 works like a charm! Thanks!
  8. I'm using two vertex buffers in my app, one is bound to the input assembler / vertex shader, the other is bound as a streamout target to the geometry shader. What I want to do is save the new vertices to the buffer, then flip the buffers each frame. The problem is, the geometry shader can only append new vertices at the end, so I need some way to clear the new streamout target before each frame. I tried to use ID3D11DeviceContext::UpdateSubresource(..) with a NULL'ed array the size of the buffer as a source, and that does clear the buffer, but no new vertices are saved to it. Maybe the geometry shader keeps track of how many vertices it has generated in total and tries to append new vertices to the buffer after that point. (which it can't since the buffer has only room for one set of vertices) I tried to use CopyResource(..) to copy the contents of an empty buffer to the buffer I want to clear, same result. I even tried releasing and recreating the buffer each frame (which is incredibly inefficient), but even that does not really work. The only time it has worked somewhat is when I create a new buffer and bind that as the SO target, [i]without deleting the old one[/i], so of course I run out of memory in a matter of seconds. I'm running out of ideas here, it has to be possible to clear a generic buffer?