Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

Newbie question - having difficulty applying shader to an image
Started by element_skate Oct 14 2016 05:44 AM

2 replies to this topic
shader problem corona api custom shaders issue help

Best Answer StarCrunch , 14 October 2016 - 09:31 AM

Hi.

 

I suspect you just need to supply the CoronaVertexUserData fields. See here for info on that. Right now those will just be getting some default (or garbage, possibly), so you'll wind up with something like 0 / 0 for the invAr and uv fields (maybe not even that, depending on the graphics driver).

 

In the shader playground, you can see up top where these are set. Just use those values (1 and 1) as your defaults. You don't even need to change them from the calling code if you like the results.

[TOPIC CONTROLS]
This topic has been archived. This means that you cannot reply to this topic.
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#1

element_skate

[GLOBAL: userInfoPane.html]
element_skate
  • Enthusiast

  • 36 posts
  • Corona SDK

Hi guys,

 

I am totally new to shaders and have been banging my head for several hours now. I followed the documentation from Corona, found some examples and even managed to create a simple image with shader.

 

My nightmare, however, started when I decided to use this specific shader ( which I found in another topic ) : https://goo.gl/kpaqiK

 

When I follow the tutorials from Corona to implement this shader I get a black rectangle and nothing happens in the simulator.

 

Here is my code so far:

-- generator.custom.portal

local kernel = {}

kernel.category = "generator"
kernel.isTimeDependent = true

kernel.name = "portal"

kernel.fragment =
[[
P_COLOR vec4 FragmentKernel( P_UV vec2 texCoord )
{
    P_UV vec2 center = vec2(0.5,0.5);
    P_UV float speed = 0.035;
    P_UV float invAr = CoronaVertexUserData.y / CoronaVertexUserData.x;
    P_UV vec2 uv = texCoord.xy / CoronaVertexUserData.xy;
    P_COLOR vec3 col = vec4(uv,0.5+0.5*sin(CoronaTotalTime),1.0).xyz;
    P_COLOR vec3 texcol;
    P_UV float x = (center.x-uv.x);
    P_UV float y = (center.y-uv.y) *invAr;
    P_UV float r = -(x*x + y*y);
    P_UV float z = 1.0 + 0.5*sin((r+CoronaTotalTime*speed)/0.013);
    texcol.x = z;
    texcol.y = z;
    texcol.z = z;
    return CoronaColorScale(vec4(texture2D(CoronaSampler0, texCoord).rgb * col*texcol,1.0));
}
]]

return kernel

And then in another place:

local k1 = require("generator_portal")
graphics.defineEffect( k1 )
		
local object =  display.newImageRect("images/rainbow.png",160, 160)
object.x = _W/2
object.y = _H/2	
object.fill.effect = "generator.custom.portal"

What I get in the simulator is just a black rectangle. Am I doing something wrong? Any help will be greatly appreciated.



[TOPIC: post.html]
#2

StarCrunch

[GLOBAL: userInfoPane.html]
StarCrunch
  • Contributor

  • 846 posts
  • Corona SDK

  Best Answer

Hi.

 

I suspect you just need to supply the CoronaVertexUserData fields. See here for info on that. Right now those will just be getting some default (or garbage, possibly), so you'll wind up with something like 0 / 0 for the invAr and uv fields (maybe not even that, depending on the graphics driver).

 

In the shader playground, you can see up top where these are set. Just use those values (1 and 1) as your defaults. You don't even need to change them from the calling code if you like the results.



[TOPIC: post.html]
#3

element_skate

[GLOBAL: userInfoPane.html]
element_skate
  • Enthusiast

  • 36 posts
  • Corona SDK

Hi.

 

I suspect you just need to supply the CoronaVertexUserData fields. See here for info on that. Right now those will just be getting some default (or garbage, possibly), so you'll wind up with something like 0 / 0 for the invAr and uv fields (maybe not even that, depending on the graphics driver).

 

In the shader playground, you can see up top where these are set. Just use those values (1 and 1) as your defaults. You don't even need to change them from the calling code if you like the results.

 

Hi, StarCrunch.

 

Thank you for the answer, it really worked! I had problems with other shaders from the forum, as well, but most probably the issue was the same - I was missing the CoronaVertexUserData fields. I hope I'll get better with these and be able to contribute with my own custom shaders soon. :)




[topic_controls]
[/topic_controls]