Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Professional Discussion / Dark Lights and Dark Shader

Author
Message
MateiSoft Romania
12
Years of Service
User Offline
Joined: 16th Oct 2013
Location:
Posted: 15th Apr 2015 13:39
Hello guys,

Any ideas or tutorials or some help on how can i implement Dark Lights renderer to work with shaders exported from Dark Shader?

A big Thank You!

Alex Matei CEO
www.alexmatei.com
Chris Tate
DBPro Master
17
Years of Service
User Offline
Joined: 29th Aug 2008
Location: London, England
Posted: 23rd Apr 2015 14:03
This is trivial if you know how texture stages work in Dark BASIC, all you need to do is include the lightmap stage (1 I think), with the texture stage (0). In the shader, stages for the texture are in the order the texture samplers are defined. The lightmap stage uses a different UV coordinate per vertex compared to your base texture stage.

MateiSoft Romania
12
Years of Service
User Offline
Joined: 16th Oct 2013
Location:
Posted: 23rd Apr 2015 20:29
Well,

This is my shader... i don't know hlsl so i cannot see where to put what you said



Alex Matei CEO
www.alexmatei.com
Chris Tate
DBPro Master
17
Years of Service
User Offline
Joined: 29th Aug 2008
Location: London, England
Posted: 24th Apr 2015 15:44
Learn it, it will serve you well.

Meanwhile you can do the following to add your lightmap to the shader:

This is your base texture:

texture BaseTex
<
string ResourceName = "Large_House.dds";
>;


... it is your texture variable (Ignore the resource name for now)

and this


sampler diffuse_smp = sampler_state
{
Texture = <BaseTex>;
MinFilter = Anisotropic;
MagFilter = Linear;
MipFilter = Linear;
AddressU = Wrap;
AddressV = Wrap;
};


is your first texture sampler; something which samples a texture (as you probably guessed).

This sample happens to be named 'diffuse_smp' and is intended to sample your base texture. It also happens to be the first sampler, therefore it uses stage zero.

Dark Lights needs a sampler created for its lightmap texture. I cannot remember if this needs to be first, stage 0, or second, stage 1. But this is a small matter of changing the order in which the samplers are defined.

So to create a new sampler. Copy and paste the base (diffuse) sampler, and base texture. Rename them to light map: for example:

texture LightMapTex
sampler LightMapSampler = sampler_state
Texture = <LightMapTex>

In dark shader you should see a new texture slot in your project providing you have set the shader as current.

Add you lightmap texture into your DarkShader project; it should be in your lightmaps folder in your executable path if you have gotten as far as light mapping a scene in DarkBASIC.

Now, your lightmap uses different UV coordinates to your base sampler. These UV coordinates are generated by Dark Lights, so it is these UV coordinates you need to use for your lightmap texture in the shader.

Lookup your shader structures:

struct app_in
{
float4 pos : POSITION;
float3 normal : NORMAL0;
float3 tangent : TANGENT0;
float3 binormal : BINORMAL0;
float2 uv : TEXCOORD0;
};

struct vs_out
{
float4 pos : POSITION;
float2 uv : TEXCOORD0;
float3 normal : TEXCOORD1;
float3 tangent : TEXCOORD2;
float3 binormal : TEXCOORD3;
float4 wpos : TEXCOORD4;
};


... and add an additional uv coordinate; float2 uv2 :TEXCOORD1 in your app_in struct, and coordinate 5 in your vs_out struct. These need to have unique texture coordinate identifiers per memeber.

This now advances your shader structures to include your second UV maps, which now need to be passed to your pixel shader.

You may aswell duplicate this line: OUT.uv = IN.uv;

into: OUT.uv2 = IN.uv2;

Finally we'll just multiply your texture pixels by your lightmap pixels for the time being; which means your object can only be seen if lit by some lightmap texture, even if the texture is plain white.

Add the code below near here in your pixel shader: float3 color = AmbientColor;


float3 lightMap = tex2D(LightMapSampler, IN.uv2);
color *= lightMap;


That should get you started. If your object is black it means your lightmap texture has not been added or is black; since zero is black and zero multiplied by anything is always zero.

Login to post a reply

Server time is: 2026-07-05 11:51:17
Your offset time is: 2026-07-05 11:51:17