Gamestudio Links
Zorro Links
Newest Posts
Blobsculptor tools and objects download here
by NeoDumont. 03/28/24 03:01
Issue with Multi-Core WFO Training
by aliswee. 03/24/24 20:20
Why Zorro supports up to 72 cores?
by Edgar_Herrera. 03/23/24 21:41
Zorro Trader GPT
by TipmyPip. 03/06/24 09:27
VSCode instead of SED
by 3run. 03/01/24 19:06
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
2 registered members (AndrewAMD, VoroneTZ), 831 guests, and 5 spiders.
Key: Admin, Global Mod, Mod
Newest Members
sakolin, rajesh7827, juergen_wue, NITRO_FOREVER, jack0roses
19043 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 1 of 3 1 2 3
Specular Shader with specular map #467704
08/23/17 18:23
08/23/17 18:23
Joined: Apr 2002
Posts: 1,246
ny
jumpman Offline OP
Serious User
jumpman  Offline OP
Serious User

Joined: Apr 2002
Posts: 1,246
ny
Hello,

Is there a specular shader that doesnt use a normal map, as well as using a specular map (alpha map or other wise) to determine which parts of the model are shiny and which parts are dull?

The shaders I see require a normal map, and apply the shininess equally over the whole model.

Re: Specular Shader with specular map [Re: jumpman] #467711
08/24/17 08:56
08/24/17 08:56
Joined: Jun 2007
Posts: 1,337
Hiporope and its pain
txesmi Offline
Serious User
txesmi  Offline
Serious User

Joined: Jun 2007
Posts: 1,337
Hiporope and its pain
Hi,
you might use the shader from the third shader tutorial.
http://www.conitec.net/shaders/shader_work3.htm

you will only need to multiply the specular lighting computation result by the texture alpha channel and add the PASS_SOLID flag to the material.

Salud!

Re: Specular Shader with specular map [Re: txesmi] #467719
08/24/17 16:34
08/24/17 16:34
Joined: Apr 2002
Posts: 1,246
ny
jumpman Offline OP
Serious User
jumpman  Offline OP
Serious User

Joined: Apr 2002
Posts: 1,246
ny
Hi Txesmi!

Thank you for pointing me to that tutorial workshop.

Im assuming here is the correct line to add the multiplication?:

float Specular = pow(saturate(dot(R, normalize(InViewDir))), SpecularPower) * SpecularIntensity * shininess;

Do I have to define the entskin storing the alpha texture? Say I have it on entskin3. I put this on the top of the fx file?:

texture entSkin1; // diffuse
texture entskin3; //shiny map

sampler ShinyMapSampler = sampler_state
{
Texture = <entSkin3>;
AddressU = Clamp;
AddressV = Clamp;
}

How then do I multiply each pixel of skin3 into that lighting equation?

shininess = texture2D(uSpecularMapSampler, vec2(vTextureCoord.s, vTextureCoord.t)).r * 255.0;

that doesnt work for me, I got that from a website trying to do it myself.

Re: Specular Shader with specular map [Re: jumpman] #467720
08/24/17 17:02
08/24/17 17:02
Joined: Apr 2002
Posts: 1,246
ny
jumpman Offline OP
Serious User
jumpman  Offline OP
Serious User

Joined: Apr 2002
Posts: 1,246
ny
I did it Txesmi! Thank you!! Here are the relevant lines:

float shininess = 2 * tex2D(ShinyMapSampler, InTex);

then I multiplied the Specular equation with shininess just like you said!

I will be adding more to this shader, and when its nice enough with a cool model, I will give it to the community so they can use it as well!

Re: Specular Shader with specular map [Re: jumpman] #467721
08/24/17 17:16
08/24/17 17:16
Joined: Jun 2007
Posts: 1,337
Hiporope and its pain
txesmi Offline
Serious User
txesmi  Offline
Serious User

Joined: Jun 2007
Posts: 1,337
Hiporope and its pain
Originally Posted By: jumpman
Im assuming here is the correct line to add the multiplication?:

float Specular = pow(saturate(dot(R, normalize(InViewDir))), SpecularPower) * SpecularIntensity * shininess;

correct

Originally Posted By: jumpman
Do I have to define the entskin storing the alpha texture? Say I have it on entskin3. I put this on the top of the fx file?:

texture entSkin1; // diffuse
texture entskin3; //shiny map

sampler ShinyMapSampler = sampler_state
{
Texture = <entSkin3>;
AddressU = Clamp;
AddressV = Clamp;
}

correct. There are more parameter in a sampler_state that you can configure (linear interpolation and such).

Originally Posted By: jumpman
How then do I multiply each pixel of skin3 into that lighting equation?

shininess = texture2D(uSpecularMapSampler, vec2(vTextureCoord.s, vTextureCoord.t)).r * 255.0;

that doesnt work for me, I got that from a website trying to do it myself.


that code line should be like this:

Code:
float shininess = tex2D ( ShinyMapSampler, inTex ).r;



Salud!

edited____
late!

Last edited by txesmi; 08/24/17 17:17.
Re: Specular Shader with specular map [Re: txesmi] #467725
08/24/17 20:39
08/24/17 20:39
Joined: Apr 2002
Posts: 1,246
ny
jumpman Offline OP
Serious User
jumpman  Offline OP
Serious User

Joined: Apr 2002
Posts: 1,246
ny
Hey Txesmi

How would I go about adding a cubic environment mapping shader with this specular shader? There are a couple I have, one is a material within the main script, and the other is an FX file.

How would I go about adding this effec to the shader? I would also want the environment mapping to only go in certain places as well, not all over the model...

Re: Specular Shader with specular map [Re: jumpman] #467736
08/25/17 11:55
08/25/17 11:55
Joined: Jun 2007
Posts: 1,337
Hiporope and its pain
txesmi Offline
Serious User
txesmi  Offline
Serious User

Joined: Jun 2007
Posts: 1,337
Hiporope and its pain
Hi,
first of all I encourage you to take a look into directX documentation and HLSL tutorials before stain your hands with the task, pretty simple by the way.

In the list of functions I linked above, there are two resolutive functions: texCUBE and reflect.

texCUBE is a bmap sampler, cubemap specific, such skyboxes and enviroment reflections. Its first parameter is a sampler, cubemap specific too.
Code:
texture mtlSkin1; // or entSkin1<->4 or myGlobalBmap_bmap or whatever
samplerCUBE sEnvironment = sampler_state { Texture = <mtlSkin1>; MipFilter = Linear; };


And its second parameter is a three-dimensional vector that serves as texture coordinates. The transformation of the vector to the coordinates into a pixel of one of the faces of the cubemap is made by the sampler itself.

Think a bit in a skycube. It certainly is a texCUBE sampler and the coordinates vector is the direction of the rendered pixel from the view point. As simple as that. This direction vector is alredy computed in the vertex shader of the tutorial and passed to the pixel shader, but inversed.
Code:
// PS
OutViewDir = vecViewPos - mul(InPos, matWorld);
// VS
in float4 InViewDir: TEXCOORD2



Try it yourself. Create a cubemap in liteC.
Code:
BMAP *bmpEnvMap = bmap_create ( "myEnvMap+6.tga" );
bmap_to_cubemap ( bmpEnvMap );
myEntMtl.skin1 = bmpEnvMap;



Declare the sampler in the shader.
Code:
texture mtlSkin1;
samplerCUBE sEnv = sampler_state { Texture = <mtlSkin1>; MipFilter = Linear; };



Sample and return it in the pixel shader.
Code:
float4 envColor = texCUBE ( sEnv, -InVierDir ); // inversed!
return envColor;



You will see that the entity is texturized as a skybox.

Let's continue. reflect function is selfexplanatory. It returns the reflexion of a vector in reference to a surface normal and we have both passed from the pixel shader: view direction and surface normal.
Code:
float3 viewDirReflexion = reflect ( -InViewDir.xyz, InNormal ); // inversed!
float4 envSample = texCUBE ( sEnv, viewDirReflexion );



If you return this sample as texture color and set the same cubemap as skybox, you will see that the entity is texturized as a perfect skybox reflecting mirror.

At this point you only need to mix this last color sample with the color you have already computed. As you may imagine you can do with those values all you want. I would simply replace the specular reflection computations by the texCUBE sample multiplied by specular term you got already. Simple and effective.

Cubic real time reflections are managed same but with an unique difference: the cubemap is rendered each frame. That is an expensive task and it is not really advisable. Forget about using it into populated sceneries.

Salud!

Re: Specular Shader with specular map [Re: txesmi] #467739
08/25/17 18:28
08/25/17 18:28
Joined: Apr 2002
Posts: 1,246
ny
jumpman Offline OP
Serious User
jumpman  Offline OP
Serious User

Joined: Apr 2002
Posts: 1,246
ny
Txesmi.....thank you! I was able to get the cubic environment mapping, as well as get it only reflecting on certain pixels of the model, using the model's skin2!!

My next problem is trying to get the Envcube reflection to be more pronounced, with more of the cubemap color coming through, I think it has to do with the final color equation. Can you help me? Here is what I made so far:

//-This line uses entity skin 2, to determine how much relfection is visible
float enviness = 1.5 * tex2D(CubeMapSampler,InTex);


//this line is me playing around:
envSample*=(enviness*2)-(Diffuse*.8); //---cool
envSample*=ShadColor;


//Here is the final output
return (envSample + Ambient + Diffuse + Specular) * Color;

I can see the cubeMap reflection on where i put white in the skin2! However, the reflection itself is mainly white, and kind of loses strength when its normals are facing the sun.

How can I add this reflection cubemap on top of the texture, with more of the color of the reflection map coming through?

The sun is on the top left, shadow on the right. You can see the envmap on the shadow side. This is OK and kinda cool. This model also has a TGA/Transparency in the first skin. This double sided is important btw.


If you look at the cubemap, it is very blue/green. Here is where I rendered just the cubemap as reflection:


Re: Specular Shader with specular map [Re: jumpman] #467740
08/25/17 20:57
08/25/17 20:57
Joined: Jun 2007
Posts: 1,337
Hiporope and its pain
txesmi Offline
Serious User
txesmi  Offline
Serious User

Joined: Jun 2007
Posts: 1,337
Hiporope and its pain
glad of been helpful laugh

Originally Posted By: jumpman
My next problem is trying to get the Envcube reflection to be more pronounced, with more of the cubemap color coming through, I think it has to do with the final color equation.

Correct, the final color depends on the final color equation grin

I am not sure of what you are looking for so I can only show you the master function of color mixing: lerp.

I think I would do something like the following:
Code:
color *= ambient + diffuse + specular;
color = lerp ( color, envSample, envMask );



but maybe you like the specular term been persistent over reflections
Code:
color *= ambient + diffuse;
color = lerp ( color, envSample, envMask );
color *= 1.0f + specular; // or color += specular; in the case the specular term is a color vector instead of a color factor... Ancha es Castilla (Castilla is wide)



Salud!

Re: Specular Shader with specular map [Re: txesmi] #467742
08/25/17 21:25
08/25/17 21:25
Joined: Apr 2002
Posts: 1,246
ny
jumpman Offline OP
Serious User
jumpman  Offline OP
Serious User

Joined: Apr 2002
Posts: 1,246
ny
Im getting closer!!!!! What is envMask though, is that referencing the mask that determines how shiny the reflection is?

Page 1 of 3 1 2 3

Moderated by  Blink, Hummel, Superku 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1