2 registered members (AndrewAMD, juanex),
1,247
guests, and 6
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
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
Serious User
|
Serious User
Joined: Jun 2007
Posts: 1,337
Hiporope and its pain
|
Im assuming here is the correct line to add the multiplication?:
float Specular = pow(saturate(dot(R, normalize(InViewDir))), SpecularPower) * SpecularIntensity * shininess;
correct 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). 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:
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: jumpman]
#467736
08/25/17 11:55
08/25/17 11:55
|
Joined: Jun 2007
Posts: 1,337 Hiporope and its pain
txesmi
Serious User
|
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.
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.
// PS
OutViewDir = vecViewPos - mul(InPos, matWorld);
// VS
in float4 InViewDir: TEXCOORD2
Try it yourself. Create a cubemap in liteC.
BMAP *bmpEnvMap = bmap_create ( "myEnvMap+6.tga" );
bmap_to_cubemap ( bmpEnvMap );
myEntMtl.skin1 = bmpEnvMap;
Declare the sampler in the shader.
texture mtlSkin1;
samplerCUBE sEnv = sampler_state { Texture = <mtlSkin1>; MipFilter = Linear; };
Sample and return it in the pixel shader.
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.
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
OP
Serious User
|
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
Serious User
|
Serious User
Joined: Jun 2007
Posts: 1,337
Hiporope and its pain
|
glad of been helpful 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 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:
color *= ambient + diffuse + specular;
color = lerp ( color, envSample, envMask );
but maybe you like the specular term been persistent over reflections
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!
|
|
|
|