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

Proper Shader Algorith For Standard Lighting Effect

8 posts in this topic

Hi,

I've got a load of source compiled and running with the from source engine I'm learning. Quite a big step for me all those static libraries, dynamincally linked libraries, a tonne of SIMD stuff that had to be commented out because it was in the wrong assembly format for my compiler (Intel whereas CB uses AT&T), pixel shader, vertex shaders etc....

Sure I've come a long way. Shoot I even know how most of it works. I printed off a load of paper copies of the source and I often nip out to local pubs for a coffee whilst having a read!

But I have hit a couple of snags in concept stuff. Mainly about what's really going on between the CPU, the RAM and the GPU and the RAM on the graphics card (not sure of proper terminology for this). That's for another thread though, this one is about shaders and lighting.

I've got the shaders to run and work. Have a look at their code, pretty simple as far as I know in shader talk:

[code]Vertex Shader(vsh):
vs.1.1
dcl_position0 v0
dcl_normal0 v3
dcl_texcoord0 v6
m4x4 oPos, v0, c0
mov oD0, c4
mov oT0, v6[/code]

The vsh does some stuff with the geometry and then moves the value stored in the constant register c4 into the output register oD0 which is then inputted into the psh. Whenever a function that affects the light is used it gets the value relating to light colour and intensity and loads it into the register c4. SetAmbientLight does this, for example.

[code]Pixel Shader:(psh)
ps.1.1
tex t0
mul r0, v0, t0
[/code]

Here the value in v0 (which I assume is the received light data from the vsh) is multiplied with the texel and the final result stored in the psh output register r0. Ok fine.

BUT (you [i]knew[/i] it was coming).....

The scene is blacker than the underside of a witch's boob on a moonless night. If I change the code for the psh to this:

[code]Pixel Shader:(psh)
ps.1.1
tex t0
add r0, v0, t0
[/code]

... then all affected geometry becomes so bright you could hunt rabbits with them on a dark winter's evening.

So, obviously something odd is happening here. The original author's shaders produces scenes that are way too dark. Yet my own alterations produce scenes that are horribly bright, and cause very bad colour mixing between the ambient light and the texel colour. Like if for example I set ambient to 0.5f,0.5f,0.5f middle of teh road grey, then instead of the predominatly green appearance of the demo model (a green tank) showing through more strongly, it just has this awful painted grey appearance to it, rather like someone has just thrown a load of grey paint over it.

So:

What is the proper method here? I just want to be able to nicely mimic with a shader what i've already achieved fine with the fixed function pipeline in the past. But I don't know the proper algorithm for lighting. The one I've made is bright but awful, the one the author made is horribly dark, even with ambient light set to max (1.0f,1.0f,1.0f).

I'd also rather not discuss point and directional lights just yet, although I have got these working well, but again I had to depart from the author's code as it was too dark. Furthermore the extra passes per light make things difficult so if possible I'd rather just talk about getting good ambient light working for now, thanks.

I'd appreciate any replies anyone can take the time to write. Seems to me good lighting it what makes a huge difference to the pleasure the eye feels when playing a game or looking at any rendered scene for that matter.

Anway, thanks :)
0

Share this post


Link to post
Share on other sites
you need to move to proper HLSL now , not the old methid

[quote name='adder_noir' timestamp='1305530935' post='4811336']
Hi,

I've got a load of source compiled and running with the from source engine I'm learning. Quite a big step for me all those static libraries, dynamincally linked libraries, a tonne of SIMD stuff that had to be commented out because it was in the wrong assembly format for my compiler (Intel whereas CB uses AT&T), pixel shader, vertex shaders etc....

Sure I've come a long way. Shoot I even know how most of it works. I printed off a load of paper copies of the source and I often nip out to local pubs for a coffee whilst having a read!

But I have hit a couple of snags in concept stuff. Mainly about what's really going on between the CPU, the RAM and the GPU and the RAM on the graphics card (not sure of proper terminology for this). That's for another thread though, this one is about shaders and lighting.

I've got the shaders to run and work. Have a look at their code, pretty simple as far as I know in shader talk:

[code]Vertex Shader(vsh):
vs.1.1
dcl_position0 v0
dcl_normal0 v3
dcl_texcoord0 v6
m4x4 oPos, v0, c0
mov oD0, c4
mov oT0, v6[/code]

The vsh does some stuff with the geometry and then moves the value stored in the constant register c4 into the output register oD0 which is then inputted into the psh. Whenever a function that affects the light is used it gets the value relating to light colour and intensity and loads it into the register c4. SetAmbientLight does this, for example.

[code]Pixel Shader:(psh)
ps.1.1
tex t0
mul r0, v0, t0
[/code]

Here the value in v0 (which I assume is the received light data from the vsh) is multiplied with the texel and the final result stored in the psh output register r0. Ok fine.

BUT (you [i]knew[/i] it was coming).....

The scene is blacker than the underside of a witch's boob on a moonless night. If I change the code for the psh to this:

[code]Pixel Shader:(psh)
ps.1.1
tex t0
add r0, v0, t0
[/code]

... then all affected geometry becomes so bright you could hunt rabbits with them on a dark winter's evening.

So, obviously something odd is happening here. The original author's shaders produces scenes that are way too dark. Yet my own alterations produce scenes that are horribly bright, and cause very bad colour mixing between the ambient light and the texel colour. Like if for example I set ambient to 0.5f,0.5f,0.5f middle of teh road grey, then instead of the predominatly green appearance of the demo model (a green tank) showing through more strongly, it just has this awful painted grey appearance to it, rather like someone has just thrown a load of grey paint over it.

So:

What is the proper method here? I just want to be able to nicely mimic with a shader what i've already achieved fine with the fixed function pipeline in the past. But I don't know the proper algorithm for lighting. The one I've made is bright but awful, the one the author made is horribly dark, even with ambient light set to max (1.0f,1.0f,1.0f).

I'd also rather not discuss point and directional lights just yet, although I have got these working well, but again I had to depart from the author's code as it was too dark. Furthermore the extra passes per light make things difficult so if possible I'd rather just talk about getting good ambient light working for now, thanks.

I'd appreciate any replies anyone can take the time to write. Seems to me good lighting it what makes a huge difference to the pleasure the eye feels when playing a game or looking at any rendered scene for that matter.

Anway, thanks :)
[/quote]
1

Share this post


Link to post
Share on other sites
Ok thanks. Out of curiousity what benefits does HLSL have over the assembly style syntax?
0

Share this post


Link to post
Share on other sites
[quote name='adder_noir' timestamp='1305593177' post='4811716']
Ok thanks. Out of curiousity what benefits does HLSL have over the assembly style syntax?
[/quote]

Well the first benefit is that it makes your code more readable and your intent more clear. I can puzzle out what the assembly is doing in a few minutes, but I would know at a glance what your HLSL is doing. Finding bugs and mistakes would be easier because I would see what your intent is inside your code. Also, modern compilers are generally more intelligent than humans at making assembly level optimizations as well as being capable of compiling to multiple types of assembly from the same HLSL code.
1

Share this post


Link to post
Share on other sites
Side point: I assume CodeBlocks uses GCC. In this case, if you can find a setting that lets you manually configure command line arguments, then changing this to pass "-masm=intel" to GCC should work.
1

Share this post


Link to post
Share on other sites
This is good information. Especially the idea about the GCC thing that may well have to be tried out sometime! I've got a simpe demo of a vertex shader here:

[code]float4x4 World;
float4x4 View;
float4x4 Projection;

struct VertexOut
{
float4 Pos : POSITION;
float4 Color : COLOR;
};

VertexOut VShader(float4 Pos : POSITION)
{
VertexOut Vert;
float4x4 Transform;

Transform = mul(World, View);
Transform = mul(Transform, Projection);
Vert.Pos = mul(Pos, Transform);

Vert.Color = float4(1, 1, 1, 1);

return Vert;
}

technique FirstTechnique
{
pass FirstPass
{
Lighting = FALSE;
ZEnable = TRUE;

VertexShader = compile vs_2_0 VShader();
}
}[/code]

But I'm not sure if it's suitable for ambient lighting. Anyways I'll have a read through the DirectX tutorial again and also the part of my book which covers shaders. If I find anything interesting I'll let you know. Thanks.
0

Share this post


Link to post
Share on other sites
Hi just a quick question, can you use HLSL for both vertex and pixel shaders? Is this a stupid question? I voted everyone up who replied to this thread so thanks ;)
0

Share this post


Link to post
Share on other sites
[quote name='adder_noir' timestamp='1305714481' post='4812447']
Hi just a quick question, can you use HLSL for both vertex and pixel shaders? Is this a stupid question? I voted everyone up who replied to this thread so thanks ;)
[/quote]

Yes, HLSL can be used for both vertex and pixel shaders, and starting from D3D10 also geometry shaders
1

Share this post


Link to post
Share on other sites
[quote name='Radikalizm' timestamp='1305719686' post='4812476']
[quote name='adder_noir' timestamp='1305714481' post='4812447']
Hi just a quick question, can you use HLSL for both vertex and pixel shaders? Is this a stupid question? I voted everyone up who replied to this thread so thanks ;)
[/quote]

Yes, HLSL can be used for both vertex and pixel shaders, and starting from D3D10 also geometry shaders
[/quote]


Cheers, I voted you up :D
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