Sign in to follow this  
wabbz111

[DX10]Glow effect

Recommended Posts

wabbz111    162
Hi guys

im trying to get a glow effect om my project but to no avail. This is based on iedoc's tutorial found [url="http://www.braynzarsoft.net/index.php?p=SimpleLighting"]here[/url].

The following are what i have done to try and get the effect going. Esssentially im taking what he did

with the diffusse light and trying to add emissive light to it so that it glows

These are the changes i made
In the vertex.fx file i added:

A matrix float4 emissive
-A Texture2D EmissiveMap
- A float4 emissive = EmissiveMap.Sample( TriLinearSample, input.texCoord )
-A finalColor = emissive * light.ambient
- A finalColor += saturate(dot(light.dir, input.normal) * light.emissive * emissive)
-and finally a return float4(finalColor, emissive.a);

For the main.cpp i did the following:
-declared [D3DXCOLOR emissive] in the light struct
-added this the following in the initscene function
-[(light.emissive = D3DXCOLOR(1.0f, 1.0f, 1.0f, 1.0f)]
-D3DX10CreateShaderResourceViewFromFile(d3dDevice, L"PurpleGalaxy.jpg", 0, 0, &EmissiveMapResourceView, 0 )
-fxEmissiveMapVar = FX->GetVariableByName("EmissiveMap")->AsShaderResource()

finally in release objects i did this
-if( EmissiveMapResourceView ) EmissiveMapResourceView->Release();

here are the files used
main.cpp
[code]#include <Windows.h>
#include <d3d10.h>
#include <d3dx10.h>
#include <string>
#pragma comment(lib, "D3D10.lib")
#pragma comment(lib, "d3dx10d.lib")
LPCTSTR WndClassName = L"firstwindow";
HWND hwnd = NULL;
const int Width = 800;
const int Height = 600;
bool InitializeWindow(HINSTANCE hInstance,
int ShowWnd,
int width, int height,
bool windowed);
HRESULT hr;
ID3D10Device* d3dDevice;
IDXGISwapChain* SwapChain;
ID3D10RenderTargetView* RenderTargetView;
ID3D10Effect* FX;
ID3D10InputLayout* VertexLayout;
ID3D10Buffer* VertexBuffer;
ID3D10Buffer* IndexBuffer;
ID3D10EffectTechnique* Technique;
ID3D10DepthStencilView* DepthStencilView;
ID3D10Texture2D* DepthStencilBuffer;
ID3D10ShaderResourceView* DiffuseMapResourceView;
ID3D10EffectShaderResourceVariable* fxDiffuseMapVar;
ID3D10ShaderResourceView* EmissiveMapResourceView;
ID3D10EffectShaderResourceVariable* fxEmissiveMapVar;
ID3D10EffectMatrixVariable* fxWVPVar;
//////////////////////////////new/////////////////////////////////////////////////////////
ID3D10EffectVariable* fxLightVar;
//////////////////////////////new/////////////////////////////////////////////////////////
D3DXMATRIX WVP;
D3DXMATRIX World;
D3DXMATRIX View;
D3DXMATRIX Projection;
D3DXVECTOR3 Position;
D3DXVECTOR3 Target;
D3DXVECTOR3 Up;
D3DXMATRIX Rotation;
D3DXMATRIX Scale;
D3DXMATRIX Translation;
D3DXMATRIX Transformations;
float rot = 0.01f;
bool InitializeDirect3dApp(HINSTANCE hInstance);
bool InitScene();
void DrawScene();
bool ReleaseObjects();
int messageloop();
LRESULT CALLBACK WndProc(HWND hWnd,
UINT msg,
WPARAM wParam,
LPARAM lParam);

struct Vertex
{
//////////////////////////////new/////////////////////////////////////////////////////////
Vertex(){}
Vertex(float x, float y, float z,
float u, float v, float nx, float ny, float nz)
: pos(x,y,z), texCoord(u,v), normal(nx,ny,nz){}
D3DXVECTOR3 pos;
D3DXVECTOR2 texCoord;
D3DXVECTOR3 normal;
//////////////////////////////new/////////////////////////////////////////////////////////
};
//////////////////////////////new/////////////////////////////////////////////////////////
struct Light
{
Light()
{
ZeroMemory(this, sizeof(Light));
}
D3DXVECTOR3 dir;
float pad;
D3DXCOLOR ambient;
D3DXCOLOR diffuse;
D3DXCOLOR emissive;
};
Light light;
//////////////////////////////new/////////////////////////////////////////////////////////

int WINAPI WinMain(HINSTANCE hInstance, //Main windows function
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nShowCmd)
{
if(!InitializeWindow(hInstance, nShowCmd, Width, Height, true))
{
MessageBox(0, L"Window Initialization - Failed",
L"Error", MB_OK);
return 0;
}
if(!InitializeDirect3dApp(hInstance))
{
MessageBox(0, L"Direct3D Initialization - Failed",
L"Error", MB_OK);
return 0;
}
if(!InitScene())
{
MessageBox(0, L"Scene Initialization - Failed",
L"Error", MB_OK);
return 0;
}
messageloop();
if(!ReleaseObjects())
{
MessageBox(0, L"Object Releasing - Failed",
L"Error", MB_OK);
return 0;
}
return 0;
}
bool InitializeWindow(HINSTANCE hInstance,
int ShowWnd,
int width, int height,
bool windowed)
{
typedef struct _WNDCLASS {
UINT cbSize;
UINT style;
WNDPROC lpfnWndProc;
int cbClsExtra;
int cbWndExtra;
HANDLE hInstance;
HICON hIcon;
HCURSOR hCursor;
HBRUSH hbrBackground;
LPCTSTR lpszMenuName;
LPCTSTR lpszClassName;
} WNDCLASS;
WNDCLASSEX wc;
wc.cbSize = sizeof(WNDCLASSEX);
wc.style = CS_HREDRAW | CS_VREDRAW;
wc.lpfnWndProc = WndProc;
wc.cbClsExtra = NULL;
wc.cbWndExtra = NULL;
wc.hInstance = hInstance;
wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = (HBRUSH)(COLOR_WINDOW + 2);
wc.lpszMenuName = NULL;
wc.lpszClassName = WndClassName;
wc.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
if (!RegisterClassEx(&wc))
{
MessageBox(NULL, L"Error registering class",
L"Error", MB_OK | MB_ICONERROR);
return 1;
}
hwnd = CreateWindowEx(
NULL,
WndClassName,
L"Window Title",
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, CW_USEDEFAULT,
width, height,
NULL,
NULL,
hInstance,
NULL
);
if (!hwnd)
{
MessageBox(NULL, L"Error creating window",
L"Error", MB_OK | MB_ICONERROR);
return 1;
}
ShowWindow(hwnd, ShowWnd);
UpdateWindow(hwnd);

return true;
}
bool InitializeDirect3dApp(HINSTANCE hInstance)
{
UINT createDeviceFlags = 0;
D3D10_DRIVER_TYPE driverTypes[] =
{
D3D10_DRIVER_TYPE_HARDWARE,
D3D10_DRIVER_TYPE_REFERENCE,
};
UINT numDriverTypes = sizeof( driverTypes ) / sizeof( driverTypes[0] );
DXGI_SWAP_CHAIN_DESC scd;
scd.BufferDesc.Width = Width;
scd.BufferDesc.Height = Height;
scd.BufferDesc.RefreshRate.Numerator = 60;
scd.BufferDesc.RefreshRate.Denominator = 1;
scd.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
scd.BufferDesc.ScanlineOrdering = DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED;
scd.BufferDesc.Scaling = DXGI_MODE_SCALING_UNSPECIFIED;
//no multisampling
scd.SampleDesc.Count = 1;
scd.SampleDesc.Quality = 0;
scd.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
scd.BufferCount = 1;
scd.OutputWindow = hwnd;
scd.Windowed = true;
scd.SwapEffect = DXGI_SWAP_EFFECT_DISCARD;
scd.Flags = 0;
D3D10CreateDeviceAndSwapChain(0, D3D10_DRIVER_TYPE_HARDWARE, 0, 0, D3D10_SDK_VERSION, &scd, &SwapChain, &d3dDevice);
ID3D10Texture2D* backBuffer;
SwapChain->GetBuffer(0, _uuidof(ID3D10Texture2D), reinterpret_cast<void**>(&backBuffer));
d3dDevice->CreateRenderTargetView(backBuffer, 0, &RenderTargetView);
backBuffer->Release();
D3D10_TEXTURE2D_DESC depthStencilDesc;
depthStencilDesc.Width = Width;
depthStencilDesc.Height = Height;
depthStencilDesc.MipLevels = 1;
depthStencilDesc.ArraySize = 1;
depthStencilDesc.Format = DXGI_FORMAT_D24_UNORM_S8_UINT;
depthStencilDesc.SampleDesc.Count = 1;
depthStencilDesc.SampleDesc.Quality = 0;
depthStencilDesc.Usage = D3D10_USAGE_DEFAULT;
depthStencilDesc.BindFlags = D3D10_BIND_DEPTH_STENCIL;
depthStencilDesc.CPUAccessFlags = 0;
depthStencilDesc.MiscFlags = 0;
d3dDevice->CreateTexture2D(&depthStencilDesc, NULL, &DepthStencilBuffer);
d3dDevice->CreateDepthStencilView(DepthStencilBuffer, NULL, &DepthStencilView);
d3dDevice->OMSetRenderTargets(1, &RenderTargetView, DepthStencilView);
// Setup the viewport
D3D10_VIEWPORT vp;
vp.Width = Width;
vp.Height = Height;
vp.MinDepth = 0.0f;
vp.MaxDepth = 1.0f;
vp.TopLeftX = 0;
vp.TopLeftY = 0;
d3dDevice->RSSetViewports( 1, &vp );
D3DXMatrixIdentity( &World );
Position = D3DXVECTOR3( 0.0f, 6.0f, -14.0f );
Target = D3DXVECTOR3( 0.0f, 0.0f, 0.0f );
Up = D3DXVECTOR3( 0.0f, 1.0f, 0.0f );
D3DXMatrixLookAtLH( &View, &Position, &Target, &Up );
return true;
}
bool InitScene()
{
//////////////////////////////new/////////////////////////////////////////////////////////
light.dir = D3DXVECTOR3(0.25f, 0.5f, -1.0f);
light.ambient = D3DXCOLOR(1.0f, 1.0f, 1.0f, 1.0f);
light.diffuse = D3DXCOLOR(1.0f, 1.0f, 1.0f, 0.0f);
light.emissive = D3DXCOLOR(1.0f, 1.0f, 1.0f, 1.0f);
//////////////////////////////new/////////////////////////////////////////////////////////
Vertex v[24];
//////////////////////////////new/////////////////////////////////////////////////////////
// Front Face
v[0] = Vertex(-1.0f, -1.0f, -1.0f, 0.0f, 1.0f,-1.0f, -1.0f, -1.0f);
v[1] = Vertex(-1.0f, 1.0f, -1.0f, 0.0f, 0.0f,-1.0f, 1.0f, -1.0f);
v[2] = Vertex( 1.0f, 1.0f, -1.0f, 1.0f, 0.0f, 1.0f, 1.0f, -1.0f);
v[3] = Vertex( 1.0f, -1.0f, -1.0f, 1.0f, 1.0f, 1.0f, -1.0f, -1.0f);
// Back Face
v[4] = Vertex(-1.0f, -1.0f, 1.0f, 1.0f, 1.0f,-1.0f, -1.0f, 1.0f);
v[5] = Vertex( 1.0f, -1.0f, 1.0f, 0.0f, 1.0f, 1.0f, -1.0f, 1.0f);
v[6] = Vertex( 1.0f, 1.0f, 1.0f, 0.0f, 0.0f, 1.0f, 1.0f, 1.0f);
v[7] = Vertex(-1.0f, 1.0f, 1.0f, 1.0f, 0.0f,-1.0f, 1.0f, 1.0f);
// Top Face
v[8] = Vertex(-1.0f, 1.0f, -1.0f, 0.0f, 1.0f,-1.0f, 1.0f, -1.0f);
v[9] = Vertex(-1.0f, 1.0f, 1.0f, 0.0f, 0.0f,-1.0f, 1.0f, 1.0f);
v[10] = Vertex( 1.0f, 1.0f, 1.0f, 1.0f, 0.0f, 1.0f, 1.0f, 1.0f);
v[11] = Vertex( 1.0f, 1.0f, -1.0f, 1.0f, 1.0f, 1.0f, 1.0f, -1.0f);
// Bottom Face
v[12] = Vertex(-1.0f, -1.0f, -1.0f, 1.0f, 1.0f,-1.0f, -1.0f, -1.0f);
v[13] = Vertex( 1.0f, -1.0f, -1.0f, 0.0f, 1.0f, 1.0f, -1.0f, -1.0f);
v[14] = Vertex( 1.0f, -1.0f, 1.0f, 0.0f, 0.0f, 1.0f, -1.0f, 1.0f);
v[15] = Vertex(-1.0f, -1.0f, 1.0f, 1.0f, 0.0f,-1.0f, -1.0f, 1.0f);
// Left Face
v[16] = Vertex(-1.0f, -1.0f, 1.0f, 0.0f, 1.0f,-1.0f, -1.0f, 1.0f);
v[17] = Vertex(-1.0f, 1.0f, 1.0f, 0.0f, 0.0f,-1.0f, 1.0f, 1.0f);
v[18] = Vertex(-1.0f, 1.0f, -1.0f, 1.0f, 0.0f,-1.0f, 1.0f, -1.0f);
v[19] = Vertex(-1.0f, -1.0f, -1.0f, 1.0f, 1.0f,-1.0f, -1.0f, -1.0f);
// Right Face
v[20] = Vertex( 1.0f, -1.0f, -1.0f, 0.0f, 1.0f, 1.0f, -1.0f, -1.0f);
v[21] = Vertex( 1.0f, 1.0f, -1.0f, 0.0f, 0.0f, 1.0f, 1.0f, -1.0f);
v[22] = Vertex( 1.0f, 1.0f, 1.0f, 1.0f, 0.0f, 1.0f, 1.0f, 1.0f);
v[23] = Vertex( 1.0f, -1.0f, 1.0f, 1.0f, 1.0f, 1.0f, -1.0f, 1.0f);
//////////////////////////////new/////////////////////////////////////////////////////////
D3D10_BUFFER_DESC vbd;
vbd.Usage = D3D10_USAGE_IMMUTABLE;
vbd.ByteWidth = sizeof(Vertex) * 24;
vbd.BindFlags = D3D10_BIND_VERTEX_BUFFER;
vbd.CPUAccessFlags = 0;
vbd.MiscFlags = 0;
D3D10_SUBRESOURCE_DATA vinitData;
vinitData.pSysMem = v;
d3dDevice->CreateBuffer(&vbd, &vinitData, &VertexBuffer);
DWORD i[36];
// Front Face
i[0] = 0; i[1] = 1; i[2] = 2;
i[3] = 0; i[4] = 2; i[5] = 3;
// Back Face
i[6] = 4; i[7] = 5; i[8] = 6;
i[9] = 4; i[10] = 6; i[11] = 7;
// Top Face
i[12] = 8; i[13] = 9; i[14] = 10;
i[15] = 8; i[16] = 10; i[17] = 11;
// Bottom Face
i[18] = 12; i[19] = 13; i[20] = 14;
i[21] = 12; i[22] = 14; i[23] = 15;
// Left Face
i[24] = 16; i[25] = 17; i[26] = 18;
i[27] = 16; i[28] = 18; i[29] = 19;
// Right Face
i[30] = 20; i[31] = 21; i[32] = 22;
i[33] = 20; i[34] = 22; i[35] = 23;
D3D10_BUFFER_DESC ibd;
ibd.Usage = D3D10_USAGE_IMMUTABLE;
ibd.ByteWidth = sizeof(DWORD) * 36;
ibd.BindFlags = D3D10_BIND_INDEX_BUFFER;
ibd.CPUAccessFlags = 0;
ibd.MiscFlags = 0;
D3D10_SUBRESOURCE_DATA iinitData;
iinitData.pSysMem = i;
d3dDevice->CreateBuffer(&ibd, &iinitData, &IndexBuffer);
UINT stride = sizeof( Vertex );
UINT offset = 0;
d3dDevice->IASetVertexBuffers( 0, 1, &VertexBuffer, &stride, &offset );
d3dDevice->IASetIndexBuffer(IndexBuffer, DXGI_FORMAT_R32_UINT, 0);
D3D10_INPUT_ELEMENT_DESC layout[] =
{
{"POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D10_INPUT_PER_VERTEX_DATA, 0},
{"TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 12, D3D10_INPUT_PER_VERTEX_DATA, 0},
//////////////////////////////new/////////////////////////////////////////////////////////
{"NORMAL", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 20, D3D10_INPUT_PER_VERTEX_DATA, 0}
//////////////////////////////new/////////////////////////////////////////////////////////
};
ID3D10Blob* compilationErrors = 0;
HRESULT hr = 0;
hr = D3DX10CreateEffectFromFile( L"vertex.fx", NULL, NULL, "fx_4_0", D3D10_SHADER_ENABLE_STRICTNESS, 0,
d3dDevice, NULL, NULL, &FX, &compilationErrors, NULL );
if(FAILED(hr))
{
MessageBoxA(0, (char*)compilationErrors->GetBufferPointer(), 0, 0);
compilationErrors->Release();
return false;
}
D3DX10CreateShaderResourceViewFromFile(d3dDevice,
L"PurpleGalaxy.jpg", 0, 0, &DiffuseMapResourceView, 0 );

D3DX10CreateShaderResourceViewFromFile(d3dDevice,
L"supernova.jpg", 0, 0, &EmissiveMapResourceView, 0 );
Technique = FX->GetTechniqueByName( "Tech" );
fxWVPVar = FX->GetVariableByName("WVP")->AsMatrix();
fxDiffuseMapVar = FX->GetVariableByName("DiffuseMap")->AsShaderResource();

fxEmissiveMapVar = FX->GetVariableByName("EmissiveMap")->AsShaderResource();
//////////////////////////////new/////////////////////////////////////////////////////////
fxLightVar = FX->GetVariableByName("light");
//////////////////////////////new/////////////////////////////////////////////////////////
D3D10_PASS_DESC PassDesc;
Technique->GetPassByIndex( 0 )->GetDesc( &PassDesc );
//////////////////////////////new/////////////////////////////////////////////////////////
d3dDevice->CreateInputLayout( layout, 3, PassDesc.pIAInputSignature,
PassDesc.IAInputSignatureSize, &VertexLayout );
//////////////////////////////new/////////////////////////////////////////////////////////
d3dDevice->IASetInputLayout( VertexLayout );
d3dDevice->IASetPrimitiveTopology( D3D10_PRIMITIVE_TOPOLOGY_TRIANGLELIST );
return true;
}
bool ReleaseObjects()
{
if( d3dDevice ) d3dDevice->ClearState();
if( VertexBuffer ) VertexBuffer->Release();
if( IndexBuffer ) IndexBuffer->Release();
if( VertexLayout ) VertexLayout->Release();
if( FX ) FX->Release();
if( RenderTargetView ) RenderTargetView->Release();
if( SwapChain ) SwapChain->Release();
if( d3dDevice ) d3dDevice->Release();
if( DiffuseMapResourceView ) DiffuseMapResourceView->Release();
if( EmissiveMapResourceView ) EmissiveMapResourceView->Release();
return true;
}
void DrawScene()
{
//Draw Scene Here
D3DXCOLOR bgColor( 0.0f, 0.0f, 0.0f, 1.0f);
d3dDevice->ClearRenderTargetView( RenderTargetView, bgColor );
d3dDevice->ClearDepthStencilView(DepthStencilView, D3D10_CLEAR_DEPTH|D3D10_CLEAR_STENCIL, 1.0f, 0);
D3DXMatrixPerspectiveFovLH(&Projection, 0.4f*3.14f, Width/Height, 1.0f, 1000.0f);
D3DXVECTOR3 rotaxis(0.0f, 1.0f, 0.0f);
D3DXMatrixRotationAxis(&Rotation, &rotaxis, rot);
D3DXMatrixTranslation( &Translation, 0.0f, 0.0f, 4.0f );
Transformations =Translation * Rotation;
rot += .0005f;
WVP = World * Transformations * View * Projection;
fxWVPVar->SetMatrix((float*)&WVP);
fxDiffuseMapVar->SetResource(DiffuseMapResourceView);
fxEmissiveMapVar->SetResource(EmissiveMapResourceView);
//////////////////////////////new/////////////////////////////////////////////////////////
fxLightVar->SetRawValue(&light, 0, sizeof(Light));
//////////////////////////////new/////////////////////////////////////////////////////////
D3D10_TECHNIQUE_DESC techDesc;
Technique->GetDesc( &techDesc );
//draw first cube
for( UINT p = 0; p < techDesc.Passes; ++p )
{
Technique->GetPassByIndex( p )->Apply( 0 );
d3dDevice->DrawIndexed(36, 0, 0);
}
D3DXMatrixRotationAxis(&Rotation, &rotaxis, -rot);
D3DXMatrixScaling( &Scale, 1.3f, 1.3f, 1.3f );
Transformations = Rotation * Scale;
WVP = World * Transformations * View * Projection;
fxWVPVar->SetMatrix((float*)&WVP);
//draw second cube
for( UINT p = 0; p < techDesc.Passes; ++p )
{
Technique->GetPassByIndex( p )->Apply( 0 );
d3dDevice->DrawIndexed(36, 0, 0);
}
SwapChain->Present( 0, 0 );
}
int messageloop(){
MSG msg;
ZeroMemory(&msg, sizeof(MSG));
while(true)
{
BOOL PeekMessageL(
LPMSG lpMsg,
HWND hWnd,
UINT wMsgFilterMin,
UINT wMsgFilterMax,
UINT wRemoveMsg
);
if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
{
if (msg.message == WM_QUIT)
break;
TranslateMessage(&msg);
DispatchMessage(&msg);
}
else{
// run game code
DrawScene();
}
}
return msg.wParam;
}
LRESULT CALLBACK WndProc(HWND hwnd,
UINT msg,
WPARAM wParam,
LPARAM lParam)
{
switch( msg )
{
case WM_KEYDOWN:
if( wParam == VK_ESCAPE ){
if(MessageBox(0, L"Are you sure you want to exit?",
L"Really?", MB_YESNO | MB_ICONQUESTION) == IDYES)
DestroyWindow(hwnd);
}
return 0;
case WM_DESTROY:
PostQuitMessage(0);
return 0;
}
return DefWindowProc(hwnd,
msg,
wParam,
lParam);
}[/code]

the effects file vertex.fx
[code]//"vertex.fx" file
struct Light
{
float3 dir;
float4 ambient;
float4 diffuse;
float4 emissive;
};
cbuffer cbPerFrame
{
Light light;
};
cbuffer cbPerObject
{
float4x4 WVP;
};
Texture2D DiffuseMap;
Texture2D EmissiveMap;
SamplerState TriLinearSample
{
Filter = MIN_MAG_MIP_LINEAR;
};
struct VS_OUTPUT //output structure for vertex shader
{
float4 Pos : SV_POSITION;
float2 texCoord : TEXCOORD;
float3 normal : NORMAL;
};
// Vertex Shader
VS_OUTPUT VS(float4 inPos : POSITION, float2 inTexCoord : TEXCOORD, float3 normal : NORMAL)
{
VS_OUTPUT output = (VS_OUTPUT)0;
output.Pos = mul(inPos, WVP);
output.normal = mul(normal, WVP);
output.texCoord = inTexCoord;
return output; //send color and position to pixel shader
}
// Pixel Shader
float4 PS(VS_OUTPUT input) : SV_Target
{
input.normal = normalize(input.normal);
float4 diffuse = DiffuseMap.Sample( TriLinearSample, input.texCoord );
float4 emissive = EmissiveMap.Sample( TriLinearSample, input.texCoord );
float3 finalColor;
finalColor = diffuse * light.ambient;
finalColor += saturate(dot(light.dir, input.normal) * light.diffuse * diffuse);

finalColor = emissive * light.ambient;
finalColor += saturate(dot(light.dir, input.normal) * light.emissive * emissive);
return float4(finalColor, diffuse.a);
return float4(finalColor, emissive.a);
}
technique10 Tech
{
pass P0
{
SetVertexShader( CompileShader( vs_4_0, VS() ) );
SetPixelShader( CompileShader( ps_4_0, PS() ) );
}
}
[/code]


Assistance with solving this issue will be greatly appreciated.

Share this post


Link to post
Share on other sites
iedoc    2525
a glow effect might not be quite so simple as just modifying that lesson's lighting code.

Here's an idea of what you could do. You start off by creating a render target that you can use as a shader resource ([url="http://www.braynzarsoft.net/index.php?p=D3D11RTT"]http://www.braynzarsoft.net/index.php?p=D3D11RTT[/url]). Then, you will create a full screen quad which you can use to blend together multiple render targets.

Then you will render only the "edges" of the object to the render target. BTW, I got this glow idea from the directx sdk sample "postProcess" or whatever.

Now that you have a texture with only the edges of the object, you will now "blur" the edges, which will result in the "glow". You can do blurring by setting the render target, then using that texture you rendered the "edges" on, as the shader resource for the full screen quad. You will draw that full screen quad multiple times onto the render target, each time with a slightly shifted texture coordinate, vertically then horizontally. This will give you the blur of the edges, which will look like the glow. Finally, just draw the full screen quad on the real render target with the final blurred edges render target set as the shader resource. You will need blending enabled of course.

So as a list:

1. Create a texture that can be used as a render target AND as a shader resource (for the glow effect)

2. Create a full screen quad (so you can blend the render targets together and create the glow effect)

3. Render only the edges of the object you want to glow to the texture used as a RT and SRV (you can find the edges using pixel normals)

4. Blur the texture by rending the full screen quad multiple times to the texture, each time with shifted tex coords

5. Draw the full screen quad with the texture containing the glow, onto the backbuffer.

Hope that at least gives you an idea. Like i mentioned above, i just got the idea from the directx sdk's "postprocess" sample in the "Direct3D" folder

Share this post


Link to post
Share on other sites
Nik02    4348
When using modern hardware, it is better to take the shifted samples for the blur in the pixel shader; this way, you don't have to issue a lot of draw calls and state changes for the blur effect.

Share this post


Link to post
Share on other sites
wabbz111    162
Hi guys,
my progress thus far.
I visited this site [url="http://beta.codeproject.com/Articles/128527/Stencil-Buffer-Glows-Part-1"]here[/url] and got an implementation of glow.
With iedoc's help i was able to integrate it with my code and get it to compile
The problem is, it is still not displaying the glow effect.
The link shows what im trying to achieve, which is get a red outline
around the cube. I have attached the code files since they are different from the previous ones above.
Please have a look and let me know where im going wrong. I greatly appreciate the help.
[attachment=8063:files.zip]

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