Ambiera Forum

Discussions, Help and Support.

Ambiera Forum > CopperCube > Programming and Scripting
just_in_case shader wisdom please

Guest
Guest
Quote
2023-05-30 22:43:43

@JIC (or anyone so knowledgeable )

I'm on my journey learning to write shaders for CC. It's going pretty well. Got about 8-9 done. But now I have an issue with this one frag shader where the camera distance causes it scale smaller the closer the camera gets. I assume I am supposed to normalize something but I have no clue what and the interwebz isn't helping. Have you run across that issue before? Thanks.


Robbo
Guest
Quote
2023-05-31 02:40:19

Sound very possible, easy to just try and see what happens although shaders can be complex and work differently depending on what your trying to achieve.

I've been trying to work out the CC source code and add new shaders in and editing existing ones....it a lot harder than using an external Action shader and just running that like just_in_cases recent shader. Having to understand and manipulate C++ code I haven't found very nice to work with..


Guest
Guest
Quote
2023-05-31 03:08:25

It's probably because I am not using the texture coordinates because it's following the camera's target. See the center of the swirl?

🔎︎



Guest
Guest
Quote
2023-05-31 03:28:05

Can't show the other pic or I am spamming the forum apparently. Anyway since VP had that issue where he couldn't turn off ReShade in CC after injecting it, I decided to finally learn this mess. Help the community and myself by being able to write shaders and not have to use 3rd party stuff and hacks. I don't mind C but man it can be tedious writing types to everything. Oh well it's part of the adventure.


just_in_case
Moderator
Quote
2023-05-31 04:36:49

First of all, it's hard to say what's wrong without looking at the code itself, and without knowing what you actually want to achieve.
Do you want the camera to scale the swirl bigger when you move closer to the object or do you want the swirl to be of constant size no matter where the camera is.

In most of the cases you don't have to pass the view vector if you are not dealing with it. So ifin your shader you want the effect to be constant regardless of camera position, you can simply omit out the code that deal with the Camera position.

Or if you want to scale the effect large when you are moving close to the object and small when you move away, then simply invert it, by addin "1-" in your calculation.

Also yeah, it can be related to TEXCOORDS itself, but without looking at the code, it is not possible to say anything why this is happening.

Also I can only guide you with HLSL shaders, as of now I am only good with HLSL only, GLSL is not that hard but as they deal differently with textures and all other stuff, I don't prefer to learn GLSL at the moment , but I do have knowledge on how it works in GLSL as well.


VP
Guest
Quote
2023-05-31 07:49:53

I know nothing about coding but I think I can see what's visually 'wrong' with the spiral. Spirals are very unusual geometry.

Your spiral is actually correct, probably just not the spiral you wanted. I can explain yours physically as:
"a pen moving from the centre to the edge of a piece of paper and the paper is rotating about it's centre with a constant rotational velocity"....

"The spiral you probably want to draw would be described as: a pen moving from the centre to the edge of a piece of paper and the paper is rotating about it's centre with a varying rotational velocity which is faster when the pen is near the centre and slows down as the pen reaches the edge."


Looking at your spiral, I think you've probably used a constant - instead of a hyperbolic - easier to imagine as concentric circles, rather than a spiral; the inner ones are smaller than the outer ones, so you need to factor pi to a varying radius, to create a parabola which appears to expand evenly (but it's actually getting bigger and bigger the further from the centre), it creates the illusion of each spiral arm staying equidistant from the last.

I hope, I've explained it well? I can't comprehend the maths any more but there are a few articles about "helical spirals", "hyperbolic curves" and "parabolas" which may explain it well for you and you'd probably find it a easier than me to understand it.


VP
Guest
Quote
2023-05-31 08:02:19

In fact, forget all that I wrote previously, it's not relevant in this case.

It looks like you've created 3 separate spirals on top of each other (red green, blue?), instead of a single spiral arm (probably to add different colours and add/merge their colours as they cross each other's paths? If that's the case, you've used the same calculation for each spiral and just changed their start rotation.

If that's the case, effectively, they're overlapping each other. So, to fix it, you'd just need to change the scale of each spiral (so each one is slightly larger than the last), then they will nest neatly together. Leave the calculation the same, the spiral is correct, just change the "scale" of each arm.


VP
Guest
Quote
2023-05-31 08:06:06

...or did you mean, the spiral is perfect until you move the camera closer - then the spiral goes wrong?


Guest
Guest
Quote
2023-05-31 19:06:53

https://files.catbox.moe/d6b4ff....

Here's the rainbow swirl shader in a ccb with code. I didn't post it yesterday because I have a hacky mess going on in my main file. It's GLSL for the moment but I will translate it to HLSL once I get some better understanding of certain parts. I have done so already with another one but that was with the help of a tutorial. I'm having a hard time finding decent sources to learn from with regards to both languages. I'd like to learn that both if I can.

@JIC
I'll look into the things you mentioned today. I'd like the shader to not react to the camera but I suspect it's because I am using the example vertex shader from the documentation with frag coordinates in fragment shader. Other shaders I've done have not had this problem because I used texture coordinates apparently. Any insights you can give will be appreciated even though the shader is not in HLSL.

@VP
The rainbow spiral seems to be okay but it is affected by the camera so the center of the spiral is the camera's target, meaning it moves with the camera becoming larger or smaller depending on the camera distance. No clue why at this point. My second day on the job.


Guest
Guest
Quote
2023-06-01 02:34:32

Yeah I was using frag coords as input when I should have been using tex coords. It's fixed. Ugly rainbow swirl is cubed.

🔎︎



just_in_case
Moderator
Quote
2023-06-01 14:40:23

Glad that you figured it out, yeah, syntax and nametags might be confusing in different shader programs.


Create reply:


Posted by: (you are not logged in)


Enter the missing letter in: "Internation?l" (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