Ambiera Forum

Discussions, Help and Support.

Ambiera Forum > CopperCube > Programming and Scripting
How send JS variable into HLSL fragmentShader part?

hadoken
Guest
Quote
2022-01-27 14:03:04

According to the docs it's somewhat done with:
myShaderCallBack = function()
{
var abc = 0.5;
ccbSetShaderConstant(2, abc', abc, abc, 0,abc);
}

How would I have to tell the fragmentShader part making use of my example variable abc for other params than float4, e.g for float alpha?
"float4 abc; \n" + 

e.g for float alpha?
"float alpha abc; \n" +



hadoken
Guest
Quote
2022-01-27 14:55:06

with "abc" as my sample variable from outside this throws me an "undeclared identifier abc" error:
var fragmentShader = 
"struct PS_OUTPUT \n" +
"{ \n" +
" float4 RGBColor : COLOR0; \n" +
"}; \n" +
" \n" +
"sampler2D tex0; \n" +
"sampler2D tex1; \n" +
" \n" +
"PS_OUTPUT main( float2 TexCoord : TEXCOORD0, \n" +
" float4 Position : POSITION, \n" +
" float4 Diffuse : COLOR0 ) \n" +
"{ \n" +
" PS_OUTPUT Output; \n" +
" float4 col1 = tex2D( tex0, TexCoord ); \n" +
" float4 col2 = tex2D( tex1, TexCoord ); \n" +
" float3 rgb = col2.rgb * col2.a + (1 - col2.a) * col1.a * col1.rgb; \n" +
" float alpha = abc; \n" +
" Output.RGBColor = float4(rgb,alpha); \n" +
" return Output; \n" +
"}";


myShaderCallBack = function()
{
var abc = 0.5;
ccbSetShaderConstant(2, 'abc', 0, 0, 0, abc);
}
Instead of something like float alpha = 0.5; I would like to make float alpha = abc; work. So, how would I have to tell the fragmentShader part to accept my variable "abc" from normal javascript part using the myShaderCallBack function in a correct way? Thanks for any professional help in advance ;-)


just_in_case
Moderator
Quote
2022-01-27 17:15:44

Just declare the
 float4 abc ;
below or above the "Sampler2D tex0" and then use float alpha = abc.w;

If you don't want to use float4 then in your shader callback, degine the value abc as the first parameter instead of 4th.
Then in your fragment shader you can define it as
float abc;
instead of float4 and then you don't have to use the subscript "abc.w" whenever you use this in your shader code, you can simply call it by "abc"

It seems a bit complicated but once you understand it, it will be an ease for you to do stuff that way.

You can watch my HLSL shader video on youtube to understand how shader works in CopperCube.


hadoken
Guest
Quote
2022-01-27 23:51:13

Thank you very much just_in_case!!!

Problem solved plus learned a lot about CC shader scripting from the official docs plus your examples today!!!

Feel like maybe posting soon something useful with this, too.




just_in_case
Moderator
Quote
2022-01-28 17:57:30

will be waiting for your shader, it seems you are going to release some sort of stickers or something similar shader, I can see you are using my overlay shader code in there in the example code you posted above. So my guess is you are going to create something that deals with overlays and alpha transparency.

Hope to see some nice results, Good Luck!


Create reply:


Posted by: (you are not logged in)


Enter the missing letter in: "Interna?ional" (you are not logged in)


Text:

 

  

Possible Codes


Feature Code
Link [url] www.example.com [/url]
Bold [b]bold text[/b]
Image [img]http://www.example.com/image.jpg[/img]
Quote [quote]quoted text[/quote]
Code [code]source code[/code]

Emoticons


   






Copyright© Ambiera e.U. all rights reserved.
Privacy Policy | Terms and Conditions | Imprint | Contact